Compare commits
3 Commits
5422fd8b68
...
809750749a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
809750749a | ||
![]() |
4d904557d8 | ||
![]() |
263a8e54fa |
@@ -9,9 +9,8 @@ Gryphn works to abstract away platform API functions (Vulkan, Metal, D3D11/D3D12
|
||||
- [x] Metal
|
||||
- [ ] Direct 3D 11
|
||||
- [ ] Direct 3D 12
|
||||
- [ ] OpenGL
|
||||
- [x] OpenGL
|
||||
- [ ] Software
|
||||
* Currently working on the OpenGL backend
|
||||
|
||||
# Features
|
||||
#### Application objects
|
||||
@@ -98,3 +97,8 @@ if (code != GN_SUCCESS) printf("Failed to create XXXX %s\n", gnErrorCodeToCStrin
|
||||
|
||||
|
||||
```
|
||||
# Known limitations
|
||||
### OpenGL:
|
||||
OpenGL currently doesn't support push constants, I have some ideas brainstormed to help me support them but for the time being the max push constant size is set to zero
|
||||
### Metal:
|
||||
The device must support argument buffers for metal, at some point I will work on a solition to support both
|
||||
|
@@ -50,11 +50,18 @@ GN_CPP_FUNCTION void openglBindGraphicsPipeline(gnCommandBuffer commandBuffer, g
|
||||
glUseProgram(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->program);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport viewport) {
|
||||
|
||||
GN_CPP_FUNCTION void openglSetViewport(gnCommandBuffer buffer, gnViewport sViewport) {
|
||||
gnViewport viewport = sViewport;
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([viewport]{
|
||||
glViewport(viewport.position.x, viewport.position.y, viewport.size.x, viewport.size.y);
|
||||
glDepthRange(viewport.minDepth, viewport.maxDepth);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor scissor) {
|
||||
|
||||
GN_CPP_FUNCTION void openglSetScissor(gnCommandBuffer buffer, gnScissor sScissor) {
|
||||
gnScissor scissor = sScissor;
|
||||
openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([scissor]{
|
||||
glScissor(scissor.position.x, scissor.position.y, scissor.size.x, scissor.size.y);
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglBindBuffer(gnCommandBufferHandle buffer, gnBufferHandle bufferToBind, gnBufferType type) {
|
||||
gnBufferType bType = type;
|
||||
@@ -89,7 +96,6 @@ GN_CPP_FUNCTION void openglDrawIndexed(gnCommandBufferHandle sBuffer, gnIndexTyp
|
||||
glDrawElementsInstancedBaseVertexBaseInstance(GL_TRIANGLES, indexCount, (type == GN_UINT16) ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, (void*)(sizeof(GLuint) * firstIndex), instanceCount, vertexOffset, firstInstance);
|
||||
}));
|
||||
}
|
||||
#include "stdio.h"
|
||||
GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle sBuffer, gnUniform sUniform, uint32_t sSet, uint32_t dynamicOffsetCount, uint32_t* dynamicOffsets) {
|
||||
gnCommandBufferHandle buffer = sBuffer;
|
||||
gnUniform uniform = sUniform;
|
||||
@@ -102,19 +108,38 @@ GN_CPP_FUNCTION void openglBindUniform(gnCommandBufferHandle sBuffer, gnUniform
|
||||
glActiveTexture(GL_TEXTURE0 + buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->setMap[set].bindings[uniform->uniform->bindings[i].image_info.binding]);
|
||||
glBindTexture(GL_TEXTURE_2D, uniform->uniform->bindings[i].image_info.texture->texture->id);
|
||||
} else if (uniform->uniform->bindings[i].type == gl_buffer) {
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 0, uniform->uniform->bindings[i].buffer_info.buffer->buffer->id);
|
||||
glBindBufferBase(
|
||||
GL_UNIFORM_BUFFER,
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->setMap[set].bindings[uniform->uniform->bindings[i].buffer_info.binding],
|
||||
uniform->uniform->bindings[i].buffer_info.buffer->buffer->id
|
||||
);
|
||||
glUniformBlockBinding(
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->program,
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->setMap[set].bindings[uniform->uniform->bindings[i].buffer_info.binding],
|
||||
0
|
||||
);
|
||||
} else if (uniform->uniform->bindings[i].type == gl_storage) {
|
||||
// glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, uniform->uniform->bindings[i].storage_info.buffer->buffer->id);
|
||||
// glFlushMappedNamedBufferRange(uniform->uniform->bindings[i].buffer_info.buffer->buffer->id, 0, uniform->uniform->bindings[i].buffer_info.buffer->info.size);
|
||||
glBindBufferBase(
|
||||
GL_SHADER_STORAGE_BUFFER,
|
||||
buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->setMap[set].bindings[uniform->uniform->bindings[i].storage_info.binding],
|
||||
uniform->uniform->bindings[i].storage_info.buffer->buffer->id
|
||||
);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
GN_CPP_FUNCTION void openglPushConstant(gnCommandBufferHandle buffer, gnPushConstantLayout layout, void* data) {
|
||||
// #include "stdio.h"
|
||||
GN_CPP_FUNCTION void openglPushConstant(gnCommandBufferHandle sBuffer, gnPushConstantLayout sLayout, void* sData) {
|
||||
// gnCommandBufferHandle buffer = sBuffer;
|
||||
// // gnPushConstantLayout layout = sLayout;
|
||||
// // void* data = malloc(sizeof(sLayout.size));
|
||||
// // memcpy(data, sData, sizeof(sLayout.size));
|
||||
|
||||
// openglCommandRunnerBindFunction(buffer->commandBuffer->commmandRunner, std::function<void()>([buffer]{
|
||||
// //TODO: implement OpenGL push constants, its just hard because OpenGL is a bitch and i hate it
|
||||
|
||||
// // GLint loc = glGetUniformLocation(buffer->commandBuffer->boundGraphicsPipeline->graphicsPipeline->program, "gnPushConstantBlock");
|
||||
// // printf("member loc: %i\n", loc);
|
||||
// // if (loc == -1) return;
|
||||
// }));
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ gnPhysicalDevice* getOpenGLDevice(gnInstanceHandle instance, uint32_t* deviceCou
|
||||
.maxColorSamples = GN_SAMPLE_BIT_1,
|
||||
.maxDepthSamples = GN_SAMPLE_BIT_1,
|
||||
.maxMemoryAllocations = 0x40000000,
|
||||
.maxPushConstantSize = 256
|
||||
.maxPushConstantSize = 0
|
||||
},
|
||||
.properties = {
|
||||
.deviceType = GN_DEDICATED_DEVICE,
|
||||
|
@@ -1,12 +1,9 @@
|
||||
#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, glSet* setMap) {
|
||||
for (size_t i = 0; i < resources.size(); i++) {
|
||||
uint32_t
|
||||
@@ -40,6 +37,29 @@ GN_CPP_FUNCTION glShader glCompilerCompilerShader(glCompiler compiler, gnUniform
|
||||
handle_resources(*compiler->glsl, arg_buffers.storage_buffers, shader.sets);
|
||||
handle_resources(*compiler->glsl, arg_buffers.sampled_images, shader.sets);
|
||||
|
||||
// for (auto &pc : arg_buffers.push_constant_buffers) {
|
||||
// compiler->glsl->set_name(pc.id, "gnPushConstantBlock");
|
||||
// auto type = compiler->glsl->get_type(pc.type_id);
|
||||
// // printf("members: %lu\n", type.member_types.size());
|
||||
// for (uint32_t i = 0; i < type.member_types.size(); ++i) {
|
||||
// // // std::string name = compiler->glsl->get_member_name(pc.type_id, i);
|
||||
|
||||
// // compiler.set_member_name(push_constant_type_id, 0, "myMat4");
|
||||
// // compiler.set_member_name(push_constant_type_id, 1, "myVec3");
|
||||
// // compiler.set_member_name(push_constant_type_id, 2, "myInt");
|
||||
|
||||
// auto member_type = compiler->glsl->get_type(type.member_types[i]);
|
||||
|
||||
// // // Example: check if it's a mat4, vec3, or int
|
||||
// // if (member_type.columns == 4 && member_type.vecsize == 4)
|
||||
// // printf("member %s: mat4\n", name.c_str());
|
||||
// // else if (member_type.vecsize == 3 && member_type.columns == 1)
|
||||
// // printf("member %s: vec3\n", name.c_str());
|
||||
// // else if (member_type.basetype == spirv_cross::SPIRType::Int)
|
||||
// // printf("member %s: int\n", name.c_str());
|
||||
// }
|
||||
// }
|
||||
|
||||
std::string output = compiler->glsl->compile();
|
||||
shader.source = (char*)malloc(sizeof(char*) * (output.size() + 1));
|
||||
strcpy(shader.source, output.c_str());
|
||||
|
Reference in New Issue
Block a user