21 #include <GLES3/gl3.h>
27 #include "primitives.h"
31 #ifndef GL_EXT_shader_pixel_local_storage
32 #define GL_EXT_shader_pixel_local_storage 1
33 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_FAST_SIZE_EXT 0x8F63
34 #define GL_MAX_SHADER_PIXEL_LOCAL_STORAGE_SIZE_EXT 0x8F67
35 #define GL_SHADER_PIXEL_LOCAL_STORAGE_EXT 0x8F64
101 std::string ext = std::string((
const char*)glGetString(GL_EXTENSIONS));
102 ASSERT(ext.find(
"GL_EXT_shader_pixel_local_storage") != std::string::npos,
"This device does not support shader pixel local storage");
104 string res =
"/data/data/com.arm.malideveloper.openglessdk.translucency/files/";
150 light_pos[0] =
vec3(-1.0 + 2.0 * alpha, 0.0, 0.0);
151 light_pos[1] =
vec3(0.8 - 2.0 * alpha, 0.0, 0.0);
162 if (normal)
attribfv(
"normal", 3, 8, 5);
163 glDrawElements(GL_TRIANGLES, teapot.
num_indices, GL_UNSIGNED_INT, 0);
171 if (normal)
attribfv(
"normal", 3, 6, 3);
172 glDrawElements(GL_TRIANGLES, sphere.
num_indices, GL_UNSIGNED_INT, 0);
180 if (normal)
attribfv(
"normal", 3, 6, 3);
181 glDrawElements(GL_TRIANGLES, cube.
num_indices, GL_UNSIGNED_INT, 0);
189 GLenum cmp = second_pass ? GL_EQUAL : GL_ALWAYS;
190 bool use_albedo = !second_pass;
191 bool use_normal = !second_pass;
194 glStencilFunc(cmp, 1, 0xFF);
198 glStencilFunc(cmp, 2, 0xFF);
202 glStencilFunc(cmp, 3, 0xFF);
207 if (use_albedo)
uniform(
"albedo", light_color[i]);
208 glStencilFunc(cmp, i + 4, 0xFF);
233 uniform(
"lightColor", light_color[i]);
236 glDrawElements(GL_TRIANGLES, quad.
num_indices, GL_UNSIGNED_INT, 0);
245 uniform(
"lightPos0", light_pos[0]);
246 uniform(
"lightPos1", light_pos[1]);
247 uniform(
"lightCol0", light_color[0]);
248 uniform(
"lightCol1", light_color[1]);
259 glDrawElements(GL_TRIANGLES, quad.
num_indices, GL_UNSIGNED_INT, 0);
265 glEnable(GL_DEPTH_TEST);
266 glEnable(GL_STENCIL_TEST);
268 glDepthMask(GL_TRUE);
271 glClearColor(0.0
f, 0.0
f, 0.0
f, 0.0
f);
272 glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
277 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
278 glStencilFunc(GL_ALWAYS, 0, 0xFF);
302 glStencilFunc(GL_LEQUAL, 1, 0xFF);
303 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
307 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
308 glStencilFunc(GL_ALWAYS, 0, 0xFF);
310 glDisable(GL_STENCIL_TEST);
314 GLenum to_invalidate[] = { GL_DEPTH, GL_STENCIL };
315 glInvalidateFramebuffer(GL_FRAMEBUFFER, 2, to_invalidate);
static float s_distortion
void on_pointer_down(float x, float y)
#define attribfv(prog, name, n, offset)
void render_pass_opaque()
GLint GLsizei GLsizei height
bool load_from_file(const string *paths, GLenum *types, int count)
void render_cube(mat4 model, bool normal=true)
float light_intensity[num_lights]
#define GL_SHADER_PIXEL_LOCAL_STORAGE_EXT
void render_sphere(mat4 model, bool normal=true)
static mat4 rotateY(float rad)
Mesh gen_normal_sphere(int t_samples, int s_samples)
bool load_mesh_binary(Mesh &mesh, string path)
void on_pointer_up(float x, float y)
void render_pass_thickness(bool second_pass)
static mat4 rotateX(float rad)
void render_pass_shading()
void init_app(int width, int height)
void cull(bool enabled, GLenum front, GLenum mode)
void uniform(string name, const mat4 &v)
GLint GLint GLint GLint GLint x
void render_pass_resolve()
static float smoothstep(float edge0, float edge1, float t)
void use_shader(Shader shader)
void render_teapot(mat4 model, bool normal=true)
static float aspect_ratio
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
void depth_write(bool enabled)
double get_elapsed_time()
float light_radius[num_lights]
static mat4 translate(float x, float y, float z)
void depth_test(bool enabled, GLenum func)
void render_app(float dt)
void update_app(float dt)