Skip to content

Commit fac6c34

Browse files
Maeikyslembcke
authored andcommitted
Adapt demo to GLES 3
1 parent 7d10641 commit fac6c34

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

demo/ChipmunkDebugDraw.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
cpTransform ChipmunkDebugDrawVPMatrix;
3232
float ChipmunkDebugDrawPointLineScale = 1.0f;
3333

34-
#define GLSL33(x) "#version 330\n" #x
34+
#ifdef SOKOL_GLCORE33
35+
#define GLSL(x) "#version 330\n" #x
36+
#endif
37+
#ifdef SOKOL_GLES3
38+
#define GLSL(x) "#version 300 es\n" #x
39+
#endif
40+
3541

3642
static sg_bindings bindings;
3743
static sg_pipeline pipeline;
@@ -84,7 +90,7 @@ ChipmunkDebugDrawInit(void)
8490
.size = sizeof(Uniforms),
8591
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
8692
},
87-
.vs.source = GLSL33(
93+
.vs.source = GLSL(
8894
layout(location = 0) in vec2 IN_pos;
8995
layout(location = 1) in vec2 IN_uv;
9096
layout(location = 2) in float IN_radius;
@@ -100,15 +106,16 @@ ChipmunkDebugDrawInit(void)
100106
} FRAG;
101107

102108
void main(){
103-
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0, 1);
109+
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0.0, 1.0);
104110
FRAG.uv = IN_uv;
105111
FRAG.fill = IN_fill;
106112
FRAG.fill.rgb *= IN_fill.a;
107113
FRAG.outline = IN_outline;
108114
FRAG.outline.a *= IN_outline.a;
109115
}
110116
),
111-
.fs.source = GLSL33(
117+
.fs.source = GLSL(
118+
precision mediump float;
112119
in struct {
113120
vec2 uv;
114121
vec4 fill;
@@ -120,9 +127,9 @@ ChipmunkDebugDrawInit(void)
120127
void main(){
121128
float len = length(FRAG.uv);
122129
float fw = length(fwidth(FRAG.uv));
123-
float mask = smoothstep(-1, fw - 1, -len);
130+
float mask = smoothstep(-1.0, fw - 1.0, -len);
124131

125-
float outline = 1 - fw;
132+
float outline = 1.0 - fw;
126133
float outline_mask = smoothstep(outline - fw, outline, len);
127134
vec4 color = FRAG.fill + (FRAG.outline - FRAG.fill*FRAG.outline.a)*outline_mask;
128135
OUT_color = color*mask;

demo/ChipmunkDemoTextSupport.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ static int glyph_indexes[256];
3939

4040
cpTransform ChipmunkDemoTextMatrix;
4141

42-
#define GLSL33(x) "#version 330\n" #x
42+
#ifdef SOKOL_GLCORE33
43+
#define GLSL(x) "#version 330\n" #x
44+
#endif
45+
#ifdef SOKOL_GLES3
46+
#define GLSL(x) "#version 300 es\n" #x
47+
#endif
4348

4449
static sg_bindings bindings;
4550
static sg_pipeline pipeline;
@@ -102,7 +107,7 @@ ChipmunkDemoTextInit(void)
102107
.size = sizeof(Uniforms),
103108
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
104109
},
105-
.vs.source = GLSL33(
110+
.vs.source = GLSL(
106111
layout(location = 0) in vec2 IN_pos;
107112
layout(location = 1) in vec2 IN_uv;
108113
layout(location = 2) in vec4 IN_color;
@@ -115,13 +120,14 @@ ChipmunkDemoTextInit(void)
115120
} FRAG;
116121

117122
void main(){
118-
gl_Position = U_vp_matrix*vec4(IN_pos, 0, 1);
123+
gl_Position = U_vp_matrix*vec4(IN_pos, 0.0, 1.0);
119124
FRAG.uv = IN_uv;
120125
FRAG.color = IN_color;
121126
}
122127
),
123128
.fs.images[0] = {.name = "U_texture", .type = SG_IMAGETYPE_2D},
124-
.fs.source = GLSL33(
129+
.fs.source = GLSL(
130+
precision mediump float;
125131
in struct {
126132
vec2 uv;
127133
vec4 color;

demo/sokol/sokol.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#define SOKOL_WIN32_FORCE_MAIN
2+
#ifndef SOKOL_GLES3
23
#define SOKOL_GLCORE33
4+
#end
35
#include "sokol_app.h"
46
#include "sokol_time.h"
57
#include "sokol_gfx.h"

0 commit comments

Comments
 (0)