summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defines.h4
-rw-r--r--src/ral/backends/opengl/backend_opengl.c11
-rw-r--r--src/ral/backends/opengl/opengl_helpers.h2
-rw-r--r--src/ral/ral_common.c11
-rw-r--r--src/ral/ral_common.h1
-rw-r--r--src/ral/ral_impl.h10
-rw-r--r--src/ral/ral_types.h4
-rw-r--r--src/render/render.c4
8 files changed, 37 insertions, 10 deletions
diff --git a/src/defines.h b/src/defines.h
index 108edef..67a4f17 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -65,7 +65,7 @@ CORE_DEFINE_HANDLE(
// NOTE: The below is now handled in xmake.lua
// Platform will inform renderer backend (unless user overrides)
#if defined(CEL_PLATFORM_LINUX)
-#define CEL_REND_BACKEND_OPENGL 1
+// #define CEL_REND_BACKEND_OPENGL 1
// #define CEL_REND_BACKEND_VULKAN 1
#endif
@@ -79,4 +79,4 @@ CORE_DEFINE_HANDLE(
// #define CEL_REND_BACKEND_METAL 1
#define CEL_REND_BACKEND_OPENGL 1
// #define CEL_REND_BACKEND_VULKAN 1
-#endif \ No newline at end of file
+#endif
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c
index f971568..6c1a301 100644
--- a/src/ral/backends/opengl/backend_opengl.c
+++ b/src/ral/backends/opengl/backend_opengl.c
@@ -416,6 +416,17 @@ void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count) {
glDrawElements(GL_TRIANGLES, index_count, GL_UNSIGNED_INT, 0);
}
+PUB void GPU_WriteTextureRegion(GPU_CmdEncoder* encoder, TextureHandle dst, u32 x_offset,
+ u32 y_offset, u32 width, u32 height, const void* data) {
+ CASSERT_MSG(data, "const void* data must not be NULL");
+
+ GPU_Texture* tex = TEXTURE_GET(dst);
+
+ glBindTexture(GL_TEXTURE_2D, tex->id);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, x_offset, y_offset, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
+ data);
+}
+
bool GPU_Backend_BeginFrame() {
glViewport(0, 0, context.swapchain.dimensions.x * 2, context.swapchain.dimensions.y * 2);
glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h
index f240050..0450c74 100644
--- a/src/ral/backends/opengl/opengl_helpers.h
+++ b/src/ral/backends/opengl/opengl_helpers.h
@@ -59,7 +59,7 @@ static u32 opengl_bindcreate_vao(GPU_Buffer* buf, VertexDescription desc) {
u32 attr_count = desc.attributes_count;
printf("N attributes %d\n", attr_count);
u64 offset = 0;
- size_t vertex_size = desc.use_full_vertex_size ? sizeof(Vertex) : desc.stride;
+ size_t vertex_size = desc.use_full_vertex_size ? sizeof(Vertex) : VertexDesc_CalcStride(&desc);
for (u32 i = 0; i < desc.attributes_count; i++) {
opengl_vertex_attr format = format_from_vertex_attr(desc.attributes[i]);
glVertexAttribPointer(i, format.count, format.data_type, GL_FALSE, vertex_size, (void*)offset);
diff --git a/src/ral/ral_common.c b/src/ral/ral_common.c
index 35bf15f..53e35f0 100644
--- a/src/ral/ral_common.c
+++ b/src/ral/ral_common.c
@@ -32,7 +32,7 @@ void VertexDesc_AddAttr(VertexDescription* builder, const char* name, VertexAttr
size_t size = VertexAttribSize(type);
builder->attributes[i] = type;
- builder->stride += size;
+ // builder->stride += size;
builder->attr_names[i] = name;
builder->attributes_count++;
@@ -59,3 +59,12 @@ size_t VertexAttribSize(VertexAttribType attr) {
break;
}
}
+
+size_t VertexDesc_CalcStride(VertexDescription* desc) {
+ size_t stride = 0;
+ for (int i = 0; i < desc->attributes_count; i++) {
+ size_t size =VertexAttribSize(desc->attributes[i]);
+ stride += size;
+ }
+ return stride;
+}
diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h
index 8fa09d9..5a797e5 100644
--- a/src/ral/ral_common.h
+++ b/src/ral/ral_common.h
@@ -56,5 +56,6 @@ void GPU_WindowResizedCallback(u32 x, u32 y);
VertexDescription static_3d_vertex_description();
void VertexDesc_AddAttr(VertexDescription* builder, const char* name, VertexAttribType type);
+size_t VertexDesc_CalcStride(VertexDescription* desc);
size_t VertexAttribSize(VertexAttribType attr);
diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h
index 0ca73c7..f5a16d2 100644
--- a/src/ral/ral_impl.h
+++ b/src/ral/ral_impl.h
@@ -73,11 +73,19 @@ void copy_buffer_to_image_oneshot(BufferHandle src, TextureHandle dst);
// --- Render commands
PUB void GPU_EncodeBindPipeline(GPU_CmdEncoder* encoder, GPU_Pipeline* pipeline);
-// PUB void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData data);
PUB void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderDataLayout layout);
void GPU_EncodeSetDefaults(GPU_CmdEncoder* encoder);
PUB void GPU_EncodeSetVertexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf);
PUB void GPU_EncodeSetIndexBuffer(GPU_CmdEncoder* encoder, BufferHandle buf);
+PUB void GPU_EncodeCopyBufToBuf();
+
+// PUB void GPU_EncodeCopyBufToTex(GPU_CmdEncoder* encoder, BufferHandle src, TextureHandle dst,
+// u32 x_offset, u32 y_offset, u32 width, u32 height, const void* data);
+/** @brief Convenience method for writing data directly into a texture. Staging memory is handled internally. */
+PUB void GPU_WriteTextureRegion(GPU_CmdEncoder* encoder, TextureHandle dst,
+ u32 x_offset, u32 y_offset, u32 width, u32 height, const void* data);
+PUB void GPU_WriteBuffer(GPU_CmdEncoder* encoder, BufferHandle buf, u64 offset, u64 size, const void* data);
+
PUB void GPU_EncodeDraw(GPU_CmdEncoder* encoder, u64 count);
PUB void GPU_EncodeDrawIndexed(GPU_CmdEncoder* encoder, u64 index_count);
PUB void GPU_EncodeDrawInstanced(GPU_CmdEncoder* encoder, u64 index_count,
diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h
index ec302c1..470e4e9 100644
--- a/src/ral/ral_types.h
+++ b/src/ral/ral_types.h
@@ -148,11 +148,11 @@ typedef enum VertexAttribType {
} VertexAttribType;
typedef struct VertexDescription {
- char* debug_label;
+ const char* debug_label;
const char* attr_names[MAX_VERTEX_ATTRIBUTES];
VertexAttribType attributes[MAX_VERTEX_ATTRIBUTES];
u32 attributes_count;
- size_t stride;
+ // size_t stride;
bool use_full_vertex_size;
} VertexDescription;
diff --git a/src/render/render.c b/src/render/render.c
index 697a79e..bad245a 100644
--- a/src/render/render.c
+++ b/src/render/render.c
@@ -287,9 +287,7 @@ PUB MeshHandle Mesh_Insert(Mesh* mesh) { return Mesh_pool_insert(Render_GetMeshP
PUB MaterialHandle Material_Insert(Material* material) {
return Material_pool_insert(Render_GetMaterialPool(), material);
}
-Mesh* Mesh_Get(MeshHandle handle) {
- return Mesh_pool_get(Render_GetMeshPool(), handle);
-}
+Mesh* Mesh_Get(MeshHandle handle) { return Mesh_pool_get(Render_GetMeshPool(), handle); }
size_t ModelExtractRenderEnts(RenderEnt_darray* entities, ModelHandle model_handle, Mat4 affine,
RenderEntityFlags flags) {