Compare commits

...

19 Commits

Author SHA1 Message Date
Gregory Wells
6c6037b76f Update README.md 2025-08-13 09:28:05 -04:00
Gregory Wells
8fc99079dc command buffer basic lifecycle 2025-08-12 23:56:35 -04:00
Gregory Wells
5b43e3d5be OpenGL buffers 2025-08-12 23:51:04 -04:00
Gregory Wells
362efd8920 command pool and command buffers 2025-08-12 23:34:30 -04:00
Gregory Wells
d48332fdcd write the functions for the command pool/buffers 2025-08-12 23:09:39 -04:00
Gregory Wells
f251613d77 opengl uniform pools 2025-08-12 23:00:22 -04:00
Gregory Wells
bb416aca61 create OpenGL render pass descriptors (faked) 2025-08-12 22:51:51 -04:00
Gregory Wells
9d4dfd85fc finish OpenGL shader creation 2025-08-12 22:49:23 -04:00
Gregory Wells
3f7b0737d7 finish cross compiliation to GLSL 2025-08-12 22:40:06 -04:00
Gregory Wells
23f46385fe actually compile shaders 2025-08-12 22:17:54 -04:00
Gregory Wells
f6484ddde5 make plain cpp 2025-08-12 20:37:36 -04:00
Gregory Wells
adf72d6436 add more stufff to utils 2025-08-12 20:32:00 -04:00
Gregory Wells
c51c29f7a4 create cpp files and functions for OpenGL shaders 2025-08-12 20:27:41 -04:00
Gregory Wells
317ffda9e7 remove warning 2025-08-12 20:27:28 -04:00
Gregory Wells
1846bdbf26 ad sprvcross to OpenGL 2025-08-12 20:19:24 -04:00
Gregory Wells
eeb2896a26 remove format that is unsupported on OpenGL 2025-08-12 20:17:31 -04:00
Gregory Wells
50e84d9802 Update utils 2025-08-12 20:02:57 -04:00
Gregory Wells
45cceff843 update utils 2025-08-12 19:52:25 -04:00
Gregory Wells
dbf90882bf remove utils 2025-08-12 19:52:07 -04:00
24 changed files with 381 additions and 65 deletions

9
.gitmodules vendored
View File

@@ -1,6 +1,9 @@
[submodule "projects/utils"]
path = projects/utils
url = https://github.com/GregoryWells2007/GryphnUtils.git
[submodule "projects/apis/metal/depends/SPIRV-Cross"]
path = projects/apis/metal/depends/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git
[submodule "projects/utils"]
path = projects/utils
url = https://github.com/GregoryWells2007/GryphnUtils.git
[submodule "projects/apis/opengl/depends/SPIRV-Cross"]
path = projects/apis/opengl/depends/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git

View File

@@ -63,6 +63,7 @@ Gryphn validation layers are meant to be more specific so there are certain ones
#### Supported layers: <br />
- GN_DEBUGGER_LAYER_PLATFORM, this only does anything on vulkan for the time being, metal currently doesnt allow you to disable its validation but that API has a lot more problems when working with it so im fine with that for the time being, it will do things like enable vulkan validation layers or it will also allow the APIs to load there specific validation layers
- GN_DEBUGGER_LAYER_FUNCTIONS, this is more for my own sake but when I am writing new backends or layers I may tend to forget to implement a specific function so this layer will just check to make sure that every function is loaded properly.
- GN_DEBUGGER_LAYER_ALLOCATORS, this layer will override all Gryphn allocation calls and provide a debug message telling the user an allocation has occured, gryphn will also keep track of all internal allocations and log when certain allocations are not being deallocated, NOTE: these are bugs in Gryphn, where a heap allocated array is never freed unless the programmer has not called the appropriate gnDestroyXXX function.
# Plans
#### 1.0 Spec <br />
Gryphn is getting to the point where I can't keep developing it in the same way I have in the past where I just implement functions and features based on when I need them so slowly over the coming weeks I want to have a true spec written down for every function, that its expected results are, what its functionality does, and just go back and look at every line of code. The spec is going to be based on what I have right now with a few modifacations and also I would like to add more features.

View File

@@ -1,5 +1,6 @@
#include "metal_shader_compiler.h"
#include "spirv_msl.hpp"
#include "stdlib.h"
// #include "iostream"
typedef struct mtlCompiler_t {
@@ -43,10 +44,10 @@ GN_CPP_FUNCTION const char* mtlCompilerShader(mtlCompiler compiler, gnUniformLay
for (size_t c = 0; c < uniformLayout->sets[i].uniformBindingCount; c++) {
gnUniformBinding gryphnBinding = uniformLayout->sets[i].uniformBindings[c];
spirv_cross::MSLResourceBinding binding = {
.stage = (compiler->stage == mtlVertex) ? spv::ExecutionModelVertex : spv::ExecutionModelFragment,
.desc_set = ((uint32_t)i + 1),
.binding = gryphnBinding.binding,
.count = 1,
.desc_set = ((uint32_t)i + 1),
.stage = (compiler->stage == mtlVertex) ? spv::ExecutionModelVertex : spv::ExecutionModelFragment,
};
if (gryphnBinding.type == GN_COMBINED_IMAGE_SAMPLER_DESCRIPTOR) {
binding.msl_texture = currentBinding;

View File

@@ -1,17 +1,11 @@
#pragma once
#include "stdint.h"
#include "stdlib.h"
#include "utils/gryphn_bool.h"
#include "utils/gryphn_cpp_function.h"
#include <core/src/uniforms/gryphn_uniform_layout.h>
#ifdef __cplusplus
#define GN_CPP_FUNCTION extern "C"
#else
#define GN_CPP_FUNCTION
#endif
#define MAX_METAL_SETS 32
#define MAX_METAL_BINDINGS 16
#define MAX_METAL_SETS 16
#define MAX_METAL_BINDINGS 32
typedef struct mtlCompiler_t* mtlCompiler;
@@ -31,33 +25,3 @@ typedef struct mtlCompilerInfo {
GN_CPP_FUNCTION mtlCompiler mtlCreateCompiler(mtlCompilerInfo* info);
GN_CPP_FUNCTION const char* mtlCompilerShader(mtlCompiler compiler, gnUniformLayout* uniformLayout);
// typedef struct mtlShaderOptions {
// gnBool useArgumentBuffers;
// mtlShaderModuleStage stage;
// const char* entryPoint;
// } mtlShaderOptions;
// typedef struct mtlBinding {
// uint32_t spvBinding;
// uint32_t metalID;
// } mtlBinding;
// typedef struct mtlSetMap {
// uint32_t setIndex, mtlSetIndex;
// mtlBinding bindings[MAX_METAL_BINDINGS];
// } mtlSetMap;
// typedef struct mtlShaderMap {
// mtlSetMap sets[MAX_METAL_SETS];
// } mtlShaderMap;
// typedef struct mtlShader {
// const char* code;
// mtlShaderMap map;
// } mtlShader;
// #ifdef __cplusplus
// extern "C"
// #endif
// mtlShader mtlCompileShader(uint32_t* code, size_t wordCount, mtlShaderOptions* options);

View File

@@ -3,7 +3,7 @@ set(CMAKE_CXX_STANDARD 17)
project(GryphnOpenGLImpl)
file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS
"src/*.c"
"src/*.c" "src/*.cpp"
)
file(GLOB_RECURSE LOADER_FILES CONFIGURE_DEPENDS
"loader/*.c"
@@ -19,8 +19,9 @@ target_include_directories(GryphnOpenGLImpl PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../../
${CMAKE_CURRENT_SOURCE_DIR}/../../../include/
)
add_subdirectory(depends/SPIRV-Cross)
target_include_directories(GryphnOpenGLImpl PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/depends/glad/include/
)
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,26 @@
#include "opengl_loader.h"
#include "commands/buffers/opengl_command_buffer.h"
gnCommandFunctions loadOpenGLCommandFunctions() {
return (gnCommandFunctions) {
._gnCommandPoolAllocateCommandBuffers = openglCommandPoolAllocateCommandBuffers,
._gnBeginCommandBuffer = openglBeginCommandBuffer,
._gnResetCommandBuffer = openglResetCommandBuffer,
._gnEndCommandBuffer = openglEndCommandBuffer,
._gnDestroyCommandBuffer = openglDestroyCommandBuffer,
._gnCommandBeginRenderPass = NULL,
._gnCommandEndRenderPass = NULL,
._gnCommandBindGraphicsPipeline = NULL,
._gnCommandSetViewport = NULL,
._gnCommandSetScissor = NULL,
._gnCommandBindUniform = NULL,
._gnCommandPushConstant = NULL,
._gnCommandBindBuffer = NULL,
._gnCommandDraw = NULL,
._gnCommandDrawIndexed = NULL,
};
}

View File

@@ -1,6 +1,11 @@
#include "opengl_loader.h"
#include "device/opengl_output_device.h"
#include "presentation_queue/opengl_presentation_queue.h"
#include "shaders/opengl_shader_module.h"
#include "renderpass/opengl_render_pass_descriptor.h"
#include "uniforms/pool/opengl_uniform_pool.h"
#include "commands/pool/opengl_command_pool.h"
#include "buffer/opengl_buffer.h"
gnDeviceFunctions loadOpenGLDeviceFunctions() {
return (gnDeviceFunctions){
@@ -8,11 +13,11 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnPresentationQueueGetImage = getOpenGLPresentationQueueImage,
._gnDestroyPresentationQueue = destroyOpenGLPresentationQueue,
._gnCreateShaderModule = NULL,
._gnDestroyShaderModule = NULL,
._gnCreateShaderModule = openglCreateShaderModule,
._gnDestroyShaderModule = openglDestroyShaderModule,
._gnCreateRenderPassDescriptor = NULL,
._gnDestroyRenderPassDescriptor = NULL,
._gnCreateRenderPassDescriptor = openglCreateRenderPass,
._gnDestroyRenderPassDescriptor = openglDestroyRenderPass,
._gnCreateGraphicsPipeline = NULL,
._gnDestroyGraphicsPipeline = NULL,
@@ -20,18 +25,19 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnCreateFramebuffer = NULL,
._gnDestroyFramebuffer = NULL,
._gnCreateCommandPool = NULL,
._gnDestroyCommandPool = NULL,
._gnCreateCommandPool = openglCreateCommandPool,
._gnDestroyCommandPool = openglDestroyCommandPool,
._gnCreateBuffer = NULL,
._gnBufferData = NULL,
._gnBufferSubData = NULL,
._gnMapBuffer = NULL,
._gnDestroyBuffer = NULL,
._gnCreateBuffer = openglCreateBuffer,
._gnBufferData = openglBufferData,
._gnBufferSubData = openglBufferSubData,
._gnMapBuffer = openglMapBuffer,
._gnUnmapBuffer = openglUnmapBuffer,
._gnDestroyBuffer = openglDestroyBuffer,
._gnCreateUniformPool = NULL,
._gnUniformPoolAllocateUniforms = NULL,
._gnDestroyUniformPool = NULL,
._gnCreateUniformPool = openglCreateUniformPool,
._gnUniformPoolAllocateUniforms = openglAllocateUniforms,
._gnDestroyUniformPool = openglDestroyUniformPool,
._gnUpdateBufferUniform = NULL,
._gnUpdateStorageUniform = NULL,

View File

@@ -0,0 +1,33 @@
#include "opengl_buffer.h"
GLenum gnBufferTypeToGLEnum(gnBufferType type) {
switch (type) {
case GN_VERTEX_BUFFER: return GL_ARRAY_BUFFER;
case GN_INDEX_BUFFER: return GL_ELEMENT_ARRAY_BUFFER;
case GN_UNIFORM_BUFFER: return GL_UNIFORM_BUFFER;
case GN_STORAGE_BUFFER: return GL_SHADER_STORAGE_BUFFER;
}
}
gnReturnCode openglCreateBuffer(gnBufferHandle buffer, gnDevice device, gnBufferInfo info) {
buffer->buffer = malloc(sizeof(gnPlatformBuffer));
glCreateBuffers(1, &buffer->buffer->id);
buffer->buffer->type = gnBufferTypeToGLEnum(info.type);
buffer->buffer->usage = (info.usage == GN_DYNAMIC_DRAW) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;
return GN_SUCCESS;
}
void openglBufferData(gnBufferHandle buffer, size_t dataSize, void* data) {
glNamedBufferData(buffer->buffer->id, dataSize, data, buffer->buffer->usage);
}
void openglBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data) {
glNamedBufferSubData(buffer->buffer->id, offset, dataSize, data);
}
void* openglMapBuffer(gnBufferHandle buffer) {
return glMapNamedBuffer(buffer->buffer->id, GL_READ_WRITE);
}
void openglUnmapBuffer(gnBufferHandle buffer) {
glUnmapNamedBuffer(buffer->buffer->id);
}
void openglDestroyBuffer(gnBufferHandle buffer) {
glDeleteBuffers(1, &buffer->buffer->id);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "core/src/buffers/gryphn_buffer.h"
#include "glad/glad.h"
typedef struct gnPlatformBuffer_t {
GLuint id;
GLenum type, usage;
} gnPlatformBuffer;
gnReturnCode openglCreateBuffer(gnBufferHandle buffer, gnDevice device, gnBufferInfo info);
void openglBufferData(gnBufferHandle buffer, size_t dataSize, void* data);
void openglBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data);
void* openglMapBuffer(gnBufferHandle buffer);
void openglUnmapBuffer(gnBufferHandle buffer);
void openglDestroyBuffer(gnBufferHandle buffer);

View File

@@ -0,0 +1,36 @@
#include "opengl_command_buffer.h"
#include "commands/pool/opengl_command_pool.h"
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool) {
for (int i = 0; i < count; i++) {
gnBool wasAbleToAllocate = GN_FALSE;
for (int c = i; c < pool->commandPool->allocatedCommandBufferCount; c++) {
if (pool->commandPool->canBeReallocated[c] == GN_TRUE) {
pool->commandPool->canBeReallocated[c] = GN_FALSE;
commandBuffers[i]->commandBuffer = &pool->commandPool->commandBuffers[c];
wasAbleToAllocate = GN_TRUE;
break;
}
}
if (!wasAbleToAllocate) {
openglResizeCommandPool(pool);
}
}
return GN_SUCCESS;
}
void openglResetCommandBuffer(gnCommandBuffer commandBuffer) {
// commandBuffer->commandBuffer->
// nothing, for now command buffers are implictly reset on begin
}
gnReturnCode openglBeginCommandBuffer(gnCommandBuffer commandBuffer) {
return GN_SUCCESS;
}
gnReturnCode openglEndCommandBuffer(gnCommandBuffer commandBuffer) {
return GN_SUCCESS;
}
void openglDestroyCommandBuffer(gnCommandBuffer commandBuffer) {
commandBuffer->commandPool->commandPool->canBeReallocated[commandBuffer->commandBuffer->index] = GN_TRUE;
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include "core/src/command/command_buffer/gryphn_command_buffer.h"
typedef struct gnPlatformCommandBuffer_t {
int index;
} gnPlatformCommandBuffer;
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);
void openglResetCommandBuffer(gnCommandBuffer commandBuffer);
gnReturnCode openglBeginCommandBuffer(gnCommandBuffer commandBuffer);
gnReturnCode openglEndCommandBuffer(gnCommandBuffer commandBuffer);
void openglDestroyCommandBuffer(gnCommandBuffer commandBuffer);

View File

@@ -0,0 +1,31 @@
#include "opengl_command_pool.h"
#include "stdlib.h"
gnReturnCode openglCreateCommandPool(gnCommandPool commandPool, gnDevice device, gnCommandPoolInfo info) {
commandPool->commandPool = malloc(sizeof(gnPlatformCommandPool));
uint32_t baseCommandBufferCount = 10;
commandPool->commandPool->allocatedCommandBufferCount = baseCommandBufferCount;
commandPool->commandPool->commandBuffers = malloc(sizeof(gnPlatformCommandBuffer) * baseCommandBufferCount);
commandPool->commandPool->canBeReallocated = malloc(sizeof(gnBool) * baseCommandBufferCount);
for (int i = 0; i < baseCommandBufferCount; i++) {
commandPool->commandPool->commandBuffers[i].index = i;
commandPool->commandPool->canBeReallocated[i] = GN_TRUE;
}
return GN_SUCCESS;
}
void openglDestroyCommandPool(gnCommandPool commandPool) {
commandPool->commandPool->allocatedCommandBufferCount = 0;
free(commandPool->commandPool->commandBuffers);
free(commandPool->commandPool->canBeReallocated);
free(commandPool->commandPool);
}
void openglResizeCommandPool(gnCommandPoolHandle pool) {
pool->commandPool->allocatedCommandBufferCount *= 2;
pool->commandPool->commandBuffers = realloc(pool->commandPool->commandBuffers, sizeof(gnPlatformCommandBuffer) * pool->commandPool->allocatedCommandBufferCount);
pool->commandPool->canBeReallocated = realloc(pool->commandPool->canBeReallocated, sizeof(gnBool) * pool->commandPool->allocatedCommandBufferCount);
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "core/src/command/command_pool/gryphn_command_pool.h"
#include "commands/buffers/opengl_command_buffer.h"
#include "utils/gryphn_bool.h"
typedef struct gnPlatformCommandPool_t {
uint32_t allocatedCommandBufferCount;
gnPlatformCommandBuffer* commandBuffers;
gnBool* canBeReallocated;
} gnPlatformCommandPool;
gnReturnCode openglCreateCommandPool(gnCommandPool commandPool, gnDevice device, gnCommandPoolInfo info);
void openglDestroyCommandPool(gnCommandPool commandPool);
void openglResizeCommandPool(gnCommandPoolHandle pool);

View File

@@ -0,0 +1,6 @@
#include "opengl_render_pass_descriptor.h"
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info) {
return GN_SUCCESS;
}
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass) {}

View File

@@ -0,0 +1,6 @@
#pragma once
#include "core/src/renderpass/gryphn_render_pass_descriptor.h"
typedef struct gnPlatformRenderPassDescriptor_t gnPlatformRenderPassDescriptor;
gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice device, gnRenderPassDescriptorInfo info);
void openglDestroyRenderPass(gnRenderPassDescriptor renderPass);

View File

@@ -0,0 +1,49 @@
#include "opengl_shader_compiler.h"
#include "spirv_glsl.hpp"
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) {
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;
}
}
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info) {
glInternalCompiler* compiler = (glInternalCompiler*)malloc(sizeof(glInternalCompiler));
compiler->glsl = new spirv_cross::CompilerGLSL(info->code, info->wordCount);
// spirv_cross::CompilerGLSL::Options options = compiler->glsl->get_common_options();
// compiler->glsl->set_common_options(options);
return compiler;
}
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler) {
int current_binding = 0;
glShader shader = {};
auto arg_buffers = compiler->glsl->get_shader_resources();
handle_resources(*compiler->glsl, arg_buffers.uniform_buffers, &current_binding, shader.sets);
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, &current_binding, shader.sets);
handle_resources(*compiler->glsl, arg_buffers.sampled_images, &current_binding, shader.sets);
shader.sets[0].bindings[3] = 69;
std::string output = compiler->glsl->compile();
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
strcpy(shader.source, output.c_str());
shader.source[output.size()] = '\0';
return shader;
}
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler) {
delete compiler->glsl;
free(compiler);
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include "stdint.h"
#include "glad/glad.h"
#include "utils/gryphn_cpp_function.h"
#define MAX_OPENGL_SETS 16
#define MAX_OPENGL_BINDINGS 32
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 {
char* source;
glSet sets[MAX_OPENGL_SETS];
} glShader;
typedef struct glCompiler_t* glCompiler;
GN_CPP_FUNCTION glCompiler glCreateCompiler(glCompilerInfo* info);
GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler);
GN_CPP_FUNCTION void glDestroyCompiler(glCompiler compiler);

View File

@@ -0,0 +1,46 @@
#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"
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) {
module->shaderModule = malloc(sizeof(gnPlatformShaderModule));
glCompilerInfo info = {
.code = shaderModuleInfo.code,
.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;
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;
}
void openglDestroyShaderModule(gnShaderModule module) {
glDeleteShader(module->shaderModule->id);
free(module->shaderModule);
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "core/src/shader_module/gryphn_shader_module.h"
#include "opengl_shader_compiler.h"
typedef struct gnPlatformShaderModule_t {
glShader shader;
GLuint id;
} gnPlatformShaderModule;
gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gnShaderModuleInfo shaderModuleInfo);
void openglDestroyShaderModule(gnShaderModule module);

View File

@@ -1,5 +1,4 @@
#include <glad/glad.h>
#include "GL/glext.h"
#include "opengl_surface.h"
#include "utils/gryphn_string.h"
@@ -76,24 +75,24 @@ void destroyOpenGLSurface(gnWindowSurface surface) {
GLint glGryphnFormatToOpenGLFormat(gnImageFormat format) {
switch (format) {
case GN_FORMAT_NONE: return GL_NONE;
case GN_FORMAT_BGRA8: return GL_BGRA;
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB_ALPHA;
case GN_FORMAT_D32S8_UINT: return GL_DEPTH_STENCIL;
case GN_FORMAT_D24S8_UINT: return GL_DEPTH_STENCIL;
// unsupprted formats
case GN_FORMAT_BGRA8: return GL_NONE;
case GN_FORMAT_BGRA8_SRGB: return GL_NONE;
}
}
GLint glGryphnFormatToOpenGLInternalFormat(gnImageFormat format) {
switch (format) {
case GN_FORMAT_NONE: return GL_NONE;
case GN_FORMAT_BGRA8: return GL_BGRA8_EXT;
case GN_FORMAT_RGBA8_SRGB: return GL_SRGB8_ALPHA8;
case GN_FORMAT_D32S8_UINT: return GL_DEPTH32F_STENCIL8;
case GN_FORMAT_D24S8_UINT: return GL_DEPTH24_STENCIL8;
// unsupprted formats
case GN_FORMAT_BGRA8: return GL_NONE;
case GN_FORMAT_BGRA8_SRGB: return GL_NONE;
}
}

View File

@@ -0,0 +1,14 @@
#include "opengl_uniform_pool.h"
gnReturnCode openglCreateUniformPool(gnUniformPool pool, gnDeviceHandle device) {
return GN_SUCCESS;
}
gnUniform* openglAllocateUniforms(gnUniformPool pool, const gnUniformAllocationInfo allocInfo) {
gnUniform* uniforms = malloc(sizeof(gnUniform) * allocInfo.setCount);
for (int i = 0; i < allocInfo.setCount; i++)
uniforms[i] = malloc(sizeof(struct gnUniform_t));
return uniforms;
}
void openglDestroyUniformPool(gnUniformPool pool) {
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include "core/src/uniforms/gryphn_uniform_pool.h"
typedef struct gnPlatformUniformPool_t { gnBool warningAvoider; } gnPlatformUniformPool;
gnReturnCode openglCreateUniformPool(gnUniformPool pool, gnDeviceHandle device);
gnUniform* openglAllocateUniforms(gnUniformPool pool, const gnUniformAllocationInfo allocInfo);
void openglDestroyUniformPool(gnUniformPool pool);

View File

@@ -84,7 +84,9 @@ gnCommandFunctions loadAPICommandFunctions(gnRenderingAPI api) {
case GN_RENDERINGAPI_SOFTWARE: return (gnCommandFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX11: return (gnCommandFunctions){ NULL };
case GN_RENDERINGAPI_DIRECTX12: return (gnCommandFunctions){ NULL };
case GN_RENDERINGAPI_OPENGL: return (gnCommandFunctions){ NULL };
#ifdef GN_API_OPENGL
case GN_RENDERINGAPI_OPENGL: return loadOpenGLCommandFunctions();
#endif
#ifdef GN_API_METAL
case GN_RENDERINGAPI_METAL: return loadMetalCommandFunctions();
#endif