Hi!
I’m trying to debug my code in the main to understand why nothing is drawn and I’ve a problem with push constants.
When I’m using an UBO it works perfectly but when I want to use a push constant my matrices are not good and nothing is draw.
Here is the code :
struct Ppll2PushConsts {
Matrix4f projMatrix;
Matrix4f viewMatrix;
Matrix4f worldMat;
};
int main() {
/*Mere* mere = new Fille();
mere->testMere();
delete mere;*/
const std::string simpleVertexShader = R"(#version 460
layout (location = 0) in vec3 position;
layout (location = 1) in vec4 color;
layout (location = 2) in vec2 texCoords;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec2 fragTexCoord;
layout (push_constant) uniform PushConsts {
mat4 projectionMatrix;
mat4 viewMatrix;
mat4 worldMat;
} pushConsts;
void main () {
gl_Position = pushConsts.projectionMatrix * pushConsts.viewMatrix * pushConsts.worldMat * vec4(position, 1.f);
fragColor = color;
fragTexCoord = texCoords;
})";
const std::string fragmentShader2 = R"(
#version 460
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec4 fragColor;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 0) out vec4 outColor;
void main () {
outColor = fragColor;
})";
VkSettup settup;
Device device(settup);
RenderWindow rw(sf::VideoMode(800, 600), "test", device);
Shader shader(device);
shader.loadFromMemory(simpleVertexShader, fragmentShader2);
/*Texture texture(device);
texture.loadFromFile("tilesets/eau.png");*/
RenderTexture rt(device);
rt.create(800, 600);
Sprite rtSprite(rt.getTexture(), Vec3f(-400, -300, 0), Vec3f (800, 600, 0), sf::IntRect(0, 0, 800, 600));
/*RectangleShape quad(Vec3f(800, 600, 0));
quad.move(Vec3f(400, -300, 0));*/
VertexBuffer vb(device);
vb.setPrimitiveType(sf::Triangles);
Vertex v1 (sf::Vector3f(0, 0, 0));
Vertex v2 (sf::Vector3f(100, 0, 0));
Vertex v3 (sf::Vector3f(100, 50, 0));
Vertex v4 (sf::Vector3f(0, 50, 0));
vb.append(v1);
vb.append(v2);
vb.append(v3);
vb.append(v1);
vb.append(v3);
vb.append(v4);
vb.update();
Ppll2PushConsts ppll2PushConsts;
ppll2PushConsts.projMatrix = rt.getView().getProjMatrix().getMatrix().transpose();
ppll2PushConsts.viewMatrix = rt.getView().getViewMatrix().getMatrix().transpose();
ppll2PushConsts.worldMat = Matrix4f();
while (rw.isOpen()) {
RenderStates currentStates;
currentStates.shader = &shader;
//currentStates.transform = quad.getTransform();
rt.clear();
rt.createDescriptorPool(nullptr);
rt.createDescriptorSetLayout(nullptr);
rt.createDescriptorSets(nullptr);
VkPushConstantRange push_constant;
push_constant.offset = 0;
//this push constant range takes up the size of a MeshPushConstants struct
push_constant.size = sizeof(Ppll2PushConsts);
//this push constant range is accessible only in the vertex shader
push_constant.stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
VkPipelineLayoutCreateInfo& pipelineLayoutInfo = rt.getPipelineLayoutCreateInfo();
pipelineLayoutInfo.pPushConstantRanges = &push_constant;
pipelineLayoutInfo.pushConstantRangeCount = 1;
rt.createGraphicPipeline(vb.getPrimitiveType(), currentStates);
std::vector<VkCommandBuffer> commandBuffers;
commandBuffers.resize(rt.getSwapchainFrameBuffers().size());
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = device.getCommandPool();
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = (uint32_t) commandBuffers.size();
if (vkAllocateCommandBuffers(device.getDevice(), &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
std::cout<<"failed to allocate command buffers!"<<std::endl;
}
for (size_t i = 0; i < commandBuffers.size(); i++) {
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
std::cout<<"failed to begin recording command buffer!"<<std::endl;
}
vkCmdPushConstants(commandBuffers[i], rt.getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Ppll2PushConsts), &ppll2PushConsts);
rt.drawVertexBuffer(commandBuffers[i], i, vb, currentStates);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
std::cout<<"failed to record command buffer!"<<std::endl;
}
}
rt.updateCommandBuffers(commandBuffers);
rt.display();
rw.clear();
rw.draw(rtSprite);
rw.display();
}
/*MyAppli app(sf::VideoMode(800, 600), "Test odfaeg");
return app.exec();*/
}
What’s wrong ?
Thanks.