Skip to content

Commit

Permalink
Update samples to use TextureView
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Nov 2, 2023
1 parent 0016816 commit 29f3da8
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion 01-HelloTriangle/hellotriangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ struct HelloWorld : public AppBase {
auto nextimg = swapchain->ImageAtIndex(presentConfig.imageIndex);
auto nextImgSize = nextimg->GetSize();

renderPass->SetAttachmentTexture(0, nextimg);
renderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());

commandBuffer->BeginRendering(renderPass);

Expand Down
8 changes: 4 additions & 4 deletions 02-Cubes/cubes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ struct Cubes : public ExampleFramework {
});

// the depth texture is not swapchained so we can set it once
renderPass->SetDepthAttachmentTexture(depthTexture.get());
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());

// create command buffer
commandBuffer = commandQueue->CreateCommandBuffer();
Expand All @@ -229,7 +229,7 @@ struct Cubes : public ExampleFramework {
auto nextimg = swapchain->ImageAtIndex(presentConfig.imageIndex);
auto nextImgSize = nextimg->GetSize();

renderPass->SetAttachmentTexture(0, nextimg);
renderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());

commandBuffer->BeginRendering(renderPass);

Expand All @@ -247,7 +247,7 @@ struct Cubes : public ExampleFramework {
commandBuffer->SetVertexBuffer(vertexBuffer);
commandBuffer->SetIndexBuffer(indexBuffer);
commandBuffer->SetFragmentSampler(textureSampler,0);
commandBuffer->SetFragmentTexture(sampledTexture.get(), 1);
commandBuffer->SetFragmentTexture(sampledTexture->GetDefaultView(), 1);
commandBuffer->DrawIndexed(std::size(BasicObjects::Cube::indices), {
.nInstances = nCubes
});
Expand All @@ -266,7 +266,7 @@ struct Cubes : public ExampleFramework {

void onresize(int width, int height) final {
createDepthTexture();
renderPass->SetDepthAttachmentTexture(depthTexture.get()); // we recreated it so we need to reset it
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView()); // we recreated it so we need to reset it
}

void sampleshutdown() final {
Expand Down
4 changes: 2 additions & 2 deletions 03-Imgui/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void main(){
auto nextimg = swapchain->ImageAtIndex(presentConfig.imageIndex);
auto nextImgSize = nextimg->GetSize();

renderPass->SetAttachmentTexture(0, nextimg);
renderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());

// create the unified vert / ind buffer
refreshBuffers(vertexBufferLength, indexBufferLength);
Expand Down Expand Up @@ -359,7 +359,7 @@ void main(){

if (ImTextureID tex_id = pcmd->GetTexID()) {
commandBuffer->SetFragmentSampler(textureSampler, 0);
commandBuffer->SetFragmentTexture(fontsTexture.get(),1);
commandBuffer->SetFragmentTexture(fontsTexture->GetDefaultView(),1);
}

commandBuffer->SetVertexBytes(ubo, 0);
Expand Down
43 changes: 22 additions & 21 deletions 04-Deferred/deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,15 @@ struct Deferred : public ExampleFramework {
});

// the depth texture is not swapchained so we can set it once
deferredRenderPass->SetDepthAttachmentTexture(depthTexture.get());
deferredRenderPass->SetAttachmentTexture(0, colorTexture.get());
deferredRenderPass->SetAttachmentTexture(1, normalTexture.get());
deferredRenderPass->SetAttachmentTexture(2, positionTexture.get());
deferredRenderPass->SetAttachmentTexture(3, idTexture.get());
deferredRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(0, colorTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(1, normalTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(2, positionTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(3, idTexture->GetDefaultView());

dirLightRenderPass->SetAttachmentTexture(0, lightingTexture.get());
dirLightRenderPass->SetDepthAttachmentTexture(depthTexture.get());
finalRenderPass->SetDepthAttachmentTexture(depthTexture.get());
dirLightRenderPass->SetAttachmentTexture(0, lightingTexture->GetDefaultView());
dirLightRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());
finalRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());

// create command buffer
commandBuffer = commandQueue->CreateCommandBuffer();
Expand Down Expand Up @@ -590,15 +590,15 @@ struct Deferred : public ExampleFramework {
.extent = {nextImgSize.width, nextImgSize.height}
});
commandBuffer->SetFragmentBytes(lightingAndFinalStageUbo, 0);
commandBuffer->SetFragmentTexture(colorTexture.get(), 1);
commandBuffer->SetFragmentTexture(normalTexture.get(), 2);
commandBuffer->SetFragmentTexture(colorTexture->GetDefaultView(), 1);
commandBuffer->SetFragmentTexture(normalTexture->GetDefaultView(), 2);
commandBuffer->SetFragmentSampler(textureSampler, 0);
commandBuffer->SetVertexBuffer(screenTriVerts);
commandBuffer->Draw(std::size(BasicObjects::ScreenTriangle::vertices));
commandBuffer->EndRendering();

// next do the final render
finalRenderPass->SetAttachmentTexture(0, nextimg);
finalRenderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());

commandBuffer->BeginRendering(finalRenderPass);

Expand All @@ -611,7 +611,7 @@ struct Deferred : public ExampleFramework {
});

commandBuffer->BindRenderPipeline(finalRenderPipeline);
commandBuffer->SetFragmentTexture(lightingTexture.get(), 1);
commandBuffer->SetFragmentTexture(lightingTexture->GetDefaultView(), 1);
commandBuffer->SetFragmentSampler(textureSampler,0);
commandBuffer->SetVertexBuffer(screenTriVerts);
commandBuffer->SetFragmentBytes(lightingAndFinalStageUbo, 0);
Expand Down Expand Up @@ -640,15 +640,15 @@ struct Deferred : public ExampleFramework {

void onresize(int width, int height) final {
updateGBuffers();
deferredRenderPass->SetDepthAttachmentTexture(depthTexture.get()); // we recreated it so we need to reset it
finalRenderPass->SetDepthAttachmentTexture(depthTexture.get());
dirLightRenderPass->SetDepthAttachmentTexture(depthTexture.get());
deferredRenderPass->SetAttachmentTexture(0, colorTexture.get());
deferredRenderPass->SetAttachmentTexture(1, normalTexture.get());
deferredRenderPass->SetAttachmentTexture(2, positionTexture.get());
deferredRenderPass->SetAttachmentTexture(3, idTexture.get());
deferredRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView()); // we recreated it so we need to reset it
finalRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());
dirLightRenderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(0, colorTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(1, normalTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(2, positionTexture->GetDefaultView());
deferredRenderPass->SetAttachmentTexture(3, idTexture->GetDefaultView());

dirLightRenderPass->SetAttachmentTexture(0, lightingTexture.get());
dirLightRenderPass->SetAttachmentTexture(0, lightingTexture->GetDefaultView());
}

void updateSelectedObject() {
Expand All @@ -663,7 +663,8 @@ struct Deferred : public ExampleFramework {
auto tmpfence = device->CreateFence(false);
tmpcmd->Begin();

tmpcmd->CopyTextureToBuffer(idTexture.get(), { .offset = {x,y}, .extent = {1,1} }, 0, imageDownloadBuffer);
auto view = idTexture->GetDefaultView();
tmpcmd->CopyTextureToBuffer(view, { .offset = {x,y}, .extent = {1,1} }, 0, imageDownloadBuffer);

tmpcmd->End();
tmpcmd->Commit({
Expand Down
6 changes: 3 additions & 3 deletions 05-XR/xr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ struct XR : public ExampleFramework {
});

// the depth texture is not swapchained so we can set it once
renderPass->SetDepthAttachmentTexture(depthTexture.get());
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());

// create command buffer
commandBuffer = commandQueue->CreateCommandBuffer();
Expand Down Expand Up @@ -713,8 +713,8 @@ struct XR : public ExampleFramework {
auto render = [this](RGL::ITexture* nextimg, RGL::ITexture* depthTexture, glm::mat4 viewProj) {

auto nextImgSize = nextimg->GetSize();
renderPass->SetAttachmentTexture(0, nextimg);
renderPass->SetDepthAttachmentTexture(depthTexture); // we recreated it so we need to reset it
renderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView()); // we recreated it so we need to reset it

commandBuffer->BeginRendering(renderPass);

Expand Down
6 changes: 3 additions & 3 deletions 06-Asteroids/asteroids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ struct Asteroids : public ExampleFramework {
});

// the depth texture is not swapchained so we can set it once
renderPass->SetDepthAttachmentTexture(depthTexture.get());
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView());

// create command buffer
commandBuffer = commandQueue->CreateCommandBuffer();
Expand Down Expand Up @@ -377,7 +377,7 @@ struct Asteroids : public ExampleFramework {
auto nextimg = swapchain->ImageAtIndex(presentConfig.imageIndex);
auto nextImgSize = nextimg->GetSize();

renderPass->SetAttachmentTexture(0, nextimg);
renderPass->SetAttachmentTexture(0, nextimg->GetDefaultView());

commandBuffer->BeginCompute(lodPipeline);
commandBuffer->SetComputeBytes(ubo,0);
Expand Down Expand Up @@ -440,7 +440,7 @@ struct Asteroids : public ExampleFramework {

void onresize(int width, int height) final {
createDepthTexture();
renderPass->SetDepthAttachmentTexture(depthTexture.get()); // we recreated it so we need to reset it
renderPass->SetDepthAttachmentTexture(depthTexture->GetDefaultView()); // we recreated it so we need to reset it
}

void sampleshutdown() final {
Expand Down
7 changes: 4 additions & 3 deletions 07-Mipmap/mipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Mipmap : public ExampleFramework {
RGLRenderPassPtr renderPass;

constexpr static auto num_mips = 4;
constexpr static auto img_size = 4096;
constexpr static auto img_size = 1024;
constexpr static glm::vec4 colors[] = {
{195/255.f,88/255.f,49/255.f, 1},
{96/255.f,111/255.f,140/255.f, 1},
Expand Down Expand Up @@ -253,14 +253,15 @@ struct Mipmap : public ExampleFramework {
}

void sampleshutdown() final {
commandBuffer.reset();
renderPass.reset();
renderPipeline.reset();
mipTexture.reset();
mipSampler.reset();
depthTexture.reset();
indexBuffer.reset();
vertexBuffer.reset();
renderPipeline.reset();
mipPipeline.reset();
commandBuffer.reset();
}

void createDepthTexture()
Expand Down

0 comments on commit 29f3da8

Please sign in to comment.