OpenGL texture API

This commit is contained in:
Gregory Wells
2025-08-18 20:24:17 -04:00
parent 2e02bbf799
commit 5db32f367a
3 changed files with 42 additions and 3 deletions

View File

@@ -7,6 +7,7 @@
#include "uniforms/uniform/opengl_uniform.h"
#include "commands/pool/opengl_command_pool.h"
#include "buffer/opengl_buffer.h"
#include "textures/opengl_texture.h"
gnDeviceFunctions loadOpenGLDeviceFunctions() {
return (gnDeviceFunctions){
@@ -44,9 +45,9 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnUpdateStorageUniform = openglUpdateStorageUniform,
._gnUpdateImageUniform = openglUpdateImageUniform,
._gnCreateTexture = NULL,
._gnTextureData = NULL,
._gnDestroyTexture = NULL,
._gnCreateTexture = openglCreateTexture,
._gnTextureData = openglTextureData,
._gnDestroyTexture = openglDestroyTexture,
._gnSubmit = NULL,
._gnPresent = NULL,

View File

@@ -0,0 +1,34 @@
#include "opengl_texture.h"
#include "surface/opengl_surface.h"
GLenum GryphnTargetToOpenGL(gnTextureType type) {
switch(type) {
case GN_TEXTURE_2D: return GL_TEXTURE_2D;
}
}
gnReturnCode openglCreateTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
texture->texture = malloc(sizeof(gnPlatformTexture));
glCreateTextures(GryphnTargetToOpenGL(info.type), 1, &texture->texture->id);
glTextureStorage2D(
texture->texture->id,
1,
glGryphnFormatToOpenGLInternalFormat(info.format),
info.extent.x, info.extent.y
);
return GN_SUCCESS;
}
void openglTextureData(gnTextureHandle texture, void* pixelData) {
glTextureSubImage2D(
texture->texture->id,
0,
0, 0,
texture->info.extent.x, texture->info.extent.y,
GL_RGBA,
GL_UNSIGNED_BYTE,
pixelData
);
}
void openglDestroyTexture(gnTexture texture) {
}

View File

@@ -5,3 +5,7 @@
typedef struct gnPlatformTexture_t {
GLuint id;
} gnPlatformTexture;
gnReturnCode openglCreateTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
void openglTextureData(gnTextureHandle texture, void* pixelData);
void openglDestroyTexture(gnTexture texture);