1 // 2 // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // Buffer.h: Defines the gl::Buffer class, representing storage of vertex and/or 8 // index data. Implements GL buffer objects and related functionality. 9 // [OpenGL ES 2.0.24] section 2.9 page 21. 10 11 #ifndef LIBANGLE_BUFFER_H_ 12 #define LIBANGLE_BUFFER_H_ 13 14 #include "common/angleutils.h" 15 #include "libANGLE/Debug.h" 16 #include "libANGLE/Error.h" 17 #include "libANGLE/IndexRangeCache.h" 18 #include "libANGLE/PackedGLEnums.h" 19 #include "libANGLE/RefCountObject.h" 20 21 namespace rx 22 { 23 class BufferImpl; 24 class GLImplFactory; 25 }; 26 27 namespace gl 28 { 29 class Buffer; 30 class Context; 31 32 class BufferState final : angle::NonCopyable 33 { 34 public: 35 BufferState(); 36 ~BufferState(); 37 38 const std::string &getLabel(); 39 getUsage()40 BufferUsage getUsage() const { return mUsage; } getAccessFlags()41 GLbitfield getAccessFlags() const { return mAccessFlags; } getAccess()42 GLenum getAccess() const { return mAccess; } isMapped()43 GLboolean isMapped() const { return mMapped; } getMapPointer()44 void *getMapPointer() const { return mMapPointer; } getMapOffset()45 GLint64 getMapOffset() const { return mMapOffset; } getMapLength()46 GLint64 getMapLength() const { return mMapLength; } getSize()47 GLint64 getSize() const { return mSize; } 48 49 private: 50 friend class Buffer; 51 52 std::string mLabel; 53 54 BufferUsage mUsage; 55 GLint64 mSize; 56 GLbitfield mAccessFlags; 57 GLenum mAccess; 58 GLboolean mMapped; 59 void *mMapPointer; 60 GLint64 mMapOffset; 61 GLint64 mMapLength; 62 }; 63 64 class Buffer final : public RefCountObject, public LabeledObject 65 { 66 public: 67 Buffer(rx::GLImplFactory *factory, GLuint id); 68 ~Buffer() override; 69 Error onDestroy(const Context *context) override; 70 71 void setLabel(const std::string &label) override; 72 const std::string &getLabel() const override; 73 74 Error bufferData(const Context *context, 75 BufferBinding target, 76 const void *data, 77 GLsizeiptr size, 78 BufferUsage usage); 79 Error bufferSubData(const Context *context, 80 BufferBinding target, 81 const void *data, 82 GLsizeiptr size, 83 GLintptr offset); 84 Error copyBufferSubData(const Context *context, 85 Buffer *source, 86 GLintptr sourceOffset, 87 GLintptr destOffset, 88 GLsizeiptr size); 89 Error map(const Context *context, GLenum access); 90 Error mapRange(const Context *context, GLintptr offset, GLsizeiptr length, GLbitfield access); 91 Error unmap(const Context *context, GLboolean *result); 92 93 void onTransformFeedback(); 94 void onPixelUnpack(); 95 96 Error getIndexRange(const gl::Context *context, 97 GLenum type, 98 size_t offset, 99 size_t count, 100 bool primitiveRestartEnabled, 101 IndexRange *outRange) const; 102 getUsage()103 BufferUsage getUsage() const { return mState.mUsage; } getAccessFlags()104 GLbitfield getAccessFlags() const { return mState.mAccessFlags; } getAccess()105 GLenum getAccess() const { return mState.mAccess; } isMapped()106 GLboolean isMapped() const { return mState.mMapped; } getMapPointer()107 void *getMapPointer() const { return mState.mMapPointer; } getMapOffset()108 GLint64 getMapOffset() const { return mState.mMapOffset; } getMapLength()109 GLint64 getMapLength() const { return mState.mMapLength; } getSize()110 GLint64 getSize() const { return mState.mSize; } 111 getImplementation()112 rx::BufferImpl *getImplementation() const { return mImpl; } 113 114 private: 115 BufferState mState; 116 rx::BufferImpl *mImpl; 117 118 mutable IndexRangeCache mIndexRangeCache; 119 }; 120 121 } // namespace gl 122 123 #endif // LIBANGLE_BUFFER_H_ 124