OSDN Git Service

Implement a Radiance prototype.
[android-x86/external-swiftshader.git] / src / Radiance / libRAD / VertexDataManager.h
1 // SwiftShader Software Renderer\r
2 //\r
3 // Copyright(c) 2005-2012 TransGaming Inc.\r
4 //\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,\r
6 // transcribed, stored in a retrieval system, translated into any human or computer\r
7 // language by any means, or disclosed to third parties without the explicit written\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express\r
9 // or implied, including but not limited to any patent rights, are granted to you.\r
10 //\r
11 \r
12 // VertexDataManager.h: Defines the VertexDataManager, a class that\r
13 // runs the Buffer translation process.\r
14 \r
15 #ifndef LIBGLESV2_VERTEXDATAMANAGER_H_\r
16 #define LIBGLESV2_VERTEXDATAMANAGER_H_\r
17 \r
18 #include "Context.h"\r
19 #include "Device.hpp"\r
20 \r
21 #define GL_APICALL\r
22 #include <GLES2/gl2.h>\r
23 \r
24 namespace es2\r
25 {\r
26 \r
27 struct TranslatedAttribute\r
28 {\r
29     sw::StreamType type;\r
30         int count;\r
31         bool normalized;\r
32 \r
33     unsigned int offset;\r
34     unsigned int stride;   // 0 means not to advance the read pointer at all\r
35 \r
36     sw::Resource *vertexBuffer;\r
37 };\r
38 \r
39 class VertexBuffer\r
40 {\r
41   public:\r
42     VertexBuffer(unsigned int size);\r
43     virtual ~VertexBuffer();\r
44 \r
45     void unmap();\r
46 \r
47     sw::Resource *getResource() const;\r
48 \r
49   protected:\r
50     sw::Resource *mVertexBuffer;\r
51 };\r
52 \r
53 class ConstantVertexBuffer : public VertexBuffer\r
54 {\r
55   public:\r
56     ConstantVertexBuffer(float x, float y, float z, float w);\r
57     ~ConstantVertexBuffer();\r
58 };\r
59 \r
60 class StreamingVertexBuffer : public VertexBuffer\r
61 {\r
62   public:\r
63     StreamingVertexBuffer(unsigned int size);\r
64     ~StreamingVertexBuffer();\r
65 \r
66     void *map(const VertexAttribute &attribute, unsigned int requiredSpace, unsigned int *streamOffset);\r
67     void reserveRequiredSpace();\r
68     void addRequiredSpace(unsigned int requiredSpace);\r
69 \r
70   protected:\r
71     unsigned int mBufferSize;\r
72     unsigned int mWritePosition;\r
73     unsigned int mRequiredSpace;\r
74 };\r
75 \r
76 class VertexDataManager\r
77 {\r
78   public:\r
79     VertexDataManager(Context *context);\r
80     virtual ~VertexDataManager();\r
81 \r
82     void dirtyCurrentValue(int index) { mDirtyCurrentValue[index] = true; }\r
83 \r
84     GLenum prepareVertexData(GLint start, GLsizei count, TranslatedAttribute *outAttribs);\r
85 \r
86   private:\r
87     unsigned int writeAttributeData(StreamingVertexBuffer *vertexBuffer, GLint start, GLsizei count, const VertexAttribute &attribute);\r
88 \r
89     Context *const mContext;\r
90 \r
91     StreamingVertexBuffer *mStreamingBuffer;\r
92 \r
93     bool mDirtyCurrentValue[MAX_VERTEX_ATTRIBS];\r
94     ConstantVertexBuffer *mCurrentValueBuffer[MAX_VERTEX_ATTRIBS];\r
95 };\r
96 \r
97 }\r
98 \r
99 #endif   // LIBGLESV2_VERTEXDATAMANAGER_H_\r