apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 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 | |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 13 | #define GL_APICALL |
shannon.woods%transgaming.com@gtempaccount.com | f26ddae | 2013-04-13 03:29:13 +0000 | [diff] [blame] | 14 | #include <GLES3/gl3.h> |
| 15 | #include <GLES3/gl3ext.h> |
daniel@transgaming.com | 29ab952 | 2012-08-27 16:25:37 +0000 | [diff] [blame] | 16 | #include <GLES2/gl2.h> |
| 17 | #include <GLES2/gl2ext.h> |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 18 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 22 | #include "common/RefCountObject.h" |
| 23 | #include "angletypes.h" |
apatrick@chromium.org | 60dafe8 | 2012-09-05 22:26:10 +0000 | [diff] [blame] | 24 | #include "libGLESv2/mathutil.h" |
daniel@transgaming.com | 15186aa | 2012-12-20 21:08:23 +0000 | [diff] [blame] | 25 | #include "libGLESv2/Uniform.h" |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 26 | #include "libGLESv2/Shader.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 27 | #include "libGLESv2/Constants.h" |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 28 | |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 29 | namespace rx |
| 30 | { |
| 31 | class ShaderExecutable; |
| 32 | class Renderer; |
shannon.woods@transgaming.com | 0b60014 | 2013-02-28 23:15:04 +0000 | [diff] [blame] | 33 | struct TranslatedAttribute; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 34 | } |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 35 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 36 | namespace gl |
| 37 | { |
| 38 | class FragmentShader; |
| 39 | class VertexShader; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 40 | class InfoLog; |
| 41 | class AttributeBindings; |
| 42 | struct Varying; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 43 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 44 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 45 | struct UniformLocation |
| 46 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 47 | UniformLocation() |
| 48 | { |
| 49 | } |
| 50 | |
daniel@transgaming.com | db01995 | 2012-12-20 21:13:32 +0000 | [diff] [blame] | 51 | UniformLocation(const std::string &name, unsigned int element, unsigned int index); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 52 | |
| 53 | std::string name; |
| 54 | unsigned int element; |
| 55 | unsigned int index; |
| 56 | }; |
| 57 | |
| 58 | // This is the result of linking a program. It is the state that would be passed to ProgramBinary. |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 59 | class ProgramBinary : public RefCountObject |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 60 | { |
| 61 | public: |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 62 | explicit ProgramBinary(rx::Renderer *renderer); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 63 | ~ProgramBinary(); |
| 64 | |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 65 | rx::ShaderExecutable *getPixelExecutable(); |
| 66 | rx::ShaderExecutable *getVertexExecutable(); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 67 | rx::ShaderExecutable *getGeometryExecutable(); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 68 | |
| 69 | GLuint getAttributeLocation(const char *name); |
| 70 | int getSemanticIndex(int attributeIndex); |
| 71 | |
| 72 | GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); |
| 73 | TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); |
| 74 | GLint getUsedSamplerRange(SamplerType type); |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 75 | bool usesPointSize() const; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 76 | bool usesPointSpriteEmulation() const; |
| 77 | bool usesGeometryShader() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 78 | |
| 79 | GLint getUniformLocation(std::string name); |
| 80 | bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 81 | bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 82 | bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 83 | bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 84 | bool setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 85 | bool setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 86 | bool setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 87 | bool setUniform4iv(GLint location, GLsizei count, const GLint *v); |
shannon.woods%transgaming.com@gtempaccount.com | 50ea4ab | 2013-04-13 03:40:36 +0000 | [diff] [blame] | 88 | bool setUniform1uiv(GLint location, GLsizei count, const GLuint *v); |
| 89 | bool setUniform2uiv(GLint location, GLsizei count, const GLuint *v); |
| 90 | bool setUniform3uiv(GLint location, GLsizei count, const GLuint *v); |
| 91 | bool setUniform4uiv(GLint location, GLsizei count, const GLuint *v); |
| 92 | bool setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 93 | bool setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 94 | bool setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
shannon.woods%transgaming.com@gtempaccount.com | a741b64 | 2013-04-13 03:40:10 +0000 | [diff] [blame] | 95 | bool setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 96 | bool setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 97 | bool setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 98 | bool setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 99 | bool setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
| 100 | bool setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 101 | |
| 102 | bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params); |
| 103 | bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params); |
shannon.woods%transgaming.com@gtempaccount.com | e229012 | 2013-04-13 03:41:07 +0000 | [diff] [blame^] | 104 | bool getUniformuiv(GLint location, GLsizei *bufSize, GLuint *params); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 105 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 106 | void dirtyAllUniforms(); |
| 107 | void applyUniforms(); |
| 108 | |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 109 | bool load(InfoLog &infoLog, const void *binary, GLsizei length); |
| 110 | bool save(void* binary, GLsizei bufSize, GLsizei *length); |
| 111 | GLint getLength(); |
| 112 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 113 | bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 114 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
| 115 | |
shannon.woods@transgaming.com | 4f4215f | 2013-02-28 23:14:58 +0000 | [diff] [blame] | 116 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
| 117 | GLint getActiveAttributeCount() const; |
| 118 | GLint getActiveAttributeMaxLength() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 119 | |
shannon.woods@transgaming.com | 4f4215f | 2013-02-28 23:14:58 +0000 | [diff] [blame] | 120 | void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
| 121 | GLint getActiveUniformCount() const; |
| 122 | GLint getActiveUniformMaxLength() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 123 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 124 | void validate(InfoLog &infoLog); |
| 125 | bool validateSamplers(InfoLog *infoLog); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 126 | bool isValidated() const; |
| 127 | |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 128 | unsigned int getSerial() const; |
| 129 | |
shannon.woods@transgaming.com | 0b60014 | 2013-02-28 23:15:04 +0000 | [diff] [blame] | 130 | void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const; |
| 131 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 132 | static std::string decorateAttribute(const std::string &name); // Prepend an underscore |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 133 | |
| 134 | private: |
| 135 | DISALLOW_COPY_AND_ASSIGN(ProgramBinary); |
| 136 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 137 | int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); |
shannon.woods@transgaming.com | 5bcf7df | 2013-01-25 21:55:33 +0000 | [diff] [blame] | 138 | bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], |
| 139 | std::string& pixelHLSL, std::string& vertexHLSL, |
| 140 | FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 141 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 142 | bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 143 | |
daniel@transgaming.com | 68aaf93 | 2012-12-20 21:13:16 +0000 | [diff] [blame] | 144 | bool linkUniforms(InfoLog &infoLog, const sh::ActiveUniforms &vertexUniforms, const sh::ActiveUniforms &fragmentUniforms); |
daniel@transgaming.com | da8d380 | 2012-12-20 21:12:55 +0000 | [diff] [blame] | 145 | bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 146 | |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 147 | std::string generateGeometryShaderHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
| 148 | std::string generatePointSpriteHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
| 149 | |
shannon.woods%transgaming.com@gtempaccount.com | 8a19eed | 2013-04-13 03:40:22 +0000 | [diff] [blame] | 150 | template <typename T> |
| 151 | bool setUniform(GLint location, GLsizei count, const T* v, GLenum targetUniformType); |
| 152 | |
shannon.woods%transgaming.com@gtempaccount.com | 36c76a9 | 2013-04-13 03:39:58 +0000 | [diff] [blame] | 153 | template <int cols, int rows> |
shannon.woods%transgaming.com@gtempaccount.com | a741b64 | 2013-04-13 03:40:10 +0000 | [diff] [blame] | 154 | bool setUniformMatrixfv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value, GLenum targetUniformType); |
shannon.woods%transgaming.com@gtempaccount.com | 36c76a9 | 2013-04-13 03:39:58 +0000 | [diff] [blame] | 155 | |
shannon.woods%transgaming.com@gtempaccount.com | 4590d89 | 2013-04-13 03:41:01 +0000 | [diff] [blame] | 156 | template <typename T> |
| 157 | bool getUniformv(GLint location, GLsizei *bufSize, T *params, GLenum uniformType); |
| 158 | |
daniel@transgaming.com | 77fbf97 | 2012-11-28 21:02:55 +0000 | [diff] [blame] | 159 | rx::Renderer *const mRenderer; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 160 | |
daniel@transgaming.com | 4f0f65e | 2012-11-28 21:00:00 +0000 | [diff] [blame] | 161 | rx::ShaderExecutable *mPixelExecutable; |
| 162 | rx::ShaderExecutable *mVertexExecutable; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 163 | rx::ShaderExecutable *mGeometryExecutable; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 164 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 165 | Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
| 166 | int mSemanticIndex[MAX_VERTEX_ATTRIBS]; |
| 167 | |
| 168 | struct Sampler |
| 169 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 170 | Sampler(); |
| 171 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 172 | bool active; |
| 173 | GLint logicalTextureUnit; |
| 174 | TextureType textureType; |
| 175 | }; |
| 176 | |
| 177 | Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 178 | Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 179 | GLuint mUsedVertexSamplerRange; |
| 180 | GLuint mUsedPixelSamplerRange; |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 181 | bool mUsesPointSize; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 182 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 183 | UniformArray mUniforms; |
| 184 | typedef std::vector<UniformLocation> UniformIndex; |
| 185 | UniformIndex mUniformIndex; |
| 186 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 187 | bool mValidated; |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 188 | |
| 189 | const unsigned int mSerial; |
| 190 | |
| 191 | static unsigned int issueSerial(); |
| 192 | static unsigned int mCurrentSerial; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 193 | }; |
| 194 | } |
| 195 | |
| 196 | #endif // LIBGLESV2_PROGRAM_BINARY_H_ |