Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / Shader.h
1 //
2 // Copyright (c) 2002-2013 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 // Shader.h: Defines the abstract gl::Shader class and its concrete derived
8 // classes VertexShader and FragmentShader. Implements GL shader objects and
9 // related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section
10 // 3.8 page 84.
11
12 #ifndef LIBGLESV2_SHADER_H_
13 #define LIBGLESV2_SHADER_H_
14
15
16 #include <string>
17 #include <list>
18 #include <vector>
19
20 #include "angle_gl.h"
21 #include <GLSLANG/ShaderLang.h>
22
23 #include "common/angleutils.h"
24 #include "libGLESv2/angletypes.h"
25
26 namespace rx
27 {
28 class ShaderImpl;
29 }
30
31 namespace gl
32 {
33 class ResourceManager;
34
35 struct PackedVarying : public sh::Varying
36 {
37     unsigned int registerIndex; // Assigned during link
38     unsigned int columnIndex; // Assigned during link, defaults to 0
39
40     PackedVarying(const sh::Varying &varying)
41       : sh::Varying(varying),
42         registerIndex(GL_INVALID_INDEX),
43         columnIndex(0)
44     {}
45
46     bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
47     bool isBuiltIn() const { return name.compare(0, 3, "gl_") == 0; }
48
49     void resetRegisterAssignment()
50     {
51         registerIndex = GL_INVALID_INDEX;
52     }
53 };
54
55 class Shader
56 {
57   public:
58     Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLuint handle);
59
60     virtual ~Shader();
61
62     GLenum getType() const { return mType; }
63     GLuint getHandle() const;
64
65     rx::ShaderImpl *getImplementation() { return mShader; }
66     const rx::ShaderImpl *getImplementation() const { return mShader; }
67
68     void deleteSource();
69     void setSource(GLsizei count, const char *const *string, const GLint *length);
70     int getInfoLogLength() const;
71     void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
72     int getSourceLength() const;
73     void getSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
74     int getTranslatedSourceLength() const;
75     void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
76     void getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const;
77
78     void compile();
79     bool isCompiled() const { return mCompiled; }
80
81     void addRef();
82     void release();
83     unsigned int getRefCount() const;
84     bool isFlaggedForDeletion() const;
85     void flagForDeletion();
86
87     const std::vector<gl::PackedVarying> &getVaryings() const;
88     const std::vector<sh::Uniform> &getUniforms() const;
89     const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const;
90     const std::vector<sh::Attribute> &getActiveAttributes() const;
91     const std::vector<sh::Attribute> &getActiveOutputVariables() const;
92
93     std::vector<gl::PackedVarying> &getVaryings();
94     std::vector<sh::Uniform> &getUniforms();
95     std::vector<sh::InterfaceBlock> &getInterfaceBlocks();
96     std::vector<sh::Attribute> &getActiveAttributes();
97     std::vector<sh::Attribute> &getActiveOutputVariables();
98
99   private:
100     DISALLOW_COPY_AND_ASSIGN(Shader);
101
102     static void getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer);
103
104     rx::ShaderImpl *mShader;
105     const GLuint mHandle;
106     const GLenum mType;
107     std::string mSource;
108     unsigned int mRefCount;     // Number of program objects this shader is attached to
109     bool mDeleteStatus;         // Flag to indicate that the shader can be deleted when no longer in use
110     bool mCompiled;             // Indicates if this shader has been successfully compiled
111
112     ResourceManager *mResourceManager;
113 };
114
115 }
116
117 #endif   // LIBGLESV2_SHADER_H_