1 // 2 // Copyright 2002 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 LIBANGLE_RENDERER_D3D_INDEXBUFFER_H_ 11 #define LIBANGLE_RENDERER_D3D_INDEXBUFFER_H_ 12 13 #include "common/PackedEnums.h" 14 #include "common/angleutils.h" 15 #include "libANGLE/Error.h" 16 17 namespace gl 18 { 19 class Context; 20 } // namespace gl 21 22 namespace rx 23 { 24 class BufferFactoryD3D; 25 26 class IndexBuffer : angle::NonCopyable 27 { 28 public: 29 IndexBuffer(); 30 virtual ~IndexBuffer(); 31 32 virtual angle::Result initialize(const gl::Context *context, 33 unsigned int bufferSize, 34 gl::DrawElementsType indexType, 35 bool dynamic) = 0; 36 37 virtual angle::Result mapBuffer(const gl::Context *context, 38 unsigned int offset, 39 unsigned int size, 40 void **outMappedMemory) = 0; 41 virtual angle::Result unmapBuffer(const gl::Context *context) = 0; 42 43 virtual angle::Result discard(const gl::Context *context) = 0; 44 45 virtual gl::DrawElementsType getIndexType() const = 0; 46 virtual unsigned int getBufferSize() const = 0; 47 virtual angle::Result setSize(const gl::Context *context, 48 unsigned int bufferSize, 49 gl::DrawElementsType indexType) = 0; 50 51 unsigned int getSerial() const; 52 53 protected: 54 void updateSerial(); 55 56 private: 57 unsigned int mSerial; 58 static unsigned int mNextSerial; 59 }; 60 61 class IndexBufferInterface : angle::NonCopyable 62 { 63 public: 64 IndexBufferInterface(BufferFactoryD3D *factory, bool dynamic); 65 virtual ~IndexBufferInterface(); 66 67 virtual angle::Result reserveBufferSpace(const gl::Context *context, 68 unsigned int size, 69 gl::DrawElementsType indexType) = 0; 70 71 gl::DrawElementsType getIndexType() const; 72 unsigned int getBufferSize() const; 73 74 unsigned int getSerial() const; 75 76 angle::Result mapBuffer(const gl::Context *context, 77 unsigned int size, 78 void **outMappedMemory, 79 unsigned int *streamOffset); 80 angle::Result unmapBuffer(const gl::Context *context); 81 82 IndexBuffer *getIndexBuffer() const; 83 84 protected: 85 unsigned int getWritePosition() const; 86 void setWritePosition(unsigned int writePosition); 87 88 angle::Result discard(const gl::Context *context); 89 90 angle::Result setBufferSize(const gl::Context *context, 91 unsigned int bufferSize, 92 gl::DrawElementsType indexType); 93 94 private: 95 IndexBuffer *mIndexBuffer; 96 97 unsigned int mWritePosition; 98 bool mDynamic; 99 }; 100 101 class StreamingIndexBufferInterface : public IndexBufferInterface 102 { 103 public: 104 explicit StreamingIndexBufferInterface(BufferFactoryD3D *factory); 105 ~StreamingIndexBufferInterface() override; 106 107 angle::Result reserveBufferSpace(const gl::Context *context, 108 unsigned int size, 109 gl::DrawElementsType indexType) override; 110 }; 111 112 class StaticIndexBufferInterface : public IndexBufferInterface 113 { 114 public: 115 explicit StaticIndexBufferInterface(BufferFactoryD3D *factory); 116 ~StaticIndexBufferInterface() override; 117 118 angle::Result reserveBufferSpace(const gl::Context *context, 119 unsigned int size, 120 gl::DrawElementsType indexType) override; 121 }; 122 123 } // namespace rx 124 125 #endif // LIBANGLE_RENDERER_D3D_INDEXBUFFER_H_ 126