OSDN Git Service

409cbd7cdd2eb0ff2abef76fa5474b5e32eae3e6
[android-x86/external-swiftshader.git] / src / Radiance / libRAD / Shader.h
1 // SwiftShader Software Renderer\r
2 //\r
3 // Copyright(c) 2005-2013 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 // Shader.h: Defines the abstract Shader class and its concrete derived\r
13 // classes VertexShader and FragmentShader. Implements GL shader objects and\r
14 // related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section\r
15 // 3.8 page 84.\r
16 \r
17 #ifndef LIBGLESV2_SHADER_H_\r
18 #define LIBGLESV2_SHADER_H_\r
19 \r
20 #include "ResourceManager.h"\r
21 \r
22 #include "compiler/TranslatorASM.h"\r
23 \r
24 #define GL_APICALL\r
25 #include <GLES2/gl2.h>\r
26 \r
27 #include <list>\r
28 #include <vector>\r
29 \r
30 namespace sh\r
31 {\r
32         class OutputASM;\r
33 }\r
34 \r
35 namespace rad\r
36 {\r
37 struct Varying\r
38 {\r
39     Varying(GLenum type, const std::string &name, int arraySize, int reg = -1, int col = -1)\r
40         : type(type), name(name), arraySize(arraySize), reg(reg), col(col)\r
41     {\r
42     }\r
43 \r
44         bool isArray() const\r
45         {\r
46                 return arraySize >= 1;\r
47         }\r
48 \r
49         int size() const   // Unify with rad::Uniform?\r
50         {\r
51                 return arraySize > 0 ? arraySize : 1;\r
52         }\r
53 \r
54     GLenum type;\r
55     std::string name;\r
56     int arraySize;\r
57 \r
58     int reg;    // First varying register, assigned during link\r
59     int col;    // First register element, assigned during link\r
60 };\r
61 \r
62 typedef std::list<Varying> VaryingList;\r
63 \r
64 class Shader\r
65 {\r
66     friend class Program;\r
67         friend class sh::OutputASM;\r
68 \r
69 public:\r
70     Shader(ResourceManager *manager, GLuint handle);\r
71 \r
72     virtual ~Shader();\r
73 \r
74     virtual GLenum getType() = 0;\r
75     GLuint getHandle() const;\r
76 \r
77     void deleteSource();\r
78     void setSource(GLsizei count, const char *const *string, const GLint *length);\r
79     int getInfoLogLength() const;\r
80     void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);\r
81     int getSourceLength() const;\r
82     void getSource(GLsizei bufSize, GLsizei *length, char *source);\r
83 \r
84     virtual void compile() = 0;\r
85     bool isCompiled();\r
86     \r
87         virtual sw::Shader *getShader() const = 0;\r
88         virtual sw::PixelShader *getPixelShader() const;\r
89         virtual sw::VertexShader *getVertexShader() const;\r
90 \r
91     void addRef();\r
92     void release();\r
93     unsigned int getRefCount() const;\r
94     bool isFlaggedForDeletion() const;\r
95     void flagForDeletion();\r
96 \r
97     static void releaseCompiler();\r
98 \r
99 protected:\r
100         static bool compilerInitialized;\r
101         TranslatorASM *createCompiler(ShShaderType type);\r
102         void clear();\r
103 \r
104     static GLenum parseType(const std::string &type);\r
105     static bool compareVarying(const Varying &x, const Varying &y);\r
106 \r
107         char *mSource;\r
108         char *mInfoLog;\r
109 \r
110     VaryingList varyings;\r
111         sh::ActiveUniforms activeUniforms;\r
112         sh::ActiveAttributes activeAttributes;\r
113 \r
114 private:\r
115         const GLuint mHandle;\r
116     unsigned int mRefCount;     // Number of program objects this shader is attached to\r
117     bool mDeleteStatus;         // Flag to indicate that the shader can be deleted when no longer in use\r
118 \r
119         ResourceManager *mResourceManager;\r
120 };\r
121 \r
122 class VertexShader : public Shader\r
123 {\r
124     friend class Program;\r
125 \r
126 public:\r
127     VertexShader(ResourceManager *manager, GLuint handle);\r
128 \r
129     ~VertexShader();\r
130 \r
131     virtual GLenum getType();\r
132     virtual void compile();\r
133     int getSemanticIndex(const std::string &attributeName);\r
134 \r
135         virtual sw::Shader *getShader() const;\r
136         virtual sw::VertexShader *getVertexShader() const;\r
137 \r
138 private:\r
139         sw::VertexShader *vertexShader;\r
140 };\r
141 \r
142 class FragmentShader : public Shader\r
143 {\r
144 public:\r
145     FragmentShader(ResourceManager *manager, GLuint handle);\r
146 \r
147     ~FragmentShader();\r
148 \r
149     virtual GLenum getType();\r
150     virtual void compile();\r
151 \r
152         virtual sw::Shader *getShader() const;\r
153         virtual sw::PixelShader *getPixelShader() const;\r
154 \r
155 private:\r
156         sw::PixelShader *pixelShader;\r
157 };\r
158 }\r
159 \r
160 #endif   // LIBGLESV2_SHADER_H_\r