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