Home | History | Annotate | Download | only in libGLESv2
      1 //
      2 // Copyright (c) 2002-2012 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 
     20 namespace rx
     21 {
     22 class Renderer;
     23 }
     24 
     25 namespace gl
     26 {
     27 class ResourceManager;
     28 class FragmentShader;
     29 class VertexShader;
     30 class ProgramBinary;
     31 class Shader;
     32 
     33 extern const char * const g_fakepath;
     34 
     35 class 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 
     48 class 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 
     65 class 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();
     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     void addRef();
     96     void release();
     97     unsigned int getRefCount() const;
     98     void flagForDeletion();
     99     bool isFlaggedForDeletion() const;
    100 
    101     void validate();
    102     bool isValidated() const;
    103 
    104     GLint getProgramBinaryLength() const;
    105 
    106   private:
    107     DISALLOW_COPY_AND_ASSIGN(Program);
    108 
    109     void unlink(bool destroy = false);
    110 
    111     FragmentShader *mFragmentShader;
    112     VertexShader *mVertexShader;
    113 
    114     AttributeBindings mAttributeBindings;
    115 
    116     BindingPointer<ProgramBinary> mProgramBinary;
    117     bool mLinked;
    118     bool mDeleteStatus;   // Flag to indicate that the program can be deleted when no longer in use
    119 
    120     unsigned int mRefCount;
    121 
    122     ResourceManager *mResourceManager;
    123     rx::Renderer *mRenderer;
    124     const GLuint mHandle;
    125 
    126     InfoLog mInfoLog;
    127 };
    128 }
    129 
    130 #endif   // LIBGLESV2_PROGRAM_H_
    131