From 55605b6d5f26818eed6b86045486fa390094002a Mon Sep 17 00:00:00 2001 From: Gregory Wells Date: Tue, 19 Aug 2025 08:39:29 -0400 Subject: [PATCH] render --- .../src/commands/commands/opengl_commands.cpp | 21 +++++++++------- .../apis/opengl/src/device/glsl_shader.glsl | 4 ++-- .../src/framebuffer/opengl_framebuffer.c | 1 - .../apis/opengl/src/present/opengl_present.c | 24 +++---------------- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/projects/apis/opengl/src/commands/commands/opengl_commands.cpp b/projects/apis/opengl/src/commands/commands/opengl_commands.cpp index c553dcd..a5662fe 100644 --- a/projects/apis/opengl/src/commands/commands/opengl_commands.cpp +++ b/projects/apis/opengl/src/commands/commands/opengl_commands.cpp @@ -3,20 +3,25 @@ #include "opengl_command_runner.h" #include "commands/buffers/opengl_command_buffer.h" #include "framebuffer/opengl_framebuffer.h" +#include +#include "buffer/opengl_buffer.h" GN_CPP_FUNCTION void openglBeginRenderPass(gnCommandBuffer buffer, gnRenderPassInfo passInfo) { - const char* func_name = "begin render pass"; - openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function([passInfo]{ - // 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); - // 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); + gnClearValue* values = (gnClearValue*)malloc(sizeof(gnClearValue*) * passInfo.clearValueCount); + memcpy(values, passInfo.clearValues, sizeof(gnClearValue*) * passInfo.clearValueCount); + + openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function([passInfo, values]{ + glBindFramebuffer(GL_FRAMEBUFFER, passInfo.framebuffer->framebuffer->framebuffers[0]); + glClearColor(values[0].r, values[0].g, values[0].b, values[0].a); + glClear(GL_COLOR_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([]{ - // glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); })); } GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer buffer, gnGraphicsPipeline graphicsPipeline); diff --git a/projects/apis/opengl/src/device/glsl_shader.glsl b/projects/apis/opengl/src/device/glsl_shader.glsl index 3ee0c18..df3ba7c 100644 --- a/projects/apis/opengl/src/device/glsl_shader.glsl +++ b/projects/apis/opengl/src/device/glsl_shader.glsl @@ -18,6 +18,6 @@ const char * fragment_shader_source = "in vec2 texcoord;\n" "\n" "void main() {\n" - " //FragColor = texture(tex, texcoord);\n" - " FragColor = vec4(texcoord, 0.0, 1.0);\n" + " FragColor = texture(tex, texcoord);\n" + " //FragColor = vec4(texcoord, 0.0, 1.0);\n" "}\n" ; diff --git a/projects/apis/opengl/src/framebuffer/opengl_framebuffer.c b/projects/apis/opengl/src/framebuffer/opengl_framebuffer.c index feac3b7..d666209 100644 --- a/projects/apis/opengl/src/framebuffer/opengl_framebuffer.c +++ b/projects/apis/opengl/src/framebuffer/opengl_framebuffer.c @@ -24,7 +24,6 @@ gnReturnCode openglCreateFramebuffer(gnFramebuffer framebuffer, gnDevice device, }); return GN_FAILED_CREATE_OBJECT; } - } return GN_SUCCESS; } diff --git a/projects/apis/opengl/src/present/opengl_present.c b/projects/apis/opengl/src/present/opengl_present.c index 9b4ba71..f336522 100644 --- a/projects/apis/opengl/src/present/opengl_present.c +++ b/projects/apis/opengl/src/present/opengl_present.c @@ -9,33 +9,15 @@ gnReturnCode openglPresent(gnOutputDeviceHandle device, gnPresentInfo info) { 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); - - // id blit = [commandBuffer blitCommandEncoder]; - // [blit copyFromTexture:info.presentationQueues[i]->images[info.imageIndices[i]]->texture->texture - // sourceSlice:0 - // sourceLevel:0 - // sourceOrigin:(MTLOrigin){0, 0, 0} - // sourceSize:(MTLSize){info.presentationQueues[i]->info.imageSize.x, info.presentationQueues[i]->info.imageSize.y, 1} - // toTexture:drawable.texture - // destinationSlice:0 - // destinationLevel:0 - // destinationOrigin:(MTLOrigin){0, 0, 0}]; - - // [blit endEncoding]; - - // [drawable texture]; - - // [commandBuffer presentDrawable:drawable]; - // [commandBuffer commit]; - // device->outputDevice->executingCommandBuffer = commandBuffer; } - // [device->outputDevice->executingCommandBuffer waitUntilCompleted]; - // 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) {