• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
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
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
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. [OpenGL ES 2.0.24] section 2.10 page 24 and section
18 // 3.8 page 84.
19 
20 #ifndef LIBGLESV2_SHADER_H_
21 #define LIBGLESV2_SHADER_H_
22 
23 #include "ResourceManager.h"
24 
25 #include "compiler/TranslatorASM.h"
26 
27 #include <GLES2/gl2.h>
28 
29 #include <string>
30 #include <list>
31 #include <vector>
32 
33 namespace glsl
34 {
35 	class OutputASM;
36 }
37 
38 namespace es2
39 {
40 
41 class Shader : public glsl::Shader
42 {
43 	friend class Program;
44 
45 public:
46 	Shader(ResourceManager *manager, GLuint handle);
47 
48 	virtual ~Shader();
49 
50 	virtual GLenum getType() const = 0;
51 	GLuint getName() const;
52 
53 	void deleteSource();
54 	void setSource(GLsizei count, const char *const *string, const GLint *length);
55 	size_t getInfoLogLength() const;
56 	void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
57 	size_t getSourceLength() const;
58 	void getSource(GLsizei bufSize, GLsizei *length, char *source);
59 
60 	void compile();
61 	bool isCompiled();
62 
63 	void addRef();
64 	void release();
65 	unsigned int getRefCount() const;
66 	bool isFlaggedForDeletion() const;
67 	void flagForDeletion();
68 
69 	static void releaseCompiler();
70 
71 protected:
72 	static bool compilerInitialized;
73 	TranslatorASM *createCompiler(GLenum shaderType);
74 	void clear();
75 
76 	static bool compareVarying(const glsl::Varying &x, const glsl::Varying &y);
77 
78 	char *mSource;
79 	std::string infoLog;
80 
81 private:
82 	virtual void createShader() = 0;
83 	virtual void deleteShader() = 0;
84 
85 	const GLuint mHandle;
86 	unsigned int mRefCount;     // Number of program objects this shader is attached to
87 	bool mDeleteStatus;         // Flag to indicate that the shader can be deleted when no longer in use
88 
89 	ResourceManager *mResourceManager;
90 };
91 
92 class VertexShader : public Shader
93 {
94 	friend class Program;
95 
96 public:
97 	VertexShader(ResourceManager *manager, GLuint handle);
98 
99 	~VertexShader();
100 
101 	virtual GLenum getType() const;
102 	int getSemanticIndex(const std::string &attributeName) const;
103 
104 	virtual sw::Shader *getShader() const;
105 	virtual sw::VertexShader *getVertexShader() const;
106 
107 private:
108 	virtual void createShader();
109 	virtual void deleteShader();
110 
111 	sw::VertexShader *vertexShader;
112 };
113 
114 class FragmentShader : public Shader
115 {
116 public:
117 	FragmentShader(ResourceManager *manager, GLuint handle);
118 
119 	~FragmentShader();
120 
121 	virtual GLenum getType() const;
122 
123 	virtual sw::Shader *getShader() const;
124 	virtual sw::PixelShader *getPixelShader() const;
125 
126 private:
127 	virtual void createShader();
128 	virtual void deleteShader();
129 
130 	sw::PixelShader *pixelShader;
131 };
132 }
133 
134 #endif   // LIBGLESV2_SHADER_H_
135