daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2010 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_H_ |
| 11 | #define LIBGLESV2_PROGRAM_H_ |
| 12 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 13 | #include <d3dx9.h> |
| 14 | #include <string> |
| 15 | #include <vector> |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 16 | #include <set> |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 17 | |
daniel@transgaming.com | 8542318 | 2010-04-22 13:35:27 +0000 | [diff] [blame^] | 18 | #include "libGLESv2/Shader.h" |
daniel@transgaming.com | e684229 | 2010-04-20 18:52:50 +0000 | [diff] [blame] | 19 | #include "libGLESv2/Context.h" |
| 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | namespace gl |
| 22 | { |
| 23 | class FragmentShader; |
| 24 | class VertexShader; |
| 25 | |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 26 | // Helper struct representing a single shader uniform |
| 27 | struct Uniform |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 28 | { |
daniel@transgaming.com | 0361b92 | 2010-03-28 19:36:15 +0000 | [diff] [blame] | 29 | Uniform(GLenum type, const std::string &name, unsigned int bytes); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 30 | |
| 31 | ~Uniform(); |
| 32 | |
daniel@transgaming.com | 0361b92 | 2010-03-28 19:36:15 +0000 | [diff] [blame] | 33 | const GLenum type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 34 | const std::string name; |
| 35 | const unsigned int bytes; |
| 36 | unsigned char *data; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | class Program |
| 40 | { |
| 41 | public: |
| 42 | Program(); |
| 43 | |
| 44 | ~Program(); |
| 45 | |
| 46 | bool attachShader(Shader *shader); |
| 47 | bool detachShader(Shader *shader); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 48 | int getAttachedShadersCount() const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 49 | |
| 50 | IDirect3DPixelShader9 *getPixelShader(); |
| 51 | IDirect3DVertexShader9 *getVertexShader(); |
| 52 | |
| 53 | void bindAttributeLocation(GLuint index, const char *name); |
| 54 | GLuint getAttributeLocation(const char *name); |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 55 | int getSemanticIndex(int attributeIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 56 | |
| 57 | GLint getSamplerMapping(unsigned int samplerIndex); |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 58 | SamplerType getSamplerType(unsigned int samplerIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 59 | |
| 60 | GLint getUniformLocation(const char *name); |
| 61 | bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 62 | bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 63 | bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 64 | bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 65 | bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
| 66 | bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
| 67 | bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
| 68 | bool setUniform1iv(GLint location, GLsizei count, const GLint *v); |
daniel@transgaming.com | 9a95e2b | 2010-04-13 03:26:03 +0000 | [diff] [blame] | 69 | bool setUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 70 | bool setUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 71 | bool setUniform4iv(GLint location, GLsizei count, const GLint *v); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 72 | |
daniel@transgaming.com | bb3d9d0 | 2010-04-13 03:26:06 +0000 | [diff] [blame] | 73 | bool getUniformfv(GLint location, GLfloat *params); |
| 74 | bool getUniformiv(GLint location, GLint *params); |
| 75 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 76 | void applyUniforms(); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 77 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 78 | void link(); |
| 79 | bool isLinked(); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 80 | int getInfoLogLength() const; |
| 81 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
daniel@transgaming.com | 6c78521 | 2010-03-30 03:36:17 +0000 | [diff] [blame] | 82 | void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 83 | |
daniel@transgaming.com | 8542318 | 2010-04-22 13:35:27 +0000 | [diff] [blame^] | 84 | void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); |
| 85 | GLint getActiveAttributeCount(); |
| 86 | GLint getActiveAttributeMaxLength(); |
| 87 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 88 | void flagForDeletion(); |
| 89 | bool isFlaggedForDeletion() const; |
| 90 | |
| 91 | private: |
| 92 | DISALLOW_COPY_AND_ASSIGN(Program); |
| 93 | |
| 94 | ID3DXBuffer *compileToBinary(const char *hlsl, const char *profile, ID3DXConstantTable **constantTable); |
| 95 | void unlink(bool destroy = false); |
| 96 | |
daniel@transgaming.com | 0e3358a | 2010-04-05 20:32:42 +0000 | [diff] [blame] | 97 | struct Varying |
| 98 | { |
| 99 | Varying(const std::string &name, char *declaration) : name(name), declaration(declaration) |
| 100 | { |
| 101 | link = -1; |
| 102 | } |
| 103 | |
| 104 | int link; |
| 105 | std::string name; |
| 106 | char *declaration; |
| 107 | }; |
| 108 | |
| 109 | typedef std::vector<Varying> VaryingArray; |
| 110 | |
| 111 | void parseVaryings(const char *structure, char *hlsl, VaryingArray &varyings); |
| 112 | bool linkVaryings(); |
| 113 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 114 | bool linkAttributes(); |
daniel@transgaming.com | 8542318 | 2010-04-22 13:35:27 +0000 | [diff] [blame^] | 115 | int getAttributeBinding(const std::string &name); |
daniel@transgaming.com | 0e3358a | 2010-04-05 20:32:42 +0000 | [diff] [blame] | 116 | |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 117 | bool linkUniforms(ID3DXConstantTable *constantTable); |
| 118 | bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); |
| 119 | bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); |
| 120 | Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); |
daniel@transgaming.com | 72d0b52 | 2010-04-13 19:53:44 +0000 | [diff] [blame] | 121 | static std::string decorate(const std::string &string); // Prepend an underscore |
daniel@transgaming.com | f4a0c8e | 2010-04-13 03:26:01 +0000 | [diff] [blame] | 122 | bool applyUniform1bv(GLint location, GLsizei count, const GLboolean *v); |
| 123 | bool applyUniform2bv(GLint location, GLsizei count, const GLboolean *v); |
| 124 | bool applyUniform3bv(GLint location, GLsizei count, const GLboolean *v); |
| 125 | bool applyUniform4bv(GLint location, GLsizei count, const GLboolean *v); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 126 | bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 127 | bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 128 | bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 129 | bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 130 | bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
| 131 | bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
| 132 | bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
| 133 | bool applyUniform1iv(GLint location, GLsizei count, const GLint *v); |
daniel@transgaming.com | 9a95e2b | 2010-04-13 03:26:03 +0000 | [diff] [blame] | 134 | bool applyUniform2iv(GLint location, GLsizei count, const GLint *v); |
| 135 | bool applyUniform3iv(GLint location, GLsizei count, const GLint *v); |
| 136 | bool applyUniform4iv(GLint location, GLsizei count, const GLint *v); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 137 | |
daniel@transgaming.com | 8542318 | 2010-04-22 13:35:27 +0000 | [diff] [blame^] | 138 | GLenum parseAttributeType(const std::string &type); |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 139 | void appendToInfoLog(const char *info, ...); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 140 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 141 | FragmentShader *mFragmentShader; |
| 142 | VertexShader *mVertexShader; |
| 143 | |
daniel@transgaming.com | 0e3358a | 2010-04-05 20:32:42 +0000 | [diff] [blame] | 144 | char *mPixelHLSL; |
| 145 | char *mVertexHLSL; |
| 146 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 147 | IDirect3DPixelShader9 *mPixelExecutable; |
| 148 | IDirect3DVertexShader9 *mVertexExecutable; |
| 149 | ID3DXConstantTable *mConstantTablePS; |
| 150 | ID3DXConstantTable *mConstantTableVS; |
| 151 | |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 152 | std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS]; |
daniel@transgaming.com | 8542318 | 2010-04-22 13:35:27 +0000 | [diff] [blame^] | 153 | Attribute mLinkedAttribute[MAX_VERTEX_ATTRIBS]; |
daniel@transgaming.com | b4ff1f8 | 2010-04-22 13:35:18 +0000 | [diff] [blame] | 154 | int mSemanticIndex[MAX_VERTEX_ATTRIBS]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 155 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 156 | struct Sampler |
| 157 | { |
| 158 | bool active; |
| 159 | GLint logicalTextureUnit; |
| 160 | SamplerType type; |
| 161 | }; |
| 162 | |
| 163 | Sampler mSamplers[MAX_TEXTURE_IMAGE_UNITS]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 164 | |
| 165 | typedef std::vector<Uniform*> UniformArray; |
| 166 | UniformArray mUniforms; |
| 167 | |
| 168 | bool mLinked; |
| 169 | bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame] | 170 | char *mInfoLog; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 171 | }; |
| 172 | } |
| 173 | |
| 174 | #endif // LIBGLESV2_PROGRAM_H_ |