actually compile shaders

This commit is contained in:
Gregory Wells
2025-08-12 22:17:54 -04:00
parent f6484ddde5
commit 23f46385fe
5 changed files with 66 additions and 5 deletions

View File

@@ -3,7 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
project(GryphnOpenGLImpl) project(GryphnOpenGLImpl)
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS
"src/*.c" "src/*.c" "src/*.cpp"
) )
file(GLOB_RECURSE LOADER_FILES CONFIGURE_DEPENDS file(GLOB_RECURSE LOADER_FILES CONFIGURE_DEPENDS
"loader/*.c" "loader/*.c"
@@ -19,8 +19,9 @@ target_include_directories(GryphnOpenGLImpl PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../ ${CMAKE_CURRENT_SOURCE_DIR}/../../
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/ ${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
) )
add_subdirectory(depends/SPIRV-Cross)
target_include_directories(GryphnOpenGLImpl PRIVATE target_include_directories(GryphnOpenGLImpl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/depends/glad/include/ ${CMAKE_CURRENT_SOURCE_DIR}/depends/glad/include/
) )
add_compile_definitions(GN_REVEAL_IMPL) add_compile_definitions(GN_REVEAL_IMPL)
target_link_libraries(GryphnOpenGLImpl GL "X11") target_link_libraries(GryphnOpenGLImpl GL "X11" spirv-cross-core spirv-cross-glsl spirv-cross-cpp)

View File

@@ -0,0 +1,19 @@
#include "opengl_shader_compiler.h"
#include "spirv_glsl.hpp"
typedef struct glCompiler_t {
spirv_cross::CompilerGLSL* glsl;
} glInternalCompiler;
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
glInternalCompiler* compiler = (glInternalCompiler*)malloc(sizeof(glInternalCompiler));
compiler->glsl = new spirv_cross::CompilerGLSL(info->code, info->wordCount);
return compiler;
}
GN_CPP_FUNCTION const char* glCompilerCompilerShader(glCompiler compiler) {
std::string output = compiler->glsl->compile();
char* copied_output = (char*)malloc(sizeof(char*) * (output.size() + 1));
strcpy(copied_output, output.c_str());
copied_output[output.size()] = '\0';
return copied_output;
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "stdint.h"
#include "glad/glad.h"
#include "utils/gryphn_cpp_function.h"
#define MAX_OPENGL_SETS 32
#define MAX_OPENGL_BINDINGS 16
typedef enum glShaderModuleStage {
glVertex = GL_VERTEX_SHADER,
mtlFragment = GL_FRAGMENT_SHADER,
mtlMaxStage
} glShaderModuleStage;
typedef struct glCompilerInfo {
uint32_t* code;
int wordCount;
const char* entryPoint;
// glShaderModuleStage stage;
} glCompilerInfo;
typedef struct glSet { uint32_t bindings[MAX_OPENGL_BINDINGS]; } glSet;
typedef struct glShader {
const char* source;
glSet sets[MAX_OPENGL_SETS];
} glShader;
typedef struct glCompiler_t* glCompiler;
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
GN_CPP_FUNCTION const char* glCompilerCompilerShader(glCompiler compiler);

View File

@@ -1,9 +1,17 @@
#include "opengl_shader_module.h" #include "opengl_shader_module.h"
// #include "stdio.h" #include "opengl_shader_compiler.h"
#include "stdlib.h"
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo) { gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo) {
module->shaderModule = malloc(sizeof(gnPlatformShaderModule));
glCompilerInfo info = {
.code = shaderModuleInfo.code,
.wordCount = shaderModuleInfo.size / 4,
.entryPoint = gnToCString(shaderModuleInfo.entryPoint),
};
module->shaderModule->compiler = glCreateCompiler(&info);
return GN_SUCCESS; return GN_SUCCESS;
} }
void openglDestroyShaderModule(gnShaderModule module) { void openglDestroyShaderModule(gnShaderModule module) {
free(module->shaderModule);
} }

View File

@@ -1,7 +1,9 @@
#pragma once
#include "core/src/shader_module/gryphn_shader_module.h" #include "core/src/shader_module/gryphn_shader_module.h"
#include "opengl_shader_compiler.h"
typedef struct gnPlatformShaderModule_t { typedef struct gnPlatformShaderModule_t {
const char* shaderSource; glCompiler compiler;
} gnPlatformShaderModule; } gnPlatformShaderModule;
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo); gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);