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; |
| 31 | } |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 32 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 33 | namespace gl |
| 34 | { |
| 35 | class FragmentShader; |
| 36 | class VertexShader; |
shannon.woods@transgaming.com | d2811d6 | 2013-02-28 23:11:19 +0000 | [diff] [blame^] | 37 | class InfoLog; |
| 38 | class AttributeBindings; |
| 39 | struct Varying; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 40 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 41 | // Struct used for correlating uniforms/elements of uniform arrays to handles |
| 42 | struct UniformLocation |
| 43 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 44 | UniformLocation() |
| 45 | { |
| 46 | } |
| 47 | |
daniel@transgaming.com | db01995 | 2012-12-20 21:13:32 +0000 | [diff] [blame] | 48 | UniformLocation(const std::string &name, unsigned int element, unsigned int index); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 49 | |
| 50 | std::string name; |
| 51 | unsigned int element; |
| 52 | unsigned int index; |
| 53 | }; |
| 54 | |
| 55 | // 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] | 56 | class ProgramBinary : public RefCountObject |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 57 | { |
| 58 | public: |
daniel@transgaming.com | 70062c9 | 2012-11-28 19:32:30 +0000 | [diff] [blame] | 59 | explicit ProgramBinary(rx::Renderer *renderer); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 60 | ~ProgramBinary(); |
| 61 | |
daniel@transgaming.com | 9589241 | 2012-11-28 20:59:09 +0000 | [diff] [blame] | 62 | rx::ShaderExecutable *getPixelExecutable(); |
| 63 | rx::ShaderExecutable *getVertexExecutable(); |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 64 | rx::ShaderExecutable *getGeometryExecutable(); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 65 | |
| 66 | GLuint getAttributeLocation(const char *name); |
| 67 | int getSemanticIndex(int attributeIndex); |
| 68 | |
| 69 | GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex); |
| 70 | TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex); |
| 71 | GLint getUsedSamplerRange(SamplerType type); |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 72 | bool usesPointSize() const; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 73 | bool usesPointSpriteEmulation() const; |
| 74 | bool usesGeometryShader() const; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 75 | |
| 76 | GLint getUniformLocation(std::string name); |
| 77 | bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 78 | bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 79 | bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 80 | bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 81 | bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
| 82 | bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
| 83 | bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
| 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); |
| 88 | |
| 89 | bool getUniformfv(GLint location, GLsizei *bufSize, GLfloat *params); |
| 90 | bool getUniformiv(GLint location, GLsizei *bufSize, GLint *params); |
| 91 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 92 | void dirtyAllUniforms(); |
| 93 | void applyUniforms(); |
| 94 | |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 95 | bool load(InfoLog &infoLog, const void *binary, GLsizei length); |
| 96 | bool save(void* binary, GLsizei bufSize, GLsizei *length); |
| 97 | GLint getLength(); |
| 98 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 99 | bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 100 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
| 101 | |
| 102 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 103 | GLint getActiveAttributeCount(); |
| 104 | GLint getActiveAttributeMaxLength(); |
| 105 | |
| 106 | void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 107 | GLint getActiveUniformCount(); |
| 108 | GLint getActiveUniformMaxLength(); |
| 109 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 110 | void validate(InfoLog &infoLog); |
| 111 | bool validateSamplers(InfoLog *infoLog); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 112 | bool isValidated() const; |
| 113 | |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 114 | unsigned int getSerial() const; |
| 115 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 116 | static std::string decorateAttribute(const std::string &name); // Prepend an underscore |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 117 | |
| 118 | private: |
| 119 | DISALLOW_COPY_AND_ASSIGN(ProgramBinary); |
| 120 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 121 | int packVaryings(InfoLog &infoLog, const Varying *packing[][4], FragmentShader *fragmentShader); |
shannon.woods@transgaming.com | 5bcf7df | 2013-01-25 21:55:33 +0000 | [diff] [blame] | 122 | bool linkVaryings(InfoLog &infoLog, int registers, const Varying *packing[][4], |
| 123 | std::string& pixelHLSL, std::string& vertexHLSL, |
| 124 | FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 125 | |
apatrick@chromium.org | 253b8d2 | 2012-06-22 19:27:21 +0000 | [diff] [blame] | 126 | bool linkAttributes(InfoLog &infoLog, const AttributeBindings &attributeBindings, FragmentShader *fragmentShader, VertexShader *vertexShader); |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 127 | |
daniel@transgaming.com | 68aaf93 | 2012-12-20 21:13:16 +0000 | [diff] [blame] | 128 | 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] | 129 | bool defineUniform(GLenum shader, const sh::Uniform &constant, InfoLog &infoLog); |
daniel@transgaming.com | b6e5510 | 2012-12-20 21:08:14 +0000 | [diff] [blame] | 130 | |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 131 | std::string generateGeometryShaderHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
| 132 | std::string generatePointSpriteHLSL(int registers, const Varying *packing[][4], FragmentShader *fragmentShader, VertexShader *vertexShader) const; |
| 133 | |
daniel@transgaming.com | 77fbf97 | 2012-11-28 21:02:55 +0000 | [diff] [blame] | 134 | rx::Renderer *const mRenderer; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 135 | |
daniel@transgaming.com | 4f0f65e | 2012-11-28 21:00:00 +0000 | [diff] [blame] | 136 | rx::ShaderExecutable *mPixelExecutable; |
| 137 | rx::ShaderExecutable *mVertexExecutable; |
shannon.woods@transgaming.com | 3e773bb | 2013-01-25 21:55:47 +0000 | [diff] [blame] | 138 | rx::ShaderExecutable *mGeometryExecutable; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 139 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 140 | Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
| 141 | int mSemanticIndex[MAX_VERTEX_ATTRIBS]; |
| 142 | |
| 143 | struct Sampler |
| 144 | { |
apatrick@chromium.org | 90080e3 | 2012-07-09 22:15:33 +0000 | [diff] [blame] | 145 | Sampler(); |
| 146 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 147 | bool active; |
| 148 | GLint logicalTextureUnit; |
| 149 | TextureType textureType; |
| 150 | }; |
| 151 | |
| 152 | Sampler mSamplersPS[MAX_TEXTURE_IMAGE_UNITS]; |
shannon.woods@transgaming.com | 233fe95 | 2013-01-25 21:51:57 +0000 | [diff] [blame] | 153 | Sampler mSamplersVS[IMPLEMENTATION_MAX_VERTEX_TEXTURE_IMAGE_UNITS]; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 154 | GLuint mUsedVertexSamplerRange; |
| 155 | GLuint mUsedPixelSamplerRange; |
daniel@transgaming.com | 087e578 | 2012-09-17 21:28:47 +0000 | [diff] [blame] | 156 | bool mUsesPointSize; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 157 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 158 | UniformArray mUniforms; |
| 159 | typedef std::vector<UniformLocation> UniformIndex; |
| 160 | UniformIndex mUniformIndex; |
| 161 | |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 162 | bool mValidated; |
daniel@transgaming.com | e87ca00 | 2012-07-24 18:30:43 +0000 | [diff] [blame] | 163 | |
| 164 | const unsigned int mSerial; |
| 165 | |
| 166 | static unsigned int issueSerial(); |
| 167 | static unsigned int mCurrentSerial; |
apatrick@chromium.org | ea09f9b | 2012-06-08 00:45:32 +0000 | [diff] [blame] | 168 | }; |
| 169 | } |
| 170 | |
| 171 | #endif // LIBGLESV2_PROGRAM_BINARY_H_ |