|
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 // Program.h: Defines the gl::Program class. Implements GL program objects |
|
8 // and related functionality. [OpenGL ES 2.0.24] section 2.10.3 page 28. |
|
9 |
|
10 #ifndef LIBGLESV2_PROGRAM_BINARY_H_ |
|
11 #define LIBGLESV2_PROGRAM_BINARY_H_ |
|
12 |
|
13 #define GL_APICALL |
|
14 #include <GLES2/gl2.h> |
|
15 #include <GLES2/gl2ext.h> |
|
16 |
|
17 #include <string> |
|
18 #include <vector> |
|
19 |
|
20 #include "common/RefCountObject.h" |
|
21 #include "angletypes.h" |
|
22 #include "libGLESv2/mathutil.h" |
|
23 #include "libGLESv2/Uniform.h" |
|
24 #include "libGLESv2/Shader.h" |
|
25 #include "libGLESv2/Constants.h" |
|
26 |
|
27 namespace rx |
|
28 { |
|
29 class ShaderExecutable; |
|
30 class Renderer; |
|
31 struct TranslatedAttribute; |
|
32 } |
|
33 |
|
34 namespace gl |
|
35 { |
|
36 class FragmentShader; |
|
37 class VertexShader; |
|
38 class InfoLog; |
|
39 class AttributeBindings; |
|
40 struct Varying; |
|
41 |
|
42 // Struct used for correlating uniforms/elements of uniform arrays to handles |
|
43 struct UniformLocation |
|
44 { |
|
45 UniformLocation() |
|
46 { |
|
47 } |
|
48 |
|
49 UniformLocation(const std::string &name, unsigned int element, unsigned int index); |
|
50 |
|
51 std::string name; |
|
52 unsigned int element; |
|
53 unsigned int index; |
|
54 }; |
|
55 |
|
56 // This is the result of linking a program. It is the state that would be passed to ProgramBinary. |
|
57 class ProgramBinary : public RefCountObject |
|
58 { |
|
59 public: |
|
60 explicit ProgramBinary(rx::Renderer *renderer); |
|
61 ~ProgramBinary(); |
|
62 |
|
63 rx::ShaderExecutable *getPixelExecutable(); |
|
64 rx::ShaderExecutable *getVertexExecutable(); |
|
65 rx::ShaderExecutable *getGeometryExecutable(); |
|
66 |
|
67 GLuint getAttributeLocation(const char *name); |
|
68 int getSemanticIndex(int attributeIndex); |
|
69 |
|
70 GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); |
|
71 TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); |
|
72 GLint getUsedSamplerRange(SamplerType type); |
|
73 bool usesPointSize() const; |
|
74 bool usesPointSpriteEmulation() const; |
|
75 bool usesGeometryShader() const; |
|
76 |
|
77 GLint getUniformLocation(std::string name); |
|
78 bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
|
79 bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
|
80 bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
|
81 bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
|
82 bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
|
83 bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
|
84 bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
|
85 bool setUniform1iv(GLint location, GLsizei count, const GLint *v); |
|
86 bool setUniform2iv(GLint location, GLsizei count, const GLint *v); |
|
87 bool setUniform3iv(GLint location, GLsizei count, const GLint *v); |
|
88 bool setUniform4iv(GLint location, GLsizei count, const GLint *v); |
|
89 |
|
90 bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params); |
|
91 bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params); |
|
92 |
|
93 void dirtyAllUniforms(); |
|
94 void applyUniforms(); |
|
95 |
|
96 bool load(InfoLog &infoLog, const void *binary, GLsizei length); |
|
97 bool save(void* binary, GLsizei bufSize, GLsizei *length); |
|
98 GLint getLength(); |
|
99 |
|
100 bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
|
101 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
|
102 |
|
103 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
|
104 GLint getActiveAttributeCount() const; |
|
105 GLint getActiveAttributeMaxLength() const; |
|
106 |
|
107 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
|
108 GLint getActiveUniformCount() const; |
|
109 GLint getActiveUniformMaxLength() const; |
|
110 |
|
111 void validate(InfoLog &infoLog); |
|
112 bool validateSamplers(InfoLog *infoLog); |
|
113 bool isValidated() const; |
|
114 |
|
115 unsigned int getSerial() const; |
|
116 |
|
117 void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const; |
|
118 |
|
119 static std::string decorateAttribute(const std::string &name); // Prepend an underscore |
|
120 |
|
121 private: |
|
122 DISALLOW_COPY_AND_ASSIGN(ProgramBinary); |
|
123 |
|
124 int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); |
|
125 bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], |
|
126 std::string& pixelHLSL, std::string& vertexHLSL, |
|
127 FragmentShader *fragmentShader, VertexShader *vertexShader); |
|
128 |
|
129 bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
|
130 |
|
131 bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms); |
|
132 bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); |
|
133 |
|
134 std::string generateGeometryShaderHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
|
135 std::string generatePointSpriteHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
|
136 |
|
137 rx::Renderer *const mRenderer; |
|
138 |
|
139 rx::ShaderExecutable *mPixelExecutable; |
|
140 rx::ShaderExecutable *mVertexExecutable; |
|
141 rx::ShaderExecutable *mGeometryExecutable; |
|
142 |
|
143 Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
|
144 int mSemanticIndex[MAX_VERTEX_ATTRIBS]; |
|
145 |
|
146 struct Sampler |
|
147 { |
|
148 Sampler(); |
|
149 |
|
150 bool active; |
|
151 GLint logicalTextureUnit; |
|
152 TextureType textureType; |
|
153 }; |
|
154 |
|
155 Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; |
|
156 Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; |
|
157 GLuint mUsedVertexSamplerRange; |
|
158 GLuint mUsedPixelSamplerRange; |
|
159 bool mUsesPointSize; |
|
160 |
|
161 UniformArray mUniforms; |
|
162 typedef std::vector<UniformLocation> UniformIndex; |
|
163 UniformIndex mUniformIndex; |
|
164 |
|
165 bool mValidated; |
|
166 |
|
167 const unsigned int mSerial; |
|
168 |
|
169 static unsigned int issueSerial(); |
|
170 static unsigned int mCurrentSerial; |
|
171 }; |
|
172 } |
|
173 |
|
174 #endif // LIBGLESV2_PROGRAM_BINARY_H_ |