Home | History | Annotate | Download | only in canvas
      1 /*
      2  * Copyright (C) 2011 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef WebGLVertexArrayObjectOES_h
     27 #define WebGLVertexArrayObjectOES_h
     28 
     29 #include "bindings/core/v8/ScriptWrappable.h"
     30 #include "core/html/canvas/WebGLBuffer.h"
     31 #include "core/html/canvas/WebGLContextObject.h"
     32 #include "platform/heap/Handle.h"
     33 #include "wtf/PassRefPtr.h"
     34 
     35 namespace blink {
     36 
     37 class WebGLVertexArrayObjectOES FINAL : public WebGLContextObject, public ScriptWrappable {
     38     DEFINE_WRAPPERTYPEINFO();
     39 public:
     40     enum VaoType {
     41         VaoTypeDefault,
     42         VaoTypeUser,
     43     };
     44 
     45     virtual ~WebGLVertexArrayObjectOES();
     46 
     47     static PassRefPtrWillBeRawPtr<WebGLVertexArrayObjectOES> create(WebGLRenderingContextBase*, VaoType);
     48 
     49     // Cached values for vertex attrib range checks
     50     class VertexAttribState FINAL {
     51         ALLOW_ONLY_INLINE_ALLOCATION();
     52     public:
     53         VertexAttribState()
     54             : enabled(false)
     55             , bytesPerElement(0)
     56             , size(4)
     57             , type(GL_FLOAT)
     58             , normalized(false)
     59             , stride(16)
     60             , originalStride(0)
     61             , offset(0)
     62             , divisor(0)
     63         {
     64         }
     65 
     66         void trace(Visitor*);
     67 
     68         bool enabled;
     69         RefPtrWillBeMember<WebGLBuffer> bufferBinding;
     70         GLsizei bytesPerElement;
     71         GLint size;
     72         GLenum type;
     73         bool normalized;
     74         GLsizei stride;
     75         GLsizei originalStride;
     76         GLintptr offset;
     77         GLuint divisor;
     78     };
     79 
     80     bool isDefaultObject() const { return m_type == VaoTypeDefault; }
     81 
     82     bool hasEverBeenBound() const { return object() && m_hasEverBeenBound; }
     83     void setHasEverBeenBound() { m_hasEverBeenBound = true; }
     84 
     85     PassRefPtrWillBeRawPtr<WebGLBuffer> boundElementArrayBuffer() const { return m_boundElementArrayBuffer; }
     86     void setElementArrayBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer>);
     87 
     88     VertexAttribState& getVertexAttribState(int index) { return m_vertexAttribState[index]; }
     89     void setVertexAttribState(GLuint, GLsizei, GLint, GLenum, GLboolean, GLsizei, GLintptr, PassRefPtrWillBeRawPtr<WebGLBuffer>);
     90     void unbindBuffer(PassRefPtrWillBeRawPtr<WebGLBuffer>);
     91     void setVertexAttribDivisor(GLuint index, GLuint divisor);
     92 
     93     virtual void trace(Visitor*) OVERRIDE;
     94 
     95 private:
     96     WebGLVertexArrayObjectOES(WebGLRenderingContextBase*, VaoType);
     97 
     98     void dispatchDetached(blink::WebGraphicsContext3D*);
     99     virtual void deleteObjectImpl(blink::WebGraphicsContext3D*, Platform3DObject) OVERRIDE;
    100 
    101     VaoType m_type;
    102     bool m_hasEverBeenBound;
    103 #if ENABLE(OILPAN)
    104     bool m_destructionInProgress;
    105 #endif
    106     RefPtrWillBeMember<WebGLBuffer> m_boundElementArrayBuffer;
    107     WillBeHeapVector<VertexAttribState> m_vertexAttribState;
    108 };
    109 
    110 } // namespace blink
    111 
    112 namespace WTF {
    113 
    114 template<>
    115 struct VectorTraits<blink::WebGLVertexArrayObjectOES::VertexAttribState> : SimpleClassVectorTraits<blink::WebGLVertexArrayObjectOES::VertexAttribState> {
    116     // Specialization needed as the VertexAttribState's struct fields
    117     // aren't handled as desired by the IsPod() trait.
    118 #if ENABLE(OILPAN)
    119     static const bool needsDestruction = false;
    120 #endif
    121     // Must use the constructor.
    122     static const bool canInitializeWithMemset = false;
    123     static const bool canCopyWithMemcpy = true;
    124 };
    125 
    126 } // namespace WTF
    127 
    128 #endif // WebGLVertexArrayObjectOES_h
    129