Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 //
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.
10 #ifndef LIBGLESV2_PROGRAM_BINARY_H_
11 #define LIBGLESV2_PROGRAM_BINARY_H_
13 #define GL_APICALL
14 #include <GLES2/gl2.h>
15 #include <GLES2/gl2ext.h>
17 #include <string>
18 #include <vector>
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"
27 namespace rx
28 {
29 class ShaderExecutable;
30 class Renderer;
31 struct TranslatedAttribute;
32 }
34 namespace gl
35 {
36 class FragmentShader;
37 class VertexShader;
38 class InfoLog;
39 class AttributeBindings;
40 struct Varying;
42 // Struct used for correlating uniforms/elements of uniform arrays to handles
43 struct UniformLocation
44 {
45 UniformLocation()
46 {
47 }
49 UniformLocation(const std::string &name, unsigned int element, unsigned int index);
51 std::string name;
52 unsigned int element;
53 unsigned int index;
54 };
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();
63 rx::ShaderExecutable *getPixelExecutable();
64 rx::ShaderExecutable *getVertexExecutable();
65 rx::ShaderExecutable *getGeometryExecutable();
67 GLuint getAttributeLocation(const char *name);
68 int getSemanticIndex(int attributeIndex);
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;
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);
90 bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params);
91 bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params);
93 void dirtyAllUniforms();
94 void applyUniforms();
96 bool load(InfoLog &infoLog, const void *binary, GLsizei length);
97 bool save(void* binary, GLsizei bufSize, GLsizei *length);
98 GLint getLength();
100 bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
101 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
103 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
104 GLint getActiveAttributeCount() const;
105 GLint getActiveAttributeMaxLength() const;
107 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
108 GLint getActiveUniformCount() const;
109 GLint getActiveUniformMaxLength() const;
111 void validate(InfoLog &infoLog);
112 bool validateSamplers(InfoLog *infoLog);
113 bool isValidated() const;
115 unsigned int getSerial() const;
117 void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const;
119 static std::string decorateAttribute(const std::string &name); // Prepend an underscore
121 private:
122 DISALLOW_COPY_AND_ASSIGN(ProgramBinary);
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);
129 bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader);
131 bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms);
132 bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog);
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;
137 rx::Renderer *const mRenderer;
139 rx::ShaderExecutable *mPixelExecutable;
140 rx::ShaderExecutable *mVertexExecutable;
141 rx::ShaderExecutable *mGeometryExecutable;
143 Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS];
144 int mSemanticIndex[MAX_VERTEX_ATTRIBS];
146 struct Sampler
147 {
148 Sampler();
150 bool active;
151 GLint logicalTextureUnit;
152 TextureType textureType;
153 };
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;
161 UniformArray mUniforms;
162 typedef std::vector<UniformLocation> UniformIndex;
163 UniformIndex mUniformIndex;
165 bool mValidated;
167 const unsigned int mSerial;
169 static unsigned int issueSerial();
170 static unsigned int mCurrentSerial;
171 };
172 }
174 #endif // LIBGLESV2_PROGRAM_BINARY_H_