sync: user's Lity3D_source.zip changes
- Engine core: improved initialization and lifecycle - Renderer: camera and rendering pipeline updates - Editor: updated editor code - Window: improved window handling - Demo/main.c: scene demo with AssetManager + scene loading - build.bat: updated build script - 11 files modified from user's manual edits
This commit is contained in:
1 parent
0669d102ce
commit
7a0533d21a
11 files changed
+707
-378
No files matched your search
@@ -1,4 +1,5 @@
|
||||
#include "renderer.h"
|
||||
#include "../Core/logger.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -22,6 +23,8 @@ Renderer* renderer_create(GraphicsDevice* device) {
|
||||
r->light_dir = (Vec3){0.5f, -1.0f, 0.3f};
|
||||
r->light_color = (Vec4){1,1,1,1};
|
||||
r->ambient_color = (Vec4){0.2f,0.2f,0.3f,1};
|
||||
r->clear_color[0] = 0.1f; r->clear_color[1] = 0.1f;
|
||||
r->clear_color[2] = 0.15f; r->clear_color[3] = 1.0f;
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -29,7 +32,7 @@ void renderer_destroy(Renderer* r) { free(r); }
|
||||
|
||||
void renderer_begin_frame(Renderer* r) {
|
||||
ID3D11DeviceContext* ctx = r->device->context;
|
||||
graphics_device_clear(r->device, 0.1f, 0.1f, 0.15f, 1.0f);
|
||||
graphics_device_clear(r->device, r->clear_color[0], r->clear_color[1], r->clear_color[2], r->clear_color[3]);
|
||||
D3D11_VIEWPORT vp = {0};
|
||||
vp.Width = (float)r->device->width;
|
||||
vp.Height = (float)r->device->height;
|
||||
@@ -43,17 +46,15 @@ void renderer_end_frame(Renderer* r) {
|
||||
}
|
||||
|
||||
void renderer_draw_mesh(Renderer* r, Mesh* m) {
|
||||
if (!m) return;
|
||||
if (!r || !m || m->icount == 0) return;
|
||||
if (!m->vb) { LOG_ERROR("renderer_draw_mesh: null vertex buffer"); return; }
|
||||
if (!m->ib) { LOG_ERROR("renderer_draw_mesh: null index buffer"); return; }
|
||||
ID3D11DeviceContext* ctx = r->device->context;
|
||||
UINT stride = sizeof(Vertex);
|
||||
UINT offset = 0;
|
||||
ctx->lpVtbl->IASetVertexBuffers(ctx, 0, 1, &m->vb, &stride, &offset);
|
||||
if (m->ib) {
|
||||
ctx->lpVtbl->IASetIndexBuffer(ctx, m->ib, DXGI_FORMAT_R32_UINT, 0);
|
||||
ctx->lpVtbl->DrawIndexed(ctx, m->icount, 0, 0);
|
||||
} else {
|
||||
ctx->lpVtbl->Draw(ctx, m->vcount, 0);
|
||||
}
|
||||
ctx->lpVtbl->IASetIndexBuffer(ctx, m->ib, DXGI_FORMAT_R32_UINT, 0);
|
||||
ctx->lpVtbl->DrawIndexed(ctx, m->icount, 0, 0);
|
||||
}
|
||||
|
||||
void renderer_draw_mesh_with_shader(Renderer* r, Mesh* m, Shader* s, const Mat4* world, Texture* t) {
|
||||
@@ -98,8 +99,18 @@ void renderer_draw_mesh_with_material(Renderer* r, Mesh* m, Material* mat, const
|
||||
void renderer_set_view(Renderer* r, const Mat4* v) { r->view = *v; }
|
||||
void renderer_set_projection(Renderer* r, const Mat4* p) { r->projection = *p; }
|
||||
void renderer_set_light(Renderer* r, Vec3 d, Vec4 c, Vec4 a) { r->light_dir=d; r->light_color=c; r->ambient_color=a; }
|
||||
void renderer_set_clear_color(Renderer* r, float rc, float g, float b, float a) {
|
||||
if (!r) return;
|
||||
r->clear_color[0] = rc; r->clear_color[1] = g;
|
||||
r->clear_color[2] = b; r->clear_color[3] = a;
|
||||
}
|
||||
GraphicsDevice* renderer_get_device(Renderer* r) { return r ? r->device : NULL; }
|
||||
|
||||
void renderer_get_view_projection(const Renderer* r, Mat4* out) {
|
||||
if (!r || !out) return;
|
||||
mat4_multiply(&r->view, &r->projection, out);
|
||||
}
|
||||
|
||||
void renderer_resize(Renderer* r, int width, int height) {
|
||||
if (r && r->device && width > 0 && height > 0) {
|
||||
graphics_device_resize(r->device, width, height);
|
||||
|
||||
Reference in new issue
Block a user