From cc445309e8a6ed5ebb53f0d70fd88845070ec527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 07:10:51 +0300 Subject: [PATCH] some --- components/render/mac/view/RenderGLView.swift | 3 +- components/render/renderConst.swift | 8 +++++ game/ver-mac/bridge/include/raylib_bridge.h | 12 +++++++- game/ver-mac/bridge/raylib_bridge.c | 29 +++++++++---------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 0f9de48..c4beeeb 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -36,7 +36,8 @@ final class RenderGLView: NSOpenGLView { updatePixelSize() sr_init(pixelWidth, pixelHeight, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, - RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS) + RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, + RENDER_CONFIG) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index 688e4f5..752320f 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -1,4 +1,5 @@ import AppKit +import RaylibBridge let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), @@ -10,3 +11,10 @@ let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ 0 ] +let RENDER_CONFIG = sr_config( + fov_y: 45.0, + near_plane: 0.1, + far_plane: 1000.0, + shadow_size: 1024, + ground_size: 40.0 +) diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index 65be1af..91b432e 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -5,11 +5,21 @@ extern "C" { #endif +// Render configuration, sourced from renderConst.swift. +typedef struct sr_config { + float fov_y; // vertical field of view (degrees) + float near_plane; // camera near plane + float far_plane; // camera far plane + int shadow_size; // shadow map resolution (px) + float ground_size; // ground plane extent +} sr_config; + // Initialise the OpenGL-backed raylib scene (no raylib window is created). // The four shader sources come from renderConstShader.swift. void sr_init(int width, int height, const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs); + const char *shadow_vs, const char *shadow_fs, + sr_config config); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 01bef49..bd08e9f 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -9,15 +9,12 @@ #include #include -#define SR_FOV_Y 45.0f -#define SR_NEAR 0.1f -#define SR_FAR 1000.0f -#define SR_SHADOW_SIZE 1024 -#define SR_GROUND_SIZE 40.0f - static int sr_width = 1; static int sr_height = 1; +// Render configuration supplied by the application (see renderConst.swift). +static sr_config sr_cfg = { 0 }; + // Cube transform (driven by the application, Euler degrees). static float sr_rot_x = 0.0f; static float sr_rot_y = 0.0f; @@ -114,8 +111,8 @@ static void sr_load_shaders(const char *main_vs, const char *main_fs, // Build a framebuffer whose depth attachment is a sampleable TEXTURE (raylib's // LoadRenderTexture() uses a non-sampleable renderbuffer, so we build it by hand). sr_shadow_fbo = rlLoadFramebuffer(); - sr_shadow_color = rlLoadTexture(NULL, SR_SHADOW_SIZE, SR_SHADOW_SIZE, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); - sr_shadow_depth = rlLoadTextureDepth(SR_SHADOW_SIZE, SR_SHADOW_SIZE, false); + sr_shadow_color = rlLoadTexture(NULL, sr_cfg.shadow_size, sr_cfg.shadow_size, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); + sr_shadow_depth = rlLoadTextureDepth(sr_cfg.shadow_size, sr_cfg.shadow_size, false); rlEnableFramebuffer(sr_shadow_fbo); rlFramebufferAttach(sr_shadow_fbo, sr_shadow_color, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0); @@ -127,7 +124,7 @@ static void sr_load_shaders(const char *main_vs, const char *main_fs, static void sr_build_ground(void) { - Mesh ground_mesh = GenMeshPlane(SR_GROUND_SIZE, SR_GROUND_SIZE, 1, 1); + Mesh ground_mesh = GenMeshPlane(sr_cfg.ground_size, sr_cfg.ground_size, 1, 1); sr_ground_model = LoadModelFromMesh(ground_mesh); sr_ground_material = LoadMaterialDefault(); sr_ground_material.shader = sr_main_shader; @@ -136,11 +133,13 @@ static void sr_build_ground(void) } void sr_init(int width, int height, const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs) + const char *shadow_vs, const char *shadow_fs, sr_config config) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; + sr_cfg = config; + rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); @@ -196,9 +195,9 @@ static Matrix sr_cube_transform(void) static void sr_render_shadow_pass(void) { - rlViewport(0, 0, SR_SHADOW_SIZE, SR_SHADOW_SIZE); - rlSetFramebufferWidth(SR_SHADOW_SIZE); - rlSetFramebufferHeight(SR_SHADOW_SIZE); + rlViewport(0, 0, sr_cfg.shadow_size, sr_cfg.shadow_size); + rlSetFramebufferWidth(sr_cfg.shadow_size); + rlSetFramebufferHeight(sr_cfg.shadow_size); rlEnableFramebuffer(sr_shadow_fbo); @@ -283,9 +282,9 @@ void sr_render(void) rlLoadIdentity(); float aspect = (float)sr_width / (float)sr_height; - double top = (double)SR_NEAR * tan((double)SR_FOV_Y * 0.5 * DEG2RAD); + double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); double right = top * (double)aspect; - rlFrustum(-right, right, -top, top, (double)SR_NEAR, (double)SR_FAR); + rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); rlMatrixMode(RL_MODELVIEW); rlLoadIdentity();