some gles3 code

This commit is contained in:
aap 2020-05-12 21:31:44 +02:00
parent 661feeabf4
commit 2233b12daa
13 changed files with 51 additions and 29 deletions

View File

@ -49,6 +49,7 @@ workspace "librw"
filter { "system:linux" } filter { "system:linux" }
platforms { "linux-x86-null", "linux-x86-gl3", platforms { "linux-x86-null", "linux-x86-gl3",
"linux-amd64-null", "linux-amd64-gl3", "linux-amd64-null", "linux-amd64-gl3",
"linux-arm-null", "linux-arm-gl3",
"ps2" } "ps2" }
if _OPTIONS["gfxlib"] == "sdl2" then if _OPTIONS["gfxlib"] == "sdl2" then
includedirs { "/usr/include/SDL2" } includedirs { "/usr/include/SDL2" }
@ -85,6 +86,8 @@ workspace "librw"
architecture "x86_64" architecture "x86_64"
filter { "platforms:*x86*" } filter { "platforms:*x86*" }
architecture "x86" architecture "x86"
filter { "platforms:*arm*" }
architecture "ARM"
filter { "platforms:win*" } filter { "platforms:win*" }
system "windows" system "windows"

View File

@ -97,6 +97,18 @@ struct UniformObject
UniformLight spotLights[MAX_LIGHTS]; 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 vao;
static GLuint ubo_state, ubo_scene, ubo_object; static GLuint ubo_state, ubo_scene, ubo_object;
static GLuint whitetex; static GLuint whitetex;
@ -1019,10 +1031,17 @@ openGLFW(EngineOpenParams *openparams)
return 0; return 0;
} }
glfwWindowHint(GLFW_SAMPLES, 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_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
glGlobals.monitor = glfwGetMonitors(&glGlobals.numMonitors)[0]; glGlobals.monitor = glfwGetMonitors(&glGlobals.numMonitors)[0];
@ -1038,6 +1057,12 @@ closeGLFW(void)
return 1; return 1;
} }
static void
glfwerr(int error, const char *desc)
{
fprintf(stderr, "GLFW Error: %s\n", desc);
}
static int static int
startGLFW(void) startGLFW(void)
{ {
@ -1047,6 +1072,7 @@ startGLFW(void)
mode = &glGlobals.modes[glGlobals.currentMode]; mode = &glGlobals.modes[glGlobals.currentMode];
glfwSetErrorCallback(glfwerr);
glfwWindowHint(GLFW_RED_BITS, mode->mode.redBits); glfwWindowHint(GLFW_RED_BITS, mode->mode.redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->mode.greenBits); glfwWindowHint(GLFW_GREEN_BITS, mode->mode.greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->mode.blueBits); glfwWindowHint(GLFW_BLUE_BITS, mode->mode.blueBits);
@ -1137,8 +1163,8 @@ initOpenGL(void)
#include "shaders/default_vs_gl3.inc" #include "shaders/default_vs_gl3.inc"
#include "shaders/simple_fs_gl3.inc" #include "shaders/simple_fs_gl3.inc"
const char *vs[] = { header_vert_src, default_vert_src, nil }; const char *vs[] = { shaderDecl, header_vert_src, default_vert_src, nil };
const char *fs[] = { simple_frag_src, nil }; const char *fs[] = { shaderDecl, simple_frag_src, nil };
defaultShader = Shader::create(vs, fs); defaultShader = Shader::create(vs, fs);
assert(defaultShader); assert(defaultShader);

View File

@ -52,8 +52,8 @@ openIm2D(void)
#include "shaders/im2d_gl3.inc" #include "shaders/im2d_gl3.inc"
#include "shaders/simple_fs_gl3.inc" #include "shaders/simple_fs_gl3.inc"
const char *vs[] = { header_vert_src, im2d_vert_src, nil }; const char *vs[] = { shaderDecl, header_vert_src, im2d_vert_src, nil };
const char *fs[] = { simple_frag_src, nil }; const char *fs[] = { shaderDecl, simple_frag_src, nil };
im2dShader = Shader::create(vs, fs); im2dShader = Shader::create(vs, fs);
assert(im2dShader); assert(im2dShader);
@ -181,8 +181,8 @@ openIm3D(void)
{ {
#include "shaders/im3d_gl3.inc" #include "shaders/im3d_gl3.inc"
#include "shaders/simple_fs_gl3.inc" #include "shaders/simple_fs_gl3.inc"
const char *vs[] = { header_vert_src, im3d_vert_src, nil }; const char *vs[] = { shaderDecl, header_vert_src, im3d_vert_src, nil };
const char *fs[] = { simple_frag_src, nil }; const char *fs[] = { shaderDecl, simple_frag_src, nil };
im3dShader = Shader::create(vs, fs); im3dShader = Shader::create(vs, fs);
assert(im3dShader); assert(im3dShader);

View File

@ -42,8 +42,8 @@ matfxOpen(void *o, int32, int32)
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline(); matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
#include "shaders/matfx_gl3.inc" #include "shaders/matfx_gl3.inc"
const char *vs[] = { header_vert_src, matfx_env_vert_src, nil }; const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
const char *fs[] = { matfx_env_frag_src, nil }; const char *fs[] = { shaderDecl, matfx_env_frag_src, nil };
envShader = Shader::create(vs, fs); envShader = Shader::create(vs, fs);
assert(envShader); assert(envShader);

View File

@ -350,7 +350,9 @@ rasterFromImage(Raster *raster, Image *image)
goto err; goto err;
break; break;
case 24: 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; conv = conv_RGB888_to_RGB888;
else else
goto err; goto err;

View File

@ -39,8 +39,8 @@ skinOpen(void *o, int32, int32)
#include "shaders/simple_fs_gl3.inc" #include "shaders/simple_fs_gl3.inc"
#include "shaders/skin_gl3.inc" #include "shaders/skin_gl3.inc"
const char *vs[] = { header_vert_src, skin_vert_src, nil }; const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
const char *fs[] = { simple_frag_src, nil }; const char *fs[] = { shaderDecl, simple_frag_src, nil };
skinShader = Shader::create(vs, fs); skinShader = Shader::create(vs, fs);
assert(skinShader); assert(skinShader);

View File

@ -158,6 +158,7 @@ enum
VSLIGHT_AMBIENT = 8, VSLIGHT_AMBIENT = 8,
}; };
extern const char *shaderDecl; // #version stuff
extern const char *header_vert_src; extern const char *header_vert_src;
// per Scene // per Scene

View File

@ -1,5 +1,3 @@
#version 330
layout(std140) uniform State layout(std140) uniform State
{ {
int u_alphaTest; 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 pcos = dot(dir, L.direction.xyz); // cos to point
float ccos = -L.minusCosAngle; float ccos = -L.minusCosAngle;
float falloff = (pcos-ccos)/(1.0-ccos); float falloff = (pcos-ccos)/(1.0-ccos);
if(falloff < 0) // outside of cone if(falloff < 0.0) // outside of cone
l = 0; l = 0.0;
l *= max(falloff, L.hardSpot); l *= max(falloff, L.hardSpot);
return l*L.color.xyz*atten; return l*L.color.xyz*atten;
} }
@ -85,4 +83,4 @@ float DoFog(float w)
#define DIRECTIONALS #define DIRECTIONALS
#define POINTLIGHTS #define POINTLIGHTS
#define SPOTLIGHTS #define SPOTLIGHTS

View File

@ -1,6 +1,4 @@
const char *header_vert_src = const char *header_vert_src =
"#version 330\n"
"layout(std140) uniform State\n" "layout(std140) uniform State\n"
"{\n" "{\n"
" int u_alphaTest;\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 pcos = dot(dir, L.direction.xyz); // cos to point\n"
" float ccos = -L.minusCosAngle;\n" " float ccos = -L.minusCosAngle;\n"
" float falloff = (pcos-ccos)/(1.0-ccos);\n" " float falloff = (pcos-ccos)/(1.0-ccos);\n"
" if(falloff < 0) // outside of cone\n" " if(falloff < 0.0) // outside of cone\n"
" l = 0;\n" " l = 0.0;\n"
" l *= max(falloff, L.hardSpot);\n" " l *= max(falloff, L.hardSpot);\n"
" return l*L.color.xyz*atten;\n" " return l*L.color.xyz*atten;\n"
"}\n" "}\n"
@ -86,4 +84,5 @@ const char *header_vert_src =
"#define DIRECTIONALS\n" "#define DIRECTIONALS\n"
"#define POINTLIGHTS\n" "#define POINTLIGHTS\n"
"#define SPOTLIGHTS\n"; "#define SPOTLIGHTS\n"
;

View File

@ -1,5 +1,3 @@
#version 330
layout(std140) uniform State layout(std140) uniform State
{ {
int u_alphaTest; int u_alphaTest;

View File

@ -53,8 +53,6 @@ const char *matfx_env_vert_src =
"}\n" "}\n"
; ;
const char *matfx_env_frag_src = const char *matfx_env_frag_src =
"#version 330\n"
"layout(std140) uniform State\n" "layout(std140) uniform State\n"
"{\n" "{\n"
" int u_alphaTest;\n" " int u_alphaTest;\n"
@ -71,6 +69,7 @@ const char *matfx_env_frag_src =
"uniform sampler2D tex1;\n" "uniform sampler2D tex1;\n"
"uniform float u_coefficient;\n" "uniform float u_coefficient;\n"
"uniform vec4 u_colorClamp;\n"
"in vec4 v_color;\n" "in vec4 v_color;\n"
"in vec2 v_tex0;\n" "in vec2 v_tex0;\n"

View File

@ -1,5 +1,3 @@
#version 330
layout(std140) uniform State layout(std140) uniform State
{ {
int u_alphaTest; int u_alphaTest;

View File

@ -1,6 +1,4 @@
const char *simple_frag_src = const char *simple_frag_src =
"#version 330\n"
"layout(std140) uniform State\n" "layout(std140) uniform State\n"
"{\n" "{\n"
" int u_alphaTest;\n" " int u_alphaTest;\n"