Skip to content

Commit

Permalink
+ Added ResourceFlags ImageWrapClampEdge, ImageWrapRepeat and ImageWr…
Browse files Browse the repository at this point in the history
…apMirroredRepeat. Needs a documentation pass. Also need to implement ImageMipNearest and ImageMipLinear which currently do nothing (mainly because mips are not supported)
  • Loading branch information
harrand committed Oct 11, 2022
1 parent 5d723e5 commit a835fb9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
3 changes: 2 additions & 1 deletion demo/gl/tz_dynamic_triangle_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ int main()
.access = tz::gl::ResourceAccess::DynamicVariable,
.flags =
{
tz::gl::ResourceFlag::ImageFilterLinear
tz::gl::ResourceFlag::ImageFilterLinear,
tz::gl::ResourceFlag::ImageWrapRepeat
}
}
)
Expand Down
3 changes: 3 additions & 0 deletions src/tz/gl/api/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ namespace tz::gl
ImageMipNearest,
/// - Indicates that a mip computed from the weighted average of the next and previous mip will be chosen.
ImageMipLinear,
ImageWrapClampEdge,
ImageWrapRepeat,
ImageWrapMirroredRepeat
};

using ResourceFlags = tz::EnumField<ResourceFlag>;
Expand Down
7 changes: 6 additions & 1 deletion src/tz/gl/impl/backend/ogl2/sampler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ namespace tz::gl::ogl2
enum class AddressMode : GLint
{
/// - An imaginary line is drawn from the out-of-bounds-coordinate back to the edge of the sampled image. The colour of the texel that it meets is used.
ClampToEdge = GL_CLAMP_TO_EDGE
ClampToEdge = GL_CLAMP_TO_EDGE,
/// - The texcoord is essentially modulo'd with the image dimensions.
Repeat = GL_REPEAT,
/// - Just like Repeat, except mirrored.
MirroredRepeat = GL_MIRRORED_REPEAT

};

/**
Expand Down
24 changes: 21 additions & 3 deletions src/tz/gl/impl/frontend/ogl2/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ namespace tz::gl
tz_assert(this->resource->get_type() == ResourceType::Image, "ImageComponent was provided a resource which was not an ImageResource. Please submit a bug report.");
const ImageResource* img_res = static_cast<const ImageResource*>(this->resource);
ogl2::LookupFilter filter = ogl2::LookupFilter::Nearest;
ogl2::AddressMode mode = ogl2::AddressMode::ClampToEdge;
#if TZ_DEBUG
if(img_res->get_flags().contains({ResourceFlag::ImageFilterNearest, ResourceFlag::ImageFilterLinear}))
{
Expand All @@ -146,6 +147,23 @@ namespace tz::gl
{
filter = ogl2::LookupFilter::Linear;
}

if(img_res->get_flags().contains({ResourceFlag::ImageWrapClampEdge, ResourceFlag::ImageWrapRepeat, ResourceFlag::ImageWrapMirroredRepeat}))
{
tz_error("ResourceFlags included all 3 of ImageWrapClampEdge, ImageWrapRepeat and ImageWrapMirroredRepeat, all of which are mutually exclusive. Please submit a bug report.");
}
if(img_res->get_flags().contains(ResourceFlag::ImageWrapClampEdge))
{
mode = ogl2::AddressMode::ClampToEdge;
}
if(img_res->get_flags().contains(ResourceFlag::ImageWrapRepeat))
{
mode = ogl2::AddressMode::Repeat;
}
if(img_res->get_flags().contains(ResourceFlag::ImageWrapMirroredRepeat))
{
mode = ogl2::AddressMode::MirroredRepeat;
}
return
{{
.format = to_ogl2(img_res->get_format()),
Expand All @@ -154,9 +172,9 @@ namespace tz::gl
{
.min_filter = filter,
.mag_filter = filter,
.address_mode_s = ogl2::AddressMode::ClampToEdge,
.address_mode_t = ogl2::AddressMode::ClampToEdge,
.address_mode_r = ogl2::AddressMode::ClampToEdge
.address_mode_s = mode,
.address_mode_t = mode,
.address_mode_r = mode
}
}};
}
Expand Down
24 changes: 21 additions & 3 deletions src/tz/gl/impl/frontend/vk2/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace tz::gl
{
vk2::LookupFilter filter = vk2::LookupFilter::Nearest;
vk2::MipLookupFilter mip_filter = vk2::MipLookupFilter::Nearest;
vk2::SamplerAddressMode mode = vk2::SamplerAddressMode::ClampToEdge;
#if TZ_DEBUG
if(res.get_flags().contains({ResourceFlag::ImageFilterNearest, ResourceFlag::ImageFilterLinear}))
{
Expand All @@ -50,16 +51,33 @@ namespace tz::gl
{
filter = vk2::LookupFilter::Linear;
}

if(res.get_flags().contains({ResourceFlag::ImageWrapClampEdge, ResourceFlag::ImageWrapRepeat, ResourceFlag::ImageWrapMirroredRepeat}))
{
tz_error("ResourceFlags included all 3 of ImageWrapClampEdge, ImageWrapRepeat and ImageWrapMirroredRepeat, all of which are mutually exclusive. Please submit a bug report.");
}
if(res.get_flags().contains(ResourceFlag::ImageWrapClampEdge))
{
mode = vk2::SamplerAddressMode::ClampToEdge;
}
if(res.get_flags().contains(ResourceFlag::ImageWrapRepeat))
{
mode = vk2::SamplerAddressMode::Repeat;
}
if(res.get_flags().contains(ResourceFlag::ImageWrapMirroredRepeat))
{
mode = vk2::SamplerAddressMode::MirroredRepeat;
}

return
{
.device = &ldev,
.min_filter = filter,
.mag_filter = filter,
.mipmap_mode = mip_filter,
.address_mode_u = vk2::SamplerAddressMode::ClampToEdge,
.address_mode_v = vk2::SamplerAddressMode::ClampToEdge,
.address_mode_w = vk2::SamplerAddressMode::ClampToEdge
.address_mode_u = mode,
.address_mode_v = mode,
.address_mode_w = mode
};
};

Expand Down

0 comments on commit a835fb9

Please sign in to comment.