rhi: Add texture wrap modes

They cannot be changed after creation, for simplicity.
This commit is contained in:
Eidolon 2023-03-24 16:37:48 -05:00
parent 70c375f9db
commit 8cc6e9a4f0
8 changed files with 121 additions and 19 deletions

View file

@ -165,7 +165,7 @@ void BlitRectPass::transfer(Rhi& rhi, Handle<TransferContext> ctx)
glm::mat3(
glm::vec3(1.f, 0.f, 0.f),
glm::vec3(0.f, output_flip_ ? -1.f : 1.f, 0.f),
glm::vec3(0.f, 0.f, 1.f)
glm::vec3(0.f, output_flip_ ? 1.f : 0.f, 1.f)
)
};

View file

@ -64,7 +64,13 @@ void ImguiPass::prepass(Rhi& rhi)
uint32_t uwidth = static_cast<uint32_t>(width);
uint32_t uheight = static_cast<uint32_t>(height);
font_atlas_ = rhi.create_texture({TextureFormat::kRGBA, uwidth, uheight});
font_atlas_ = rhi.create_texture({
TextureFormat::kRGBA,
uwidth,
uheight,
TextureWrapMode::kRepeat,
TextureWrapMode::kRepeat
});
io.Fonts->SetTexID(font_atlas_);
}

View file

@ -166,7 +166,13 @@ void PostprocessWipePass::prepass(Rhi& rhi)
}
}
wipe_tex_ = rhi.create_texture({TextureFormat::kLuminance, mask_w_, mask_h_});
wipe_tex_ = rhi.create_texture({
TextureFormat::kLuminance,
mask_w_,
mask_h_,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
void PostprocessWipePass::transfer(Rhi& rhi, Handle<TransferContext> ctx)

View file

@ -71,7 +71,13 @@ void FramebufferManager::prepass(Rhi& rhi)
// Recreate the framebuffer textures
if (main_color_ == kNullHandle)
{
main_color_ = rhi.create_texture({TextureFormat::kRGBA, current_width, current_height});
main_color_ = rhi.create_texture({
TextureFormat::kRGBA,
current_width,
current_height,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
if (main_depth_ == kNullHandle)
{
@ -80,20 +86,44 @@ void FramebufferManager::prepass(Rhi& rhi)
if (post_colors_[0] == kNullHandle)
{
post_colors_[0] = rhi.create_texture({TextureFormat::kRGBA, current_width, current_height});
post_colors_[0] = rhi.create_texture({
TextureFormat::kRGBA,
current_width,
current_height,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
if (post_colors_[1] == kNullHandle)
{
post_colors_[1] = rhi.create_texture({TextureFormat::kRGBA, current_width, current_height});
post_colors_[1] = rhi.create_texture({
TextureFormat::kRGBA,
current_width,
current_height,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
if (wipe_start_color_ == kNullHandle)
{
wipe_start_color_ = rhi.create_texture({TextureFormat::kRGBA, current_width, current_height});
wipe_start_color_ = rhi.create_texture({
TextureFormat::kRGBA,
current_width,
current_height,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
if (wipe_end_color_ == kNullHandle)
{
wipe_end_color_ = rhi.create_texture({TextureFormat::kRGBA, current_width, current_height});
wipe_end_color_ = rhi.create_texture({
TextureFormat::kRGBA,
current_width,
current_height,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
}
@ -119,7 +149,7 @@ void MainPaletteManager::prepass(Rhi& rhi)
{
if (!palette_)
{
palette_ = rhi.create_texture({TextureFormat::kRGBA, 256, 1});
palette_ = rhi.create_texture({TextureFormat::kRGBA, 256, 1, TextureWrapMode::kClamp, TextureWrapMode::kClamp});
}
}
@ -148,9 +178,15 @@ void CommonResourcesManager::prepass(Rhi& rhi)
{
if (!init_)
{
black_ = rhi.create_texture({TextureFormat::kRGBA, 1, 1});
white_ = rhi.create_texture({TextureFormat::kRGBA, 1, 1});
transparent_ = rhi.create_texture({TextureFormat::kRGBA, 1, 1});
black_ = rhi.create_texture({TextureFormat::kRGBA, 1, 1, TextureWrapMode::kClamp, TextureWrapMode::kClamp});
white_ = rhi.create_texture({TextureFormat::kRGBA, 1, 1, TextureWrapMode::kClamp, TextureWrapMode::kClamp});
transparent_ = rhi.create_texture({
TextureFormat::kRGBA,
1,
1,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
}
@ -266,7 +302,13 @@ Handle<Texture> FlatTextureManager::find_or_create_indexed(Rhi& rhi, lumpnum_t l
}
uint32_t flat_size = get_flat_size(lump);
Handle<Texture> new_tex = rhi.create_texture({TextureFormat::kLuminanceAlpha, flat_size, flat_size});
Handle<Texture> new_tex = rhi.create_texture({
TextureFormat::kLuminanceAlpha,
flat_size,
flat_size,
TextureWrapMode::kRepeat,
TextureWrapMode::kRepeat
});
flats_.insert({lump, new_tex});
to_upload_.push_back(lump);
return new_tex;

View file

@ -46,7 +46,13 @@ void SoftwarePass::prepass(Rhi& rhi)
if (!screen_texture_)
{
screen_texture_ = rhi.create_texture({TextureFormat::kLuminance, width_, height_});
screen_texture_ = rhi.create_texture({
TextureFormat::kLuminance,
width_,
height_,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
}
// If the screen width won't fit the unpack alignment, we need to copy the screen.

View file

@ -88,7 +88,13 @@ static Rect trimmed_patch_dim(const patch_t* patch);
static void create_atlas(Rhi& rhi, TwodeePassData& pass_data)
{
Atlas new_atlas;
new_atlas.tex = rhi.create_texture({TextureFormat::kLuminanceAlpha, 2048, 2048});
new_atlas.tex = rhi.create_texture({
TextureFormat::kLuminanceAlpha,
2048,
2048,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
new_atlas.tex_width = 2048;
new_atlas.tex_height = 2048;
new_atlas.rp_ctx = std::make_unique<stbrp_context>();
@ -501,12 +507,24 @@ void TwodeePass::prepass(Rhi& rhi)
if (!data_->default_tex)
{
data_->default_tex = rhi.create_texture({TextureFormat::kLuminanceAlpha, 2, 1});
data_->default_tex = rhi.create_texture({
TextureFormat::kLuminanceAlpha,
2,
1,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
data_->upload_default_tex = true;
}
if (!data_->default_colormap_tex)
{
data_->default_colormap_tex = rhi.create_texture({TextureFormat::kLuminance, 256, 1});
data_->default_colormap_tex = rhi.create_texture({
TextureFormat::kLuminance,
256,
1,
TextureWrapMode::kClamp,
TextureWrapMode::kClamp
});
data_->upload_default_tex = true;
}
if (!render_pass_)

View file

@ -110,6 +110,21 @@ constexpr GLenum map_texture_format(rhi::TextureFormat format)
}
}
constexpr GLenum map_texture_wrap(rhi::TextureWrapMode wrap)
{
switch (wrap)
{
case rhi::TextureWrapMode::kClamp:
return GL_CLAMP_TO_EDGE;
case rhi::TextureWrapMode::kRepeat:
return GL_REPEAT;
case rhi::TextureWrapMode::kMirroredRepeat:
return GL_MIRRORED_REPEAT;
default:
return GL_NEAREST;
}
}
constexpr GLenum map_internal_texture_format(rhi::TextureFormat format)
{
switch (format)
@ -527,9 +542,9 @@ rhi::Handle<rhi::Texture> GlCoreRhi::create_texture(const rhi::TextureDesc& desc
GL_ASSERT;
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
GL_ASSERT;
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, map_texture_wrap(desc.u_wrap));
GL_ASSERT;
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
gl_->TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, map_texture_wrap(desc.v_wrap));
GL_ASSERT;
gl_->TexImage2D(GL_TEXTURE_2D, 0, internal_format, desc.width, desc.height, 0, format, GL_UNSIGNED_BYTE, nullptr);
GL_ASSERT;

View file

@ -432,11 +432,20 @@ struct RenderbufferDesc
uint32_t height;
};
enum class TextureWrapMode
{
kRepeat,
kMirroredRepeat,
kClamp
};
struct TextureDesc
{
TextureFormat format;
uint32_t width;
uint32_t height;
TextureWrapMode u_wrap;
TextureWrapMode v_wrap;
};
struct BufferDesc