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 |
daniel@transgaming.com | 29ab952 | 2012-08-27 16:25:37 +0000 | [diff] [blame] | 14 | #include <GLES2/gl2.h> |
| 15 | #include <GLES2/gl2ext.h> |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 16 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
| 19 | |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 20 | #include "common/RefCountObject.h" |
| 21 | #include "angletypes.h" |
apatrick@chromium.org | 60dafe8 | 2012-09-05 22:26:10 +0000 | [diff] [blame] | 22 | #include "libGLESv2/mathutil.h" |
daniel@transgaming.com | 15186aa | 2012-12-20 21:08:23 +0000 | [diff] [blame] | 23 | #include "libGLESv2/Uniform.h" |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 24 | #include "libGLESv2/Shader.h" |
| 25 | #include "Context.h" |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 26 | |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 27 | namespace rx |
| 28 | { |
| 29 | class ShaderExecutable; |
| 30 | class Renderer; |
shannon.woods@transgaming.com | 0b60014 | 2013-02-28 23:15:04 +0000 | [diff] [blame^] | 31 | struct TranslatedAttribute; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 32 | } |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 33 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
| 36 | class FragmentShader; |
| 37 | class VertexShader; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame] | 38 | class InfoLog; |
| 39 | class AttributeBindings; |
| 40 | struct Varying; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 41 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 42 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 43 | struct UniformLocation |
| 44 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 45 | UniformLocation() |
| 46 | { |
| 47 | } |
| 48 | |
daniel@transgaming.com | db01995 | 2012-12-20 21:13:32 +0000 | [diff] [blame] | 49 | UniformLocation(const std::string &name, unsigned int element, unsigned int index); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 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. |
daniel@transgaming.com | 989c1c8 | 2012-07-24 18:40:38 +0000 | [diff] [blame] | 57 | class ProgramBinary : public RefCountObject |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 58 | { |
| 59 | public: |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 60 | explicit ProgramBinary(rx::Renderer *renderer); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 61 | ~ProgramBinary(); |
| 62 | |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 63 | rx::ShaderExecutable *getPixelExecutable(); |
| 64 | rx::ShaderExecutable *getVertexExecutable(); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 65 | rx::ShaderExecutable *getGeometryExecutable(); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 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); |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 73 | bool usesPointSize() const; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 74 | bool usesPointSpriteEmulation() const; |
| 75 | bool usesGeometryShader() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 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 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 93 | void dirtyAllUniforms(); |
| 94 | void applyUniforms(); |
| 95 | |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 96 | bool load(InfoLog &infoLog, const void *binary, GLsizei length); |
| 97 | bool save(void* binary, GLsizei bufSize, GLsizei *length); |
| 98 | GLint getLength(); |
| 99 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 100 | bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 101 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
| 102 | |
shannon.woods@transgaming.com | 4f4215f | 2013-02-28 23:14:58 +0000 | [diff] [blame] | 103 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
| 104 | GLint getActiveAttributeCount() const; |
| 105 | GLint getActiveAttributeMaxLength() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 106 | |
shannon.woods@transgaming.com | 4f4215f | 2013-02-28 23:14:58 +0000 | [diff] [blame] | 107 | void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const; |
| 108 | GLint getActiveUniformCount() const; |
| 109 | GLint getActiveUniformMaxLength() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 110 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 111 | void validate(InfoLog &infoLog); |
| 112 | bool validateSamplers(InfoLog *infoLog); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 113 | bool isValidated() const; |
| 114 | |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 115 | unsigned int getSerial() const; |
| 116 | |
shannon.woods@transgaming.com | 0b60014 | 2013-02-28 23:15:04 +0000 | [diff] [blame^] | 117 | void sortAttributesByLayout(rx::TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS], int sortedSemanticIndices[MAX_VERTEX_ATTRIBS]) const; |
| 118 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 119 | static std::string decorateAttribute(const std::string &name); // Prepend an underscore |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 120 | |
| 121 | private: |
| 122 | DISALLOW_COPY_AND_ASSIGN(ProgramBinary); |
| 123 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 124 | int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); |
shannon.woods@transgaming.com | 5bcf7df | 2013-01-25 21:55:33 +0000 | [diff] [blame] | 125 | bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], |
| 126 | std::string& pixelHLSL, std::string& vertexHLSL, |
| 127 | FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 128 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 129 | bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 130 | |
daniel@transgaming.com | 68aaf93 | 2012-12-20 21:13:16 +0000 | [diff] [blame] | 131 | 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] | 132 | bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 133 | |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 77fbf97 | 2012-11-28 21:02:55 +0000 | [diff] [blame] | 137 | rx::Renderer *const mRenderer; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 138 | |
daniel@transgaming.com | 4f0f65e | 2012-11-28 21:00:00 +0000 | [diff] [blame] | 139 | rx::ShaderExecutable *mPixelExecutable; |
| 140 | rx::ShaderExecutable *mVertexExecutable; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 141 | rx::ShaderExecutable *mGeometryExecutable; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 142 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 143 | Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
| 144 | int mSemanticIndex[MAX_VERTEX_ATTRIBS]; |
| 145 | |
| 146 | struct Sampler |
| 147 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 148 | Sampler(); |
| 149 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 150 | bool active; |
| 151 | GLint logicalTextureUnit; |
| 152 | TextureType textureType; |
| 153 | }; |
| 154 | |
| 155 | Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 156 | Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 157 | GLuint mUsedVertexSamplerRange; |
| 158 | GLuint mUsedPixelSamplerRange; |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 159 | bool mUsesPointSize; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 160 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 161 | UniformArray mUniforms; |
| 162 | typedef std::vector<UniformLocation> UniformIndex; |
| 163 | UniformIndex mUniformIndex; |
| 164 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 165 | bool mValidated; |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 166 | |
| 167 | const unsigned int mSerial; |
| 168 | |
| 169 | static unsigned int issueSerial(); |
| 170 | static unsigned int mCurrentSerial; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 171 | }; |
| 172 | } |
| 173 | |
| 174 | #endif // LIBGLESV2_PROGRAM_BINARY_H_ |