From cb55a7716f136ccaa7b71a20ed55c8d9745637ca Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Mon, 18 Aug 2025 00:08:18 -0400 Subject: [PATCH] copy needed data into renderpass --- .../metal/src/renderpass/metal_render_pass.h | 2 - .../opengl_render_pass_descriptor.c | 46 ++++++++++++++++++- .../opengl_render_pass_descriptor.h | 30 +++++++++++- 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/projects/apis/metal/src/renderpass/metal_render_pass.h b/projects/apis/metal/src/renderpass/metal_render_pass.h index ed874db..cc35001 100644 --- a/projects/apis/metal/src/renderpass/metal_render_pass.h +++ b/projects/apis/metal/src/renderpass/metal_render_pass.h @@ -22,8 +22,6 @@ typedef struct gnPlatformRenderPassDescriptor_t { uint32_t subpassCount; mtlSubpass* subpasses; mtlSubpassCopyInfo* copyInfos; - - } gnPlatformRenderPassDescriptor; gnReturnCode createMetalRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info); diff --git a/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.c b/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.c index dc2a62a..7a34a09 100644 --- a/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.c +++ b/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.c @@ -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); +} diff --git a/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.h b/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.h index 8c7386b..36d7111 100644 --- a/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.h +++ b/projects/apis/opengl/src/renderpass/opengl_render_pass_descriptor.h @@ -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);