Skip to content

Commit

Permalink
Create mipmapped texture and read it
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Oct 27, 2023
1 parent 0979564 commit 8826ca8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
30 changes: 28 additions & 2 deletions 07-Mipmap/mipmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ struct Mipmap : public ExampleFramework {

RGLCommandBufferPtr commandBuffer;
RGLBufferPtr vertexBuffer, indexBuffer;
RGLTexturePtr depthTexture;
RGLTexturePtr depthTexture, mipTexture;
RGLSamplerPtr mipSampler;
RGLRenderPipelinePtr renderPipeline;
RGLRenderPassPtr renderPass;

Expand All @@ -33,9 +34,30 @@ struct Mipmap : public ExampleFramework {

createDepthTexture();

mipTexture = device->CreateTexture({
.usage = {.TransferDestination = true, .Sampled = true},
.aspect = {.HasColor = true},
.width = 4096,
.height = 4096,
.mipLevels = 4,
.format = RGL::TextureFormat::RGBA16_Sfloat,
.debugName = "Mip Texture"
}
);
mipSampler = device->CreateSampler({});

RGL::PipelineLayoutDescriptor layoutConfig{
.bindings = {

{
.binding = 0,
.type = RGL::BindingType::Sampler,
.stageFlags = RGL::BindingVisibility::Fragment,
},
{
.binding = 1,
.type = RGL::BindingType::SampledImage,
.stageFlags = RGL::BindingVisibility::Fragment,
},
},
.constants = {{ ubo, 0, RGL::StageVisibility::Vertex}}
};
Expand Down Expand Up @@ -157,6 +179,8 @@ struct Mipmap : public ExampleFramework {
commandBuffer->SetVertexBytes(ubo, 0);
commandBuffer->SetVertexBuffer(vertexBuffer);
commandBuffer->SetIndexBuffer(indexBuffer);
commandBuffer->SetFragmentSampler(mipSampler, 0);
commandBuffer->SetFragmentTexture(mipTexture.get(), 1);
commandBuffer->DrawIndexed(std::size(BasicObjects::Quad::indices));

commandBuffer->EndRendering();
Expand All @@ -174,6 +198,8 @@ struct Mipmap : public ExampleFramework {
commandBuffer.reset();
renderPass.reset();
renderPipeline.reset();
mipTexture.reset();
mipSampler.reset();
depthTexture.reset();
indexBuffer.reset();
vertexBuffer.reset();
Expand Down
7 changes: 6 additions & 1 deletion 07-Mipmap/mipmap.frag
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

layout(binding = 0) uniform sampler g_sampler;
layout(binding = 1) uniform texture2D tex;

layout(location = 0) in vec2 uv;
layout(location = 0) out vec4 outcolor;
void main(){
outcolor = vec4(uv,1,1);
vec3 sampled = texture(sampler2D(tex,g_sampler),uv).rgb;

outcolor = vec4(sampled,1);
}

0 comments on commit 8826ca8

Please sign in to comment.