• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/renderer/IndexRangeCache.h"
15 
16 namespace rx
17 {
18 class Renderer;
19 
20 class IndexBuffer
21 {
22   public:
23     IndexBuffer();
24     virtual ~IndexBuffer();
25 
26     virtual bool initialize(unsigned int bufferSize, GLenum indexType, bool dynamic) = 0;
27 
28     virtual bool mapBuffer(unsigned int offset, unsigned int size, void** outMappedMemory) = 0;
29     virtual bool unmapBuffer() = 0;
30 
31     virtual bool discard() = 0;
32 
33     virtual GLenum getIndexType() const = 0;
34     virtual unsigned int getBufferSize() const = 0;
35     virtual bool setSize(unsigned int bufferSize, GLenum indexType) = 0;
36 
37     unsigned int getSerial() const;
38 
39   protected:
40     void updateSerial();
41 
42   private:
43     DISALLOW_COPY_AND_ASSIGN(IndexBuffer);
44 
45     unsigned int mSerial;
46     static unsigned int mNextSerial;
47 };
48 
49 class IndexBufferInterface
50 {
51   public:
52     IndexBufferInterface(Renderer *renderer, bool dynamic);
53     virtual ~IndexBufferInterface();
54 
55     virtual bool reserveBufferSpace(unsigned int size, GLenum indexType) = 0;
56 
57     GLenum getIndexType() const;
58     unsigned int getBufferSize() const;
59 
60     unsigned int getSerial() const;
61 
62     bool mapBuffer(unsigned int size, void** outMappedMemory, unsigned int *streamOffset);
63     bool unmapBuffer();
64 
65     IndexBuffer *getIndexBuffer() const;
66 
67   protected:
68     unsigned int getWritePosition() const;
69     void setWritePosition(unsigned int writePosition);
70 
71     bool discard();
72 
73     bool setBufferSize(unsigned int bufferSize, GLenum indexType);
74 
75   private:
76     DISALLOW_COPY_AND_ASSIGN(IndexBufferInterface);
77 
78     rx::Renderer *const mRenderer;
79 
80     IndexBuffer* mIndexBuffer;
81 
82     unsigned int mWritePosition;
83     bool mDynamic;
84 };
85 
86 class StreamingIndexBufferInterface : public IndexBufferInterface
87 {
88   public:
89     StreamingIndexBufferInterface(Renderer *renderer);
90     ~StreamingIndexBufferInterface();
91 
92     virtual bool reserveBufferSpace(unsigned int size, GLenum indexType);
93 };
94 
95 class StaticIndexBufferInterface : public IndexBufferInterface
96 {
97   public:
98     explicit StaticIndexBufferInterface(Renderer *renderer);
99     ~StaticIndexBufferInterface();
100 
101     virtual bool reserveBufferSpace(unsigned int size, GLenum indexType);
102 
103     IndexRangeCache *getIndexRangeCache();
104 
105   private:
106     IndexRangeCache mIndexRangeCache;
107 };
108 
109 }
110 
111 #endif // LIBGLESV2_RENDERER_INDEXBUFFER_H_