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 = &pool->commandPool->commandBuffers[c];
|
||||||
commandBuffers[i]->commandBuffer->commmandRunner = openglCreateCommandRunner();
|
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);
|
// glGenBuffers(1, &commandBuffers[i]->commandBuffer->vertexBuffer);
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, commandBuffers[i]->commandBuffer->vertexBuffer);
|
// glBindBuffer(GL_ARRAY_BUFFER, commandBuffers[i]->commandBuffer->vertexBuffer);
|
||||||
// glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
|
// glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
|
||||||
|
@@ -7,6 +7,7 @@ typedef struct gnPlatformCommandBuffer_t {
|
|||||||
int index;
|
int index;
|
||||||
openglCommandRunner commmandRunner;
|
openglCommandRunner commmandRunner;
|
||||||
gnGraphicsPipeline boundGraphicsPipeline;
|
gnGraphicsPipeline boundGraphicsPipeline;
|
||||||
|
gnBuffer boundVertexBuffer, boundIndexBuffer;
|
||||||
} gnPlatformCommandBuffer;
|
} gnPlatformCommandBuffer;
|
||||||
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
|
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
|
||||||
|
|
||||||
|
@@ -7,6 +7,8 @@
|
|||||||
#include "buffer/opengl_buffer.h"
|
#include "buffer/opengl_buffer.h"
|
||||||
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
#include "graphics_pipeline/opengl_graphics_pipeline.h"
|
||||||
#include "renderpass/opengl_render_pass_descriptor.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) {
|
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo sPassInfo) {
|
||||||
gnRenderPassInfo passInfo = sPassInfo;
|
gnRenderPassInfo passInfo = sPassInfo;
|
||||||
@@ -36,8 +38,17 @@ GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer commandBuffer, g
|
|||||||
gnCommandBuffer buffer = commandBuffer;
|
gnCommandBuffer buffer = commandBuffer;
|
||||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, pipeline]{
|
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, pipeline]{
|
||||||
buffer->commandBuffer->boundGraphicsPipeline = pipeline;
|
buffer->commandBuffer->boundGraphicsPipeline = pipeline;
|
||||||
|
|
||||||
glBindVertexArray(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject);
|
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);
|
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]{
|
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([bType, bBuffer, bBufferToBind]{
|
||||||
if (bType == GN_VERTEX_BUFFER) {
|
if (bType == GN_VERTEX_BUFFER) {
|
||||||
|
bBuffer->commandBuffer->boundVertexBuffer = bBufferToBind;
|
||||||
glVertexArrayVertexBuffer(
|
glVertexArrayVertexBuffer(
|
||||||
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, 0,
|
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, 0,
|
||||||
bBufferToBind->buffer->id, 0,
|
bBuffer->commandBuffer->boundVertexBuffer->buffer->id, 0,
|
||||||
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->stride
|
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->stride
|
||||||
);
|
);
|
||||||
} else if (bType == GN_INDEX_BUFFER) {
|
} else if (bType == GN_INDEX_BUFFER) {
|
||||||
|
bBuffer->commandBuffer->boundIndexBuffer = bBufferToBind;
|
||||||
glVertexArrayElementBuffer(bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, bBufferToBind->buffer->id);
|
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);
|
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) {
|
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle sBuffer, gnIndexType sType, int sIndexCount, int sFirstIndex, int sVertexOffset, int sInstanceCount, int sFirstInstance) {
|
||||||
gnCommandBuffer buffer = sBuffer;
|
gnCommandBuffer buffer = sBuffer;
|
||||||
gnIndexType type = sType;
|
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);
|
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) {
|
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle sBuffer, gnUniform sUniform, uint32_t sSet, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets) {
|
||||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([]{
|
gnCommandBufferHandle buffer = sBuffer;
|
||||||
glActiveTexture(GL_TEXTURE0);
|
gnUniform uniform = sUniform;
|
||||||
glBindTexture(GL_TEXTURE_2D, 5);
|
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) {
|
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));
|
device->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
|
||||||
float vertices[] = {
|
float vertices[] = {
|
||||||
-1.0f, 1.0f, 0.0f, 0.0f,
|
-1.0f, 1.0f, 0.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, 1.0f,
|
1.0f, -1.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
-1.0f, 1.0f, 0.0f, 0.0f,
|
-1.0f, 1.0f, 0.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,
|
1.0f, -1.0f, 1.0f, 0.0f,
|
||||||
};
|
};
|
||||||
glCreateBuffers(1, &device->outputDevice->buffer);
|
glCreateBuffers(1, &device->outputDevice->buffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
||||||
|
@@ -1,14 +1,39 @@
|
|||||||
#include "opengl_graphics_pipeline.h"
|
#include "opengl_graphics_pipeline.h"
|
||||||
#include "shaders/opengl_shader_module.h"
|
|
||||||
#include "core/src/instance/gryphn_instance.h"
|
#include "core/src/instance/gryphn_instance.h"
|
||||||
|
#include "shaders/opengl_shader_module.h"
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
|
||||||
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
|
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();
|
graphicsPipeline->graphicsPipeline->program = glCreateProgram();
|
||||||
for (int i = 0; i < info.shaderModuleCount; i++)
|
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);
|
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
|
||||||
GLint linked;
|
GLint linked;
|
||||||
glGetProgramiv(graphicsPipeline->graphicsPipeline->program, GL_LINK_STATUS, &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);
|
glCreateVertexArrays(1, &graphicsPipeline->graphicsPipeline->vertexArrayObject);
|
||||||
|
|
||||||
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||||
|
@@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
#include "core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
#include "core/src/pipelines/graphics_pipeline/gryphn_graphics_pipeline.h"
|
||||||
|
#include "shaders/opengl_shader_compiler.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct gnPlatformGraphicsPipeline_t {
|
typedef struct gnPlatformGraphicsPipeline_t {
|
||||||
|
glSet setMap[MAX_OPENGL_SETS];
|
||||||
GLuint program;
|
GLuint program;
|
||||||
|
|
||||||
GLuint vertexArrayObject;
|
GLuint vertexArrayObject;
|
||||||
|
@@ -13,9 +13,9 @@ gnReturnCode openglPresent(gnOutputDeviceHandle device, gnPresentInfo info) {
|
|||||||
|
|
||||||
glUseProgram(device->outputDevice->shaderProgram);
|
glUseProgram(device->outputDevice->shaderProgram);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, GLuintArrayListAt(info.presentationQueues[i]->presentationQueue->textures, info.imageIndices[i]));
|
glBindTexture(GL_TEXTURE_2D, GLuintArrayListAt(info.presentationQueues[i]->presentationQueue->textures, info.imageIndices[i]));
|
||||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glUseProgram(0);
|
glUseProgram(0);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
@@ -5,16 +5,15 @@ typedef struct glCompiler_t {
|
|||||||
spirv_cross::CompilerGLSL* glsl;
|
spirv_cross::CompilerGLSL* glsl;
|
||||||
} glInternalCompiler;
|
} 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++) {
|
for (size_t i = 0; i < resources.size(); i++) {
|
||||||
uint32_t
|
uint32_t
|
||||||
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
set = compiler.get_decoration(resources[i].id, spv::DecorationDescriptorSet),
|
||||||
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
binding = compiler.get_decoration(resources[i].id, spv::DecorationBinding);
|
||||||
setMap[set].bindings[binding] = *currentBinding;
|
|
||||||
|
|
||||||
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
compiler.unset_decoration(resources[i].id, spv::DecorationBinding);
|
||||||
compiler.set_decoration(resources[i].id, spv::DecorationBinding, *currentBinding);
|
compiler.set_decoration(resources[i].id, spv::DecorationBinding, setMap[set].bindings[binding]);
|
||||||
*currentBinding = (*currentBinding) + 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,16 +24,21 @@ GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
|
|||||||
// compiler->glsl->set_common_options(options);
|
// compiler->glsl->set_common_options(options);
|
||||||
return compiler;
|
return compiler;
|
||||||
}
|
}
|
||||||
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler) {
|
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniformLayout* layout) {
|
||||||
int current_binding = 0;
|
|
||||||
|
|
||||||
glShader shader = {};
|
glShader shader = {};
|
||||||
auto arg_buffers = compiler->glsl->get_shader_resources();
|
uint32_t currentBinding = 0;
|
||||||
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, ¤t_binding, shader.sets);
|
for (uint32_t i = 0; i < layout->setCount; i++) {
|
||||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, ¤t_binding, shader.sets);
|
for (size_t c = 0; c < layout->sets[i].uniformBindingCount; c++) {
|
||||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, ¤t_binding, shader.sets);
|
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();
|
std::string output = compiler->glsl->compile();
|
||||||
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
#include "utils/gryphn_cpp_function.h"
|
#include "utils/gryphn_cpp_function.h"
|
||||||
|
#include "core/src/uniforms/gryphn_uniform_layout.h"
|
||||||
|
|
||||||
#define MAX_OPENGL_SETS 16
|
#define MAX_OPENGL_SETS 16
|
||||||
#define MAX_OPENGL_BINDINGS 32
|
#define MAX_OPENGL_BINDINGS 32
|
||||||
@@ -28,5 +29,5 @@ typedef struct glShader {
|
|||||||
|
|
||||||
typedef struct glCompiler_t* glCompiler;
|
typedef struct glCompiler_t* glCompiler;
|
||||||
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
|
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);
|
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);
|
||||||
|
@@ -1,11 +1,7 @@
|
|||||||
#include "opengl_shader_module.h"
|
#include "opengl_shader_module.h"
|
||||||
#include "opengl_shader_compiler.h"
|
#include "opengl_shader_compiler.h"
|
||||||
#include "output_device/gryphn_output_device.h"
|
|
||||||
#include "instance/gryphn_instance.h"
|
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
#include "stdio.h"
|
|
||||||
|
|
||||||
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
||||||
switch (stage) {
|
switch (stage) {
|
||||||
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
||||||
@@ -21,29 +17,10 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
|
|||||||
.wordCount = shaderModuleInfo.size / 4,
|
.wordCount = shaderModuleInfo.size / 4,
|
||||||
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
|
||||||
};
|
};
|
||||||
glCompiler compiler = glCreateCompiler(&info);
|
module->shaderModule->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)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
void openglDestroyShaderModule(gnShaderModule module) {
|
void openglDestroyShaderModule(gnShaderModule module) {
|
||||||
glDeleteShader(module->shaderModule->id);
|
glDestroyCompiler(module->shaderModule->compiler);
|
||||||
free(module->shaderModule);
|
free(module->shaderModule);
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,10 @@
|
|||||||
#include "opengl_shader_compiler.h"
|
#include "opengl_shader_compiler.h"
|
||||||
|
|
||||||
typedef struct gnPlatformShaderModule_t {
|
typedef struct gnPlatformShaderModule_t {
|
||||||
glShader shader;
|
glCompiler compiler;
|
||||||
GLuint id;
|
|
||||||
} gnPlatformShaderModule;
|
} gnPlatformShaderModule;
|
||||||
|
|
||||||
|
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage);
|
||||||
|
|
||||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||||
void openglDestroyShaderModule(gnShaderModule module);
|
void openglDestroyShaderModule(gnShaderModule module);
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
#include "opengl_uniform.h"
|
#include "opengl_uniform.h"
|
||||||
|
|
||||||
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info) {
|
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info) {
|
||||||
uniform->uniform->type = gl_buffer;
|
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||||
uniform->uniform->buffer_info = *info;
|
uniform->uniform->bindings[info->binding].type = gl_buffer;
|
||||||
|
uniform->uniform->bindings[info->binding].buffer_info = *info;
|
||||||
}
|
}
|
||||||
void openglUpdateStorageUniform(gnUniform uniform, gnStorageUniformInfo* info) {
|
void openglUpdateStorageUniform(gnUniform uniform, gnStorageUniformInfo* info) {
|
||||||
uniform->uniform->type = gl_storage;
|
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||||
uniform->uniform->storage_info = *info;
|
uniform->uniform->bindings[info->binding].type = gl_storage;
|
||||||
|
uniform->uniform->bindings[info->binding].storage_info = *info;
|
||||||
}
|
}
|
||||||
void openglUpdateImageUniform(gnUniform uniform, gnImageUniformInfo* info) {
|
void openglUpdateImageUniform(gnUniform uniform, gnImageUniformInfo* info) {
|
||||||
uniform->uniform->type = gl_image;
|
uniform->uniform->bindings[info->binding].isUpdated = GN_TRUE;
|
||||||
uniform->uniform->image_info = *info;
|
uniform->uniform->bindings[info->binding].type = gl_image;
|
||||||
|
uniform->uniform->bindings[info->binding].image_info = *info;
|
||||||
}
|
}
|
||||||
|
@@ -1,18 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
#include "core/src/uniforms/gryphn_uniform.h"
|
#include "core/src/uniforms/gryphn_uniform.h"
|
||||||
|
#include "shaders/opengl_shader_compiler.h"
|
||||||
|
|
||||||
typedef enum openglUniformType {
|
typedef enum openglUniformType {
|
||||||
gl_buffer, gl_storage, gl_image
|
gl_buffer, gl_storage, gl_image
|
||||||
} openglUniformType;
|
} openglUniformType;
|
||||||
|
|
||||||
typedef struct gnPlatformUniform_t {
|
typedef struct glUniformBinding {
|
||||||
openglUniformType type;
|
openglUniformType type;
|
||||||
union {
|
union {
|
||||||
gnBufferUniformInfo buffer_info;
|
gnBufferUniformInfo buffer_info;
|
||||||
gnStorageUniformInfo storage_info;
|
gnStorageUniformInfo storage_info;
|
||||||
gnImageUniformInfo image_info;
|
gnImageUniformInfo image_info;
|
||||||
};
|
};
|
||||||
|
gnBool isUpdated;
|
||||||
|
} glUniformBinding;
|
||||||
|
|
||||||
|
typedef struct gnPlatformUniform_t {
|
||||||
|
glUniformBinding bindings[MAX_OPENGL_BINDINGS];
|
||||||
} gnPlatformUniform;
|
} gnPlatformUniform;
|
||||||
|
|
||||||
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info);
|
void openglUpdateBufferUniform(gnUniform uniform, gnBufferUniformInfo* info);
|
||||||
|
Reference in New Issue
Block a user