vulkan framebuffers
This commit is contained in:
34
rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.c
Normal file
34
rendering_api/vulkan/src/framebuffers/vulkan_framebuffer.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "vulkan_framebuffer.h"
|
||||
#include "textures/vulkan_texture.h"
|
||||
#include "renderpass/vulkan_render_pass_descriptor.h"
|
||||
#include "output_device/vulkan_output_devices.h"
|
||||
|
||||
gnReturnCode gnCreateFramebufferFn(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t info) {
|
||||
framebuffer->framebuffer = malloc(sizeof(struct gnPlatformFramebuffer_t));
|
||||
|
||||
VkImageView* attachments = malloc(sizeof(VkImageView) * info.attachmentCount);
|
||||
for (int i = 0; i < info.attachmentCount; i++)
|
||||
attachments[i] = info.attachments[i].texture->imageView;
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||
.renderPass = info.renderPassDescriptor->renderPassDescriptor->renderPass,
|
||||
.attachmentCount = info.attachmentCount,
|
||||
.pAttachments = attachments,
|
||||
.width = info.size.x,
|
||||
.height = info.size.y,
|
||||
.layers = 1
|
||||
};
|
||||
|
||||
if (vkCreateFramebuffer(device->outputDevice->device, &framebufferInfo, NULL, &framebuffer->framebuffer->framebuffer) != VK_SUCCESS) {
|
||||
return GN_FAILED_TO_CREATE_FRAMEBUFFER;
|
||||
}
|
||||
|
||||
free(attachments);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
void gnDestroyFramebufferFn(struct gnFramebuffer_t* framebuffer) {
|
||||
vkDestroyFramebuffer(framebuffer->device->outputDevice->device, framebuffer->framebuffer->framebuffer, NULL);
|
||||
free(framebuffer->framebuffer);
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include "core/framebuffer/gryphn_framebuffer.h"
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
typedef struct gnPlatformFramebuffer_t {
|
||||
VkFramebuffer framebuffer;
|
||||
} gnPlatformFramebuffer;
|
@@ -1,9 +1,11 @@
|
||||
#include "gryphn_framebuffer.h"
|
||||
#include "core/gryphn_platform_functions.h"
|
||||
|
||||
gnReturnCode gnCreateFramebuffer(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t framebufferInfo) {
|
||||
framebuffer->device = device;
|
||||
return device->deviceFunctions->_gnCreateFramebuffer(framebuffer, device, framebufferInfo);
|
||||
}
|
||||
|
||||
void gnDestroyFramebuffer(struct gnFramebuffer_t *framebuffer) {
|
||||
|
||||
framebuffer->device->deviceFunctions->_gnDestroyFramebuffer(framebuffer);
|
||||
}
|
||||
|
@@ -8,8 +8,9 @@
|
||||
#include "window_surface/gryphn_surface.h"
|
||||
#include "window_surface/gryphn_surface_create_functions.h"
|
||||
#include "shader_module/gryphn_shader_module.h"
|
||||
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||
#include "renderpass/gryphn_render_pass_descriptor.h"
|
||||
#include "pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||
#include "framebuffer/gryphn_framebuffer.h"
|
||||
|
||||
typedef struct gnFunctions_t {
|
||||
gnReturnCode (*_gnCreateInstance)(gnInstance* instance, struct gnInstanceInfo_t info);
|
||||
@@ -62,4 +63,7 @@ typedef struct gnDeviceFunctions_t {
|
||||
|
||||
gnReturnCode (*_gnCreateGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline, struct gnOutputDevice_t* device, struct gnGraphicsPipelineInfo_t pipelineInfo);
|
||||
void (*_gnDestroyGraphicsPipeline)(struct gnGraphicsPipeline_t* pipeline);
|
||||
|
||||
gnReturnCode (*_gnCreateFramebuffer)(struct gnFramebuffer_t* framebuffer, struct gnOutputDevice_t* device, struct gnFramebufferInfo_t framebufferInfo);
|
||||
void (*_gnDestroyFramebuffer)(struct gnFramebuffer_t* framebuffer);
|
||||
} gnDeviceFunctions;
|
||||
|
@@ -77,4 +77,6 @@ void gnLoadDeviceFunctions(struct gnDynamicLibrary_t* lib, struct gnDeviceFuncti
|
||||
gnLoadDLLFunction(lib, functions->_gnDestroyRenderPassDescriptor, "gnDestroyRenderPassDescriptorFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnCreateGraphicsPipeline, "gnCreateGraphicsPipelineFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnDestroyGraphicsPipeline, "gnDestroyGraphicsPipelineFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnCreateFramebuffer, "gnCreateFramebufferFn");
|
||||
gnLoadDLLFunction(lib, functions->_gnDestroyFramebuffer, "gnDestroyFramebufferFn");
|
||||
}
|
||||
|
@@ -24,7 +24,8 @@ typedef enum gnReturnCode_t {
|
||||
GN_FAILED_TO_CREATE_RENDER_PASS,
|
||||
GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE,
|
||||
GN_UNSUPPORTED_SHADER_MODULE,
|
||||
GN_UNKNOWN_SUBPASS
|
||||
GN_UNKNOWN_SUBPASS,
|
||||
GN_FAILED_TO_CREATE_FRAMEBUFFER
|
||||
} gnReturnCode;
|
||||
|
||||
typedef gnReturnCode gnErrorCode;
|
||||
@@ -54,5 +55,6 @@ static const char* gnErrorCodeToCString(enum gnReturnCode_t returnCode) {
|
||||
case GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE: return "GN_FAILED_TO_CREATE_GRAPHICS_PIPELINE";
|
||||
case GN_UNSUPPORTED_SHADER_MODULE: return "GN_UNSUPPORTED_SHADER_MODULE";
|
||||
case GN_UNKNOWN_SUBPASS: return "GN_UNKNOWN_SUBPASS";
|
||||
case GN_FAILED_TO_CREATE_FRAMEBUFFER: return "GN_FAILED_TO_CREATE_FRAMEBUFFER";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user