From 2233b12daaa29240957c092805985d074f3b398a Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 12 May 2020 21:31:44 +0200 Subject: [PATCH] some gles3 code --- premake5.lua | 3 +++ src/gl/gl3device.cpp | 30 ++++++++++++++++++++++++++++-- src/gl/gl3immed.cpp | 8 ++++---- src/gl/gl3matfx.cpp | 4 ++-- src/gl/gl3raster.cpp | 4 +++- src/gl/gl3skin.cpp | 4 ++-- src/gl/rwgl3.h | 1 + src/gl/shaders/header.vert | 8 +++----- src/gl/shaders/header_vs.inc | 9 ++++----- src/gl/shaders/matfx_env.frag | 2 -- src/gl/shaders/matfx_gl3.inc | 3 +-- src/gl/shaders/simple.frag | 2 -- src/gl/shaders/simple_fs_gl3.inc | 2 -- 13 files changed, 51 insertions(+), 29 deletions(-) diff --git a/premake5.lua b/premake5.lua index abb0686..05cec14 100644 --- a/premake5.lua +++ b/premake5.lua @@ -49,6 +49,7 @@ workspace "librw" filter { "system:linux" } platforms { "linux-x86-null", "linux-x86-gl3", "linux-amd64-null", "linux-amd64-gl3", + "linux-arm-null", "linux-arm-gl3", "ps2" } if _OPTIONS["gfxlib"] == "sdl2" then includedirs { "/usr/include/SDL2" } @@ -85,6 +86,8 @@ workspace "librw" architecture "x86_64" filter { "platforms:*x86*" } architecture "x86" + filter { "platforms:*arm*" } + architecture "ARM" filter { "platforms:win*" } system "windows" diff --git a/src/gl/gl3device.cpp b/src/gl/gl3device.cpp index c209aff..7eee33b 100644 --- a/src/gl/gl3device.cpp +++ b/src/gl/gl3device.cpp @@ -97,6 +97,18 @@ struct UniformObject UniformLight spotLights[MAX_LIGHTS]; }; +const char *shaderDecl330 = "#version 330\n"; +const char *shaderDecl310es = +"#version 310 es\n"\ +"precision highp float;\n"\ +"precision highp int;\n"; + +#ifdef RW_GLES3 +const char *shaderDecl = shaderDecl310es; +#else +const char *vertShaderDecl = shaderDecl330; +#endif + static GLuint vao; static GLuint ubo_state, ubo_scene, ubo_object; static GLuint whitetex; @@ -1019,10 +1031,17 @@ openGLFW(EngineOpenParams *openparams) return 0; } glfwWindowHint(GLFW_SAMPLES, 0); +#ifdef RW_GLES3 + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); +#else + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); +#endif glGlobals.monitor = glfwGetMonitors(&glGlobals.numMonitors)[0]; @@ -1038,6 +1057,12 @@ closeGLFW(void) return 1; } +static void +glfwerr(int error, const char *desc) +{ + fprintf(stderr, "GLFW Error: %s\n", desc); +} + static int startGLFW(void) { @@ -1047,6 +1072,7 @@ startGLFW(void) mode = &glGlobals.modes[glGlobals.currentMode]; + glfwSetErrorCallback(glfwerr); glfwWindowHint(GLFW_RED_BITS, mode->mode.redBits); glfwWindowHint(GLFW_GREEN_BITS, mode->mode.greenBits); glfwWindowHint(GLFW_BLUE_BITS, mode->mode.blueBits); @@ -1137,8 +1163,8 @@ initOpenGL(void) #include "shaders/default_vs_gl3.inc" #include "shaders/simple_fs_gl3.inc" - const char *vs[] = { header_vert_src, default_vert_src, nil }; - const char *fs[] = { simple_frag_src, nil }; + const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil }; + const char *fs[] = { shaderDecl, simple_frag_src, nil }; defaultShader = Shader::create(vs, fs); assert(defaultShader); diff --git a/src/gl/gl3immed.cpp b/src/gl/gl3immed.cpp index 1b98920..387a837 100644 --- a/src/gl/gl3immed.cpp +++ b/src/gl/gl3immed.cpp @@ -52,8 +52,8 @@ openIm2D(void) #include "shaders/im2d_gl3.inc" #include "shaders/simple_fs_gl3.inc" - const char *vs[] = { header_vert_src, im2d_vert_src, nil }; - const char *fs[] = { simple_frag_src, nil }; + const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil }; + const char *fs[] = { shaderDecl, simple_frag_src, nil }; im2dShader = Shader::create(vs, fs); assert(im2dShader); @@ -181,8 +181,8 @@ openIm3D(void) { #include "shaders/im3d_gl3.inc" #include "shaders/simple_fs_gl3.inc" - const char *vs[] = { header_vert_src, im3d_vert_src, nil }; - const char *fs[] = { simple_frag_src, nil }; + const char *vs[] = { shaderDecl, header_vert_src, im3d_vert_src, nil }; + const char *fs[] = { shaderDecl, simple_frag_src, nil }; im3dShader = Shader::create(vs, fs); assert(im3dShader); diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index 2e9049c..6679eab 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -42,8 +42,8 @@ matfxOpen(void *o, int32, int32) matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline(); #include "shaders/matfx_gl3.inc" - const char *vs[] = { header_vert_src, matfx_env_vert_src, nil }; - const char *fs[] = { matfx_env_frag_src, nil }; + const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil }; + const char *fs[] = { shaderDecl, matfx_env_frag_src, nil }; envShader = Shader::create(vs, fs); assert(envShader); diff --git a/src/gl/gl3raster.cpp b/src/gl/gl3raster.cpp index a0adc18..f331438 100644 --- a/src/gl/gl3raster.cpp +++ b/src/gl/gl3raster.cpp @@ -350,7 +350,9 @@ rasterFromImage(Raster *raster, Image *image) goto err; break; case 24: - if(raster->format == Raster::C888) + if(raster->format == Raster::C8888) + conv = conv_RGB888_to_RGBA8888; + else if(raster->format == Raster::C888) conv = conv_RGB888_to_RGB888; else goto err; diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index 8363f17..4a37a82 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -39,8 +39,8 @@ skinOpen(void *o, int32, int32) #include "shaders/simple_fs_gl3.inc" #include "shaders/skin_gl3.inc" - const char *vs[] = { header_vert_src, skin_vert_src, nil }; - const char *fs[] = { simple_frag_src, nil }; + const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil }; + const char *fs[] = { shaderDecl, simple_frag_src, nil }; skinShader = Shader::create(vs, fs); assert(skinShader); diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index b7a1022..031495b 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -158,6 +158,7 @@ enum VSLIGHT_AMBIENT = 8, }; +extern const char *shaderDecl; // #version stuff extern const char *header_vert_src; // per Scene diff --git a/src/gl/shaders/header.vert b/src/gl/shaders/header.vert index 20c5097..60127a4 100644 --- a/src/gl/shaders/header.vert +++ b/src/gl/shaders/header.vert @@ -1,5 +1,3 @@ -#version 330 - layout(std140) uniform State { int u_alphaTest; @@ -72,8 +70,8 @@ vec3 DoSpotLight(Light L, vec3 V, vec3 N) float pcos = dot(dir, L.direction.xyz); // cos to point float ccos = -L.minusCosAngle; float falloff = (pcos-ccos)/(1.0-ccos); - if(falloff < 0) // outside of cone - l = 0; + if(falloff < 0.0) // outside of cone + l = 0.0; l *= max(falloff, L.hardSpot); return l*L.color.xyz*atten; } @@ -85,4 +83,4 @@ float DoFog(float w) #define DIRECTIONALS #define POINTLIGHTS -#define SPOTLIGHTS \ No newline at end of file +#define SPOTLIGHTS diff --git a/src/gl/shaders/header_vs.inc b/src/gl/shaders/header_vs.inc index b127335..569638b 100644 --- a/src/gl/shaders/header_vs.inc +++ b/src/gl/shaders/header_vs.inc @@ -1,6 +1,4 @@ const char *header_vert_src = -"#version 330\n" - "layout(std140) uniform State\n" "{\n" " int u_alphaTest;\n" @@ -73,8 +71,8 @@ const char *header_vert_src = " float pcos = dot(dir, L.direction.xyz); // cos to point\n" " float ccos = -L.minusCosAngle;\n" " float falloff = (pcos-ccos)/(1.0-ccos);\n" -" if(falloff < 0) // outside of cone\n" -" l = 0;\n" +" if(falloff < 0.0) // outside of cone\n" +" l = 0.0;\n" " l *= max(falloff, L.hardSpot);\n" " return l*L.color.xyz*atten;\n" "}\n" @@ -86,4 +84,5 @@ const char *header_vert_src = "#define DIRECTIONALS\n" "#define POINTLIGHTS\n" -"#define SPOTLIGHTS\n"; +"#define SPOTLIGHTS\n" +; diff --git a/src/gl/shaders/matfx_env.frag b/src/gl/shaders/matfx_env.frag index f77426c..aa831d2 100644 --- a/src/gl/shaders/matfx_env.frag +++ b/src/gl/shaders/matfx_env.frag @@ -1,5 +1,3 @@ -#version 330 - layout(std140) uniform State { int u_alphaTest; diff --git a/src/gl/shaders/matfx_gl3.inc b/src/gl/shaders/matfx_gl3.inc index 9ffd868..fa41ec5 100644 --- a/src/gl/shaders/matfx_gl3.inc +++ b/src/gl/shaders/matfx_gl3.inc @@ -53,8 +53,6 @@ const char *matfx_env_vert_src = "}\n" ; const char *matfx_env_frag_src = -"#version 330\n" - "layout(std140) uniform State\n" "{\n" " int u_alphaTest;\n" @@ -71,6 +69,7 @@ const char *matfx_env_frag_src = "uniform sampler2D tex1;\n" "uniform float u_coefficient;\n" +"uniform vec4 u_colorClamp;\n" "in vec4 v_color;\n" "in vec2 v_tex0;\n" diff --git a/src/gl/shaders/simple.frag b/src/gl/shaders/simple.frag index 9be99ad..eef08cc 100644 --- a/src/gl/shaders/simple.frag +++ b/src/gl/shaders/simple.frag @@ -1,5 +1,3 @@ -#version 330 - layout(std140) uniform State { int u_alphaTest; diff --git a/src/gl/shaders/simple_fs_gl3.inc b/src/gl/shaders/simple_fs_gl3.inc index 74b4ec0..a8e691e 100644 --- a/src/gl/shaders/simple_fs_gl3.inc +++ b/src/gl/shaders/simple_fs_gl3.inc @@ -1,6 +1,4 @@ const char *simple_frag_src = -"#version 330\n" - "layout(std140) uniform State\n" "{\n" " int u_alphaTest;\n"