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