diff --git a/shaders/blend_amap_alpha.f.glsl b/shaders/blend_amap_alpha.f.glsl index 6adb70b..1f46f9d 100644 --- a/shaders/blend_amap_alpha.f.glsl +++ b/shaders/blend_amap_alpha.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float threshold; diff --git a/shaders/blend_amap_color.f.glsl b/shaders/blend_amap_color.f.glsl index c1c4353..5250bf6 100644 --- a/shaders/blend_amap_color.f.glsl +++ b/shaders/blend_amap_color.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform vec4 color; diff --git a/shaders/copy.f.glsl b/shaders/copy.f.glsl index 6363711..46c53c3 100644 --- a/shaders/copy.f.glsl +++ b/shaders/copy.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; in vec2 tex_coord; diff --git a/shaders/copy_alpha_key.f.glsl b/shaders/copy_alpha_key.f.glsl index 2aaeaeb..03c3a12 100644 --- a/shaders/copy_alpha_key.f.glsl +++ b/shaders/copy_alpha_key.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform vec4 color; diff --git a/shaders/copy_color_reverse.f.glsl b/shaders/copy_color_reverse.f.glsl index 4160336..7a491af 100644 --- a/shaders/copy_color_reverse.f.glsl +++ b/shaders/copy_color_reverse.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; in vec2 tex_coord; diff --git a/shaders/copy_key.f.glsl b/shaders/copy_key.f.glsl index 4ab69e4..3c33ff0 100644 --- a/shaders/copy_key.f.glsl +++ b/shaders/copy_key.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform vec4 color; diff --git a/shaders/copy_use_amap_border.f.glsl b/shaders/copy_use_amap_border.f.glsl index ef1f4da..f11ba31 100644 --- a/shaders/copy_use_amap_border.f.glsl +++ b/shaders/copy_use_amap_border.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float threshold; diff --git a/shaders/copy_use_amap_under.f.glsl b/shaders/copy_use_amap_under.f.glsl index 342713c..3a57319 100644 --- a/shaders/copy_use_amap_under.f.glsl +++ b/shaders/copy_use_amap_under.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float threshold; diff --git a/shaders/dungeon.f.glsl b/shaders/dungeon.f.glsl index 0e7c456..cb60d00 100644 --- a/shaders/dungeon.f.glsl +++ b/shaders/dungeon.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float alpha_mod; diff --git a/shaders/dungeon.v.glsl b/shaders/dungeon.v.glsl index 4cfe35f..4828602 100644 --- a/shaders/dungeon.v.glsl +++ b/shaders/dungeon.v.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform mat4 local_transform; uniform mat4 view_transform; uniform mat4 proj_transform; diff --git a/shaders/dungeon_skybox.f.glsl b/shaders/dungeon_skybox.f.glsl index 2ef08a0..fdb1aab 100644 --- a/shaders/dungeon_skybox.f.glsl +++ b/shaders/dungeon_skybox.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform samplerCube tex; in vec3 tex_coord; diff --git a/shaders/dungeon_skybox.v.glsl b/shaders/dungeon_skybox.v.glsl index 6f36502..18f7ea3 100644 --- a/shaders/dungeon_skybox.v.glsl +++ b/shaders/dungeon_skybox.v.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform mat4 view_transform; uniform mat4 proj_transform; diff --git a/shaders/fill.f.glsl b/shaders/fill.f.glsl index 1dce654..27d5c84 100644 --- a/shaders/fill.f.glsl +++ b/shaders/fill.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform vec4 color; in vec2 tex_coord; diff --git a/shaders/fill_amap_over_border.f.glsl b/shaders/fill_amap_over_border.f.glsl index 88b5310..a5f4835 100644 --- a/shaders/fill_amap_over_border.f.glsl +++ b/shaders/fill_amap_over_border.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float threshold; uniform vec4 color; diff --git a/shaders/fill_amap_under_border.f.glsl b/shaders/fill_amap_under_border.f.glsl index 02406e8..df6839d 100644 --- a/shaders/fill_amap_under_border.f.glsl +++ b/shaders/fill_amap_under_border.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float threshold; uniform vec4 color; diff --git a/shaders/hitbox.f.glsl b/shaders/hitbox.f.glsl index d0602b6..e1e3e4a 100644 --- a/shaders/hitbox.f.glsl +++ b/shaders/hitbox.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform vec2 bot_left; uniform vec2 top_right; @@ -29,11 +27,11 @@ float point_in_rect(vec2 p, vec2 bot_left, vec2 top_right) { } void main() { - ivec2 size = textureSize(tex, 0); + vec2 size = vec2(textureSize(tex, 0)); vec2 tex_bot_left = bot_left / size; vec2 tex_top_right = top_right / size; vec4 texel = texture(tex, tex_coord); float t = point_in_rect(tex_coord, tex_bot_left, tex_top_right); - frag_color = t * texel + (1 - t) * vec4(0, 0, 0, 0); + frag_color = t * texel + (1.0 - t) * vec4(0, 0, 0, 0); } diff --git a/shaders/hitbox_noblend.f.glsl b/shaders/hitbox_noblend.f.glsl index 9c13e00..f935441 100644 --- a/shaders/hitbox_noblend.f.glsl +++ b/shaders/hitbox_noblend.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform vec2 bot_left; uniform vec2 top_right; @@ -29,12 +27,12 @@ float point_in_rect(vec2 p, vec2 bot_left, vec2 top_right) { } void main() { - ivec2 size = textureSize(tex, 0); + vec2 size = vec2(textureSize(tex, 0)); vec2 tex_bot_left = bot_left / size; vec2 tex_top_right = top_right / size; vec4 texel = texture(tex, tex_coord); - texel.a = 1; + texel.a = 1.0; float t = point_in_rect(tex_coord, tex_bot_left, tex_top_right); - frag_color = t * texel + (1 - t) * vec4(0, 0, 0, 0); + frag_color = t * texel + (1.0 - t) * vec4(0, 0, 0, 0); } diff --git a/shaders/render.f.glsl b/shaders/render.f.glsl index d3f73ae..d7131e7 100644 --- a/shaders/render.f.glsl +++ b/shaders/render.f.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform sampler2D tex; uniform float alpha_mod; diff --git a/shaders/render.v.glsl b/shaders/render.v.glsl index e76cec5..711a935 100644 --- a/shaders/render.v.glsl +++ b/shaders/render.v.glsl @@ -14,8 +14,6 @@ * along with this program; if not, see . */ -#version 140 - uniform mat4 world_transform; uniform mat4 view_transform; diff --git a/src/video.c b/src/video.c index 0cd6644..da0e22c 100644 --- a/src/video.c +++ b/src/video.c @@ -32,6 +32,19 @@ struct sdl_private sdl; +/* + * Define this to target OpenGL ES 3.0. + */ +//#define USE_GLES + +static const GLchar glsl_preamble[] = +#ifdef USE_GLES + "#version 300 es\n" + "precision highp float;\n"; +#else + "#version 140\n"; +#endif + /* * Transform from the window coordinate system -> clip-space. * @@ -84,16 +97,17 @@ static GLuint load_shader_file(const char *path, GLenum type) { GLint shader_compiled; GLuint shader; - const GLchar *source; - - source = read_shader_file(path); + const GLchar *source[2] = { + glsl_preamble, + read_shader_file(path) + }; shader = glCreateShader(type); - glShaderSource(shader, 1, &source, NULL); + glShaderSource(shader, 2, source, NULL); glCompileShader(shader); glGetShaderiv(shader, GL_COMPILE_STATUS, &shader_compiled); if (!shader_compiled) ERROR("Failed to compile shader: %s", path); - free((char*)source); + free((char*)source[1]); return shader; } @@ -164,9 +178,15 @@ int gfx_init(void) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) ERROR("SDL_Init failed: %s", SDL_GetError()); +#ifdef USE_GLES + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); +#else SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); +#endif sdl.format = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA32); sdl.window = SDL_CreateWindow("XSystem4", @@ -455,7 +475,7 @@ void gfx_init_texture_blank(struct texture *t, int w, int h) void gfx_copy_main_surface(struct texture *dst) { init_texture(dst, main_surface.w, main_surface.h); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, main_surface.w, main_surface.h, 0); + glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, main_surface.w, main_surface.h, 0); } void gfx_delete_texture(struct texture *t)