1 // 2 // Copyright (c) 2002-2014 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 "common/angleutils.h" 14 #include "common/RefCountObject.h" 15 #include "libGLESv2/Constants.h" 16 #include "libGLESv2/ProgramBinary.h" 17 18 #include <GLES2/gl2.h> 19 20 #include <vector> 21 #include <string> 22 #include <set> 23 24 namespace rx 25 { 26 class Renderer; 27 } 28 29 namespace gl 30 { 31 struct Caps; 32 class ResourceManager; 33 class Shader; 34 35 extern const char * const g_fakepath; 36 37 class AttributeBindings 38 { 39 public: 40 AttributeBindings(); 41 ~AttributeBindings(); 42 43 void bindAttributeLocation(GLuint index, const char *name); 44 int getAttributeBinding(const std::string &name) const; 45 46 private: 47 std::set<std::string> mAttributeBinding[MAX_VERTEX_ATTRIBS]; 48 }; 49 50 class InfoLog 51 { 52 public: 53 InfoLog(); 54 ~InfoLog(); 55 56 int getLength() const; 57 void getLog(GLsizei bufSize, GLsizei *length, char *infoLog); 58 59 void appendSanitized(const char *message); 60 void append(const char *info, ...); 61 void reset(); 62 private: 63 DISALLOW_COPY_AND_ASSIGN(InfoLog); 64 char *mInfoLog; 65 }; 66 67 class Program 68 { 69 public: 70 Program(rx::Renderer *renderer, ResourceManager *manager, GLuint handle); 71 72 ~Program(); 73 74 bool attachShader(Shader *shader); 75 bool detachShader(Shader *shader); 76 int getAttachedShadersCount() const; 77 78 void bindAttributeLocation(GLuint index, const char *name); 79 80 bool link(const Caps &caps); 81 bool isLinked(); 82 bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length); 83 ProgramBinary *getProgramBinary() const; 84 85 int getInfoLogLength() const; 86 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog); 87 void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders); 88 89 void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); 90 GLint getActiveAttributeCount(); 91 GLint getActiveAttributeMaxLength(); 92 93 void getActiveUniform(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name); 94 GLint getActiveUniformCount(); 95 GLint getActiveUniformMaxLength(); 96 97 GLint getActiveUniformBlockCount(); 98 GLint getActiveUniformBlockMaxLength(); 99 100 void bindUniformBlock(GLuint uniformBlockIndex, GLuint uniformBlockBinding); 101 GLuint getUniformBlockBinding(GLuint uniformBlockIndex) const; 102 103 void setTransformFeedbackVaryings(GLsizei count, const GLchar *const *varyings, GLenum bufferMode); 104 void getTransformFeedbackVarying(GLuint index, GLsizei bufSize, GLsizei *length, GLsizei *size, GLenum *type, GLchar *name) const; 105 GLsizei getTransformFeedbackVaryingCount() const; 106 GLsizei getTransformFeedbackVaryingMaxLength() const; 107 GLenum getTransformFeedbackBufferMode() const; 108 109 void addRef(); 110 void release(); 111 unsigned int getRefCount() const; 112 void flagForDeletion(); 113 bool isFlaggedForDeletion() const; 114 115 void validate(const Caps &caps); 116 bool isValidated() const; 117 118 GLint getProgramBinaryLength() const; 119 120 private: 121 DISALLOW_COPY_AND_ASSIGN(Program); 122 123 void unlink(bool destroy = false); 124 void resetUniformBlockBindings(); 125 126 Shader *mFragmentShader; 127 Shader *mVertexShader; 128 129 AttributeBindings mAttributeBindings; 130 131 GLuint mUniformBlockBindings[IMPLEMENTATION_MAX_COMBINED_SHADER_UNIFORM_BUFFERS]; 132 133 std::vector<std::string> mTransformFeedbackVaryings; 134 GLuint mTransformFeedbackBufferMode; 135 136 BindingPointer<ProgramBinary> mProgramBinary; 137 bool mLinked; 138 bool mDeleteStatus; // Flag to indicate that the program can be deleted when no longer in use 139 140 unsigned int mRefCount; 141 142 ResourceManager *mResourceManager; 143 rx::Renderer *mRenderer; 144 const GLuint mHandle; 145 146 InfoLog mInfoLog; 147 }; 148 } 149 150 #endif // LIBGLESV2_PROGRAM_H_ 151