Browse Source

gpu: try to patch some simple GLSL shaders on the fly so that they

work on OpenGL ES contexts.
legacy
Sam Hocevar sam 13 years ago
parent
commit
23ab462042
3 changed files with 28 additions and 17 deletions
  1. +2
    -9
      src/easymesh/shiny.lolfx
  2. +24
    -6
      src/gpu/shader.cpp
  3. +2
    -2
      tutorial/11_fractal.lolfx

+ 2
- 9
src/easymesh/shiny.lolfx View File

@@ -1,10 +1,6 @@


-- GLSL.Vert -- -- GLSL.Vert --
#if defined GL_ES
#version 100
#else
#version 120 #version 120
#endif


attribute vec3 in_Vertex; attribute vec3 in_Vertex;
attribute vec3 in_Normal; attribute vec3 in_Normal;
@@ -13,7 +9,8 @@ attribute vec4 in_Color;
uniform mat4 in_ModelView; uniform mat4 in_ModelView;
uniform mat4 in_Proj; uniform mat4 in_Proj;
uniform mat3 in_NormalMat; uniform mat3 in_NormalMat;
uniform vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
// FIXME: the light direction should be passed in the code
vec3 in_LightDir = vec3(0.3, 0.3, 0.7);
uniform float in_Damage; uniform float in_Damage;


varying vec4 pass_Color; varying vec4 pass_Color;
@@ -53,11 +50,7 @@ void main(void)
} }


-- GLSL.Frag -- -- GLSL.Frag --
#if defined GL_ES
#version 100
#else
#version 120 #version 120
#endif


#if defined GL_ES #if defined GL_ES
precision highp float; precision highp float;


+ 24
- 6
src/gpu/shader.cpp View File

@@ -216,7 +216,7 @@ Shader::Shader(char const *vert, char const *frag)
Log::Error("failed to compile vertex shader: %s", errbuf); Log::Error("failed to compile vertex shader: %s", errbuf);
Log::Error("shader source:\n%s\n", buf); Log::Error("shader source:\n%s\n", buf);
} }
else if (len > 1)
else if (len > 16)
{ {
Log::Debug("compile log for vertex shader: %s", errbuf); Log::Debug("compile log for vertex shader: %s", errbuf);
Log::Debug("shader source:\n%s\n", buf); Log::Debug("shader source:\n%s\n", buf);
@@ -260,7 +260,7 @@ Shader::Shader(char const *vert, char const *frag)
Log::Error("failed to compile fragment shader: %s", errbuf); Log::Error("failed to compile fragment shader: %s", errbuf);
Log::Error("shader source:\n%s\n", buf); Log::Error("shader source:\n%s\n", buf);
} }
else if (len > 1)
else if (len > 16)
{ {
Log::Debug("compile log for fragment shader: %s", errbuf); Log::Debug("compile log for fragment shader: %s", errbuf);
Log::Debug("shader source:\n%s\n", buf); Log::Debug("shader source:\n%s\n", buf);
@@ -308,7 +308,7 @@ Shader::Shader(char const *vert, char const *frag)
{ {
Log::Error("failed to link program: %s", errbuf); Log::Error("failed to link program: %s", errbuf);
} }
else if (len > 1)
else if (len > 16)
{ {
Log::Debug("link log for program: %s", errbuf); Log::Debug("link log for program: %s", errbuf);
} }
@@ -610,6 +610,10 @@ int ShaderData::GetVersion()
#if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__ #if !defined USE_D3D9 && !defined _XBOX && !defined __CELLOS_LV2__
if (!version) if (!version)
{ {
#if defined HAVE_GLES_2X
/* GLES 2.x supports #version 100, that's all. */
return 100;
#else
char buf[4096]; char buf[4096];
GLsizei len; GLsizei len;


@@ -643,6 +647,7 @@ int ShaderData::GetVersion()
version = 110; version = 110;


glDeleteShader(id); glDeleteShader(id);
#endif
} }
#endif #endif


@@ -650,9 +655,6 @@ int ShaderData::GetVersion()
} }


/* Simple shader source patching for old GLSL versions. /* Simple shader source patching for old GLSL versions.
* If supported version is 1.30, do nothing.
* If supported version is 1.20:
* - replace "#version 130" with "#version 120"
*/ */
void ShaderData::Patch(char *dst, char const *vert, char const *frag) void ShaderData::Patch(char *dst, char const *vert, char const *frag)
{ {
@@ -667,6 +669,22 @@ void ShaderData::Patch(char *dst, char const *vert, char const *frag)
if (parser) if (parser)
ver_shader = atoi(parser + strlen("#version")); ver_shader = atoi(parser + strlen("#version"));


/* This is GL ES, we only know version 100. */
if (ver_shader > 100 && ver_driver == 100)
{
/* FIXME: this isn't elegant but honestly, we don't care, this
* whole file is going to die soon. */
char *p = strstr(dst, "#version");
if (p)
{
p += 8;
while (*p == ' ')
p++;
if (p[0] == '1' && p[1] && p[2])
p[1] = p[2] = '0';
}
}

if (ver_shader > 120 && ver_driver <= 120) if (ver_shader > 120 && ver_driver <= 120)
{ {
char const *end = dst + strlen(dst) + 1; char const *end = dst + strlen(dst) + 1;


+ 2
- 2
tutorial/11_fractal.lolfx View File

@@ -2,7 +2,7 @@


#version 120 #version 120


#if defined HAVE_GLES_2X
#if defined GL_ES
precision highp float; precision highp float;
#endif #endif


@@ -53,7 +53,7 @@ void main(void)


#version 120 #version 120


#if defined HAVE_GLES_2X
#if defined GL_ES
precision highp float; precision highp float;
#endif #endif




Loading…
Cancel
Save