28 #ifndef DISABLE_GL_FIXED
32 const char * src_ptr = shader_src.
c_str();
49 for(std::list<Shader_GL_Fixed *>::iterator it = m_shaders.begin(), iend = m_shaders.end(); it != iend; ++it)
58 m_shaders.push_back(&shader_gl_fixed);
72 #ifndef DISABLE_GL_SHADER
73 Shader_GL_Shader::Shader_GL_Shader(
const String &shader_src,
const Type &
type)
76 const char * src_ptr = shader_src.
c_str();
77 glShaderSource(m_shader, 1, reinterpret_cast<const GLchar **>(&src_ptr), 0);
89 std::cerr <<
"Shader initialization failure: " << log << std::endl;
104 for(std::list<Shader_GL_Shader *>::iterator it = m_shaders.begin(), iend = m_shaders.end(); it != iend; ++it)
113 m_shaders.push_back(&shader_gl_shader);
126 std::cerr <<
"Shader link failure: " << log << std::endl;
134 : m_constant_table(0),
137 String shader_src_full = shader_src;
142 pos = shader_src_full.
find(
"// Attributes");
143 shader_src_full = shader_src_full.
substr(0, pos) +
"struct VS_INPUT {" + shader_src_full.
substr(pos + 13);
144 pos = shader_src_full.
find(
"// Varyings");
145 shader_src_full = shader_src_full.
substr(0, pos) +
"};\nstruct VS_OUTPUT {\nfloat4 gl_Position : POSITION;" + shader_src_full.
substr(pos + 11);
146 pos = shader_src_full.
rfind(
"static");
147 pos = shader_src_full.
find(
';', pos);
148 shader_src_full = shader_src_full.
substr(0, pos + 1) +
"\n}; " + shader_src_full.
substr(pos + 1);
149 pos = shader_src_full.
find(
"static float4 gl_Position");
150 pos2 = shader_src_full.
find(
';', pos);
151 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos2 + 1);
153 std::set<String> ins;
154 std::set<String> outs;
155 outs.insert(
"gl_Position");
157 for(pos2 = shader_src_full.
find(
"uniform ");; pos2 = pos) {
158 pos = shader_src_full.
rfind(
" = ", pos2);
161 pos2 = shader_src_full.
find(
';', pos);
162 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos2);
165 pos = shader_src_full.
find(
"static ", pos);
168 pos = shader_src_full.
find(
' ', pos + 7) + 1;
169 pos2 = shader_src_full.
find(
';', pos);
171 outs.insert(shader_src_full.
substr(pos, pos2 - pos));
173 ins.insert(shader_src_full.
substr(pos, pos2 - pos));
177 pos = shader_src_full.
find(
"static ", pos);
180 pos2 = shader_src_full.
find(
';', pos);
181 String sub = shader_src_full.
substr(pos + 7, pos2 - (pos + 7));
188 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos + 7, pos2 - (pos + 7))
189 + sub + shader_src_full.
substr(pos2);
192 pos = shader_src_full.
find(
"uniform ", pos);
195 pos2 = shader_src_full.
find(
": register(", pos);
196 uniforms +=
", " + shader_src_full.
substr(pos, pos2 - pos);
197 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos2 + 14);
200 pos = shader_src_full.
find(
"void gl_main()");
201 pos2 = shader_src_full.
find(
'{', pos) + 1;
203 if(shader_src_full[pos2] ==
'}')
205 else if(shader_src_full[pos2] ==
'{')
210 String main_body = shader_src_full.
substr(pos + 14, (pos2 + 1) - (pos + 14));
212 for(std::set<String>::iterator it = ins.begin(), iend = ins.end(); it != iend; ++it) {
213 for(pos = main_body.
size();;) {
214 pos = main_body.
rfind(*it, pos);
217 main_body = main_body.
substr(0, pos) +
"v." + main_body.
substr(pos);
220 for(std::set<String>::iterator it = outs.begin(), iend = outs.end(); it != iend; ++it) {
221 for(pos = main_body.
size();;) {
222 pos = main_body.
rfind(*it, pos);
225 main_body = main_body.
substr(0, pos) +
"o." + main_body.
substr(pos);
229 shader_src_full = shader_front +
"VS_OUTPUT vs_main(const VS_INPUT v" + uniforms +
") {VS_OUTPUT o; " + main_body +
"return o;}";
235 pos = shader_src_full.
find(
"// Varyings");
236 shader_src_full = shader_src_full.
substr(0, pos) +
"struct PS_INPUT {\nfloat4 gl_Position : POSITION;" + shader_src_full.
substr(pos + 11);
237 pos = shader_src_full.
rfind(
"static");
238 pos = shader_src_full.
find(
';', pos);
239 shader_src_full = shader_src_full.
substr(0, pos + 1) +
"\n}; " + shader_src_full.
substr(pos + 1);
240 pos = shader_src_full.
find(
"static float4 gl_Color[1]");
241 pos2 = shader_src_full.
find(
';', pos);
242 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos2 + 1);
244 std::set<String> ins;
246 for(pos2 = shader_src_full.
find(
"#define GL_USES_FRAG_COLOR");; pos2 = pos) {
247 pos = shader_src_full.
rfind(
" = ", pos2);
250 pos2 = shader_src_full.
find(
';', pos);
251 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos2);
254 pos = shader_src_full.
find(
"static ", pos);
257 pos = shader_src_full.
find(
' ', pos + 7) + 1;
258 pos2 = shader_src_full.
find(
';', pos);
259 ins.insert(shader_src_full.
substr(pos, pos2 - pos));
263 pos = shader_src_full.
find(
"static ", pos);
266 pos2 = shader_src_full.
find(
';', pos);
267 String sub = shader_src_full.
substr(pos + 7, pos2 - (pos + 7));
274 shader_src_full = shader_src_full.
substr(0, pos) + shader_src_full.
substr(pos + 7, pos2 - (pos + 7))
275 + sub + shader_src_full.
substr(pos2);
278 pos = shader_src_full.
find(
"void gl_main()");
279 pos2 = shader_src_full.
find(
'{', pos) + 1;
281 if(shader_src_full[pos2] ==
'}')
283 else if(shader_src_full[pos2] ==
'{')
288 String main_body = shader_src_full.
substr(pos + 14, (pos2 + 1) - (pos + 14));
290 for(std::set<String>::iterator it = ins.begin(), iend = ins.end(); it != iend; ++it) {
291 for(pos = main_body.
size();;) {
292 pos = main_body.
rfind(*it, pos);
295 main_body = main_body.
substr(0, pos) +
"p." + main_body.
substr(pos);
298 for(pos = main_body.
size();;) {
299 pos = main_body.
rfind(
"gl_Color[0]", pos);
302 main_body = main_body.
substr(0, pos) +
"gl_Color" + main_body.
substr(pos + 11);
305 shader_src_full = shader_front +
"float4 ps_main(const PS_INPUT p" + uniforms +
") : COLOR {\nfloat4 gl_Color;" + main_body +
"return gl_Color;}";
308 std::cerr <<
"Shader Source Full:" << std::endl << shader_src_full << std::endl;
314 shader_src_full.
size(),
317 type ==
VERTEX ?
"vs_main" :
"ps_main",
318 type ==
VERTEX ?
"vs_3_0" :
"ps_3_0",
322 type ==
VERTEX ? &m_constant_table : 0);
325 std::cerr <<
"Errors:" << std::endl << reinterpret_cast<char *>(errors->GetBufferPointer());
339 if(m_constant_table) {
340 m_constant_table->Release();
349 : m_vertex_shader(0),
363 m_vertex_shader = &sdx;
366 if(m_fragment_shader)
368 m_fragment_shader = &sdx;
void attach(Shader &shader)
#define GL_FRAGMENT_SHADER
The Direct3D9 Rendering System.
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum type
#define glCreateShaderObjectARB
GL_APICALL void GL_APIENTRY glShaderSource(GLuint shader, GLsizei count, const GLchar **string, const GLint *length)
size_t find(const String &str, size_t pos=0) const
typedef HRESULT(WINAPI *LPD3DXIMTSIGNALCALLBACK)(CONST D3DXVECTOR2 *uv
virtual ~Program_GL_Shader()
virtual ~Shader_GL_Fixed()
Shader::Type type() const
#define GL_INFO_LOG_LENGTH
const char * c_str() const
GL_APICALL void GL_APIENTRY glDeleteShader(GLuint shader)
String substr(size_t pos=0, size_t n=npos) const
GL_APICALL void GL_APIENTRY glGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
static D3DXCompileShader_fcn D3DXCompileShader()
#define glCompileShaderARB
GL_APICALL GLuint GL_APIENTRY glCreateProgram(void)
GL_APICALL void GL_APIENTRY glAttachShader(GLuint program, GLuint shader)
GL_APICALL GLuint GL_APIENTRY glCreateShader(GLenum type)
GL_APICALL void GL_APIENTRY glLinkProgram(GLuint program)
LPDIRECT3DPIXELSHADER9 m_pixel_shader
GL_APICALL void GL_APIENTRY glGetShaderiv(GLuint shader, GLenum pname, GLint *params)
size_t rfind(const String &str, size_t pos=npos) const
static const size_type npos
#define GL_COMPILE_STATUS
GL_APICALL void GL_APIENTRY glCompileShader(GLuint shader)
#define glShaderSourceARB
GL_APICALL void GL_APIENTRY glGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
LPDIRECT3DVERTEXSHADER9 m_vertex_shader
A base class for Vertex_Shader and Fragment_Shader.
GL_APICALL void GL_APIENTRY glDeleteProgram(GLuint program)
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
void attach(Shader &shader)
interface ID3DXBuffer * LPD3DXBUFFER
void attach(Shader &shader)
#define glGetProgramivARB
#define GL_FRAGMENT_SHADER_ARB
GL_APICALL void GL_APIENTRY glGetProgramiv(GLuint program, GLenum pname, GLint *params)
GL_APICALL void GL_APIENTRY glDetachShader(GLuint program, GLuint shader)
#define GL_VERTEX_SHADER_ARB