1 // SwiftShader Software Renderer
\r
3 // Copyright(c) 2005-2013 TransGaming Inc.
\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
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
17 #ifndef LIBGL_SHADER_H_
\r
18 #define LIBGL_SHADER_H_
\r
20 #include "ResourceManager.h"
\r
22 #include "compiler/TranslatorASM.h"
\r
25 #include <GLES2/gl2.h>
\r
38 class Shader : public sh::Shader
\r
40 friend class Program;
\r
43 Shader(ResourceManager *manager, GLuint handle);
\r
47 virtual GLenum getType() = 0;
\r
48 GLuint getHandle() const;
\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
57 virtual void compile() = 0;
\r
62 unsigned int getRefCount() const;
\r
63 bool isFlaggedForDeletion() const;
\r
64 void flagForDeletion();
\r
66 static void releaseCompiler();
\r
69 static bool compilerInitialized;
\r
70 TranslatorASM *createCompiler(ShShaderType type);
\r
73 static GLenum parseType(const std::string &type);
\r
74 static bool compareVarying(const sh::Varying &x, const sh::Varying &y);
\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
84 ResourceManager *mResourceManager;
\r
87 class VertexShader : public Shader
\r
89 friend class Program;
\r
92 VertexShader(ResourceManager *manager, GLuint handle);
\r
96 virtual GLenum getType();
\r
97 virtual void compile();
\r
98 int getSemanticIndex(const std::string &attributeName);
\r
100 virtual sw::Shader *getShader() const;
\r
101 virtual sw::VertexShader *getVertexShader() const;
\r
104 sw::VertexShader *vertexShader;
\r
107 class FragmentShader : public Shader
\r
110 FragmentShader(ResourceManager *manager, GLuint handle);
\r
114 virtual GLenum getType();
\r
115 virtual void compile();
\r
117 virtual sw::Shader *getShader() const;
\r
118 virtual sw::PixelShader *getPixelShader() const;
\r
121 sw::PixelShader *pixelShader;
\r
125 #endif // LIBGL_SHADER_H_
\r