Introduce chkgfx #3

Merged
kornerr merged 57 commits from rfix into master 2026-10-22 03:17:23 +00:00
5 changed files with 31 additions and 53 deletions
Showing only changes of commit 127277e762 - Show all commits

No files matched your search

+23 -23
View File
@@ -1,25 +1,25 @@
let RAYLIB_SHADER_MAIN_VS = """ let RAYLIB_SHADER_MAIN_VS = """
"#version 330\n" #version 330
"layout(location = 0) in vec3 vertexPosition;\n" layout(location = 0) in vec3 vertexPosition;
"layout(location = 1) in vec2 vertexTexCoord;\n" layout(location = 1) in vec2 vertexTexCoord;
"layout(location = 2) in vec3 vertexNormal;\n" layout(location = 2) in vec3 vertexNormal;
"\n"
"uniform mat4 mvp;\n" uniform mat4 mvp;
"uniform mat4 matModel;\n" uniform mat4 matModel;
"uniform mat4 u_lightMVP;\n" uniform mat4 u_lightMVP;
"\n"
"out vec3 vWorldPos;\n" out vec3 vWorldPos;
"out vec3 vNormal;\n" out vec3 vNormal;
"out vec2 vTexCoord;\n" out vec2 vTexCoord;
"out vec4 vLightClip;\n" out vec4 vLightClip;
"\n"
"void main()\n" void main()
"{\n" {
" vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" vec4 worldPos = matModel * vec4(vertexPosition, 1.0);
" vWorldPos = worldPos.xyz;\n" vWorldPos = worldPos.xyz;
" vNormal = normalize(mat3(matModel) * vertexNormal);\n" vNormal = normalize(mat3(matModel) * vertexNormal);
" vTexCoord = vertexTexCoord;\n" vTexCoord = vertexTexCoord;
" vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);
" gl_Position = mvp * vec4(vertexPosition, 1.0);\n" gl_Position = mvp * vec4(vertexPosition, 1.0);
"}\n"; }
""" """
+1 -1
View File
@@ -57,7 +57,7 @@ final class RaylibGLNSView: NSOpenGLView {
context.setValues(&swapInterval, for: .swapInterval) context.setValues(&swapInterval, for: .swapInterval)
updatePixelSize() updatePixelSize()
sr_init(pixelWidth, pixelHeight) sr_init(pixelWidth, pixelHeight, RAYLIB_SHADER_MAIN_VS)
loadModel() loadModel()
startTime = CACurrentMediaTime() startTime = CACurrentMediaTime()
ready = true ready = true
+2 -1
View File
@@ -6,7 +6,8 @@ extern "C" {
#endif #endif
// Initialise the OpenGL-backed raylib scene (no raylib window is created). // Initialise the OpenGL-backed raylib scene (no raylib window is created).
void sr_init(int width, int height); // main_vs is the main vertex shader source (see raylibConstShader.swift).
void sr_init(int width, int height, const char *main_vs);
// Load the textured cube glTF model. // Load the textured cube glTF model.
void sr_load_model(const char *gltf_path); void sr_load_model(const char *gltf_path);
+4 -28
View File
@@ -88,30 +88,6 @@ static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float r
return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation); return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation);
} }
static const char *SR_MAIN_VS =
"#version 330\n"
"layout(location = 0) in vec3 vertexPosition;\n"
"layout(location = 1) in vec2 vertexTexCoord;\n"
"layout(location = 2) in vec3 vertexNormal;\n"
"\n"
"uniform mat4 mvp;\n"
"uniform mat4 matModel;\n"
"uniform mat4 u_lightMVP;\n"
"\n"
"out vec3 vWorldPos;\n"
"out vec3 vNormal;\n"
"out vec2 vTexCoord;\n"
"out vec4 vLightClip;\n"
"\n"
"void main()\n"
"{\n"
" vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n"
" vWorldPos = worldPos.xyz;\n"
" vNormal = normalize(mat3(matModel) * vertexNormal);\n"
" vTexCoord = vertexTexCoord;\n"
" vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n"
" gl_Position = mvp * vec4(vertexPosition, 1.0);\n"
"}\n";
static const char *SR_MAIN_FS = static const char *SR_MAIN_FS =
"#version 330\n" "#version 330\n"
@@ -224,9 +200,9 @@ static const char *SR_SHADOW_FS =
" finalColor = vec4(1.0);\n" " finalColor = vec4(1.0);\n"
"}\n"; "}\n";
static void sr_load_shaders(void) static void sr_load_shaders(const char *main_vs)
{ {
sr_main_shader = LoadShaderFromMemory(SR_MAIN_VS, SR_MAIN_FS); sr_main_shader = LoadShaderFromMemory(main_vs, SR_MAIN_FS);
sr_shadow_shader = LoadShaderFromMemory(SR_SHADOW_VS, SR_SHADOW_FS); sr_shadow_shader = LoadShaderFromMemory(SR_SHADOW_VS, SR_SHADOW_FS);
loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos"); loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos");
@@ -270,7 +246,7 @@ static void sr_build_ground(void)
sr_ground_shadow_material.shader = sr_shadow_shader; sr_ground_shadow_material.shader = sr_shadow_shader;
} }
void sr_init(int width, int height) void sr_init(int width, int height, const char *main_vs)
{ {
if (width > 0) sr_width = width; if (width > 0) sr_width = width;
if (height > 0) sr_height = height; if (height > 0) sr_height = height;
@@ -278,7 +254,7 @@ void sr_init(int width, int height)
rlLoadExtensions(sr_gl_loader); rlLoadExtensions(sr_gl_loader);
rlglInit(sr_width, sr_height); rlglInit(sr_width, sr_height);
sr_load_shaders(); sr_load_shaders(main_vs);
sr_build_ground(); sr_build_ground();
sr_ready = 1; sr_ready = 1;
+1
View File
@@ -0,0 +1 @@
../../../../components/raylib/raylibConstShader.swift