1 // 2 // Copyright (c) 2002-2012 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 // IndexBuffer.h: Defines the abstract IndexBuffer class and IndexBufferInterface 8 // class with derivations, classes that perform graphics API agnostic index buffer operations. 9 10 #ifndef LIBGLESV2_RENDERER_INDEXBUFFER_H_ 11 #define LIBGLESV2_RENDERER_INDEXBUFFER_H_ 12 13 #include "common/angleutils.h" 14 #include "libGLESv2/Error.h" 15 #include "libGLESv2/renderer/IndexRangeCache.h" 16 17 namespace rx 18 { 19 class Renderer; 20 21 class IndexBuffer 22 { 23 public: 24 IndexBuffer(); 25 virtual ~IndexBuffer(); 26 27 virtual gl::Error initialize(unsigned int bufferSize, GLenum indexType, bool dynamic) = 0; 28 29 virtual gl::Error mapBuffer(unsigned int offset, unsigned int size, void** outMappedMemory) = 0; 30 virtual gl::Error unmapBuffer() = 0; 31 32 virtual gl::Error discard() = 0; 33 34 virtual GLenum getIndexType() const = 0; 35 virtual unsigned int getBufferSize() const = 0; 36 virtual gl::Error setSize(unsigned int bufferSize, GLenum indexType) = 0; 37 38 unsigned int getSerial() const; 39 40 protected: 41 void updateSerial(); 42 43 private: 44 DISALLOW_COPY_AND_ASSIGN(IndexBuffer); 45 46 unsigned int mSerial; 47 static unsigned int mNextSerial; 48 }; 49 50 class IndexBufferInterface 51 { 52 public: 53 IndexBufferInterface(Renderer *renderer, bool dynamic); 54 virtual ~IndexBufferInterface(); 55 56 virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType) = 0; 57 58 GLenum getIndexType() const; 59 unsigned int getBufferSize() const; 60 61 unsigned int getSerial() const; 62 63 gl::Error mapBuffer(unsigned int size, void** outMappedMemory, unsigned int *streamOffset); 64 gl::Error unmapBuffer(); 65 66 IndexBuffer *getIndexBuffer() const; 67 68 protected: 69 unsigned int getWritePosition() const; 70 void setWritePosition(unsigned int writePosition); 71 72 gl::Error discard(); 73 74 gl::Error setBufferSize(unsigned int bufferSize, GLenum indexType); 75 76 private: 77 DISALLOW_COPY_AND_ASSIGN(IndexBufferInterface); 78 79 rx::Renderer *const mRenderer; 80 81 IndexBuffer* mIndexBuffer; 82 83 unsigned int mWritePosition; 84 bool mDynamic; 85 }; 86 87 class StreamingIndexBufferInterface : public IndexBufferInterface 88 { 89 public: 90 StreamingIndexBufferInterface(Renderer *renderer); 91 ~StreamingIndexBufferInterface(); 92 93 virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType); 94 }; 95 96 class StaticIndexBufferInterface : public IndexBufferInterface 97 { 98 public: 99 explicit StaticIndexBufferInterface(Renderer *renderer); 100 ~StaticIndexBufferInterface(); 101 102 virtual gl::Error reserveBufferSpace(unsigned int size, GLenum indexType); 103 104 IndexRangeCache *getIndexRangeCache(); 105 106 private: 107 IndexRangeCache mIndexRangeCache; 108 }; 109 110 } 111 112 #endif // LIBGLESV2_RENDERER_INDEXBUFFER_H_ 113