OSDN Git Service

Make the GLSL compiler independent of the API shader class.
[android-x86/external-swiftshader.git] / src / OpenGL / libGL / Shader.h
1 // SwiftShader Software Renderer\r
2 //\r
3 // Copyright(c) 2005-2013 TransGaming Inc.\r
4 //\r
5 // All rights reserved. No part of this software may be copied, distributed, transmitted,\r
6 // transcribed, stored in a retrieval system, translated into any human or computer\r
7 // language by any means, or disclosed to third parties without the explicit written\r
8 // agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express\r
9 // or implied, including but not limited to any patent rights, are granted to you.\r
10 //\r
11 \r
12 // Shader.h: Defines the abstract Shader class and its concrete derived\r
13 // classes VertexShader and FragmentShader. Implements GL shader objects and\r
14 // related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section\r
15 // 3.8 page 84.\r
16 \r
17 #ifndef LIBGL_SHADER_H_\r
18 #define LIBGL_SHADER_H_\r
19 \r
20 #include "ResourceManager.h"\r
21 \r
22 #include "compiler/TranslatorASM.h"\r
23 \r
24 #define GL_APICALL\r
25 #include <GLES2/gl2.h>\r
26 \r
27 #include <list>\r
28 #include <vector>\r
29 \r
30 namespace sh\r
31 {\r
32         class OutputASM;\r
33 }\r
34 \r
35 namespace es2\r
36 {\r
37 \r
38 class Shader : public sh::Shader\r
39 {\r
40     friend class Program;\r
41 \r
42 public:\r
43     Shader(ResourceManager *manager, GLuint handle);\r
44 \r
45     virtual ~Shader();\r
46 \r
47     virtual GLenum getType() = 0;\r
48     GLuint getHandle() const;\r
49 \r
50     void deleteSource();\r
51     void setSource(GLsizei count, const char *const *string, const GLint *length);\r
52     int getInfoLogLength() const;\r
53     void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);\r
54     int getSourceLength() const;\r
55     void getSource(GLsizei bufSize, GLsizei *length, char *source);\r
56 \r
57     virtual void compile() = 0;\r
58     bool isCompiled();\r
59     \r
60     void addRef();\r
61     void release();\r
62     unsigned int getRefCount() const;\r
63     bool isFlaggedForDeletion() const;\r
64     void flagForDeletion();\r
65 \r
66     static void releaseCompiler();\r
67 \r
68 protected:\r
69         static bool compilerInitialized;\r
70         TranslatorASM *createCompiler(ShShaderType type);\r
71         void clear();\r
72 \r
73     static GLenum parseType(const std::string &type);\r
74     static bool compareVarying(const sh::Varying &x, const sh::Varying &y);\r
75 \r
76         char *mSource;\r
77         char *mInfoLog;\r
78 \r
79 private:\r
80         const GLuint mHandle;\r
81     unsigned int mRefCount;     // Number of program objects this shader is attached to\r
82     bool mDeleteStatus;         // Flag to indicate that the shader can be deleted when no longer in use\r
83 \r
84         ResourceManager *mResourceManager;\r
85 };\r
86 \r
87 class VertexShader : public Shader\r
88 {\r
89     friend class Program;\r
90 \r
91 public:\r
92     VertexShader(ResourceManager *manager, GLuint handle);\r
93 \r
94     ~VertexShader();\r
95 \r
96     virtual GLenum getType();\r
97     virtual void compile();\r
98     int getSemanticIndex(const std::string &attributeName);\r
99 \r
100         virtual sw::Shader *getShader() const;\r
101         virtual sw::VertexShader *getVertexShader() const;\r
102 \r
103 private:\r
104         sw::VertexShader *vertexShader;\r
105 };\r
106 \r
107 class FragmentShader : public Shader\r
108 {\r
109 public:\r
110     FragmentShader(ResourceManager *manager, GLuint handle);\r
111 \r
112     ~FragmentShader();\r
113 \r
114     virtual GLenum getType();\r
115     virtual void compile();\r
116 \r
117         virtual sw::Shader *getShader() const;\r
118         virtual sw::PixelShader *getPixelShader() const;\r
119 \r
120 private:\r
121         sw::PixelShader *pixelShader;\r
122 };\r
123 }\r
124 \r
125 #endif   // LIBGL_SHADER_H_\r