actually compile shaders
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -1,9 +1,17 @@
|
||||
#include "opengl_shader_module.h"
|
||||
// #include "stdio.h"
|
||||
#include "opengl_shader_compiler.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
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;
|
||||
}
|
||||
void openglDestroyShaderModule(gnShaderModule module) {
|
||||
|
||||
free(module->shaderModule);
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include "core/src/shader_module/gryphn_shader_module.h"
|
||||
#include "opengl_shader_compiler.h"
|
||||
|
||||
typedef struct gnPlatformShaderModule_t {
|
||||
const char* shaderSource;
|
||||
glCompiler compiler;
|
||||
} gnPlatformShaderModule;
|
||||
|
||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||
|
Reference in New Issue
Block a user