Compare commits
7 Commits
5db32f367a
...
51bd6e28fa
Author | SHA1 | Date | |
---|---|---|---|
![]() |
51bd6e28fa | ||
![]() |
7b1266281c | ||
![]() |
be2f91e2bb | ||
![]() |
d1862e3d6f | ||
![]() |
10cd374731 | ||
![]() |
4477c41dc4 | ||
![]() |
916df68f06 |
@@ -1,5 +1,6 @@
|
||||
#include "opengl_loader.h"
|
||||
#include "commands/buffers/opengl_command_buffer.h"
|
||||
#include "commands/commands/opengl_commands.h"
|
||||
|
||||
gnCommandFunctions loadOpenGLCommandFunctions() {
|
||||
return (gnCommandFunctions) {
|
||||
@@ -10,8 +11,8 @@ gnCommandFunctions loadOpenGLCommandFunctions() {
|
||||
._gnEndCommandBuffer = openglEndCommandBuffer,
|
||||
._gnDestroyCommandBuffer = openglDestroyCommandBuffer,
|
||||
|
||||
._gnCommandBeginRenderPass = NULL,
|
||||
._gnCommandEndRenderPass = NULL,
|
||||
._gnCommandBeginRenderPass = openglBeginRenderPass,
|
||||
._gnCommandEndRenderPass = openglEndRenderPass,
|
||||
|
||||
._gnCommandBindGraphicsPipeline = NULL,
|
||||
._gnCommandSetViewport = NULL,
|
||||
|
@@ -8,6 +8,9 @@
|
||||
#include "commands/pool/opengl_command_pool.h"
|
||||
#include "buffer/opengl_buffer.h"
|
||||
#include "textures/opengl_texture.h"
|
||||
#include "framebuffer/opengl_framebuffer.h"
|
||||
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
||||
#include "submit/opengl_submit.h"
|
||||
|
||||
gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||
return (gnDeviceFunctions){
|
||||
@@ -21,11 +24,11 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||
._gnCreateRenderPassDescriptor = openglCreateRenderPass,
|
||||
._gnDestroyRenderPassDescriptor = openglDestroyRenderPass,
|
||||
|
||||
._gnCreateGraphicsPipeline = NULL,
|
||||
._gnDestroyGraphicsPipeline = NULL,
|
||||
._gnCreateGraphicsPipeline = openglCreateGraphicsPipeline,
|
||||
._gnDestroyGraphicsPipeline = openglDestroyGraphicsPipeline,
|
||||
|
||||
._gnCreateFramebuffer = NULL,
|
||||
._gnDestroyFramebuffer = NULL,
|
||||
._gnCreateFramebuffer = openglCreateFramebuffer,
|
||||
._gnDestroyFramebuffer = openglDestroyFramebuffer,
|
||||
|
||||
._gnCreateCommandPool = openglCreateCommandPool,
|
||||
._gnDestroyCommandPool = openglDestroyCommandPool,
|
||||
@@ -49,7 +52,7 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
|
||||
._gnTextureData = openglTextureData,
|
||||
._gnDestroyTexture = openglDestroyTexture,
|
||||
|
||||
._gnSubmit = NULL,
|
||||
._gnSubmit = openglSubmit,
|
||||
._gnPresent = NULL,
|
||||
|
||||
._gnWaitForDevice = waitForOpenGLDevice
|
||||
|
@@ -8,6 +8,7 @@ gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* comm
|
||||
if (pool->commandPool->canBeReallocated[c] == GN_TRUE) {
|
||||
pool->commandPool->canBeReallocated[c] = GN_FALSE;
|
||||
commandBuffers[i]->commandBuffer = &pool->commandPool->commandBuffers[c];
|
||||
commandBuffers[i]->commandBuffer->commmandRunner = openglCreateCommandRunner();
|
||||
wasAbleToAllocate = GN_TRUE;
|
||||
break;
|
||||
}
|
||||
@@ -21,11 +22,9 @@ gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* comm
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
|
||||
void openglResetCommandBuffer(gnCommandBuffer commandBuffer) {
|
||||
// commandBuffer->commandBuffer->
|
||||
// nothing, for now command buffers are implictly reset on begin
|
||||
}
|
||||
void openglResetCommandBuffer(gnCommandBuffer commandBuffer) { /* nothing, for now command buffers are implictly reset on begin */ }
|
||||
gnReturnCode openglBeginCommandBuffer(gnCommandBuffer commandBuffer) {
|
||||
openglResetCommandRunner(commandBuffer->commandBuffer->commmandRunner);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
gnReturnCode openglEndCommandBuffer(gnCommandBuffer commandBuffer) {
|
||||
@@ -33,4 +32,5 @@ gnReturnCode openglEndCommandBuffer(gnCommandBuffer commandBuffer) {
|
||||
}
|
||||
void openglDestroyCommandBuffer(gnCommandBuffer commandBuffer) {
|
||||
commandBuffer->commandPool->commandPool->canBeReallocated[commandBuffer->commandBuffer->index] = GN_TRUE;
|
||||
openglDestroyCommandRunner(&commandBuffer->commandBuffer->commmandRunner);
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#pragma once
|
||||
#include "core/src/command/command_buffer/gryphn_command_buffer.h"
|
||||
#include "commands/commands/opengl_command_runner.h"
|
||||
|
||||
typedef struct gnPlatformCommandBuffer_t {
|
||||
int index;
|
||||
openglCommandRunner commmandRunner;
|
||||
} gnPlatformCommandBuffer;
|
||||
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
|
||||
|
||||
|
@@ -0,0 +1,23 @@
|
||||
#include "opengl_command_runner.h"
|
||||
#include "vector"
|
||||
|
||||
typedef struct openglCommandRunner_t {
|
||||
std::vector<std::function<void()>> commands;
|
||||
} glCommandRunner;
|
||||
|
||||
GN_CPP_FUNCTION openglCommandRunner openglCreateCommandRunner() { return new glCommandRunner(); }
|
||||
GN_CPP_FUNCTION void openglRunCommandRunner(openglCommandRunner runner) {
|
||||
for (int i = 0; i < runner->commands.size(); i++)
|
||||
runner->commands[i]();
|
||||
}
|
||||
GN_CPP_FUNCTION void openglResetCommandRunner(openglCommandRunner runner) { runner->commands.clear(); }
|
||||
GN_CPP_FUNCTION void openglDestroyCommandRunner(openglCommandRunner* runner) {
|
||||
*runner = NULL;
|
||||
delete runner;
|
||||
}
|
||||
|
||||
void openglCommandRunnerBindFunction(openglCommandRunner runner, std::function<void()> function) {
|
||||
runner->commands.push_back(function);
|
||||
}
|
||||
|
||||
// void openglCommandRunnerBindFunction(openglCommandRunner runner, openglFunctionBinding binding) { runner->commands.push_back(binding); }
|
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "utils/gryphn_cpp_function.h"
|
||||
typedef struct openglCommandRunner_t* openglCommandRunner;
|
||||
|
||||
GN_CPP_FUNCTION openglCommandRunner openglCreateCommandRunner();
|
||||
GN_CPP_FUNCTION void openglResetCommandRunner(openglCommandRunner runner);
|
||||
GN_CPP_FUNCTION void openglRunCommandRunner(openglCommandRunner runner);
|
||||
GN_CPP_FUNCTION void openglDestroyCommandRunner(openglCommandRunner* runner);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "functional"
|
||||
#define openglBindFunction(expr) std::function<void()>([=]{ expr; })
|
||||
void openglCommandRunnerBindFunction(openglCommandRunner runner, std::function<void()> function);
|
||||
#endif
|
@@ -0,0 +1,29 @@
|
||||
#include "glad/glad.h"
|
||||
#include "opengl_commands.h"
|
||||
#include "opengl_command_runner.h"
|
||||
#include "commands/buffers/opengl_command_buffer.h"
|
||||
#include "framebuffer/opengl_framebuffer.h"
|
||||
|
||||
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) {
|
||||
const char* func_name = "begin render pass";
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([passInfo]{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, passInfo.framebuffer->framebuffer->framebuffers[0]);
|
||||
glClearColor(passInfo.clearValues[0].r, passInfo.clearValues[0].g, passInfo.clearValues[0].b, passInfo.clearValues[0].a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glViewport(passInfo.offset.x, passInfo.offset.y, passInfo.size.x, passInfo.size.y);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglEndRenderPass(gnCommandBuffer buffer) {
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([]{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline);
|
||||
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport viewport);
|
||||
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor scissor);
|
||||
GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type);
|
||||
GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
|
||||
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);
|
||||
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets);
|
||||
GN_CPP_FUNCTION void openglBindVertexBytes(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
|
14
projects/apis/opengl/src/commands/commands/opengl_commands.h
Normal file
14
projects/apis/opengl/src/commands/commands/opengl_commands.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "core/src/command/commands/gryphn_command.h"
|
||||
#include "utils/gryphn_cpp_function.h"
|
||||
|
||||
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo);
|
||||
GN_CPP_FUNCTION void openglEndRenderPass(gnCommandBuffer buffer);
|
||||
GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline);
|
||||
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport viewport);
|
||||
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor scissor);
|
||||
GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type);
|
||||
GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
|
||||
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);
|
||||
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets);
|
||||
GN_CPP_FUNCTION void openglBindVertexBytes(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
|
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);
|
@@ -0,0 +1,15 @@
|
||||
#include "opengl_graphics_pipeline.h"
|
||||
#include "shaders/opengl_shader_module.h"
|
||||
|
||||
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
||||
graphicsPipeline->graphicsPipeline->program = glCreateProgram();
|
||||
for (int i = 0; i < info.shaderModuleCount; i++)
|
||||
glAttachShader(graphicsPipeline->graphicsPipeline->program, info.shaderModules[i]->shaderModule->id);
|
||||
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void openglDestroyGraphicsPipeline(gnGraphicsPipeline graphicsPipeline) {
|
||||
glDeleteProgram(graphicsPipeline->graphicsPipeline->program);
|
||||
free(graphicsPipeline->graphicsPipeline);
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
#include "glad/glad.h"
|
||||
#include "core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||
|
||||
typedef struct gnPlatformGraphicsPipeline_t {
|
||||
GLuint program;
|
||||
} gnPlatformGraphicsPipeline;
|
||||
|
||||
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info);
|
||||
void openglDestroyGraphicsPipeline(gnGraphicsPipeline graphicsPipeline);
|
11
projects/apis/opengl/src/submit/opengl_submit.c
Normal file
11
projects/apis/opengl/src/submit/opengl_submit.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "core/src/submit/gryphn_submit.h"
|
||||
#include "commands/buffers/opengl_command_buffer.h"
|
||||
|
||||
gnReturnCode openglSubmit(gnOutputDevice device, gnSubmitInfo info) {
|
||||
if (device == GN_NULL_HANDLE) return GN_INVALID_HANDLE;
|
||||
|
||||
for (uint32_t i = 0; i < info.commandBufferCount; i++)
|
||||
openglRunCommandRunner(info.commandBuffers[i]->commandBuffer->commmandRunner);
|
||||
|
||||
return GN_SUCCESS;
|
||||
}
|
3
projects/apis/opengl/src/submit/opengl_submit.h
Normal file
3
projects/apis/opengl/src/submit/opengl_submit.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include "core/src/submit/gryphn_submit.h"
|
||||
gnReturnCode openglSubmit(gnOutputDevice device, gnSubmitInfo info);
|
Reference in New Issue
Block a user