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 | |
| 13 | #include "Context.h" |
| 14 | |
| 15 | #include <d3dx9.h> |
| 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
| 19 | namespace gl |
| 20 | { |
| 21 | class FragmentShader; |
| 22 | class VertexShader; |
| 23 | |
| 24 | enum UniformType |
| 25 | { |
| 26 | UNIFORM_1FV, |
| 27 | UNIFORM_2FV, |
| 28 | UNIFORM_3FV, |
| 29 | UNIFORM_4FV, |
| 30 | UNIFORM_MATRIX_2FV, |
| 31 | UNIFORM_MATRIX_3FV, |
| 32 | UNIFORM_MATRIX_4FV, |
| 33 | UNIFORM_1IV |
| 34 | }; |
| 35 | |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 36 | // Helper struct representing a single shader uniform |
| 37 | struct Uniform |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 38 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | Uniform(UniformType type, const std::string &name, unsigned int bytes); |
| 40 | |
| 41 | ~Uniform(); |
| 42 | |
| 43 | const UniformType type; |
| 44 | const std::string name; |
| 45 | const unsigned int bytes; |
| 46 | unsigned char *data; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | class Program |
| 50 | { |
| 51 | public: |
| 52 | Program(); |
| 53 | |
| 54 | ~Program(); |
| 55 | |
| 56 | bool attachShader(Shader *shader); |
| 57 | bool detachShader(Shader *shader); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame^] | 58 | int getAttachedShadersCount() const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 59 | |
| 60 | IDirect3DPixelShader9 *getPixelShader(); |
| 61 | IDirect3DVertexShader9 *getVertexShader(); |
| 62 | |
| 63 | void bindAttributeLocation(GLuint index, const char *name); |
| 64 | GLuint getAttributeLocation(const char *name); |
| 65 | bool isActiveAttribute(int attributeIndex); |
| 66 | int getInputMapping(int attributeIndex); |
| 67 | |
| 68 | GLint getSamplerMapping(unsigned int samplerIndex); |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 69 | SamplerType getSamplerType(unsigned int samplerIndex); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 70 | |
| 71 | GLint getUniformLocation(const char *name); |
| 72 | bool setUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 73 | bool setUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 74 | bool setUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 75 | bool setUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 76 | bool setUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
| 77 | bool setUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
| 78 | bool setUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
| 79 | bool setUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 80 | |
| 81 | void applyUniforms(); |
daniel@transgaming.com | fab5a1a | 2010-03-11 19:22:30 +0000 | [diff] [blame] | 82 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 83 | void link(); |
| 84 | bool isLinked(); |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame^] | 85 | int getInfoLogLength() const; |
| 86 | void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 87 | |
| 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 | |
| 97 | bool linkAttributes(); |
daniel@transgaming.com | 86487c2 | 2010-03-11 19:41:43 +0000 | [diff] [blame] | 98 | bool linkUniforms(ID3DXConstantTable *constantTable); |
| 99 | bool defineUniform(const D3DXHANDLE &constantHandle, const D3DXCONSTANT_DESC &constantDescription, std::string name = ""); |
| 100 | bool defineUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); |
| 101 | Uniform *createUniform(const D3DXCONSTANT_DESC &constantDescription, std::string &name); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 102 | bool applyUniform1fv(GLint location, GLsizei count, const GLfloat *v); |
| 103 | bool applyUniform2fv(GLint location, GLsizei count, const GLfloat *v); |
| 104 | bool applyUniform3fv(GLint location, GLsizei count, const GLfloat *v); |
| 105 | bool applyUniform4fv(GLint location, GLsizei count, const GLfloat *v); |
| 106 | bool applyUniformMatrix2fv(GLint location, GLsizei count, const GLfloat *value); |
| 107 | bool applyUniformMatrix3fv(GLint location, GLsizei count, const GLfloat *value); |
| 108 | bool applyUniformMatrix4fv(GLint location, GLsizei count, const GLfloat *value); |
| 109 | bool applyUniform1iv(GLint location, GLsizei count, const GLint *v); |
| 110 | |
daniel@transgaming.com | cba5057 | 2010-03-28 19:36:09 +0000 | [diff] [blame^] | 111 | void appendToInfoLog(const char *info); |
| 112 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 113 | FragmentShader *mFragmentShader; |
| 114 | VertexShader *mVertexShader; |
| 115 | |
| 116 | IDirect3DPixelShader9 *mPixelExecutable; |
| 117 | IDirect3DVertexShader9 *mVertexExecutable; |
| 118 | ID3DXConstantTable *mConstantTablePS; |
| 119 | ID3DXConstantTable *mConstantTableVS; |
| 120 | |
| 121 | char *mAttributeName[MAX_VERTEX_ATTRIBS]; |
| 122 | int mInputMapping[MAX_VERTEX_ATTRIBS]; |
| 123 | |
daniel@transgaming.com | 416485f | 2010-03-16 06:23:23 +0000 | [diff] [blame] | 124 | struct Sampler |
| 125 | { |
| 126 | bool active; |
| 127 | GLint logicalTextureUnit; |
| 128 | SamplerType type; |
| 129 | }; |
| 130 | |
| 131 | Sampler mSamplers[MAX_TEXTURE_IMAGE_UNITS]; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 132 | |
| 133 | typedef std::vector<Uniform*> UniformArray; |
| 134 | UniformArray mUniforms; |
| 135 | |
| 136 | bool mLinked; |
| 137 | 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^] | 138 | char *mInfoLog; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 139 | }; |
| 140 | } |
| 141 | |
| 142 | #endif // LIBGLESV2_PROGRAM_H_ |