diff options
-rw-r--r-- | o3d/core/cross/command_buffer/renderer_cb.cc | 26 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/texture_cb.cc | 86 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/texture_cb.h | 4 | ||||
-rw-r--r-- | o3d/core/cross/gl/renderer_gl.cc | 26 | ||||
-rw-r--r-- | o3d/core/cross/gl/texture_gl.cc | 69 | ||||
-rw-r--r-- | o3d/core/cross/gl/texture_gl.h | 4 | ||||
-rw-r--r-- | o3d/core/win/d3d9/texture_d3d9.cc | 8 |
7 files changed, 114 insertions, 109 deletions
diff --git a/o3d/core/cross/command_buffer/renderer_cb.cc b/o3d/core/cross/command_buffer/renderer_cb.cc index 16a522e..493da78 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.cc +++ b/o3d/core/cross/command_buffer/renderer_cb.cc @@ -320,12 +320,12 @@ Texture2D::Ref RendererCB::CreatePlatformSpecificTexture2D( Texture::Format format, int levels, bool enable_render_surfaces) { - Bitmap bitmap; - bitmap.set_format(format); - bitmap.set_width(width); - bitmap.set_height(height); - bitmap.set_num_mipmaps(levels); - return Texture2D::Ref(Texture2DCB::Create(service_locator(), &bitmap, + Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); + bitmap->set_format(format); + bitmap->set_width(width); + bitmap->set_height(height); + bitmap->set_num_mipmaps(levels); + return Texture2D::Ref(Texture2DCB::Create(service_locator(), bitmap, enable_render_surfaces)); } @@ -337,13 +337,13 @@ TextureCUBE::Ref RendererCB::CreatePlatformSpecificTextureCUBE( Texture::Format format, int levels, bool enable_render_surfaces) { - Bitmap bitmap; - bitmap.set_format(format); - bitmap.set_width(edge); - bitmap.set_height(edge); - bitmap.set_num_mipmaps(levels); - bitmap.set_is_cubemap(true); - return TextureCUBE::Ref(TextureCUBECB::Create(service_locator(), &bitmap, + Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); + bitmap->set_format(format); + bitmap->set_width(edge); + bitmap->set_height(edge); + bitmap->set_num_mipmaps(levels); + bitmap->set_is_cubemap(true); + return TextureCUBE::Ref(TextureCUBECB::Create(service_locator(), bitmap, enable_render_surfaces)); } diff --git a/o3d/core/cross/command_buffer/texture_cb.cc b/o3d/core/cross/command_buffer/texture_cb.cc index 069bfd3..3d530a7 100644 --- a/o3d/core/cross/command_buffer/texture_cb.cc +++ b/o3d/core/cross/command_buffer/texture_cb.cc @@ -236,7 +236,8 @@ Texture2DCB::Texture2DCB(ServiceLocator* service_locator, renderer_(static_cast<RendererCB*>( service_locator->GetService<Renderer>())), resource_id_(resource_id), - has_levels_(0) { + has_levels_(0), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { DCHECK_NE(format(), Texture::UNKNOWN_FORMAT); } @@ -301,12 +302,12 @@ Texture2DCB* Texture2DCB::Create(ServiceLocator* service_locator, enable_render_surfaces); // Setup the backing bitmap. - texture->backing_bitmap_.SetFrom(bitmap); - if (texture->backing_bitmap_.image_data()) { + texture->backing_bitmap_->SetFrom(bitmap); + if (texture->backing_bitmap_->image_data()) { if (resize_to_pot) { texture->has_levels_ = (1 << bitmap->num_mipmaps()) - 1; } else { - texture->backing_bitmap_.FreeData(); + texture->backing_bitmap_->FreeData(); } } return texture; @@ -327,21 +328,21 @@ bool Texture2DCB::Lock(int level, void** data) { << "\" is already locked."; return false; } - if (!backing_bitmap_.image_data()) { + if (!backing_bitmap_->image_data()) { DCHECK_EQ(has_levels_, 0); - backing_bitmap_.Allocate(format(), width(), height(), levels(), false); + backing_bitmap_->Allocate(format(), width(), height(), levels(), false); } - *data = backing_bitmap_.GetMipData(level, TextureCUBE::FACE_POSITIVE_X); + *data = backing_bitmap_->GetMipData(level, TextureCUBE::FACE_POSITIVE_X); if (!HasLevel(level)) { DCHECK(!resize_to_pot_); - DCHECK_EQ(backing_bitmap_.width(), width()); - DCHECK_EQ(backing_bitmap_.height(), height()); - DCHECK_EQ(backing_bitmap_.format(), format()); - DCHECK_GT(backing_bitmap_.num_mipmaps(), level); - DCHECK(!backing_bitmap_.is_cubemap()); + DCHECK_EQ(backing_bitmap_->width(), width()); + DCHECK_EQ(backing_bitmap_->height(), height()); + DCHECK_EQ(backing_bitmap_->format(), format()); + DCHECK_GT(backing_bitmap_->num_mipmaps(), level); + DCHECK(!backing_bitmap_->is_cubemap()); CopyBackResourceToBitmap(renderer_, resource_id_, level, TextureCUBE::FACE_POSITIVE_X, - backing_bitmap_); + *backing_bitmap_.Get()); has_levels_ |= 1 << level; } locked_levels_ |= 1 << level; @@ -363,19 +364,19 @@ bool Texture2DCB::Unlock(int level) { << "\" is not locked."; return false; } - DCHECK(backing_bitmap_.image_data()); - DCHECK_EQ(backing_bitmap_.width(), width()); - DCHECK_EQ(backing_bitmap_.height(), height()); - DCHECK_EQ(backing_bitmap_.format(), format()); - DCHECK_GT(backing_bitmap_.num_mipmaps(), level); - DCHECK(!backing_bitmap_.is_cubemap()); + DCHECK(backing_bitmap_->image_data()); + DCHECK_EQ(backing_bitmap_->width(), width()); + DCHECK_EQ(backing_bitmap_->height(), height()); + DCHECK_EQ(backing_bitmap_->format(), format()); + DCHECK_GT(backing_bitmap_->num_mipmaps(), level); + DCHECK(!backing_bitmap_->is_cubemap()); DCHECK(HasLevel(level)); UpdateResourceFromBitmap(renderer_, resource_id_, level, TextureCUBE::FACE_POSITIVE_X, - backing_bitmap_, resize_to_pot_); + *backing_bitmap_.Get(), resize_to_pot_); locked_levels_ &= ~(1 << level); if (!resize_to_pot_ && (locked_levels_ == 0)) { - backing_bitmap_.FreeData(); + backing_bitmap_->FreeData(); has_levels_ = 0; } return true; @@ -407,7 +408,8 @@ TextureCUBECB::TextureCUBECB(ServiceLocator* service_locator, enable_render_surfaces), renderer_(static_cast<RendererCB*>( service_locator->GetService<Renderer>())), - resource_id_(resource_id) { + resource_id_(resource_id), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { for (unsigned int i = 0; i < 6; ++i) { has_levels_[i] = 0; } @@ -474,14 +476,14 @@ TextureCUBECB* TextureCUBECB::Create(ServiceLocator* service_locator, resize_to_pot, enable_render_surfaces); // Setup the backing bitmap. - texture->backing_bitmap_.SetFrom(bitmap); - if (texture->backing_bitmap_.image_data()) { + texture->backing_bitmap_->SetFrom(bitmap); + if (texture->backing_bitmap_->image_data()) { if (resize_to_pot) { for (unsigned int face = 0; face < 6; ++face) { texture->has_levels_[face] = (1 << bitmap->num_mipmaps()) - 1; } } else { - texture->backing_bitmap_.FreeData(); + texture->backing_bitmap_->FreeData(); } } return texture; @@ -503,26 +505,26 @@ bool TextureCUBECB::Lock(CubeFace face, int level, void** data) { << "\" is already locked."; return false; } - if (!backing_bitmap_.image_data()) { + if (!backing_bitmap_->image_data()) { for (unsigned int i = 0; i < 6; ++i) { DCHECK_EQ(has_levels_[i], 0); } - backing_bitmap_.Allocate(format(), edge_length(), edge_length(), + backing_bitmap_->Allocate(format(), edge_length(), edge_length(), levels(), true); } - *data = backing_bitmap_.GetMipData(level, face); + *data = backing_bitmap_->GetMipData(level, face); if (!HasLevel(level, face)) { // TODO: add some API so we don't have to copy back the data if we // will rewrite it all. DCHECK(!resize_to_pot_); - DCHECK_EQ(backing_bitmap_.width(), edge_length()); - DCHECK_EQ(backing_bitmap_.height(), edge_length()); - DCHECK_EQ(backing_bitmap_.format(), format()); - DCHECK_GT(backing_bitmap_.num_mipmaps(), level); - DCHECK(backing_bitmap_.is_cubemap()); + DCHECK_EQ(backing_bitmap_->width(), edge_length()); + DCHECK_EQ(backing_bitmap_->height(), edge_length()); + DCHECK_EQ(backing_bitmap_->format(), format()); + DCHECK_GT(backing_bitmap_->num_mipmaps(), level); + DCHECK(backing_bitmap_->is_cubemap()); CopyBackResourceToBitmap(renderer_, resource_id_, level, TextureCUBE::FACE_POSITIVE_X, - backing_bitmap_); + *backing_bitmap_.Get()); has_levels_[face] |= 1 << level; } locked_levels_[face] |= 1 << level; @@ -544,15 +546,15 @@ bool TextureCUBECB::Unlock(CubeFace face, int level) { << "\" is not locked."; return false; } - DCHECK(backing_bitmap_.image_data()); - DCHECK_EQ(backing_bitmap_.width(), edge_length()); - DCHECK_EQ(backing_bitmap_.height(), edge_length()); - DCHECK_EQ(backing_bitmap_.format(), format()); - DCHECK_GT(backing_bitmap_.num_mipmaps(), level); - DCHECK(backing_bitmap_.is_cubemap()); + DCHECK(backing_bitmap_->image_data()); + DCHECK_EQ(backing_bitmap_->width(), edge_length()); + DCHECK_EQ(backing_bitmap_->height(), edge_length()); + DCHECK_EQ(backing_bitmap_->format(), format()); + DCHECK_GT(backing_bitmap_->num_mipmaps(), level); + DCHECK(backing_bitmap_->is_cubemap()); DCHECK(HasLevel(level, face)); UpdateResourceFromBitmap(renderer_, resource_id_, level, face, - backing_bitmap_, resize_to_pot_); + *backing_bitmap_.Get(), resize_to_pot_); locked_levels_[face] &= ~(1 << level); if (!resize_to_pot_) { bool has_locked_level = false; @@ -563,7 +565,7 @@ bool TextureCUBECB::Unlock(CubeFace face, int level) { } } if (!has_locked_level) { - backing_bitmap_.FreeData(); + backing_bitmap_->FreeData(); for (unsigned int i = 0; i < 6; ++i) { has_levels_[i] = 0; } diff --git a/o3d/core/cross/command_buffer/texture_cb.h b/o3d/core/cross/command_buffer/texture_cb.h index 5831f70..ee525ac 100644 --- a/o3d/core/cross/command_buffer/texture_cb.h +++ b/o3d/core/cross/command_buffer/texture_cb.h @@ -113,7 +113,7 @@ class Texture2DCB : public Texture2D { // A bitmap used to back the NPOT textures on POT-only hardware, and to back // the pixel buffer for Lock(). - Bitmap backing_bitmap_; + Bitmap::Ref backing_bitmap_; // Bitfield that indicates mip levels that are currently stored in the // backing bitmap. @@ -184,7 +184,7 @@ class TextureCUBECB : public TextureCUBE { // A bitmap used to back the NPOT textures on POT-only hardware, and to back // the pixel buffer for Lock(). - Bitmap backing_bitmap_; + Bitmap::Ref backing_bitmap_; // Bitfields that indicates mip levels that are currently stored in the // backing bitmap, one per face. diff --git a/o3d/core/cross/gl/renderer_gl.cc b/o3d/core/cross/gl/renderer_gl.cc index 7033cbc..7f31a91 100644 --- a/o3d/core/cross/gl/renderer_gl.cc +++ b/o3d/core/cross/gl/renderer_gl.cc @@ -1523,13 +1523,13 @@ Texture2D::Ref RendererGL::CreatePlatformSpecificTexture2D( bool enable_render_surfaces) { DLOG(INFO) << "RendererGL CreateTexture2D"; MakeCurrentLazy(); - Bitmap bitmap; - bitmap.set_format(format); - bitmap.set_width(width); - bitmap.set_height(height); - bitmap.set_num_mipmaps(levels); + Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); + bitmap->set_format(format); + bitmap->set_width(width); + bitmap->set_height(height); + bitmap->set_num_mipmaps(levels); return Texture2D::Ref(Texture2DGL::Create(service_locator(), - &bitmap, + bitmap, enable_render_surfaces)); } @@ -1540,14 +1540,14 @@ TextureCUBE::Ref RendererGL::CreatePlatformSpecificTextureCUBE( bool enable_render_surfaces) { DLOG(INFO) << "RendererGL CreateTextureCUBE"; MakeCurrentLazy(); - Bitmap bitmap; - bitmap.set_format(format); - bitmap.set_width(edge_length); - bitmap.set_height(edge_length); - bitmap.set_num_mipmaps(levels); - bitmap.set_is_cubemap(true); + Bitmap::Ref bitmap = Bitmap::Ref(new Bitmap(service_locator())); + bitmap->set_format(format); + bitmap->set_width(edge_length); + bitmap->set_height(edge_length); + bitmap->set_num_mipmaps(levels); + bitmap->set_is_cubemap(true); return TextureCUBE::Ref(TextureCUBEGL::Create(service_locator(), - &bitmap, + bitmap, enable_render_surfaces)); } diff --git a/o3d/core/cross/gl/texture_gl.cc b/o3d/core/cross/gl/texture_gl.cc index 1b7155f..d4b767f 100644 --- a/o3d/core/cross/gl/texture_gl.cc +++ b/o3d/core/cross/gl/texture_gl.cc @@ -269,7 +269,8 @@ Texture2DGL::Texture2DGL(ServiceLocator* service_locator, renderer_(static_cast<RendererGL*>( service_locator->GetService<Renderer>())), gl_texture_(texture), - has_levels_(0) { + has_levels_(0), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { DLOG(INFO) << "Texture2DGL Construct from GLint"; DCHECK_NE(format(), Texture::UNKNOWN_FORMAT); } @@ -331,21 +332,21 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, enable_render_surfaces); // Setup the backing bitmap. - texture->backing_bitmap_.SetFrom(bitmap); - if (texture->backing_bitmap_.image_data()) { + texture->backing_bitmap_->SetFrom(bitmap); + if (texture->backing_bitmap_->image_data()) { if (resize_to_pot) { texture->has_levels_ = (1 << bitmap->num_mipmaps()) - 1; } else { - texture->backing_bitmap_.FreeData(); + texture->backing_bitmap_->FreeData(); } } else { // If no backing store was provided to the routine, and the hardware does // not support npot textures, allocate a 0-initialized mip-chain here // for use during Texture2DGL::Lock. if (resize_to_pot) { - texture->backing_bitmap_.AllocateData(); - memset(texture->backing_bitmap_.image_data(), 0, - texture->backing_bitmap_.GetTotalSize()); + texture->backing_bitmap_->AllocateData(); + memset(texture->backing_bitmap_->image_data(), 0, + texture->backing_bitmap_->GetTotalSize()); texture->has_levels_ = (1 << bitmap->num_mipmaps()) - 1; } } @@ -355,14 +356,14 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, void Texture2DGL::UpdateBackedMipLevel(unsigned int level) { DCHECK_LT(level, levels()); - DCHECK(backing_bitmap_.image_data()); - DCHECK_EQ(backing_bitmap_.width(), width()); - DCHECK_EQ(backing_bitmap_.height(), height()); - DCHECK_EQ(backing_bitmap_.format(), format()); + DCHECK(backing_bitmap_->image_data()); + DCHECK_EQ(backing_bitmap_->width(), width()); + DCHECK_EQ(backing_bitmap_->height(), height()); + DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level)); glBindTexture(GL_TEXTURE_2D, gl_texture_); UpdateGLImageFromBitmap(GL_TEXTURE_2D, level, TextureCUBE::FACE_POSITIVE_X, - backing_bitmap_, resize_to_pot_); + *backing_bitmap_.Get(), resize_to_pot_); } Texture2DGL::~Texture2DGL() { @@ -392,11 +393,11 @@ bool Texture2DGL::Lock(int level, void** data) { << "\" is already locked."; return false; } - if (!backing_bitmap_.image_data()) { + if (!backing_bitmap_->image_data()) { DCHECK_EQ(has_levels_, 0); - backing_bitmap_.Allocate(format(), width(), height(), levels(), false); + backing_bitmap_->Allocate(format(), width(), height(), levels(), false); } - *data = backing_bitmap_.GetMipData(level, TextureCUBE::FACE_POSITIVE_X); + *data = backing_bitmap_->GetMipData(level, TextureCUBE::FACE_POSITIVE_X); if (!HasLevel(level)) { // TODO: add some API so we don't have to copy back the data if we // will rewrite it all. @@ -435,7 +436,7 @@ bool Texture2DGL::Unlock(int level) { UpdateBackedMipLevel(level); locked_levels_ &= ~(1 << level); if (!resize_to_pot_ && (locked_levels_ == 0)) { - backing_bitmap_.FreeData(); + backing_bitmap_->FreeData(); has_levels_ = 0; } CHECK_GL_ERROR(); @@ -495,7 +496,8 @@ TextureCUBEGL::TextureCUBEGL(ServiceLocator* service_locator, enable_render_surfaces), renderer_(static_cast<RendererGL*>( service_locator->GetService<Renderer>())), - gl_texture_(texture) { + gl_texture_(texture), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { DLOG(INFO) << "TextureCUBEGL Construct"; for (unsigned int i = 0; i < 6; ++i) { has_levels_[i] = 0; @@ -574,23 +576,23 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, resize_to_pot, enable_render_surfaces); // Setup the backing bitmap, and upload the data if we have any. - texture->backing_bitmap_.SetFrom(bitmap); - if (texture->backing_bitmap_.image_data()) { + texture->backing_bitmap_->SetFrom(bitmap); + if (texture->backing_bitmap_->image_data()) { if (resize_to_pot) { for (unsigned int face = 0; face < 6; ++face) { texture->has_levels_[face] = (1 << bitmap->num_mipmaps()) - 1; } } else { - texture->backing_bitmap_.FreeData(); + texture->backing_bitmap_->FreeData(); } } else { // If no backing store was provided to the routine, and the hardware does // not support npot textures, allocate a 0-initialized mip-chain here // for use during TextureCUBEGL::Lock. if (resize_to_pot) { - texture->backing_bitmap_.AllocateData(); - memset(texture->backing_bitmap_.image_data(), 0, - texture->backing_bitmap_.GetTotalSize()); + texture->backing_bitmap_->AllocateData(); + memset(texture->backing_bitmap_->image_data(), 0, + texture->backing_bitmap_->GetTotalSize()); for (unsigned int face = 0; face < 6; ++face) { texture->has_levels_[face] = (1 << bitmap->num_mipmaps()) - 1; } @@ -604,14 +606,15 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, void TextureCUBEGL::UpdateBackedMipLevel(unsigned int level, TextureCUBE::CubeFace face) { DCHECK_LT(level, levels()); - DCHECK(backing_bitmap_.image_data()); - DCHECK(backing_bitmap_.is_cubemap()); - DCHECK_EQ(backing_bitmap_.width(), edge_length()); - DCHECK_EQ(backing_bitmap_.height(), edge_length()); - DCHECK_EQ(backing_bitmap_.format(), format()); + DCHECK(backing_bitmap_->image_data()); + DCHECK(backing_bitmap_->is_cubemap()); + DCHECK_EQ(backing_bitmap_->width(), edge_length()); + DCHECK_EQ(backing_bitmap_->height(), edge_length()); + DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level, face)); glBindTexture(GL_TEXTURE_2D, gl_texture_); - UpdateGLImageFromBitmap(kCubemapFaceList[face], level, face, backing_bitmap_, + UpdateGLImageFromBitmap(kCubemapFaceList[face], level, face, + *backing_bitmap_.Get(), resize_to_pot_); } @@ -667,14 +670,14 @@ bool TextureCUBEGL::Lock(CubeFace face, int level, void** data) { << "\" is already locked."; return false; } - if (!backing_bitmap_.image_data()) { + if (!backing_bitmap_->image_data()) { for (unsigned int i = 0; i < 6; ++i) { DCHECK_EQ(has_levels_[i], 0); } - backing_bitmap_.Allocate(format(), edge_length(), edge_length(), + backing_bitmap_->Allocate(format(), edge_length(), edge_length(), levels(), true); } - *data = backing_bitmap_.GetMipData(level, face); + *data = backing_bitmap_->GetMipData(level, face); GLenum gl_target = kCubemapFaceList[face]; if (!HasLevel(level, face)) { // TODO: add some API so we don't have to copy back the data if we @@ -722,7 +725,7 @@ bool TextureCUBEGL::Unlock(CubeFace face, int level) { } } if (!has_locked_level) { - backing_bitmap_.FreeData(); + backing_bitmap_->FreeData(); for (unsigned int i = 0; i < 6; ++i) { has_levels_[i] = 0; } diff --git a/o3d/core/cross/gl/texture_gl.h b/o3d/core/cross/gl/texture_gl.h index 671071e..cb76660 100644 --- a/o3d/core/cross/gl/texture_gl.h +++ b/o3d/core/cross/gl/texture_gl.h @@ -130,7 +130,7 @@ class Texture2DGL : public Texture2D { // A bitmap used to back the NPOT textures on POT-only hardware, and to back // the pixel buffer for Lock(). - Bitmap backing_bitmap_; + Bitmap::Ref backing_bitmap_; // Bitfield that indicates mip levels that are currently stored in the // backing bitmap. @@ -207,7 +207,7 @@ class TextureCUBEGL : public TextureCUBE { // A bitmap used to back the NPOT textures on POT-only hardware, and to back // the pixel buffer for Lock(). - Bitmap backing_bitmap_; + Bitmap::Ref backing_bitmap_; // Bitfields that indicates mip levels that are currently stored in the // backing bitmap, one per face. diff --git a/o3d/core/win/d3d9/texture_d3d9.cc b/o3d/core/win/d3d9/texture_d3d9.cc index 7477848..e35b1af 100644 --- a/o3d/core/win/d3d9/texture_d3d9.cc +++ b/o3d/core/win/d3d9/texture_d3d9.cc @@ -229,9 +229,9 @@ Texture2DD3D9::Texture2DD3D9(ServiceLocator* service_locator, bitmap.CheckAlphaIsOne(), resize_to_pot, enable_render_surfaces), - d3d_texture_(tex) { + d3d_texture_(tex), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { DCHECK(tex); - backing_bitmap_ = Bitmap::Ref(new Bitmap(service_locator)); } // Attempts to create a IDirect3DTexture9 with the given specs. If the creation @@ -487,8 +487,8 @@ TextureCUBED3D9::TextureCUBED3D9(ServiceLocator* service_locator, bitmap.CheckAlphaIsOne(), resize_to_pot, enable_render_surfaces), - d3d_cube_texture_(tex) { - backing_bitmap_ = Bitmap::Ref(new Bitmap(service_locator)); + d3d_cube_texture_(tex), + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { } // Attempts to create a D3D9 CubeTexture with the given specs. If creation |