zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Shader.h
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * zenilib is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * zenilib is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
74 #ifndef ZENI_SHADER_H
75 #define ZENI_SHADER_H
76 
77 #include <Zeni/Core.h>
78 #include <Zeni/Hash_Map.h>
79 
80 #ifndef DISABLE_GL
81 #if defined(REQUIRE_GL_ES)
82 #include <GLES/gl.h>
83 #else
84 #include <GL/glew.h>
85 #endif
86 
90 
91 namespace Zeni {
92 
93  class ZENI_GRAPHICS_DLL Video_DX9;
94  class ZENI_GRAPHICS_DLL Video_GL_Fixed;
95  class ZENI_GRAPHICS_DLL Video_GL_Shader;
96 
97  class ZENI_GRAPHICS_DLL Shader {
98  Shader(const Shader &);
99  Shader & operator=(const Shader &);
100 
101  public:
102  enum Type {VERTEX, FRAGMENT};
103 
104  Shader() {}
105  virtual ~Shader() {}
106  };
107 
108  class ZENI_GRAPHICS_DLL Program {
109  Program(const Program &);
110  Program & operator=(const Program &);
111 
112  public:
113  Program() {}
114  virtual ~Program() {}
115 
116  virtual void attach(Shader &shader) = 0;
117  virtual void link() = 0;
118  };
119 
120 #ifndef DISABLE_GL_FIXED
121  class ZENI_GRAPHICS_DLL Shader_GL_Fixed : public Shader {
123  Shader_GL_Fixed & operator=(const Shader_GL_Fixed &);
124 
125  public:
126  Shader_GL_Fixed(const String &shader_src, const Type &type);
127  virtual ~Shader_GL_Fixed();
128 
129  inline GLuint get() const;
130 
131  private:
132  GLuint m_shader;
133  };
134 
135  class ZENI_GRAPHICS_DLL Program_GL_Fixed : public Program {
137  Program_GL_Fixed & operator=(const Program_GL_Fixed &);
138 
139  public:
140  Program_GL_Fixed();
141  ~Program_GL_Fixed();
142 
143  void attach(Shader &shader);
144  void link();
145 
146  inline GLuint get() const;
147 
148  private:
149 #ifdef _WINDOWS
150 #pragma warning( push )
151 #pragma warning( disable : 4251 )
152 #endif
153  std::list<Shader_GL_Fixed *> m_shaders;
154 #ifdef _WINDOWS
155 #pragma warning( pop )
156 #endif
157  GLuint m_program;
158  };
159 #endif
160 
161 #ifndef DISABLE_GL_SHADER
162  class ZENI_GRAPHICS_DLL Shader_GL_Shader : public Shader {
164  Shader_GL_Shader & operator=(const Shader_GL_Shader &);
165 
166  public:
167  Shader_GL_Shader(const String &shader_src, const Type &type);
168  ~Shader_GL_Shader();
169 
170  inline GLuint get() const;
171 
172  private:
173  GLuint m_shader;
174  };
175 
176  class ZENI_GRAPHICS_DLL Program_GL_Shader : public Program {
178  Program_GL_Shader & operator=(const Program_GL_Shader &);
179 
180  public:
181  Program_GL_Shader();
182  virtual ~Program_GL_Shader();
183 
184  void attach(Shader &shader);
185  void link();
186 
187  inline GLuint get() const;
188 
189  private:
190 #ifdef _WINDOWS
191 #pragma warning( push )
192 #pragma warning( disable : 4251 )
193 #endif
194  std::list<Shader_GL_Shader *> m_shaders;
195 #ifdef _WINDOWS
196 #pragma warning( pop )
197 #endif
198  GLuint m_program;
199  };
200 #endif
201 
202 #ifndef DISABLE_DX9
203  class ZENI_GRAPHICS_DLL Shader_DX9 : public Shader {
204  Shader_DX9(const Shader_DX9 &);
205  Shader_DX9 & operator=(const Shader_DX9 &);
206 
207  public:
208  Shader_DX9(const String &shader_src, const Type &type, Video_DX9 &vdx);
209  ~Shader_DX9();
210 
211  inline Shader::Type type() const;
212  inline LPD3DXCONSTANTTABLE get_constant_table() const;
213  inline LPDIRECT3DVERTEXSHADER9 get_vertex_shader() const;
214  inline LPDIRECT3DPIXELSHADER9 get_pixel_shader() const;
215 
216  private:
217  LPD3DXCONSTANTTABLE m_constant_table;
218  union {
221  };
222  };
223 
224  class ZENI_GRAPHICS_DLL Program_DX9 : public Program {
225  Program_DX9(const Program_DX9 &);
226  Program_DX9 & operator=(const Program_DX9 &);
227 
228  public:
229  Program_DX9();
230  virtual ~Program_DX9();
231 
232  void attach(Shader &shader);
233  void link();
234 
235  inline const Shader_DX9 * get_vertex_shader() const;
236  inline const Shader_DX9 * get_fragment_shader() const;
237 
238  private:
239  Shader_DX9 * m_vertex_shader;
240  Shader_DX9 * m_fragment_shader;
241  };
242 #endif
243 
244  struct ZENI_GRAPHICS_DLL Shader_Init_Failure : public Error {
245  Shader_Init_Failure() : Error("Zeni Shader Failed to Initialize Correctly") {}
246  };
247 
248  struct ZENI_GRAPHICS_DLL Shader_Link_Failure : public Error {
249  Shader_Link_Failure() : Error("Zeni Shader Failed to Link Correctly") {}
250  };
251 
252 }
253 
254 #endif
255 
256 #endif
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
Definition: gl2ext.h:845
interface IDirect3DVertexShader9 IDirect3DVertexShader9
Definition: d3d9.h:260
struct IDirect3DVertexShader9 * LPDIRECT3DVERTEXSHADER9
Definition: d3d9.h:1040
interface ID3DXConstantTable ID3DXConstantTable
Definition: d3dx9shader.h:268
struct IDirect3DPixelShader9 * LPDIRECT3DPIXELSHADER9
Definition: d3d9.h:1079
interface ID3DXConstantTable * LPD3DXCONSTANTTABLE
Definition: d3dx9shader.h:269
GLuint shader
Definition: glew.h:1799
LPDIRECT3DPIXELSHADER9 m_pixel_shader
Definition: Shader.h:220
interface IDirect3DPixelShader9 IDirect3DPixelShader9
Definition: d3d9.h:261
LPDIRECT3DVERTEXSHADER9 m_vertex_shader
Definition: Shader.h:219
A base class for Vertex_Shader and Fragment_Shader.
Definition: Shader.h:97
unsigned int GLuint
Definition: gl2.h:32
virtual ~Program()
Definition: Shader.h:114
The Error Class.
Definition: Error.h:52
virtual ~Shader()
Definition: Shader.h:105