rm cube
This commit is contained in:
1 parent
1d6caf5102
commit
31abcb5b49
5 files changed
-82
No files matched your search
@@ -23,13 +23,6 @@ static float sr_rot_z = 0.0f;
|
|||||||
|
|
||||||
static int sr_ready = 0;
|
static int sr_ready = 0;
|
||||||
|
|
||||||
static Model sr_model = { 0 };
|
|
||||||
static int sr_has_model = 0;
|
|
||||||
|
|
||||||
static Material sr_cube_material = { 0 };
|
|
||||||
static Material sr_cube_shadow_material = { 0 };
|
|
||||||
static Texture2D sr_cube_normal = { 0 };
|
|
||||||
|
|
||||||
static Model sr_ground_model = { 0 };
|
static Model sr_ground_model = { 0 };
|
||||||
static Material sr_ground_material = { 0 };
|
static Material sr_ground_material = { 0 };
|
||||||
static Material sr_ground_shadow_material = { 0 };
|
static Material sr_ground_shadow_material = { 0 };
|
||||||
@@ -201,47 +194,6 @@ void raybri_init(
|
|||||||
sr_ready = 1;
|
sr_ready = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void raybri_load_model(const char *gltf_path)
|
|
||||||
{
|
|
||||||
if (!sr_ready || gltf_path == NULL) return;
|
|
||||||
|
|
||||||
sr_model = LoadModel(gltf_path);
|
|
||||||
sr_has_model = (sr_model.meshCount > 0);
|
|
||||||
|
|
||||||
// The matching normal map sits next to the glTF; load it separately.
|
|
||||||
char asset_dir[1024];
|
|
||||||
const char *slash = strrchr(gltf_path, '/');
|
|
||||||
size_t dir_len = (slash != NULL) ? (size_t)(slash - gltf_path + 1) : 0;
|
|
||||||
snprintf(asset_dir, sizeof(asset_dir), "%.*s", (int)dir_len, gltf_path);
|
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
int cube_mat_index = (sr_model.materialCount > 0) ? sr_model.meshMaterial[0] : 0;
|
|
||||||
sr_cube_material = sr_model.materials[cube_mat_index];
|
|
||||||
sr_cube_material.shader = sr_main_shader;
|
|
||||||
|
|
||||||
Texture2D base_tex = sr_cube_material.maps[MATERIAL_MAP_DIFFUSE].texture;
|
|
||||||
SetTextureFilter(base_tex, TEXTURE_FILTER_BILINEAR);
|
|
||||||
SetTextureWrap(base_tex, TEXTURE_WRAP_CLAMP);
|
|
||||||
|
|
||||||
char normal_path[1024];
|
|
||||||
snprintf(normal_path, sizeof(normal_path), "%scube_normal.png", asset_dir);
|
|
||||||
if (FileExists(normal_path))
|
|
||||||
{
|
|
||||||
sr_cube_normal = LoadTexture(normal_path);
|
|
||||||
SetTextureFilter(sr_cube_normal, TEXTURE_FILTER_BILINEAR);
|
|
||||||
SetTextureWrap(sr_cube_normal, TEXTURE_WRAP_CLAMP);
|
|
||||||
}
|
|
||||||
|
|
||||||
sr_cube_shadow_material = sr_cube_material;
|
|
||||||
sr_cube_shadow_material.shader = sr_shadow_shader;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "SR: failed to load model: %s\n", gltf_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void raybri_resize(int width, int height)
|
void raybri_resize(int width, int height)
|
||||||
{
|
{
|
||||||
if (width > 0) sr_width = width;
|
if (width > 0) sr_width = width;
|
||||||
@@ -305,12 +257,6 @@ static void sr_render_main_pass(void)
|
|||||||
// --- Ground (procedural grid floor) ---
|
// --- Ground (procedural grid floor) ---
|
||||||
sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f);
|
sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f);
|
||||||
|
|
||||||
// --- Cubes ---
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush while the projection/modelview matrices are still active, otherwise
|
// Flush while the projection/modelview matrices are still active, otherwise
|
||||||
// rlgl draws the pending batch with the restored (2D) projection.
|
// rlgl draws the pending batch with the restored (2D) projection.
|
||||||
rlDrawRenderBatchActive();
|
rlDrawRenderBatchActive();
|
||||||
@@ -348,11 +294,6 @@ static void sr_render_shadow_pass(void)
|
|||||||
rlLoadIdentity();
|
rlLoadIdentity();
|
||||||
rlMultMatrixf(MatrixToFloat(sr_light_view));
|
rlMultMatrixf(MatrixToFloat(sr_light_view));
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
DrawMesh(sr_model.meshes[0], sr_cube_shadow_material, sr_cube_transform());
|
|
||||||
}
|
|
||||||
|
|
||||||
rlDrawRenderBatchActive();
|
rlDrawRenderBatchActive();
|
||||||
|
|
||||||
rlMatrixMode(RL_PROJECTION);
|
rlMatrixMode(RL_PROJECTION);
|
||||||
@@ -415,20 +356,8 @@ void raybri_shutdown(void)
|
|||||||
{
|
{
|
||||||
if (!sr_ready) return;
|
if (!sr_ready) return;
|
||||||
|
|
||||||
if (sr_has_model)
|
|
||||||
{
|
|
||||||
UnloadModel(sr_model);
|
|
||||||
sr_has_model = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
UnloadModel(sr_ground_model);
|
UnloadModel(sr_ground_model);
|
||||||
|
|
||||||
if (sr_cube_normal.id > 0)
|
|
||||||
{
|
|
||||||
UnloadTexture(sr_cube_normal);
|
|
||||||
sr_cube_normal.id = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sr_shadow_color > 0) rlUnloadTexture(sr_shadow_color);
|
if (sr_shadow_color > 0) rlUnloadTexture(sr_shadow_color);
|
||||||
if (sr_shadow_depth > 0) rlUnloadTexture(sr_shadow_depth);
|
if (sr_shadow_depth > 0) rlUnloadTexture(sr_shadow_depth);
|
||||||
if (sr_shadow_fbo > 0) rlUnloadFramebuffer(sr_shadow_fbo);
|
if (sr_shadow_fbo > 0) rlUnloadFramebuffer(sr_shadow_fbo);
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ void raybri_init(
|
|||||||
raybri_config config
|
raybri_config config
|
||||||
);
|
);
|
||||||
|
|
||||||
// Load the textured cube glTF model.
|
|
||||||
void raybri_load_model(const char *gltf_path);
|
|
||||||
|
|
||||||
// Resize the viewport.
|
// Resize the viewport.
|
||||||
void raybri_resize(int width, int height);
|
void raybri_resize(int width, int height);
|
||||||
|
|
||||||
|
|||||||
@@ -26,12 +26,6 @@ func renderInit(_ vm: RenderVM) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderLoadCubeModel(_ vm: RenderVM) {
|
|
||||||
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
|
||||||
raybri_load_model(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func renderStartTimer(_ vm: RenderVM) {
|
func renderStartTimer(_ vm: RenderVM) {
|
||||||
// Make a time mark for calculating time delta
|
// Make a time mark for calculating time delta
|
||||||
vm.startTime = CACurrentMediaTime()
|
vm.startTime = CACurrentMediaTime()
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ RenderComponent:
|
|||||||
- didPrepareGL: renderInit(RenderVM.shared!)
|
- didPrepareGL: renderInit(RenderVM.shared!)
|
||||||
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
- didPrepareGL: RenderVM.shared!.didPrepareGL = true
|
||||||
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
- didPrepareGL: renderStartTimer(RenderVM.shared!)
|
||||||
- didPrepareGL: renderLoadCubeModel(RenderVM.shared!)
|
|
||||||
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
- pixelSize: RenderVM.shared!.pixelSize = c.pixelSize
|
||||||
- willDeinit: renderDeinit(RenderVM.shared!)
|
- willDeinit: renderDeinit(RenderVM.shared!)
|
||||||
shoulds:
|
shoulds:
|
||||||
|
|||||||
@@ -334,7 +334,6 @@ func renderRegisterEffects(_ ctrl: DialectController) {
|
|||||||
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
|
F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) },
|
||||||
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
|
F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true },
|
||||||
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) },
|
||||||
F.didPrepareGL, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) },
|
|
||||||
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize },
|
||||||
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) },
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user