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