Compare commits
6 Commits
f5d7257e66
...
0c89bdb791
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0c89bdb791 | ||
![]() |
c7ae6532fd | ||
![]() |
18ec089ebc | ||
![]() |
0c0988b75a | ||
![]() |
01de997df5 | ||
![]() |
380c5d056f |
@@ -10,6 +10,9 @@ gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* comm
|
||||
commandBuffers[i]->commandBuffer = &pool->commandPool->commandBuffers[c];
|
||||
commandBuffers[i]->commandBuffer->commmandRunner = openglCreateCommandRunner();
|
||||
|
||||
commandBuffers[i]->commandBuffer->boundVertexBuffer = GN_NULL_HANDLE;
|
||||
commandBuffers[i]->commandBuffer->boundIndexBuffer = GN_NULL_HANDLE;
|
||||
|
||||
// glGenBuffers(1, &commandBuffers[i]->commandBuffer->vertexBuffer);
|
||||
// glBindBuffer(GL_ARRAY_BUFFER, commandBuffers[i]->commandBuffer->vertexBuffer);
|
||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
|
||||
|
@@ -7,6 +7,7 @@ typedef struct gnPlatformCommandBuffer_t {
|
||||
int index;
|
||||
openglCommandRunner commmandRunner;
|
||||
gnGraphicsPipeline boundGraphicsPipeline;
|
||||
gnBuffer boundVertexBuffer, boundIndexBuffer;
|
||||
} gnPlatformCommandBuffer;
|
||||
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
|
||||
|
||||
|
@@ -7,6 +7,8 @@
|
||||
#include "buffer/opengl_buffer.h"
|
||||
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
||||
#include "renderpass/opengl_render_pass_descriptor.h"
|
||||
#include "uniforms/uniform/opengl_uniform.h"
|
||||
#include "textures/opengl_texture.h"
|
||||
|
||||
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo sPassInfo) {
|
||||
gnRenderPassInfo passInfo = sPassInfo;
|
||||
@@ -36,8 +38,17 @@ GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer commandBuffer, g
|
||||
gnCommandBuffer buffer = commandBuffer;
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, pipeline]{
|
||||
buffer->commandBuffer->boundGraphicsPipeline = pipeline;
|
||||
|
||||
glBindVertexArray(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject);
|
||||
|
||||
if (buffer->commandBuffer->boundVertexBuffer != GN_NULL_HANDLE)
|
||||
glVertexArrayVertexBuffer(
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, 0,
|
||||
buffer->commandBuffer->boundVertexBuffer->buffer->id, 0,
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->stride
|
||||
);
|
||||
if (buffer->commandBuffer->boundIndexBuffer != GN_NULL_HANDLE)
|
||||
glVertexArrayElementBuffer(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, buffer->commandBuffer->boundIndexBuffer->buffer->id);
|
||||
|
||||
glUseProgram(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->program);
|
||||
}));
|
||||
}
|
||||
@@ -54,12 +65,14 @@ GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHand
|
||||
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([bType, bBuffer, bBufferToBind]{
|
||||
if (bType == GN_VERTEX_BUFFER) {
|
||||
bBuffer->commandBuffer->boundVertexBuffer = bBufferToBind;
|
||||
glVertexArrayVertexBuffer(
|
||||
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, 0,
|
||||
bBufferToBind->buffer->id, 0,
|
||||
bBuffer->commandBuffer->boundVertexBuffer->buffer->id, 0,
|
||||
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->stride
|
||||
);
|
||||
} else if (bType == GN_INDEX_BUFFER) {
|
||||
bBuffer->commandBuffer->boundIndexBuffer = bBufferToBind;
|
||||
glVertexArrayElementBuffer(bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, bBufferToBind->buffer->id);
|
||||
}
|
||||
}));
|
||||
@@ -70,7 +83,6 @@ GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int sVertexCount, int sF
|
||||
glDrawArraysInstancedBaseInstance(GL_TRIANGLES, firstVertex, vertexCount, instanceCount, firstInstance);
|
||||
}));
|
||||
}
|
||||
// #include "stdio.h"
|
||||
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle sBuffer, gnIndexType sType, int sIndexCount, int sFirstIndex, int sVertexOffset, int sInstanceCount, int sFirstInstance) {
|
||||
gnCommandBuffer buffer = sBuffer;
|
||||
gnIndexType type = sType;
|
||||
@@ -79,10 +91,19 @@ GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle sBuffer, gnIndexTyp
|
||||
glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, indexCount, (type == GN_UINT16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(sizeof(GLuint) * firstIndex), instanceCount, vertexOffset, firstInstance);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets) {
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([]{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, 5);
|
||||
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle sBuffer, gnUniform sUniform, uint32_t sSet, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets) {
|
||||
gnCommandBufferHandle buffer = sBuffer;
|
||||
gnUniform uniform = sUniform;
|
||||
uint32_t set = sSet;
|
||||
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, uniform, set]{
|
||||
for (int i = 0; i < MAX_OPENGL_BINDINGS; i++) {
|
||||
if (!uniform->uniform->bindings[i].isUpdated) continue;
|
||||
if (uniform->uniform->bindings[i].type == gl_image) {
|
||||
glActiveTexture(GL_TEXTURE0 + buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->setMap[set].bindings[uniform->uniform->bindings[i].image_info.binding]);
|
||||
glBindTexture(GL_TEXTURE_2D, uniform->uniform->bindings[i].image_info.texture->texture->id);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) {
|
||||
|
@@ -10,13 +10,13 @@ gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceH
|
||||
|
||||
device->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
||||
float vertices[] = {
|
||||
-1.0f, 1.0f, 0.0f, 0.0f,
|
||||
-1.0f, -1.0f, 0.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
-1.0f, -1.0f, 0.0f, 0.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
|
||||
-1.0f, 1.0f, 0.0f, 0.0f,
|
||||
1.0f, 1.0f, 1.0f, 0.0f,
|
||||
1.0f, -1.0f, 1.0f, 1.0f,
|
||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||
1.0f, 1.0f, 1.0f, 1.0f,
|
||||
1.0f, -1.0f, 1.0f, 0.0f,
|
||||
};
|
||||
glCreateBuffers(1, &device->outputDevice->buffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
||||
|
@@ -1,14 +1,39 @@
|
||||
#include "opengl_graphics_pipeline.h"
|
||||
#include "shaders/opengl_shader_module.h"
|
||||
#include "core/src/instance/gryphn_instance.h"
|
||||
|
||||
#include "shaders/opengl_shader_module.h"
|
||||
#include "stdio.h"
|
||||
|
||||
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
||||
|
||||
GLuint* ids = malloc(sizeof(GLuint) * info.shaderModuleCount);
|
||||
for (int i = 0; i < info.shaderModuleCount; i++) {
|
||||
glShader shader = glCompilerCompilerShader(info.shaderModules[i]->shaderModule->compiler, &info.uniformLayout);
|
||||
if (i == 0)
|
||||
for (int set = 0; set < MAX_OPENGL_SETS; set++)
|
||||
for (int binding = 0; binding < MAX_OPENGL_BINDINGS; binding++)
|
||||
graphicsPipeline->graphicsPipeline->setMap[set].bindings[binding] = shader.sets[set].bindings[binding];
|
||||
|
||||
ids[i] = glCreateShader(gnShaderTypeToGLEnum(info.shaderModules[i]->info.stage));
|
||||
const char* source = shader.source;
|
||||
printf("Shader Source %s\n", source);
|
||||
glShaderSource(ids[i], 1, &source, NULL);
|
||||
glCompileShader(ids[i]);
|
||||
|
||||
GLint returnCode;
|
||||
glGetShaderiv(ids[i], GL_COMPILE_STATUS, &returnCode);
|
||||
if(!returnCode) {
|
||||
char infoLog[512];
|
||||
glGetShaderInfoLog(ids[i], 512, NULL, infoLog);
|
||||
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
||||
.message = gnCreateString(infoLog)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
graphicsPipeline->graphicsPipeline->program = glCreateProgram();
|
||||
for (int i = 0; i < info.shaderModuleCount; i++)
|
||||
glAttachShader(graphicsPipeline->graphicsPipeline->program, info.shaderModules[i]->shaderModule->id);
|
||||
glAttachShader(graphicsPipeline->graphicsPipeline->program, ids[i]);
|
||||
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
|
||||
GLint linked;
|
||||
glGetProgramiv(graphicsPipeline->graphicsPipeline->program, GL_LINK_STATUS, &linked);
|
||||
@@ -24,6 +49,9 @@ gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, g
|
||||
});
|
||||
}
|
||||
|
||||
for (int i = 0; i < info.shaderModuleCount; i++)
|
||||
glDeleteShader(ids[i]);
|
||||
|
||||
glCreateVertexArrays(1, &graphicsPipeline->graphicsPipeline->vertexArrayObject);
|
||||
|
||||
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
|
@@ -1,8 +1,11 @@
|
||||
#pragma once
|
||||
#include "glad/glad.h"
|
||||
#include "core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||
#include "shaders/opengl_shader_compiler.h"
|
||||
|
||||
|
||||
typedef struct gnPlatformGraphicsPipeline_t {
|
||||
glSet setMap[MAX_OPENGL_SETS];
|
||||
GLuint program;
|
||||
|
||||
GLuint vertexArrayObject;
|
||||
|
@@ -13,9 +13,9 @@ gnReturnCode openglPresent(gnOutputDeviceHandle device, gnPresentInfo info) {
|
||||
|
||||
glUseProgram(device->outputDevice->shaderProgram);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, GLuintArrayListAt(info.presentationQueues[i]->presentationQueue->textures, info.imageIndices[i]));
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glUseProgram(0);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
@@ -5,16 +5,15 @@ typedef struct glCompiler_t {
|
||||
spirv_cross::CompilerGLSL* glsl;
|
||||
} glInternalCompiler;
|
||||
|
||||
void handle_resources(spirv_cross::CompilerGLSL& compiler, spirv_cross::SmallVector<spirv_cross::Resource>& resources, int* currentBinding, glSet* setMap) {
|
||||
|
||||
|
||||
void handle_resources(spirv_cross::CompilerGLSL& compiler, spirv_cross::SmallVector<spirv_cross::Resource>& resources, glSet* setMap) {
|
||||
for (size_t i = 0; i < resources.size(); i++) {
|
||||
uint32_t
|
||||
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
||||
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
||||
setMap[set].bindings[binding] = *currentBinding;
|
||||
|
||||
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
||||
compiler.set_decoration(resources[i].id, spv::DecorationBinding, *currentBinding);
|
||||
*currentBinding = (*currentBinding) + 1;
|
||||
compiler.set_decoration(resources[i].id, spv::DecorationBinding, setMap[set].bindings[binding]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,16 +24,21 @@ GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
|
||||
// compiler->glsl->set_common_options(options);
|
||||
return compiler;
|
||||
}
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler) {
|
||||
int current_binding = 0;
|
||||
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniformLayout* layout) {
|
||||
glShader shader = {};
|
||||
auto arg_buffers = compiler->glsl->get_shader_resources();
|
||||
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, ¤t_binding, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, ¤t_binding, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, ¤t_binding, shader.sets);
|
||||
uint32_t currentBinding = 0;
|
||||
for (uint32_t i = 0; i < layout->setCount; i++) {
|
||||
for (size_t c = 0; c < layout->sets[i].uniformBindingCount; c++) {
|
||||
gnUniformBinding gryphnBinding = layout->sets[i].uniformBindings[c];
|
||||
shader.sets[i].bindings[c] = currentBinding;
|
||||
currentBinding++;
|
||||
}
|
||||
}
|
||||
|
||||
shader.sets[0].bindings[3] = 69;
|
||||
auto arg_buffers = compiler->glsl->get_shader_resources();
|
||||
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, shader.sets);
|
||||
|
||||
std::string output = compiler->glsl->compile();
|
||||
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||
|
@@ -2,6 +2,7 @@
|
||||
#include "stdint.h"
|
||||
#include "glad/glad.h"
|
||||
#include "utils/gryphn_cpp_function.h"
|
||||
#include "core/src/uniforms/gryphn_uniform_layout.h"
|
||||
|
||||
#define MAX_OPENGL_SETS 16
|
||||
#define MAX_OPENGL_BINDINGS 32
|
||||
@@ -28,5 +29,5 @@ typedef struct glShader {
|
||||
|
||||
typedef struct glCompiler_t* glCompiler;
|
||||
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler);
|
||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniformLayout* layout);
|
||||
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);
|
||||
|
@@ -1,11 +1,7 @@
|
||||
#include "opengl_shader_module.h"
|
||||
#include "opengl_shader_compiler.h"
|
||||
#include "output_device/gryphn_output_device.h"
|
||||
#include "instance/gryphn_instance.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#include "stdio.h"
|
||||
|
||||
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
||||
switch (stage) {
|
||||
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
||||
@@ -21,29 +17,10 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
|
||||
.wordCount = shaderModuleInfo.size / 4,
|
||||
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
||||
};
|
||||
glCompiler compiler = glCreateCompiler(&info);
|
||||
module->shaderModule->shader = glCompilerCompilerShader(compiler);
|
||||
glDestroyCompiler(compiler);
|
||||
|
||||
module->shaderModule->id = glCreateShader(gnShaderTypeToGLEnum(shaderModuleInfo.stage));
|
||||
const char* source = module->shaderModule->shader.source;
|
||||
printf("Shader Source %s\n", source);
|
||||
glShaderSource(module->shaderModule->id, 1, &source, NULL);
|
||||
glCompileShader(module->shaderModule->id);
|
||||
|
||||
GLint returnCode;
|
||||
glGetShaderiv(module->shaderModule->id, GL_COMPILE_STATUS, &returnCode);
|
||||
if(!returnCode) {
|
||||
char infoLog[512];
|
||||
glGetShaderInfoLog(module->shaderModule->id, 512, NULL, infoLog);
|
||||
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
|
||||
.message = gnCreateString(infoLog)
|
||||
});
|
||||
}
|
||||
|
||||
module->shaderModule->compiler = glCreateCompiler(&info);
|
||||
return GN_SUCCESS;
|
||||
}
|
||||
void openglDestroyShaderModule(gnShaderModule module) {
|
||||
glDeleteShader(module->shaderModule->id);
|
||||
glDestroyCompiler(module->shaderModule->compiler);
|
||||
free(module->shaderModule);
|
||||
}
|
||||
|
@@ -3,9 +3,10 @@
|
||||
#include "opengl_shader_compiler.h"
|
||||
|
||||
typedef struct gnPlatformShaderModule_t {
|
||||
glShader shader;
|
||||
GLuint id;
|
||||
glCompiler compiler;
|
||||
} gnPlatformShaderModule;
|
||||
|
||||
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage);
|
||||
|
||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||
void openglDestroyShaderModule(gnShaderModule module);
|
||||
|
@@ -1,14 +1,17 @@
|
||||
#include "opengl_uniform.h"
|
||||
|
||||
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info) {
|
||||
uniform->uniform->type = gl_buffer;
|
||||
uniform->uniform->buffer_info = *info;
|
||||
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||
uniform->uniform->bindings[info->binding].type = gl_buffer;
|
||||
uniform->uniform->bindings[info->binding].buffer_info = *info;
|
||||
}
|
||||
void openglUpdateStorageUniform(gnUniform uniform, gnStorageUniformInfo* info) {
|
||||
uniform->uniform->type = gl_storage;
|
||||
uniform->uniform->storage_info = *info;
|
||||
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||
uniform->uniform->bindings[info->binding].type = gl_storage;
|
||||
uniform->uniform->bindings[info->binding].storage_info = *info;
|
||||
}
|
||||
void openglUpdateImageUniform(gnUniform uniform, gnImageUniformInfo* info) {
|
||||
uniform->uniform->type = gl_image;
|
||||
uniform->uniform->image_info = *info;
|
||||
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||
uniform->uniform->bindings[info->binding].type = gl_image;
|
||||
uniform->uniform->bindings[info->binding].image_info = *info;
|
||||
}
|
||||
|
@@ -1,18 +1,24 @@
|
||||
#pragma once
|
||||
#include "glad/glad.h"
|
||||
#include "core/src/uniforms/gryphn_uniform.h"
|
||||
#include "shaders/opengl_shader_compiler.h"
|
||||
|
||||
typedef enum openglUniformType {
|
||||
gl_buffer, gl_storage, gl_image
|
||||
} openglUniformType;
|
||||
|
||||
typedef struct gnPlatformUniform_t {
|
||||
typedef struct glUniformBinding {
|
||||
openglUniformType type;
|
||||
union {
|
||||
gnBufferUniformInfo buffer_info;
|
||||
gnStorageUniformInfo storage_info;
|
||||
gnImageUniformInfo image_info;
|
||||
};
|
||||
gnBool isUpdated;
|
||||
} glUniformBinding;
|
||||
|
||||
typedef struct gnPlatformUniform_t {
|
||||
glUniformBinding bindings[MAX_OPENGL_BINDINGS];
|
||||
} gnPlatformUniform;
|
||||
|
||||
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info);
|
||||
|
Reference in New Issue
Block a user