Compare commits

...

8 Commits

Author SHA1 Message Date
Gregory Wells
5db32f367a OpenGL texture API 2025-08-18 20:24:17 -04:00
Gregory Wells
2e02bbf799 fix formats in OpenGL 2025-08-18 20:23:59 -04:00
Gregory Wells
8658c7646f add support for more formats in vulkan 2025-08-18 20:11:41 -04:00
Gregory Wells
c99a4cdb31 fix validation 2025-08-18 16:31:20 -04:00
Gregory Wells
f045793322 just create texture storage 2025-08-18 16:20:33 -04:00
Gregory Wells
5213e0135a fix OpenGL surface format stuff 2025-08-18 01:07:03 -04:00
Gregory Wells
e973386511 implmenent debug callback for OpenGL 2025-08-18 01:06:40 -04:00
Gregory Wells
cb55a7716f copy needed data into renderpass 2025-08-18 00:08:18 -04:00
13 changed files with 203 additions and 30 deletions

View File

@@ -22,8 +22,6 @@ typedef struct gnPlatformRenderPassDescriptor_t {
uint32_t subpassCount;
mtlSubpass* subpasses;
mtlSubpassCopyInfo* copyInfos;
} gnPlatformRenderPassDescriptor;
gnReturnCode createMetalRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);

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

@@ -2,6 +2,9 @@
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {
if (instanceInfo->coreAPI != GN_RENDERINGAPI_OPENGL) return GN_UNSUPPORTED_API;
instance->instance = malloc(sizeof(gnPlatformInstance));
instance->instance->enableDebugger = instance->enabledLayerCounts[GN_DEBUGGER_LAYER_PLATFORM] >= 1;
return GN_SUCCESS;
}
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators) {

View File

@@ -2,7 +2,9 @@
#include <GL/gl.h>
#include "instance/gryphn_instance.h"
typedef struct gnPlatformInstance_t {} gnPlatformInstance;
typedef struct gnPlatformInstance_t {
gnBool enableDebugger;
} gnPlatformInstance;
gnReturnCode openglCreateInstance(gnInstanceHandle instance, gnInstanceCreateInfo* instanceInfo, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);
void openglDestroyInstance(gnInstanceHandle instance, gryphnInstanceFunctionLayers* next, gnAllocators* allocators);

View File

@@ -5,8 +5,6 @@
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo) {
presentationQueue->presentationQueue = malloc(sizeof(struct gnPlatformPresentationQueue_t));
uint32_t convertedFormat = glGryphnFormatToOpenGLFormat(presentationInfo.format.format);
presentationQueue->imageCount = presentationInfo.minImageCount;
presentationQueue->images = malloc(sizeof(gnTexture) * presentationInfo.minImageCount);
presentationQueue->presentationQueue->textures = GLuintArrayListCreate();
@@ -14,19 +12,13 @@ gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentatio
for (int i = 0; i < presentationInfo.minImageCount; i++) {
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));
glGenTextures(1, &presentationQueue->images[i]->texture->id);
glTexImage2D(
GL_TEXTURE_2D,
0,
glCreateTextures(GL_TEXTURE_2D, 1, &presentationQueue->images[i]->texture->id);
glTextureStorage2D(
presentationQueue->images[i]->texture->id,
1,
glGryphnFormatToOpenGLInternalFormat(presentationInfo.format.format),
presentationInfo.imageSize.x, presentationInfo.imageSize.y,
0,
glGryphnFormatToOpenGLFormat(presentationInfo.format.format),
GL_UNSIGNED_BYTE,
NULL
presentationInfo.imageSize.x, presentationInfo.imageSize.y
);
GLuintArrayListAdd(presentationQueue->presentationQueue->textures, presentationQueue->images[i]->texture->id);
uint32_tArrayListAdd(presentationQueue->presentationQueue->avaliableTextures, i);
}

View File

@@ -1,6 +1,50 @@
#include "opengl_render_pass_descriptor.h"
#include "surface/opengl_surface.h"
#include "stdlib.h"
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info) {
if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE;
renderPass->renderPassDescriptor = malloc(sizeof(gnPlatformRenderPassDescriptor));
renderPass->renderPassDescriptor->subpassCount = info.subpassCount;
renderPass->renderPassDescriptor->subpasses = malloc(sizeof(glSubpass) * info.subpassCount);
for (uint32_t i = 0; i < info.subpassCount; i++) {
renderPass->renderPassDescriptor->subpasses[i] = (glSubpass){
.colorAttachmentCount = info.subpassInfos[i].colorAttachmentCount,
.colorAttachments = malloc(sizeof(glColorAttachment) * info.subpassInfos[i].colorAttachmentCount),
.depthAttachment.index = -1
};
gnBool resolve = !(info.subpassInfos[i].resolveAttachments == NULL);
for (uint32_t c = 0; c < info.subpassInfos[i].colorAttachmentCount; c++) {
uint32_t attachmentIndex = info.subpassInfos[i].colorAttachments[c].index;
int resolveAttachmentIndex = -1;
if (resolve)
resolveAttachmentIndex = info.subpassInfos[i].resolveAttachments[c].index;
renderPass->renderPassDescriptor->subpasses[i].colorAttachments[c] = (glColorAttachment){
.loadOperation = info.attachmentInfos[attachmentIndex].loadOperation,
.storeOperation = info.attachmentInfos[attachmentIndex].storeOperation,
.attachmentIndex = attachmentIndex,
.resolveAttachmentIndex = resolveAttachmentIndex,
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[attachmentIndex].format)
};
}
if (info.subpassInfos[i].depthAttachment != NULL) {
uint32_t depthAttachmentIndex = info.subpassInfos[i].depthAttachment->index;
renderPass->renderPassDescriptor->subpasses[i].depthAttachment = (gnDepthAttachment){
.index = depthAttachmentIndex,
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[depthAttachmentIndex].format),
.loadOperation = info.attachmentInfos[depthAttachmentIndex].loadOperation,
.storeOperation = info.attachmentInfos[depthAttachmentIndex].storeOperation,
};
}
}
return GN_SUCCESS;
}
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass) {}
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass) {
for (int i = 0; i < renderPass->renderPassDescriptor->subpassCount; i++)
free(renderPass->renderPassDescriptor->subpasses[i].colorAttachments);
free(renderPass->renderPassDescriptor->subpasses);
free(renderPass->renderPassDescriptor);
}

View File

@@ -1,6 +1,34 @@
#pragma once
#include "glad/glad.h"
#include "core/src/renderpass/gryphn_render_pass_descriptor.h"
#include "utils/gryphn_color.h"
typedef struct gnPlatformRenderPassDescriptor_t gnPlatformRenderPassDescriptor;
typedef struct glColorAttachment {
gnColor clearColor;
gnLoadOperation loadOperation;
gnStoreOperation storeOperation;
GLint format;
uint32_t attachmentIndex;
int resolveAttachmentIndex; // -1 = no attachment
} glColorAttachment;
typedef struct gnDepthAttachment {
int index;
gnLoadOperation loadOperation;
gnStoreOperation storeOperation;
GLint format;
} gnDepthAttachment;
typedef struct glSubpass {
uint32_t colorAttachmentCount;
glColorAttachment* colorAttachments;
gnDepthAttachment depthAttachment;
} glSubpass;
typedef struct gnPlatformRenderPassDescriptor_t {
uint32_t subpassCount;
glSubpass* subpasses;
} gnPlatformRenderPassDescriptor;
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass);

View File

@@ -2,6 +2,55 @@
#include "opengl_surface.h"
#include "utils/gryphn_string.h"
#include "stdio.h"
void GLAPIENTRY openglMessageCallback( GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam ) {
gnInstanceHandle handle = (gnInstanceHandle)userParam;
gnMessageSeverity gryphnSeverity;
if (severity == GL_DEBUG_SEVERITY_HIGH) gryphnSeverity = GN_MESSAGE_ERROR;
else if (severity == GL_DEBUG_SEVERITY_MEDIUM) gryphnSeverity = GN_MESSAGE_WARNING;
else if (severity == GL_DEBUG_SEVERITY_LOW) gryphnSeverity = GN_MESSAGE_WARNING;
else if (severity == GL_DEBUG_SEVERITY_NOTIFICATION) gryphnSeverity = GN_MESSAGE_VERBOSE;
else {
handle->debugger.callback(
GN_MESSAGE_ERROR,
GN_DEBUG_MESSAGE_VALIDATION,
(gnMessageData){ .message = gnCreateString("Uknown severity type from OpenGL") },
handle->debugger.userData
);
}
gnMessageType gryphnType;
if (type == GL_DEBUG_TYPE_ERROR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
else if (type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
else if (type == GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
else if (type == GL_DEBUG_TYPE_PORTABILITY) gryphnType = GN_DEBUG_MESSAGE_VALIDATION;
else if (type == GL_DEBUG_TYPE_PERFORMANCE) gryphnType = GN_DEBUG_MESSAGE_PERFORMANCE;
else if (type == GL_DEBUG_TYPE_OTHER) gryphnType = GN_DEBUG_MESSAGE_GENERAL;
else {
handle->debugger.callback(
GN_MESSAGE_ERROR,
GN_DEBUG_MESSAGE_VALIDATION,
(gnMessageData){ .message = gnCreateString("Uknown message type from OpenGL") },
handle->debugger.userData
);
}
handle->debugger.callback(
gryphnSeverity,
gryphnType,
(gnMessageData){ .message = gnCreateString(message) },
handle->debugger.userData
);
}
#ifdef GN_PLATFORM_LINUX
#ifdef GN_WINDOW_X11
#include <X11/Xlib.h>
@@ -27,6 +76,10 @@ gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHan
return GN_UNKNOWN_ERROR;
}
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(openglMessageCallback, instance);
return GN_SUCCESS;
}
@@ -50,11 +103,14 @@ gnSurfaceDetails genOpenGLSurfaceDetails(
) {
gnSurfaceDetails surfaceDetails;
surfaceDetails.formatCount = 1;
surfaceDetails.formats = (gnSurfaceFormat[]){
(gnSurfaceFormat){
.format = GN_FORMAT_RGBA8_SRGB,
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
}
surfaceDetails.formats = malloc(sizeof(gnSurfaceFormat) * 2);
surfaceDetails.formats[0] = (gnSurfaceFormat){
.format = GN_FORMAT_RGBA8,
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
};
surfaceDetails.formats[1] = (gnSurfaceFormat){
.format = GN_FORMAT_RGBA8_SRGB,
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
};
surfaceDetails.minImageCount = 2;
@@ -75,7 +131,8 @@ void destroyOpenGLSurface(gnWindowSurface surface) {
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
switch (format) {
case GN_FORMAT_NONE: return GL_NONE;
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB_ALPHA;
case GN_FORMAT_RGBA8: return GL_RGBA;
case GN_FORMAT_RGBA8_SRGB: return GL_RGBA;
case GN_FORMAT_D32S8_UINT: return GL_DEPTH_STENCIL;
case GN_FORMAT_D24S8_UINT: return GL_DEPTH_STENCIL;
@@ -87,6 +144,7 @@ GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format) {
switch (format) {
case GN_FORMAT_NONE: return GL_NONE;
case GN_FORMAT_RGBA8: return GL_RGBA8;
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB8_ALPHA8;
case GN_FORMAT_D32S8_UINT: return GL_DEPTH32F_STENCIL8;
case GN_FORMAT_D24S8_UINT: return GL_DEPTH24_STENCIL8;

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);

View File

@@ -144,8 +144,15 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, gnExtent3D
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
size_t imageSize = info.extent.width * info.extent.height;
if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; }
if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; }
switch (info.format) {
case GN_FORMAT_NONE: imageSize *= 0; break;
case GN_FORMAT_BGRA8_SRGB: imageSize *= 4; break;
case GN_FORMAT_BGRA8: imageSize *= 4; break;
case GN_FORMAT_RGBA8: imageSize *= 4; break;
case GN_FORMAT_RGBA8_SRGB: imageSize *= 4; break;
case GN_FORMAT_D32S8_UINT: imageSize *= 5; break;
case GN_FORMAT_D24S8_UINT: imageSize *= 4; break;
};
texture->texture->size = imageSize;
VkImageCreateInfo imageInfo = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,

View File

@@ -109,6 +109,7 @@ VkFormat vkGryphnFormatToVulkanFormat(gnImageFormat format) {
case GN_FORMAT_NONE: return VK_FORMAT_UNDEFINED;
case GN_FORMAT_BGRA8_SRGB: return VK_FORMAT_B8G8R8A8_SRGB;
case GN_FORMAT_BGRA8: return VK_FORMAT_B8G8R8A8_UNORM;
case GN_FORMAT_RGBA8: return VK_FORMAT_R8G8B8A8_UNORM;
case GN_FORMAT_RGBA8_SRGB: return VK_FORMAT_R8G8B8A8_SRGB;
case GN_FORMAT_D32S8_UINT: return VK_FORMAT_D32_SFLOAT_S8_UINT;
case GN_FORMAT_D24S8_UINT: return VK_FORMAT_D24_UNORM_S8_UINT;

View File

@@ -2,8 +2,9 @@
typedef enum gnImageFormat {
GN_FORMAT_NONE,
GN_FORMAT_BGRA8_SRGB,
GN_FORMAT_BGRA8,
GN_FORMAT_BGRA8_SRGB,
GN_FORMAT_RGBA8,
GN_FORMAT_RGBA8_SRGB,
GN_FORMAT_D24S8_UINT,
GN_FORMAT_D32S8_UINT,