Compare commits

...

4 Commits

Author SHA1 Message Date
Gregory Wells
97a70e911d fix glBufferData not being called to set buffer size 2025-08-17 23:37:40 -04:00
Gregory Wells
2f1db4043a remove usless include 2025-08-17 23:28:35 -04:00
Gregory Wells
eb11649a03 dont destroy texture if handle is NULL 2025-08-17 23:28:21 -04:00
Gregory Wells
026fc52d7c uniform API in OpenGL 2025-08-17 23:15:14 -04:00
7 changed files with 45 additions and 6 deletions

View File

@@ -4,6 +4,7 @@
#include "shaders/opengl_shader_module.h" #include "shaders/opengl_shader_module.h"
#include "renderpass/opengl_render_pass_descriptor.h" #include "renderpass/opengl_render_pass_descriptor.h"
#include "uniforms/pool/opengl_uniform_pool.h" #include "uniforms/pool/opengl_uniform_pool.h"
#include "uniforms/uniform/opengl_uniform.h"
#include "commands/pool/opengl_command_pool.h" #include "commands/pool/opengl_command_pool.h"
#include "buffer/opengl_buffer.h" #include "buffer/opengl_buffer.h"
@@ -39,9 +40,9 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnUniformPoolAllocateUniforms = openglAllocateUniforms, ._gnUniformPoolAllocateUniforms = openglAllocateUniforms,
._gnDestroyUniformPool = openglDestroyUniformPool, ._gnDestroyUniformPool = openglDestroyUniformPool,
._gnUpdateBufferUniform = NULL, ._gnUpdateBufferUniform = openglUpdateBufferUniform,
._gnUpdateStorageUniform = NULL, ._gnUpdateStorageUniform = openglUpdateStorageUniform,
._gnUpdateImageUniform = NULL, ._gnUpdateImageUniform = openglUpdateImageUniform,
._gnCreateTexture = NULL, ._gnCreateTexture = NULL,
._gnTextureData = NULL, ._gnTextureData = NULL,

View File

@@ -14,6 +14,7 @@ gnReturnCode openglCreateBuffer(gnBufferHandle buffer, gnDevice device, gnBuffer
glCreateBuffers(1, &buffer->buffer->id); glCreateBuffers(1, &buffer->buffer->id);
buffer->buffer->type = gnBufferTypeToGLEnum(info.type); buffer->buffer->type = gnBufferTypeToGLEnum(info.type);
buffer->buffer->usage = (info.usage == GN_DYNAMIC_DRAW) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; buffer->buffer->usage = (info.usage == GN_DYNAMIC_DRAW) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
glNamedBufferData(buffer->buffer->id, info.size, NULL, buffer->buffer->usage);
return GN_SUCCESS; return GN_SUCCESS;
} }
void openglBufferData(gnBufferHandle buffer, size_t dataSize, void* data) { void openglBufferData(gnBufferHandle buffer, size_t dataSize, void* data) {

View File

@@ -1,12 +1,15 @@
#include "opengl_uniform_pool.h" #include "opengl_uniform_pool.h"
#include "uniforms/uniform/opengl_uniform.h"
gnReturnCode openglCreateUniformPool(gnUniformPool pool, gnDeviceHandle device) { gnReturnCode openglCreateUniformPool(gnUniformPool pool, gnDeviceHandle device) {
return GN_SUCCESS; return GN_SUCCESS;
} }
gnUniform* openglAllocateUniforms(gnUniformPool pool, const gnUniformAllocationInfo allocInfo) { gnUniform* openglAllocateUniforms(gnUniformPool pool, const gnUniformAllocationInfo allocInfo) {
gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount); gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount);
for (int i = 0; i < allocInfo.setCount; i++) for (int i = 0; i < allocInfo.setCount; i++) {
uniforms[i] = malloc(sizeof(struct gnUniform_t)); uniforms[i] = malloc(sizeof(struct gnUniform_t));
uniforms[i]->uniform = malloc(sizeof(struct gnPlatformUniform_t));
}
return uniforms; return uniforms;
} }
void openglDestroyUniformPool(gnUniformPool pool) { void openglDestroyUniformPool(gnUniformPool pool) {

View File

@@ -0,0 +1,14 @@
#include "opengl_uniform.h"
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info) {
uniform->uniform->type = gl_buffer;
uniform->uniform->buffer_info = *info;
}
void openglUpdateStorageUniform(gnUniform uniform, gnStorageUniformInfo* info) {
uniform->uniform->type = gl_storage;
uniform->uniform->storage_info = *info;
}
void openglUpdateImageUniform(gnUniform uniform, gnImageUniformInfo* info) {
uniform->uniform->type = gl_image;
uniform->uniform->image_info = *info;
}

View File

@@ -0,0 +1,20 @@
#pragma once
#include "glad/glad.h"
#include "core/src/uniforms/gryphn_uniform.h"
typedef enum openglUniformType {
gl_buffer, gl_storage, gl_image
} openglUniformType;
typedef struct gnPlatformUniform_t {
openglUniformType type;
union {
gnBufferUniformInfo buffer_info;
gnStorageUniformInfo storage_info;
gnImageUniformInfo image_info;
};
} gnPlatformUniform;
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info);
void openglUpdateStorageUniform(gnUniform uniform, gnStorageUniformInfo* info);
void openglUpdateImageUniform(gnUniform uniform, gnImageUniformInfo* info);

View File

@@ -2,8 +2,6 @@
#include "command/command_pool/gryphn_command_pool.h" #include "command/command_pool/gryphn_command_pool.h"
#include "instance/gryphn_instance.h" #include "instance/gryphn_instance.h"
#include "stdio.h"
gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) { gnReturnCode gnCommandPoolAllocateCommandBuffersFromPointer(gnCommandBufferHandle* buffers, uint32_t count, gnCommandPoolHandle commandPool) {
for (uint32_t i = 0; i < count; i++) { for (uint32_t i = 0; i < count; i++) {
buffers[i] = malloc(sizeof(struct gnCommandBuffer_t)); buffers[i] = malloc(sizeof(struct gnCommandBuffer_t));

View File

@@ -6,6 +6,7 @@ gnReturnCode gnCreateTexture(gnTexture* texture, gnDevice device, const gnTextur
*texture = malloc(sizeof(struct gnTexture_t)); *texture = malloc(sizeof(struct gnTexture_t));
(*texture)->device = device; (*texture)->device = device;
(*texture)->info = info; (*texture)->info = info;
return device->instance->callingLayer->deviceFunctions._gnCreateTexture(*texture, device, info); return device->instance->callingLayer->deviceFunctions._gnCreateTexture(*texture, device, info);
} }
@@ -13,5 +14,6 @@ void gnTextureData(gnTextureHandle texture, void* pixelData) {
texture->device->instance->callingLayer->deviceFunctions._gnTextureData(texture, pixelData); texture->device->instance->callingLayer->deviceFunctions._gnTextureData(texture, pixelData);
} }
void gnDestroyTexture(gnTexture texture) { void gnDestroyTexture(gnTexture texture) {
if (texture == GN_NULL_HANDLE) return;
texture->device->instance->callingLayer->deviceFunctions._gnDestroyTexture(texture); texture->device->instance->callingLayer->deviceFunctions._gnDestroyTexture(texture);
} }