From 17a1700b2651acb0d4c71d66b2e5aa877d9915cf Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 28 Feb 2008 18:45:40 +0000 Subject: [PATCH] Fixes for texture padding --- panda/src/display/graphicsOutput.cxx | 10 +------- panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx | 5 ++-- panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx | 3 +-- .../glstuff/glGraphicsStateGuardian_src.cxx | 9 ++------ panda/src/gobj/texture.cxx | 23 +++++++++++++++++++ panda/src/gobj/texture.h | 1 + 6 files changed, 30 insertions(+), 21 deletions(-) diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index fcd5a86eca..632b62ad65 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -316,15 +316,7 @@ add_render_texture(Texture *tex, RenderTextureMode mode, // Go ahead and tell the texture our anticipated size, even if it // might be inaccurate (particularly if this is a GraphicsWindow, // which has system-imposed restrictions on size). - if (Texture::get_textures_power_2() != ATS_none) { - tex->set_x_size(Texture::up_to_power_2(get_x_size())); - tex->set_y_size(Texture::up_to_power_2(get_y_size())); - } else { - tex->set_x_size(get_x_size()); - tex->set_y_size(get_y_size()); - } - tex->set_pad_size(tex->get_x_size() - get_x_size(), - tex->get_y_size() - get_y_size()); + tex->set_size_padded(get_x_size(), get_y_size()); if (mode == RTM_bind_or_copy && !support_render_texture) { mode = RTM_copy_texture; diff --git a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx index ae6bb9ac34..fd2e74b0b3 100644 --- a/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx +++ b/panda/src/dxgsg8/dxGraphicsStateGuardian8.cxx @@ -1426,9 +1426,8 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, HRESULT hr; int xo, yo, w, h; dr->get_region_pixels_i(xo, yo, w, h); - tex->set_x_size(Texture::up_to_power_2(w)); - tex->set_y_size(Texture::up_to_power_2(h)); - + tex->set_size_padded(w, h); + TextureContext *tc = tex->prepare_now(get_prepared_objects(), this); if (tc == (TextureContext *)NULL) { return; diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index 3466aa7e8a..009e8d1106 100755 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -2029,8 +2029,7 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, HRESULT hr; int xo, yo, w, h; dr->get_region_pixels_i(xo, yo, w, h); - tex->set_x_size(Texture::up_to_power_2(w)); - tex->set_y_size(Texture::up_to_power_2(h)); + tex->set_size_padded(w, h); bool use_stretch_rect; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 944a23c2df..2821d443a5 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3429,13 +3429,8 @@ framebuffer_copy_to_texture(Texture *tex, int z, const DisplayRegion *dr, int xo, yo, w, h; dr->get_region_pixels(xo, yo, w, h); - if (_supports_tex_non_pow2) { - tex->set_x_size(w); - tex->set_y_size(h); - } else { - tex->set_x_size(Texture::up_to_power_2(w)); - tex->set_y_size(Texture::up_to_power_2(h)); - } + tex->set_size_padded(w, h); + if (tex->get_compression() == Texture::CM_default) { // Unless the user explicitly turned on texture compression, turn // it off for the copy-to-texture case. diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 2630b92647..97e8e853d3 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -2880,6 +2880,28 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) { } +//////////////////////////////////////////////////////////////////// +// Function: Texture::set_size_padded +// Description: Changes the size of the texture, padding +// if necessary, and setting the pad region +// as well. +//////////////////////////////////////////////////////////////////// +void Texture:: +set_size_padded(int x, int y, int z) { + if (get_textures_power_2() != ATS_none) { + set_x_size(up_to_power_2(x)); + set_y_size(up_to_power_2(y)); + set_z_size(up_to_power_2(z)); + } else { + set_x_size(x); + set_y_size(y); + set_z_size(z); + } + set_pad_size(get_x_size() - x, + get_y_size() - y, + get_z_size() - z); +} + //////////////////////////////////////////////////////////////////// // Function: Texture::consider_rescale // Access: Private @@ -3893,3 +3915,4 @@ operator << (ostream &out, Texture::CompressionMode cm) { return out << "(**invalid Texture::CompressionMode(" << (int)cm << ")**)"; } + diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 5193c6646b..5f85225c63 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -350,6 +350,7 @@ PUBLISHED: INLINE int get_pad_z_size() const; INLINE void set_pad_size(int x=0, int y=0, int z=0); + void set_size_padded(int x=1, int y=1, int z=1); void set_format(Format format); void set_component_type(ComponentType component_type);