Skip to content

Commit c6c777e

Browse files
committed
support both GLES 3.0 and GL 3.2
1 parent 470104c commit c6c777e

6 files changed

Lines changed: 24 additions & 6 deletions

File tree

renderer/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ cmake_path(SET SHADERS_H NORMALIZE ${GENERATED_HEADERS}/shaders.h)
33
set(SHADERS
44
shaders/fragment.glsl
55
shaders/vertex.glsl
6+
shaders/version_300_es.glsl
7+
shaders/version_150_core.glsl
68
)
79
add_custom_command(
810
OUTPUT ${SHADERS_H}

renderer/HardwareOpenGL.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,15 @@ renderer_type Renderer_type = RENDERER_OPENGL;
6868
int WindowGL = 0;
6969

7070
struct Renderer {
71-
Renderer() : shader_{shaders::vertex, shaders::fragment, {
71+
Renderer() : shader_{
72+
std::string{kGlslVersion} + std::string{shaders::vertex},
73+
std::string{kGlslVersion} + std::string{shaders::fragment},
74+
{
7275
vertexAttrib(3, GL_FLOAT, GL_FALSE, &PosColorUV2Vertex::pos, "in_pos"),
7376
vertexAttrib(4, GL_FLOAT, GL_FALSE, &PosColorUV2Vertex::color, "in_color"),
7477
vertexAttrib(2, GL_FLOAT, GL_FALSE, &PosColorUV2Vertex::uv0, "in_uv0"),
7578
vertexAttrib(2, GL_FLOAT, GL_FALSE, &PosColorUV2Vertex::uv1, "in_uv1")
76-
}} {
79+
}} {
7780
shader_.Use();
7881

7982
// these are effectively just constants, for now
@@ -143,6 +146,13 @@ struct Renderer {
143146
glm::mat4x4 projection_;
144147
GLint texture_enable_{};
145148
ShaderProgram<PosColorUV2Vertex> shader_;
149+
150+
static constexpr auto kGlslVersion =
151+
#if defined(ANDROID)
152+
shaders::version_300_es;
153+
#else
154+
shaders::version_150_core;
155+
#endif
146156
};
147157
std::optional<Renderer> gRenderer;
148158

@@ -424,8 +434,10 @@ int opengl_Setup(oeApplication *app, int *width, int *height) {
424434
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
425435
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
426436
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
437+
#if !defined(ANDROID)
427438
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
428439
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
440+
#endif
429441
Uint32 flags = SDL_WINDOW_OPENGL;
430442

431443
if (fullscreen) {

renderer/shaders/fragment.glsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 150 core
1+
// version must be prepended to this file
22

33
/*
44
* Descent 3
@@ -18,6 +18,8 @@
1818
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21+
precision highp float;
22+
2123
in vec4 vertex_color;
2224
in vec2 vertex_uv0;
2325
in vec2 vertex_uv1;
@@ -50,9 +52,9 @@ void main()
5052
* max(texture(u_texture0, vertex_uv0), vec4(float(!bool((u_texture_enable >> 0) & 1))))
5153
* max(texture(u_texture1, vertex_uv1), vec4(float(!bool((u_texture_enable >> 1) & 1))));
5254

53-
float fog_factor = clamp((u_fog_end - length(vertex_modelview_pos)) * branchless_invert_or_zero(u_fog_end - u_fog_start), 0, 1);
55+
float fog_factor = clamp((u_fog_end - length(vertex_modelview_pos)) * branchless_invert_or_zero(u_fog_end - u_fog_start), 0.0, 1.0);
5456
// out_color is unchanged when fog_factor is 1 (ie, fog distance == u_fog_start). thus, to disable,
5557
// fog_factor must also be 1. invert u_fog_enable (so that it is 1 when disabled) and take the max.
5658
fog_factor = max(fog_factor, float(!u_fog_enable));
57-
out_color = out_color * fog_factor + (1 - fog_factor) * u_fog_color;
59+
out_color = out_color * fog_factor + (1.0 - fog_factor) * u_fog_color;
5860
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#version 150 core
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#version 300 es

renderer/shaders/vertex.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 150 core
1+
// version must be prepended to this file
22

33
/*
44
* Descent 3

0 commit comments

Comments
 (0)