Kann einen gleichmäßigen Puffer mit Shader Binary nicht bindenC++

Programme in C++. Entwicklerforum
Anonymous
 Kann einen gleichmäßigen Puffer mit Shader Binary nicht binden

Post by Anonymous »

Ich kompile den GLSL -Quellcode im laufenden Flug mit Shaderc. Ich weiß, dass es funktioniert, weil ich keine OpenGL -Fehler bekomme und das Netz korrekt auf dem Bildschirm gerendert wird. Wenn ich jedoch einige zusätzliche Informationen über einheitliche Puffer hochladen wollte, funktionierte es nicht.

Code: Select all

#version 450 core

layout (location = 0) out vec4 out_colour;

layout (binding = 0, std140) uniform Colours
{
vec3 Colour;
};

void main()
{
out_colour = vec4(Colour, 1.0);
}
< /code>
Der Code, der für das Kompilieren verantwortlich ist: < /p>
shaderc::Compiler compiler;
shaderc::CompileOptions compileOptions;
compileOptions.SetTargetEnvironment(shaderc_target_env_opengl, shaderc_env_version_opengl_4_5);
compileOptions.SetGenerateDebugInfo();
compileOptions.SetOptimizationLevel(shaderc_optimization_level_performance);
compileOptions.SetAutoBindUniforms(true);

uint32_t programId = glCreateProgram();

// m_Sources: std::unordered_map
for (const auto& [stage, source] : m_Sources)
{
const shaderc::CompilationResult result = compiler.CompileGlslToSpv(source, ShaderUtils::ShaderStageToShaderC(stage), m_Name.data(), compileOptions);
assert(result.GetCompilationStatus() == shaderc_compilation_status_success, "Failed to compile shader!");
auto binary = std::vector(result.begin(), result.end());

uint32_t shader = glCreateShader(ShaderUtils::ShaderStageToOpenGL(stage));
glShaderBinary(1, &shader, GL_SHADER_BINARY_FORMAT_SPIR_V, binary.data(), (uint32_t)binary.size() * sizeof(uint32_t));
glSpecializeShader(shader, "main", 0, nullptr, nullptr);
glAttachShader(programId, shader);
}

glLinkProgram(programId);
glValidateProgram(programId);
< /code>
Nach all dem verwende ich Spirv-Cross, um die Reflexionsdaten (Name, Bindung, Größe usw.) zu erhalten. Code für den UBO: < /p>
glm::vec3 colour = { 0.2f, 1.0f, 0.3f };
uint32_t ubo;
glCreateBuffers(1, &ubo);
glNamedBufferData(ubo, sizeof(glm::vec3), nullptr, GL_DYNAMIC_DRAW);
glNamedBufferSubData(ubo, 0, sizeof(glm::vec3), glm::value_ptr(colour));

uint32_t bindingPoint = 0; // Actually this comes from the reflection
glBindBuffer(GL_UNIFORM_BUFFER, ubo);
glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, ubo);
< /code>
All dies funktioniert nicht. Das Rechteck, das ich rendern möchte, ist nicht grün, sondern schwarz. Seltsamerweise, wenn ich GlshaderSource 
und glcompileshader verwende, funktioniert alles einwandfrei. Ich habe völlig keine Ideen mehr.>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post