|
1 // |
|
2 // Copyright (c) 2002-2013 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 // Shader.h: Defines the abstract gl::Shader class and its concrete derived |
|
8 // classes VertexShader and FragmentShader. Implements GL shader objects and |
|
9 // related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section |
|
10 // 3.8 page 84. |
|
11 |
|
12 #ifndef LIBGLESV2_SHADER_H_ |
|
13 #define LIBGLESV2_SHADER_H_ |
|
14 |
|
15 #define GL_APICALL |
|
16 #include <GLES2/gl2.h> |
|
17 #include <string> |
|
18 #include <list> |
|
19 #include <vector> |
|
20 |
|
21 #include "compiler/CompilerUniform.h" |
|
22 #include "common/angleutils.h" |
|
23 |
|
24 namespace rx |
|
25 { |
|
26 class Renderer; |
|
27 } |
|
28 |
|
29 namespace gl |
|
30 { |
|
31 class ResourceManager; |
|
32 |
|
33 struct Varying |
|
34 { |
|
35 Varying(GLenum type, const std::string &name, int size, bool array) |
|
36 : type(type), name(name), size(size), array(array), reg(-1), col(-1) |
|
37 { |
|
38 } |
|
39 |
|
40 GLenum type; |
|
41 std::string name; |
|
42 int size; // Number of 'type' elements |
|
43 bool array; |
|
44 |
|
45 int reg; // First varying register, assigned during link |
|
46 int col; // First register element, assigned during link |
|
47 }; |
|
48 |
|
49 typedef std::list<Varying> VaryingList; |
|
50 |
|
51 class Shader |
|
52 { |
|
53 friend class ProgramBinary; |
|
54 |
|
55 public: |
|
56 Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle); |
|
57 |
|
58 virtual ~Shader(); |
|
59 |
|
60 virtual GLenum getType() = 0; |
|
61 GLuint getHandle() const; |
|
62 |
|
63 void deleteSource(); |
|
64 void setSource(GLsizei count, const char **string, const GLint *length); |
|
65 int getInfoLogLength() const; |
|
66 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
|
67 int getSourceLength() const; |
|
68 void getSource(GLsizei bufSize, GLsizei *length, char *buffer); |
|
69 int getTranslatedSourceLength() const; |
|
70 void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer); |
|
71 const sh::ActiveUniforms &getUniforms(); |
|
72 |
|
73 virtual void compile() = 0; |
|
74 virtual void uncompile(); |
|
75 bool isCompiled(); |
|
76 const char *getHLSL(); |
|
77 |
|
78 void addRef(); |
|
79 void release(); |
|
80 unsigned int getRefCount() const; |
|
81 bool isFlaggedForDeletion() const; |
|
82 void flagForDeletion(); |
|
83 |
|
84 static void releaseCompiler(); |
|
85 |
|
86 protected: |
|
87 void parseVaryings(); |
|
88 void resetVaryingsRegisterAssignment(); |
|
89 |
|
90 void compileToHLSL(void *compiler); |
|
91 |
|
92 void getSourceImpl(char *source, GLsizei bufSize, GLsizei *length, char *buffer); |
|
93 |
|
94 static GLenum parseType(const std::string &type); |
|
95 static bool compareVarying(const Varying &x, const Varying &y); |
|
96 |
|
97 const rx::Renderer *const mRenderer; |
|
98 |
|
99 VaryingList mVaryings; |
|
100 |
|
101 bool mUsesMultipleRenderTargets; |
|
102 bool mUsesFragColor; |
|
103 bool mUsesFragData; |
|
104 bool mUsesFragCoord; |
|
105 bool mUsesFrontFacing; |
|
106 bool mUsesPointSize; |
|
107 bool mUsesPointCoord; |
|
108 bool mUsesDepthRange; |
|
109 bool mUsesFragDepth; |
|
110 |
|
111 static void *mFragmentCompiler; |
|
112 static void *mVertexCompiler; |
|
113 |
|
114 private: |
|
115 DISALLOW_COPY_AND_ASSIGN(Shader); |
|
116 |
|
117 void initializeCompiler(); |
|
118 |
|
119 const GLuint mHandle; |
|
120 unsigned int mRefCount; // Number of program objects this shader is attached to |
|
121 bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use |
|
122 |
|
123 char *mSource; |
|
124 char *mHlsl; |
|
125 char *mInfoLog; |
|
126 sh::ActiveUniforms mActiveUniforms; |
|
127 |
|
128 ResourceManager *mResourceManager; |
|
129 }; |
|
130 |
|
131 struct Attribute |
|
132 { |
|
133 Attribute() : type(GL_NONE), name("") |
|
134 { |
|
135 } |
|
136 |
|
137 Attribute(GLenum type, const std::string &name) : type(type), name(name) |
|
138 { |
|
139 } |
|
140 |
|
141 GLenum type; |
|
142 std::string name; |
|
143 }; |
|
144 |
|
145 typedef std::vector<Attribute> AttributeArray; |
|
146 |
|
147 class VertexShader : public Shader |
|
148 { |
|
149 friend class ProgramBinary; |
|
150 |
|
151 public: |
|
152 VertexShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle); |
|
153 |
|
154 ~VertexShader(); |
|
155 |
|
156 virtual GLenum getType(); |
|
157 virtual void compile(); |
|
158 virtual void uncompile(); |
|
159 int getSemanticIndex(const std::string &attributeName); |
|
160 |
|
161 private: |
|
162 DISALLOW_COPY_AND_ASSIGN(VertexShader); |
|
163 |
|
164 void parseAttributes(); |
|
165 |
|
166 AttributeArray mAttributes; |
|
167 }; |
|
168 |
|
169 class FragmentShader : public Shader |
|
170 { |
|
171 public: |
|
172 FragmentShader(ResourceManager *manager,const rx::Renderer *renderer, GLuint handle); |
|
173 |
|
174 ~FragmentShader(); |
|
175 |
|
176 virtual GLenum getType(); |
|
177 virtual void compile(); |
|
178 |
|
179 private: |
|
180 DISALLOW_COPY_AND_ASSIGN(FragmentShader); |
|
181 }; |
|
182 } |
|
183 |
|
184 #endif // LIBGLESV2_SHADER_H_ |