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