finish OpenGL shader creation
This commit is contained in:
@@ -1,7 +1,17 @@
|
|||||||
#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"
|
||||||
|
|
||||||
|
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
|
||||||
|
switch (stage) {
|
||||||
|
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
|
||||||
|
case GN_FRAGMENT_SHADER_MODULE: return GL_FRAGMENT_SHADER;
|
||||||
|
case GN_ALL_SHADER_MODULE: return GL_VERTEX_SHADER | GL_FRAGMENT_SHADER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo) {
|
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo) {
|
||||||
module->shaderModule = malloc(sizeof(gnPlatformShaderModule));
|
module->shaderModule = malloc(sizeof(gnPlatformShaderModule));
|
||||||
glCompilerInfo info = {
|
glCompilerInfo info = {
|
||||||
@@ -12,8 +22,25 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
|
|||||||
glCompiler compiler = glCreateCompiler(&info);
|
glCompiler compiler = glCreateCompiler(&info);
|
||||||
module->shaderModule->shader = glCompilerCompilerShader(compiler);
|
module->shaderModule->shader = glCompilerCompilerShader(compiler);
|
||||||
glDestroyCompiler(compiler);
|
glDestroyCompiler(compiler);
|
||||||
|
|
||||||
|
module->shaderModule->id = glCreateShader(gnShaderTypeToGLEnum(shaderModuleInfo.stage));
|
||||||
|
const char* source = module->shaderModule->shader.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);
|
||||||
free(module->shaderModule);
|
free(module->shaderModule);
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
typedef struct gnPlatformShaderModule_t {
|
typedef struct gnPlatformShaderModule_t {
|
||||||
glShader shader;
|
glShader shader;
|
||||||
|
GLuint id;
|
||||||
} gnPlatformShaderModule;
|
} gnPlatformShaderModule;
|
||||||
|
|
||||||
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
|
||||||
|
Reference in New Issue
Block a user