OpenGL framebuffer API
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include "commands/pool/opengl_command_pool.h"
|
#include "commands/pool/opengl_command_pool.h"
|
||||||
#include "buffer/opengl_buffer.h"
|
#include "buffer/opengl_buffer.h"
|
||||||
#include "textures/opengl_texture.h"
|
#include "textures/opengl_texture.h"
|
||||||
|
#include "framebuffer/opengl_framebuffer.h"
|
||||||
|
|
||||||
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||||
return (gnDeviceFunctions){
|
return (gnDeviceFunctions){
|
||||||
@@ -24,8 +25,8 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
|||||||
._gnCreateGraphicsPipeline = NULL,
|
._gnCreateGraphicsPipeline = NULL,
|
||||||
._gnDestroyGraphicsPipeline = NULL,
|
._gnDestroyGraphicsPipeline = NULL,
|
||||||
|
|
||||||
._gnCreateFramebuffer = NULL,
|
._gnCreateFramebuffer = openglCreateFramebuffer,
|
||||||
._gnDestroyFramebuffer = NULL,
|
._gnDestroyFramebuffer = openglDestroyFramebuffer,
|
||||||
|
|
||||||
._gnCreateCommandPool = openglCreateCommandPool,
|
._gnCreateCommandPool = openglCreateCommandPool,
|
||||||
._gnDestroyCommandPool = openglDestroyCommandPool,
|
._gnDestroyCommandPool = openglDestroyCommandPool,
|
||||||
|
35
projects/apis/opengl/src/framebuffer/opengl_framebuffer.c
Normal file
35
projects/apis/opengl/src/framebuffer/opengl_framebuffer.c
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "opengl_framebuffer.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
#include "renderpass/opengl_render_pass_descriptor.h"
|
||||||
|
#include "textures/opengl_texture.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "core/src/output_device/gryphn_output_device.h"
|
||||||
|
#include "core/src/instance/gryphn_instance.h"
|
||||||
|
|
||||||
|
gnReturnCode openglCreateFramebuffer(gnFramebuffer framebuffer, gnDevice device, gnFramebufferInfo info) {
|
||||||
|
framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t));
|
||||||
|
framebuffer->framebuffer->framebufferCount = info.renderPassDescriptor->renderPassDescriptor->subpassCount;
|
||||||
|
framebuffer->framebuffer->framebuffers = malloc(sizeof(GLuint) * info.renderPassDescriptor->renderPassDescriptor->subpassCount);
|
||||||
|
for (int i = 0; i < info.renderPassDescriptor->renderPassDescriptor->subpassCount; i++) {
|
||||||
|
glCreateFramebuffers(1, &framebuffer->framebuffer->framebuffers[i]);
|
||||||
|
for (int c = 0; c < info.renderPassDescriptor->renderPassDescriptor->subpasses[i].colorAttachmentCount; c++)
|
||||||
|
glNamedFramebufferTexture(framebuffer->framebuffer->framebuffers[i], GL_COLOR_ATTACHMENT0 + c, info.attachments[info.renderPassDescriptor->renderPassDescriptor->subpasses[i].colorAttachments[c].attachmentIndex]->texture->id, 0);
|
||||||
|
if (info.renderPassDescriptor->renderPassDescriptor->subpasses[i].depthAttachment.index >= 0)
|
||||||
|
glNamedFramebufferTexture(framebuffer->framebuffer->framebuffers[i], GL_DEPTH_STENCIL_ATTACHMENT, info.attachments[info.renderPassDescriptor->renderPassDescriptor->subpasses[i].depthAttachment.index]->texture->id, 0);
|
||||||
|
if (glCheckNamedFramebufferStatus(framebuffer->framebuffer->framebuffers[i], GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
|
char string[500];
|
||||||
|
snprintf(string, 500, "Failed to create OpenGL framebuffer: 0x%x\n", glCheckNamedFramebufferStatus(framebuffer->framebuffer->framebuffers[i], GL_FRAMEBUFFER));
|
||||||
|
gnDebuggerSetErrorMessage(framebuffer->device->instance->debugger, (gnMessageData){
|
||||||
|
.message = gnCreateString(string)
|
||||||
|
});
|
||||||
|
return GN_FAILED_CREATE_OBJECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return GN_SUCCESS;
|
||||||
|
}
|
||||||
|
void openglDestroyFramebuffer(gnFramebuffer framebuffer) {
|
||||||
|
for (int i = 0; i < framebuffer->framebuffer->framebufferCount; i++)
|
||||||
|
glDeleteFramebuffers(1, &framebuffer->framebuffer->framebuffers[i]);
|
||||||
|
free(framebuffer->framebuffer);
|
||||||
|
}
|
11
projects/apis/opengl/src/framebuffer/opengl_framebuffer.h
Normal file
11
projects/apis/opengl/src/framebuffer/opengl_framebuffer.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "glad/glad.h"
|
||||||
|
#include "core/src/framebuffer/gryphn_framebuffer.h"
|
||||||
|
|
||||||
|
typedef struct gnPlatformFramebuffer_t {
|
||||||
|
uint32_t framebufferCount;
|
||||||
|
GLuint* framebuffers;
|
||||||
|
} gnPlatformFramebuffer_t;
|
||||||
|
|
||||||
|
gnReturnCode openglCreateFramebuffer(gnFramebuffer framebuffer, gnDevice device, gnFramebufferInfo info);
|
||||||
|
void openglDestroyFramebuffer(gnFramebuffer framebuffer);
|
Reference in New Issue
Block a user