Compare commits

...

7 Commits

Author SHA1 Message Date
Gregory Wells
f5d7257e66 fix framebuffers being drawn flipped 2025-08-19 17:43:56 -04:00
Gregory Wells
16d2e7b8fc SRGB in OpenGL 2025-08-19 16:50:16 -04:00
Gregory Wells
7f6ec430de finish the most basic rendering pipeline 2025-08-19 16:31:19 -04:00
Gregory Wells
50d8a669b3 draw commands 2025-08-19 08:50:00 -04:00
Gregory Wells
55605b6d5f render 2025-08-19 08:39:29 -04:00
Gregory Wells
740cf1e628 render fullscreen texcoord quad 2025-08-18 23:22:09 -04:00
Gregory Wells
453f7b70db create framebuffer object 2025-08-18 23:02:56 -04:00
24 changed files with 294 additions and 33 deletions

View File

@@ -14,14 +14,14 @@ gnCommandFunctions loadOpenGLCommandFunctions() {
._gnCommandBeginRenderPass = openglBeginRenderPass,
._gnCommandEndRenderPass = openglEndRenderPass,
._gnCommandBindGraphicsPipeline = NULL,
._gnCommandSetViewport = NULL,
._gnCommandSetScissor = NULL,
._gnCommandBindUniform = NULL,
._gnCommandPushConstant = NULL,
._gnCommandBindGraphicsPipeline = openglBindGraphicsPipeline,
._gnCommandSetViewport = openglSetViewport,
._gnCommandSetScissor = openglSetScissor,
._gnCommandBindUniform = openglBindUniform,
._gnCommandPushConstant = openglPushConstant,
._gnCommandBindBuffer = NULL,
._gnCommandDraw = NULL,
._gnCommandDrawIndexed = NULL,
._gnCommandBindBuffer = openglBindBuffer,
._gnCommandDraw = openglDraw,
._gnCommandDrawIndexed = openglDrawIndexed,
};
}

View File

@@ -11,6 +11,7 @@
#include "framebuffer/opengl_framebuffer.h"
#include "graphics_pipeline/opengl_graphics_pipeline.h"
#include "submit/opengl_submit.h"
#include "present/opengl_present.h"
gnDeviceFunctions loadOpenGLDeviceFunctions() {
return (gnDeviceFunctions){
@@ -53,7 +54,7 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnDestroyTexture = openglDestroyTexture,
._gnSubmit = openglSubmit,
._gnPresent = NULL,
._gnPresent = openglPresent,
._gnWaitForDevice = waitForOpenGLDevice
};

View File

@@ -14,14 +14,16 @@ gnReturnCode openglCreateBuffer(gnBufferHandle buffer, gnDevice device, gnBuffer
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;
glNamedBufferData(buffer->buffer->id, info.size, NULL, buffer->buffer->usage);
glNamedBufferStorage(buffer->buffer->id, info.size, NULL, GL_DYNAMIC_STORAGE_BIT | GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_COHERENT_BIT | GL_MAP_PERSISTENT_BIT);
return GN_SUCCESS;
}
void openglBufferData(gnBufferHandle buffer, size_t dataSize, void* data) {
glNamedBufferData(buffer->buffer->id, dataSize, data, buffer->buffer->usage);
openglBufferSubData(buffer, 0, dataSize, data);
}
#include "stdio.h"
void openglBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize, gnBufferMemory data) {
glNamedBufferSubData(buffer->buffer->id, offset, dataSize, data);
glBindBuffer(buffer->buffer->type, buffer->buffer->id);
glBufferSubData(buffer->buffer->type, 0, dataSize, data);
}
void* openglMapBuffer(gnBufferHandle buffer) {
return glMapNamedBuffer(buffer->buffer->id, GL_READ_WRITE);

View File

@@ -1,6 +1,7 @@
#pragma once
#include "core/src/buffers/gryphn_buffer.h"
#include "glad/glad.h"
#include "utils/gryphn_cpp_function.h"
typedef struct gnPlatformBuffer_t {
GLuint id;
@@ -13,3 +14,6 @@ void openglBufferSubData(gnBufferHandle buffer, size_t offset, size_t dataSize,
void* openglMapBuffer(gnBufferHandle buffer);
void openglUnmapBuffer(gnBufferHandle buffer);
void openglDestroyBuffer(gnBufferHandle buffer);
GN_CPP_FUNCTION GLenum gnBufferTypeToGLEnum(gnBufferType type);

View File

@@ -9,6 +9,15 @@ gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* comm
pool->commandPool->canBeReallocated[c] = GN_FALSE;
commandBuffers[i]->commandBuffer = &pool->commandPool->commandBuffers[c];
commandBuffers[i]->commandBuffer->commmandRunner = openglCreateCommandRunner();
// glGenBuffers(1, &commandBuffers[i]->commandBuffer->vertexBuffer);
// glBindBuffer(GL_ARRAY_BUFFER, commandBuffers[i]->commandBuffer->vertexBuffer);
// glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);
// gl
// glGenBuffers(1, &commandBuffers[i]->commandBuffer->indexBuffer);
wasAbleToAllocate = GN_TRUE;
break;
}

View File

@@ -1,10 +1,12 @@
#pragma once
#include "glad/glad.h"
#include "core/src/command/command_buffer/gryphn_command_buffer.h"
#include "commands/commands/opengl_command_runner.h"
typedef struct gnPlatformCommandBuffer_t {
int index;
openglCommandRunner commmandRunner;
gnGraphicsPipeline boundGraphicsPipeline;
} gnPlatformCommandBuffer;
gnReturnCode openglCommandPoolAllocateCommandBuffers(gnCommandBufferHandle* commandBuffers, uint32_t count, gnCommandPoolHandle pool);

View File

@@ -3,27 +3,88 @@
#include "opengl_command_runner.h"
#include "commands/buffers/opengl_command_buffer.h"
#include "framebuffer/opengl_framebuffer.h"
#include <string.h>
#include "buffer/opengl_buffer.h"
#include "graphics_pipeline/opengl_graphics_pipeline.h"
#include "renderpass/opengl_render_pass_descriptor.h"
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) {
const char* func_name = "begin render pass";
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([passInfo]{
GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo sPassInfo) {
gnRenderPassInfo passInfo = sPassInfo;
gnClearValue* values = (gnClearValue*)malloc(sizeof(gnClearValue*) * passInfo.clearValueCount);
memcpy(values, passInfo.clearValues, sizeof(gnClearValue*) * passInfo.clearValueCount);
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([passInfo, values]{
glBindFramebuffer(GL_FRAMEBUFFER, passInfo.framebuffer->framebuffer->framebuffers[0]);
glClearColor(passInfo.clearValues[0].r, passInfo.clearValues[0].g, passInfo.clearValues[0].b, passInfo.clearValues[0].a);
if (passInfo.renderPassDescriptor->renderPassDescriptor->subpasses[0].colorAttachments[0].format == GL_SRGB8_ALPHA8) glEnable(GL_FRAMEBUFFER_SRGB);
glClearColor(values[0].r, values[0].g, values[0].b, values[0].a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glViewport(passInfo.offset.x, passInfo.offset.y, passInfo.size.x, passInfo.size.y);
free(values);
}));
}
GN_CPP_FUNCTION void openglEndRenderPass(gnCommandBuffer buffer) {
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([]{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDisable(GL_FRAMEBUFFER_SRGB);
}));
}
GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline);
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport viewport);
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor scissor);
GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type);
GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets);
GN_CPP_FUNCTION void openglBindVertexBytes(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer commandBuffer, gnGraphicsPipeline graphicsPipeline) {
gnGraphicsPipeline pipeline = graphicsPipeline;
gnCommandBuffer buffer = commandBuffer;
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, pipeline]{
buffer->commandBuffer->boundGraphicsPipeline = pipeline;
glBindVertexArray(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject);
glUseProgram(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->program);
}));
}
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport viewport) {
}
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor scissor) {
}
GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type) {
gnBufferType bType = type;
gnCommandBufferHandle bBuffer = buffer;
gnBufferHandle bBufferToBind = bufferToBind;
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([bType, bBuffer, bBufferToBind]{
if (bType == GN_VERTEX_BUFFER) {
glVertexArrayVertexBuffer(
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, 0,
bBufferToBind->buffer->id, 0,
bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->stride
);
} else if (bType == GN_INDEX_BUFFER) {
glVertexArrayElementBuffer(bBuffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->vertexArrayObject, bBufferToBind->buffer->id);
}
}));
}
GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int sVertexCount, int sFirstVertex, int sInstanceCount, int sFirstInstance) {
int vertexCount = sVertexCount, firstVertex = sFirstVertex, instanceCount = sInstanceCount, firstInstance = sFirstInstance;
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([vertexCount, firstVertex, 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) {
gnCommandBuffer buffer = sBuffer;
gnIndexType type = sType;
int indexCount = sIndexCount, firstIndex = sFirstIndex, vertexOffset = sVertexOffset, instanceCount = sInstanceCount, firstInstance = sFirstInstance;
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer, type, indexCount, 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) {
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([]{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 5);
}));
}
GN_CPP_FUNCTION void openglPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) {
}

View File

@@ -11,4 +11,4 @@ GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHand
GN_CPP_FUNCTION void openglDraw(gnCommandBuffer buffer, int vertexCount, int firstVertex, int instanceCount, int firstInstance);
GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle buffer, gnIndexType type, int indexCount, int firstIndex, int vertexOffset, int instanceCount, int firstInstance);
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle buffer, gnUniform uniform, uint32_t set, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets);
GN_CPP_FUNCTION void openglBindVertexBytes(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);
GN_CPP_FUNCTION void openglPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data);

View File

@@ -0,0 +1,23 @@
const char * vertex_shader_source =
"#version 450 core\n"
"\n"
"layout(location = 0) in vec2 inPosition;\n"
"layout(location = 1) in vec2 inTexcoord;\n"
"\n"
"out vec2 texcoord;\n"
"\n"
"void main() {\n"
" gl_Position = vec4(inPosition, 0.0, 1.0);\n"
" texcoord = inTexcoord;\n"
"}\n" ;
const char * fragment_shader_source =
"#version 450 core\n"
"\n"
"out vec4 FragColor;\n"
"layout(binding = 0) uniform sampler2D tex;\n"
"in vec2 texcoord;\n"
"\n"
"void main() {\n"
" FragColor = texture(tex, texcoord);\n"
" //FragColor = vec4(texcoord, 0.0, 1.0);\n"
"}\n" ;

View File

@@ -1,5 +1,72 @@
#include "glad/glad.h"
#include "opengl_output_device.h"
#include "glsl_shader.glsl"
#include "stdlib.h"
#include "core/src/instance/gryphn_instance.h"
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) { return GN_SUCCESS; }
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) {
int success;
char infoLog[512];
device->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
float vertices[] = {
-1.0f, 1.0f, 0.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 1.0f, 1.0f,
};
glCreateBuffers(1, &device->outputDevice->buffer);
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, (void*)(sizeof(float) * 2));
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertex_shader_source, NULL);
glCompileShader(vertexShader);
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if(!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString(infoLog)
});
}
unsigned int fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragment_shader_source, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if(!success) {
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString(infoLog)
});
}
device->outputDevice->shaderProgram = glCreateProgram();
glAttachShader(device->outputDevice->shaderProgram, vertexShader);
glAttachShader(device->outputDevice->shaderProgram, fragmentShader);
glLinkProgram(device->outputDevice->shaderProgram);
glGetProgramiv(device->outputDevice->shaderProgram, GL_LINK_STATUS, &success);
if(!success) {
glGetProgramInfoLog(device->outputDevice->shaderProgram, 512, NULL, infoLog);
gnDebuggerSetErrorMessage(instance->debugger, (gnMessageData){
.message = gnCreateString(infoLog)
});
}
return GN_SUCCESS;
}
void waitForOpenGLDevice(const gnOutputDeviceHandle device) {}
void destroyOpenGLOutputDevice(gnOutputDeviceHandle device) {}

View File

@@ -1,7 +1,9 @@
#pragma once
#include <output_device/gryphn_output_device.h>
typedef struct gnPlatformOutputDevice_t {} gnPlatformOutputDevice;
typedef struct gnPlatformOutputDevice_t {
unsigned int buffer, shaderProgram;
} gnPlatformOutputDevice;
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
void waitForOpenGLDevice(const gnOutputDeviceHandle device);

View File

@@ -24,7 +24,6 @@ gnReturnCode openglCreateFramebuffer(gnFramebuffer framebuffer, gnDevice device,
});
return GN_FAILED_CREATE_OBJECT;
}
}
return GN_SUCCESS;
}

View File

@@ -1,5 +1,8 @@
#include "opengl_graphics_pipeline.h"
#include "shaders/opengl_shader_module.h"
#include "core/src/instance/gryphn_instance.h"
#include "stdio.h"
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info) {
graphicsPipeline->graphicsPipeline = malloc(sizeof(gnPlatformGraphicsPipeline));
@@ -7,6 +10,40 @@ gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, g
for (int i = 0; i < info.shaderModuleCount; i++)
glAttachShader(graphicsPipeline->graphicsPipeline->program, info.shaderModules[i]->shaderModule->id);
glLinkProgram(graphicsPipeline->graphicsPipeline->program);
GLint linked;
glGetProgramiv(graphicsPipeline->graphicsPipeline->program, GL_LINK_STATUS, &linked);
if (!linked) {
GLchar infoLog[512];
glGetProgramInfoLog(graphicsPipeline->graphicsPipeline->program, 512, NULL, infoLog);
gnDebuggerSetErrorMessage(device->instance->debugger, (gnMessageData){
.message = gnCreateString(infoLog)
});
} else {
gnDebuggerSetVerboseMessage(&device->instance->debugger, (gnMessageData){
.message = gnCreateString("Successfully linked program")
});
}
glCreateVertexArrays(1, &graphicsPipeline->graphicsPipeline->vertexArrayObject);
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 3, GL_FLOAT, GL_FALSE, 0);
glVertexArrayAttribBinding(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0, 0);
// Attribute 1: texcoord (2 floats)
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 1, 2, GL_FLOAT, GL_FALSE, sizeof(float)*3);
glVertexArrayAttribBinding(graphicsPipeline->graphicsPipeline->vertexArrayObject, 1, 0);
// Attribute 2: color (3 floats)
glVertexArrayAttribFormat(graphicsPipeline->graphicsPipeline->vertexArrayObject, 2, 3, GL_FLOAT, GL_FALSE, sizeof(float)*5);
glVertexArrayAttribBinding(graphicsPipeline->graphicsPipeline->vertexArrayObject, 2, 0);
graphicsPipeline->graphicsPipeline->stride = (sizeof(float) * 8);
// Enable them
glEnableVertexArrayAttrib(graphicsPipeline->graphicsPipeline->vertexArrayObject, 0);
glEnableVertexArrayAttrib(graphicsPipeline->graphicsPipeline->vertexArrayObject, 1);
glEnableVertexArrayAttrib(graphicsPipeline->graphicsPipeline->vertexArrayObject, 2);
return GN_SUCCESS;
}
void openglDestroyGraphicsPipeline(gnGraphicsPipeline graphicsPipeline) {

View File

@@ -4,6 +4,9 @@
typedef struct gnPlatformGraphicsPipeline_t {
GLuint program;
GLuint vertexArrayObject;
GLsizei stride;
} gnPlatformGraphicsPipeline;
gnReturnCode openglCreateGraphicsPipeline(gnGraphicsPipeline graphicsPipeline, gnOutputDevice device, gnGraphicsPipelineInfo info);

View File

@@ -0,0 +1,35 @@
#include "opengl_present.h"
#include "presentation_queue/opengl_presentation_queue.h"
#include "device/opengl_output_device.h"
#include "surface/opengl_surface.h"
gnReturnCode openglPresent(gnOutputDeviceHandle device, gnPresentInfo info) {
for (uint32_t i =0 ; i < info.presentationQueueCount; i++) {
uint32_tArrayListAdd(info.presentationQueues[i]->presentationQueue->avaliableTextures, info.imageIndices[i]);
glBindVertexArray(0);
if (info.presentationQueues[i]->presentationQueue->format == GL_SRGB8_ALPHA8) glEnable(GL_FRAMEBUFFER_SRGB);
glUseProgram(device->outputDevice->shaderProgram);
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
glBindTexture(GL_TEXTURE_2D, GLuintArrayListAt(info.presentationQueues[i]->presentationQueue->textures, info.imageIndices[i]));
glDrawArrays(GL_TRIANGLES, 0, 6);
glActiveTexture(GL_TEXTURE0);
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
swapBuffers(info.presentationQueues[i]->info.surface);
glDisable(GL_FRAMEBUFFER_SRGB);
}
// for (uint32_t i = 0; i < info.presentationQueueCount; i++) {
// if (info.presentationQueues[i]->info.imageSize.x != info.presentationQueues[i]->info.surface->windowSurface->layer.drawableSize.width ||
// info.presentationQueues[i]->info.imageSize.y != info.presentationQueues[i]->info.surface->windowSurface->layer.drawableSize.height) {
// return GN_SUBOPTIMAL_PRESENTATION_QUEUE;
// }
// }
return GN_SUCCESS;
}

View File

@@ -0,0 +1,4 @@
#pragma once
#include "core/src/present/gryphn_present.h"
gnReturnCode openglPresent(gnOutputDeviceHandle device, gnPresentInfo info);

View File

@@ -9,6 +9,7 @@ gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentatio
presentationQueue->images = malloc(sizeof(gnTexture) * presentationInfo.minImageCount);
presentationQueue->presentationQueue->textures = GLuintArrayListCreate();
presentationQueue->presentationQueue->avaliableTextures = uint32_tArrayListCreate();
presentationQueue->presentationQueue->format = glGryphnFormatToOpenGLInternalFormat(presentationInfo.format.format);
for (int i = 0; i < presentationInfo.minImageCount; i++) {
presentationQueue->images[i] = malloc(sizeof(struct gnTexture_t));
presentationQueue->images[i]->texture = malloc(sizeof(gnPlatformTexture));

View File

@@ -7,6 +7,7 @@ GN_ARRAY_LIST_HEADER(GLuint);
typedef struct gnPlatformPresentationQueue_t {
GLuintArrayList textures;
uint32_tArrayList avaliableTextures;
GLenum format;
} gnPlatformPresentationQueue_t;
gnReturnCode createOpenGLPresentationQueue(gnPresentationQueueHandle presentationQueue, gnOutputDeviceHandle device, gnPresentationQueueInfo presentationInfo);

View File

@@ -26,7 +26,7 @@ gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice
.storeOperation = info.attachmentInfos[attachmentIndex].storeOperation,
.attachmentIndex = attachmentIndex,
.resolveAttachmentIndex = resolveAttachmentIndex,
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[attachmentIndex].format)
.format = glGryphnFormatToOpenGLInternalFormat(info.attachmentInfos[attachmentIndex].format)
};
}
@@ -34,7 +34,7 @@ gnReturnCode openglCreateRenderPass(gnRenderPassDescriptor renderPass, gnDevice
uint32_t depthAttachmentIndex = info.subpassInfos[i].depthAttachment->index;
renderPass->renderPassDescriptor->subpasses[i].depthAttachment = (gnDepthAttachment){
.index = depthAttachmentIndex,
.format = glGryphnFormatToOpenGLFormat(info.attachmentInfos[depthAttachmentIndex].format),
.format = glGryphnFormatToOpenGLInternalFormat(info.attachmentInfos[depthAttachmentIndex].format),
.loadOperation = info.attachmentInfos[depthAttachmentIndex].loadOperation,
.storeOperation = info.attachmentInfos[depthAttachmentIndex].storeOperation,
};

View File

@@ -8,7 +8,7 @@ typedef struct glColorAttachment {
gnLoadOperation loadOperation;
gnStoreOperation storeOperation;
GLint format;
GLenum format;
uint32_t attachmentIndex;
int resolveAttachmentIndex; // -1 = no attachment
} glColorAttachment;

View File

@@ -4,6 +4,8 @@
#include "instance/gryphn_instance.h"
#include "stdlib.h"
#include "stdio.h"
GLenum gnShaderTypeToGLEnum(gnShaderModuleStage stage) {
switch (stage) {
case GN_VERTEX_SHADER_MODULE: return GL_VERTEX_SHADER;
@@ -25,6 +27,7 @@ gnReturnCode openglCreateShaderModule(gnShaderModule module, gnDevice device, gn
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);

View File

@@ -89,6 +89,10 @@ gnUInt2 getWindowSize(gnPlatformWindowSurface* surface) {
return (gnUInt2){ attr.width, attr.height };
}
void swapBuffers(gnWindowSurface surface) {
glXSwapBuffers(surface->windowSurface->display, surface->windowSurface->window);
}
#endif
#ifdef GN_WINFDOW_WAYLAND
@@ -105,11 +109,11 @@ gnSurfaceDetails genOpenGLSurfaceDetails(
surfaceDetails.formatCount = 1;
surfaceDetails.formats = malloc(sizeof(gnSurfaceFormat) * 2);
surfaceDetails.formats[0] = (gnSurfaceFormat){
.format = GN_FORMAT_RGBA8,
.format = GN_FORMAT_RGBA8_SRGB,
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
};
surfaceDetails.formats[1] = (gnSurfaceFormat){
.format = GN_FORMAT_RGBA8_SRGB,
.format = GN_FORMAT_RGBA8,
.colorSpace = GN_COLOR_SPACE_SRGB_NONLINEAR
};

View File

@@ -15,6 +15,7 @@ gnReturnCode createGLXContext(gnWindowSurfaceHandle windowSurface, gnInstanceHan
#endif
gnUInt2 getWindowSize(gnPlatformWindowSurface* surface);
void swapBuffers(gnWindowSurface surface);
gnSurfaceDetails genOpenGLSurfaceDetails(gnWindowSurfaceHandle windowSurface, gnPhysicalDevice device);
void destroyOpenGLSurface(gnWindowSurface surface);

View File

@@ -18,7 +18,9 @@ gnReturnCode openglCreateTexture(gnTexture texture, gnDevice device, const gnTex
);
return GN_SUCCESS;
}
#include "stdio.h"
void openglTextureData(gnTextureHandle texture, void* pixelData) {
printf("OpenGL id: %u\n", texture->texture->id);
glTextureSubImage2D(
texture->texture->id,
0,