1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 // Shader.h: Defines the abstract Shader class and its concrete derived
16 // classes VertexShader and FragmentShader. Implements GL shader objects and
17 // related functionality.
20 #ifndef LIBGL_SHADER_H_
21 #define LIBGL_SHADER_H_
23 #include "ResourceManager.h"
25 #include "compiler/TranslatorASM.h"
44 class Shader : public glsl::Shader
49 Shader(ResourceManager *manager, GLuint handle);
53 virtual GLenum getType() = 0;
54 GLuint getName() const;
57 void setSource(GLsizei count, const char *const *string, const GLint *length);
58 int getInfoLogLength() const;
59 void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
60 int getSourceLength() const;
61 void getSource(GLsizei bufSize, GLsizei *length, char *source);
68 unsigned int getRefCount() const;
69 bool isFlaggedForDeletion() const;
70 void flagForDeletion();
72 static void releaseCompiler();
75 static bool compilerInitialized;
76 TranslatorASM *createCompiler(GLenum shaderType);
79 static bool compareVarying(const glsl::Varying &x, const glsl::Varying &y);
85 virtual void createShader() = 0;
86 virtual void deleteShader() = 0;
89 unsigned int mRefCount; // Number of program objects this shader is attached to
90 bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
92 ResourceManager *mResourceManager;
95 class VertexShader : public Shader
100 VertexShader(ResourceManager *manager, GLuint handle);
104 virtual GLenum getType();
105 int getSemanticIndex(const std::string &attributeName);
107 virtual sw::Shader *getShader() const;
108 virtual sw::VertexShader *getVertexShader() const;
111 virtual void createShader();
112 virtual void deleteShader();
114 sw::VertexShader *vertexShader;
117 class FragmentShader : public Shader
120 FragmentShader(ResourceManager *manager, GLuint handle);
124 virtual GLenum getType();
126 virtual sw::Shader *getShader() const;
127 virtual sw::PixelShader *getPixelShader() const;
130 virtual void createShader();
131 virtual void deleteShader();
133 sw::PixelShader *pixelShader;
137 #endif // LIBGL_SHADER_H_