| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 : Texture2D(service_locator, | 224 : Texture2D(service_locator, |
| 225 bitmap.width(), | 225 bitmap.width(), |
| 226 bitmap.height(), | 226 bitmap.height(), |
| 227 bitmap.format(), | 227 bitmap.format(), |
| 228 bitmap.num_mipmaps(), | 228 bitmap.num_mipmaps(), |
| 229 bitmap.CheckAlphaIsOne(), | 229 bitmap.CheckAlphaIsOne(), |
| 230 resize_to_pot, | 230 resize_to_pot, |
| 231 enable_render_surfaces), | 231 enable_render_surfaces), |
| 232 d3d_texture_(tex) { | 232 d3d_texture_(tex) { |
| 233 DCHECK(tex); | 233 DCHECK(tex); |
| 234 backing_bitmap_ = Bitmap::Ref(new Bitmap(service_locator)); |
| 234 } | 235 } |
| 235 | 236 |
| 236 // Attempts to create a IDirect3DTexture9 with the given specs. If the creation | 237 // Attempts to create a IDirect3DTexture9 with the given specs. If the creation |
| 237 // of the texture succeeds then it creates a Texture2DD3D9 object around it and | 238 // of the texture succeeds then it creates a Texture2DD3D9 object around it and |
| 238 // returns it. This is the safe way to create a Texture2DD3D9 object that | 239 // returns it. This is the safe way to create a Texture2DD3D9 object that |
| 239 // contains a valid D3D9 texture. | 240 // contains a valid D3D9 texture. |
| 240 Texture2DD3D9* Texture2DD3D9::Create(ServiceLocator* service_locator, | 241 Texture2DD3D9* Texture2DD3D9::Create(ServiceLocator* service_locator, |
| 241 Bitmap* bitmap, | 242 Bitmap* bitmap, |
| 242 RendererD3D9* renderer, | 243 RendererD3D9* renderer, |
| 243 bool enable_render_surfaces) { | 244 bool enable_render_surfaces) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 256 DLOG(ERROR) << "Failed to create Texture2D (D3D9) : "; | 257 DLOG(ERROR) << "Failed to create Texture2D (D3D9) : "; |
| 257 return NULL; | 258 return NULL; |
| 258 } | 259 } |
| 259 | 260 |
| 260 Texture2DD3D9 *texture = new Texture2DD3D9(service_locator, | 261 Texture2DD3D9 *texture = new Texture2DD3D9(service_locator, |
| 261 d3d_texture, | 262 d3d_texture, |
| 262 *bitmap, | 263 *bitmap, |
| 263 resize_to_pot, | 264 resize_to_pot, |
| 264 enable_render_surfaces); | 265 enable_render_surfaces); |
| 265 | 266 |
| 266 texture->backing_bitmap_.SetFrom(bitmap); | 267 texture->backing_bitmap_->SetFrom(bitmap); |
| 267 if (texture->backing_bitmap_.image_data()) { | 268 if (texture->backing_bitmap_->image_data()) { |
| 268 for (unsigned int i = 0; i < bitmap->num_mipmaps(); ++i) { | 269 for (unsigned int i = 0; i < bitmap->num_mipmaps(); ++i) { |
| 269 if (!texture->UpdateBackedMipLevel(i)) { | 270 if (!texture->UpdateBackedMipLevel(i)) { |
| 270 DLOG(ERROR) << "Failed to upload bitmap to texture."; | 271 DLOG(ERROR) << "Failed to upload bitmap to texture."; |
| 271 delete texture; | 272 delete texture; |
| 272 return NULL; | 273 return NULL; |
| 273 } | 274 } |
| 274 mip_width = std::max(1U, mip_width >> 1); | 275 mip_width = std::max(1U, mip_width >> 1); |
| 275 mip_height = std::max(1U, mip_height >> 1); | 276 mip_height = std::max(1U, mip_height >> 1); |
| 276 } | 277 } |
| 277 if (!resize_to_pot) | 278 if (!resize_to_pot) |
| 278 texture->backing_bitmap_.FreeData(); | 279 texture->backing_bitmap_->FreeData(); |
| 279 } else { | 280 } else { |
| 280 if (resize_to_pot) { | 281 if (resize_to_pot) { |
| 281 texture->backing_bitmap_.AllocateData(); | 282 texture->backing_bitmap_->AllocateData(); |
| 282 memset(texture->backing_bitmap_.image_data(), 0, | 283 memset(texture->backing_bitmap_->image_data(), 0, |
| 283 texture->backing_bitmap_.GetTotalSize()); | 284 texture->backing_bitmap_->GetTotalSize()); |
| 284 } | 285 } |
| 285 } | 286 } |
| 286 | 287 |
| 287 return texture; | 288 return texture; |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Destructor releases the D3D9 texture resource. | 291 // Destructor releases the D3D9 texture resource. |
| 291 Texture2DD3D9::~Texture2DD3D9() { | 292 Texture2DD3D9::~Texture2DD3D9() { |
| 292 d3d_texture_ = NULL; | 293 d3d_texture_ = NULL; |
| 293 } | 294 } |
| 294 | 295 |
| 295 bool Texture2DD3D9::UpdateBackedMipLevel(unsigned int level) { | 296 bool Texture2DD3D9::UpdateBackedMipLevel(unsigned int level) { |
| 296 DCHECK_LT(level, static_cast<unsigned int>(levels())); | 297 DCHECK_LT(level, static_cast<unsigned int>(levels())); |
| 297 DCHECK(backing_bitmap_.image_data()); | 298 DCHECK(backing_bitmap_->image_data()); |
| 298 DCHECK_EQ(backing_bitmap_.width(), width()); | 299 DCHECK_EQ(backing_bitmap_->width(), width()); |
| 299 DCHECK_EQ(backing_bitmap_.height(), height()); | 300 DCHECK_EQ(backing_bitmap_->height(), height()); |
| 300 DCHECK_EQ(backing_bitmap_.format(), format()); | 301 DCHECK_EQ(backing_bitmap_->format(), format()); |
| 301 DCHECK_EQ(backing_bitmap_.num_mipmaps(), levels()); | 302 DCHECK_EQ(backing_bitmap_->num_mipmaps(), levels()); |
| 302 | 303 |
| 303 unsigned int mip_width = std::max(1, width() >> level); | 304 unsigned int mip_width = std::max(1, width() >> level); |
| 304 unsigned int mip_height = std::max(1, height() >> level); | 305 unsigned int mip_height = std::max(1, height() >> level); |
| 305 unsigned int rect_width = mip_width; | 306 unsigned int rect_width = mip_width; |
| 306 unsigned int rect_height = mip_height; | 307 unsigned int rect_height = mip_height; |
| 307 if (resize_to_pot_) { | 308 if (resize_to_pot_) { |
| 308 rect_width = std::max(1U, Bitmap::GetPOTSize(width()) >> level); | 309 rect_width = std::max(1U, Bitmap::GetPOTSize(width()) >> level); |
| 309 rect_height = std::max(1U, Bitmap::GetPOTSize(height()) >> level); | 310 rect_height = std::max(1U, Bitmap::GetPOTSize(height()) >> level); |
| 310 } | 311 } |
| 311 | 312 |
| 312 RECT rect = {0, 0, rect_width, rect_height}; | 313 RECT rect = {0, 0, rect_width, rect_height}; |
| 313 D3DLOCKED_RECT out_rect; | 314 D3DLOCKED_RECT out_rect; |
| 314 out_rect.pBits = 0; | 315 out_rect.pBits = 0; |
| 315 | 316 |
| 316 if (!HR(d3d_texture_->LockRect(level, &out_rect, &rect, 0))) { | 317 if (!HR(d3d_texture_->LockRect(level, &out_rect, &rect, 0))) { |
| 317 DLOG(ERROR) << "Failed to lock texture level " << level << "."; | 318 DLOG(ERROR) << "Failed to lock texture level " << level << "."; |
| 318 return false; | 319 return false; |
| 319 } | 320 } |
| 320 | 321 |
| 321 DCHECK(out_rect.pBits); | 322 DCHECK(out_rect.pBits); |
| 322 // TODO: check that the returned pitch is what we expect. | 323 // TODO: check that the returned pitch is what we expect. |
| 323 | 324 |
| 324 const unsigned char *mip_data = | 325 const unsigned char *mip_data = |
| 325 backing_bitmap_.GetMipData(level, TextureCUBE::FACE_POSITIVE_X); | 326 backing_bitmap_->GetMipData(level, TextureCUBE::FACE_POSITIVE_X); |
| 326 if (resize_to_pot_) { | 327 if (resize_to_pot_) { |
| 327 Bitmap::Scale(mip_width, mip_height, format(), mip_data, | 328 Bitmap::Scale(mip_width, mip_height, format(), mip_data, |
| 328 rect_width, rect_height, | 329 rect_width, rect_height, |
| 329 static_cast<unsigned char *>(out_rect.pBits)); | 330 static_cast<unsigned char *>(out_rect.pBits)); |
| 330 } else { | 331 } else { |
| 331 unsigned int mip_size = | 332 unsigned int mip_size = |
| 332 Bitmap::GetBufferSize(mip_width, mip_height, format()); | 333 Bitmap::GetBufferSize(mip_width, mip_height, format()); |
| 333 memcpy(out_rect.pBits, mip_data, mip_size); | 334 memcpy(out_rect.pBits, mip_data, mip_size); |
| 334 } | 335 } |
| 335 | 336 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 << "Level " << level << " of texture \"" << name() | 387 << "Level " << level << " of texture \"" << name() |
| 387 << "\" is already locked."; | 388 << "\" is already locked."; |
| 388 return false; | 389 return false; |
| 389 } | 390 } |
| 390 if (render_surfaces_enabled()) { | 391 if (render_surfaces_enabled()) { |
| 391 O3D_ERROR(service_locator()) | 392 O3D_ERROR(service_locator()) |
| 392 << "Attempting to lock a render-target texture: " << name(); | 393 << "Attempting to lock a render-target texture: " << name(); |
| 393 return false; | 394 return false; |
| 394 } | 395 } |
| 395 if (resize_to_pot_) { | 396 if (resize_to_pot_) { |
| 396 DCHECK(backing_bitmap_.image_data()); | 397 DCHECK(backing_bitmap_->image_data()); |
| 397 *texture_data = backing_bitmap_.GetMipData(level, | 398 *texture_data = backing_bitmap_->GetMipData(level, |
| 398 TextureCUBE::FACE_POSITIVE_X); | 399 TextureCUBE::FACE_POSITIVE_X); |
| 399 locked_levels_ |= 1 << level; | 400 locked_levels_ |= 1 << level; |
| 400 return true; | 401 return true; |
| 401 } else { | 402 } else { |
| 402 RECT rect = {0, 0, width(), height()}; | 403 RECT rect = {0, 0, width(), height()}; |
| 403 D3DLOCKED_RECT out_rect = {0}; | 404 D3DLOCKED_RECT out_rect = {0}; |
| 404 | 405 |
| 405 if (HR(d3d_texture_->LockRect(level, &out_rect, &rect, 0))) { | 406 if (HR(d3d_texture_->LockRect(level, &out_rect, &rect, 0))) { |
| 406 *texture_data = out_rect.pBits; | 407 *texture_data = out_rect.pBits; |
| 407 locked_levels_ |= 1 << level; | 408 locked_levels_ |= 1 << level; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 } | 453 } |
| 453 | 454 |
| 454 bool Texture2DD3D9::OnResetDevice() { | 455 bool Texture2DD3D9::OnResetDevice() { |
| 455 if (render_surfaces_enabled()) { | 456 if (render_surfaces_enabled()) { |
| 456 DCHECK(d3d_texture_ == NULL); | 457 DCHECK(d3d_texture_ == NULL); |
| 457 Renderer* renderer = service_locator()->GetService<Renderer>(); | 458 Renderer* renderer = service_locator()->GetService<Renderer>(); |
| 458 RendererD3D9 *renderer_d3d9 = down_cast<RendererD3D9*>(renderer); | 459 RendererD3D9 *renderer_d3d9 = down_cast<RendererD3D9*>(renderer); |
| 459 bool resize_to_pot; | 460 bool resize_to_pot; |
| 460 unsigned int mip_width, mip_height; | 461 unsigned int mip_width, mip_height; |
| 461 return HR(CreateTexture2DD3D9(renderer_d3d9, | 462 return HR(CreateTexture2DD3D9(renderer_d3d9, |
| 462 &backing_bitmap_, | 463 backing_bitmap_, |
| 463 render_surfaces_enabled(), | 464 render_surfaces_enabled(), |
| 464 &resize_to_pot, | 465 &resize_to_pot, |
| 465 &mip_width, | 466 &mip_width, |
| 466 &mip_height, | 467 &mip_height, |
| 467 &d3d_texture_)); | 468 &d3d_texture_)); |
| 468 } | 469 } |
| 469 return true; | 470 return true; |
| 470 } | 471 } |
| 471 | 472 |
| 472 const Texture::RGBASwizzleIndices& Texture2DD3D9::GetABGR32FSwizzleIndices() { | 473 const Texture::RGBASwizzleIndices& Texture2DD3D9::GetABGR32FSwizzleIndices() { |
| 473 return g_d3d_abgr32f_swizzle_indices; | 474 return g_d3d_abgr32f_swizzle_indices; |
| 474 } | 475 } |
| 475 | 476 |
| 476 // Constructs a cube texture object from the given (existing) D3D Cube texture. | 477 // Constructs a cube texture object from the given (existing) D3D Cube texture. |
| 477 TextureCUBED3D9::TextureCUBED3D9(ServiceLocator* service_locator, | 478 TextureCUBED3D9::TextureCUBED3D9(ServiceLocator* service_locator, |
| 478 IDirect3DCubeTexture9* tex, | 479 IDirect3DCubeTexture9* tex, |
| 479 const Bitmap& bitmap, | 480 const Bitmap& bitmap, |
| 480 bool resize_to_pot, | 481 bool resize_to_pot, |
| 481 bool enable_render_surfaces) | 482 bool enable_render_surfaces) |
| 482 : TextureCUBE(service_locator, | 483 : TextureCUBE(service_locator, |
| 483 bitmap.width(), | 484 bitmap.width(), |
| 484 bitmap.format(), | 485 bitmap.format(), |
| 485 bitmap.num_mipmaps(), | 486 bitmap.num_mipmaps(), |
| 486 bitmap.CheckAlphaIsOne(), | 487 bitmap.CheckAlphaIsOne(), |
| 487 resize_to_pot, | 488 resize_to_pot, |
| 488 enable_render_surfaces), | 489 enable_render_surfaces), |
| 489 d3d_cube_texture_(tex) { | 490 d3d_cube_texture_(tex) { |
| 491 backing_bitmap_ = Bitmap::Ref(new Bitmap(service_locator)); |
| 490 } | 492 } |
| 491 | 493 |
| 492 // Attempts to create a D3D9 CubeTexture with the given specs. If creation | 494 // Attempts to create a D3D9 CubeTexture with the given specs. If creation |
| 493 // fails the method returns NULL. Otherwise, it wraps around the newly created | 495 // fails the method returns NULL. Otherwise, it wraps around the newly created |
| 494 // texture a TextureCUBED3D9 object and returns a pointer to it. | 496 // texture a TextureCUBED3D9 object and returns a pointer to it. |
| 495 TextureCUBED3D9* TextureCUBED3D9::Create(ServiceLocator* service_locator, | 497 TextureCUBED3D9* TextureCUBED3D9::Create(ServiceLocator* service_locator, |
| 496 Bitmap *bitmap, | 498 Bitmap *bitmap, |
| 497 RendererD3D9 *renderer, | 499 RendererD3D9 *renderer, |
| 498 bool enable_render_surfaces) { | 500 bool enable_render_surfaces) { |
| 499 DCHECK_NE(bitmap->format(), Texture::UNKNOWN_FORMAT); | 501 DCHECK_NE(bitmap->format(), Texture::UNKNOWN_FORMAT); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 512 DLOG(ERROR) << "Failed to create TextureCUBE (D3D9)"; | 514 DLOG(ERROR) << "Failed to create TextureCUBE (D3D9)"; |
| 513 return NULL; | 515 return NULL; |
| 514 } | 516 } |
| 515 | 517 |
| 516 TextureCUBED3D9 *texture = new TextureCUBED3D9(service_locator, | 518 TextureCUBED3D9 *texture = new TextureCUBED3D9(service_locator, |
| 517 d3d_texture, | 519 d3d_texture, |
| 518 *bitmap, | 520 *bitmap, |
| 519 resize_to_pot, | 521 resize_to_pot, |
| 520 enable_render_surfaces); | 522 enable_render_surfaces); |
| 521 | 523 |
| 522 texture->backing_bitmap_.SetFrom(bitmap); | 524 texture->backing_bitmap_->SetFrom(bitmap); |
| 523 if (texture->backing_bitmap_.image_data()) { | 525 if (texture->backing_bitmap_->image_data()) { |
| 524 for (int face = 0; face < 6; ++face) { | 526 for (int face = 0; face < 6; ++face) { |
| 525 unsigned int mip_edge = edge; | 527 unsigned int mip_edge = edge; |
| 526 for (unsigned int i = 0; i < bitmap->num_mipmaps(); ++i) { | 528 for (unsigned int i = 0; i < bitmap->num_mipmaps(); ++i) { |
| 527 if (!texture->UpdateBackedMipLevel(i, static_cast<CubeFace>(face))) { | 529 if (!texture->UpdateBackedMipLevel(i, static_cast<CubeFace>(face))) { |
| 528 DLOG(ERROR) << "Failed to upload bitmap to texture."; | 530 DLOG(ERROR) << "Failed to upload bitmap to texture."; |
| 529 delete texture; | 531 delete texture; |
| 530 return NULL; | 532 return NULL; |
| 531 } | 533 } |
| 532 mip_edge = std::max(1U, mip_edge >> 1); | 534 mip_edge = std::max(1U, mip_edge >> 1); |
| 533 } | 535 } |
| 534 } | 536 } |
| 535 if (!resize_to_pot) | 537 if (!resize_to_pot) |
| 536 texture->backing_bitmap_.FreeData(); | 538 texture->backing_bitmap_->FreeData(); |
| 537 } else { | 539 } else { |
| 538 if (resize_to_pot) { | 540 if (resize_to_pot) { |
| 539 texture->backing_bitmap_.AllocateData(); | 541 texture->backing_bitmap_->AllocateData(); |
| 540 memset(texture->backing_bitmap_.image_data(), 0, | 542 memset(texture->backing_bitmap_->image_data(), 0, |
| 541 texture->backing_bitmap_.GetTotalSize()); | 543 texture->backing_bitmap_->GetTotalSize()); |
| 542 } | 544 } |
| 543 } | 545 } |
| 544 | 546 |
| 545 return texture; | 547 return texture; |
| 546 } | 548 } |
| 547 | 549 |
| 548 | 550 |
| 549 | 551 |
| 550 // Destructor releases the D3D9 texture resource. | 552 // Destructor releases the D3D9 texture resource. |
| 551 TextureCUBED3D9::~TextureCUBED3D9() { | 553 TextureCUBED3D9::~TextureCUBED3D9() { |
| 552 for (unsigned int i = 0; i < 6; ++i) { | 554 for (unsigned int i = 0; i < 6; ++i) { |
| 553 if (locked_levels_[i] != 0) { | 555 if (locked_levels_[i] != 0) { |
| 554 O3D_ERROR(service_locator()) | 556 O3D_ERROR(service_locator()) |
| 555 << "TextureCUBE \"" << name() << "\" was never unlocked before " | 557 << "TextureCUBE \"" << name() << "\" was never unlocked before " |
| 556 << "being destroyed."; | 558 << "being destroyed."; |
| 557 break; // No need to report it more than once. | 559 break; // No need to report it more than once. |
| 558 } | 560 } |
| 559 } | 561 } |
| 560 d3d_cube_texture_ = NULL; | 562 d3d_cube_texture_ = NULL; |
| 561 } | 563 } |
| 562 | 564 |
| 563 bool TextureCUBED3D9::UpdateBackedMipLevel(unsigned int level, | 565 bool TextureCUBED3D9::UpdateBackedMipLevel(unsigned int level, |
| 564 TextureCUBE::CubeFace face) { | 566 TextureCUBE::CubeFace face) { |
| 565 DCHECK_LT(level, static_cast<unsigned int>(levels())); | 567 DCHECK_LT(level, static_cast<unsigned int>(levels())); |
| 566 DCHECK(backing_bitmap_.image_data()); | 568 DCHECK(backing_bitmap_->image_data()); |
| 567 DCHECK(backing_bitmap_.is_cubemap()); | 569 DCHECK(backing_bitmap_->is_cubemap()); |
| 568 DCHECK_EQ(backing_bitmap_.width(), edge_length()); | 570 DCHECK_EQ(backing_bitmap_->width(), edge_length()); |
| 569 DCHECK_EQ(backing_bitmap_.height(), edge_length()); | 571 DCHECK_EQ(backing_bitmap_->height(), edge_length()); |
| 570 DCHECK_EQ(backing_bitmap_.format(), format()); | 572 DCHECK_EQ(backing_bitmap_->format(), format()); |
| 571 DCHECK_EQ(backing_bitmap_.num_mipmaps(), levels()); | 573 DCHECK_EQ(backing_bitmap_->num_mipmaps(), levels()); |
| 572 | 574 |
| 573 unsigned int mip_edge = std::max(1, edge_length() >> level); | 575 unsigned int mip_edge = std::max(1, edge_length() >> level); |
| 574 unsigned int rect_edge = mip_edge; | 576 unsigned int rect_edge = mip_edge; |
| 575 if (resize_to_pot_) { | 577 if (resize_to_pot_) { |
| 576 rect_edge = std::max(1U, Bitmap::GetPOTSize(edge_length()) >> level); | 578 rect_edge = std::max(1U, Bitmap::GetPOTSize(edge_length()) >> level); |
| 577 } | 579 } |
| 578 | 580 |
| 579 RECT rect = {0, 0, rect_edge, rect_edge}; | 581 RECT rect = {0, 0, rect_edge, rect_edge}; |
| 580 D3DLOCKED_RECT out_rect; | 582 D3DLOCKED_RECT out_rect; |
| 581 out_rect.pBits = 0; | 583 out_rect.pBits = 0; |
| 582 | 584 |
| 583 if (!HR(d3d_cube_texture_->LockRect(DX9CubeFace(face), level, &out_rect, | 585 if (!HR(d3d_cube_texture_->LockRect(DX9CubeFace(face), level, &out_rect, |
| 584 &rect, 0))) { | 586 &rect, 0))) { |
| 585 O3D_ERROR(service_locator()) | 587 O3D_ERROR(service_locator()) |
| 586 << "Failed to lock texture level " << level << " face " << face << "."; | 588 << "Failed to lock texture level " << level << " face " << face << "."; |
| 587 return false; | 589 return false; |
| 588 } | 590 } |
| 589 | 591 |
| 590 DCHECK(out_rect.pBits); | 592 DCHECK(out_rect.pBits); |
| 591 // TODO: check that the returned pitch is what we expect. | 593 // TODO: check that the returned pitch is what we expect. |
| 592 | 594 |
| 593 const unsigned char *mip_data = backing_bitmap_.GetMipData(level, face); | 595 const unsigned char *mip_data = backing_bitmap_->GetMipData(level, face); |
| 594 if (resize_to_pot_) { | 596 if (resize_to_pot_) { |
| 595 Bitmap::Scale(mip_edge, mip_edge, format(), mip_data, | 597 Bitmap::Scale(mip_edge, mip_edge, format(), mip_data, |
| 596 rect_edge, rect_edge, | 598 rect_edge, rect_edge, |
| 597 static_cast<unsigned char *>(out_rect.pBits)); | 599 static_cast<unsigned char *>(out_rect.pBits)); |
| 598 } else { | 600 } else { |
| 599 unsigned int mip_size = | 601 unsigned int mip_size = |
| 600 Bitmap::GetBufferSize(mip_edge, mip_edge, format()); | 602 Bitmap::GetBufferSize(mip_edge, mip_edge, format()); |
| 601 memcpy(out_rect.pBits, mip_data, mip_size); | 603 memcpy(out_rect.pBits, mip_data, mip_size); |
| 602 } | 604 } |
| 603 | 605 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 << "Level " << level << " Face " << face << " of texture \"" << name() | 659 << "Level " << level << " Face " << face << " of texture \"" << name() |
| 658 << "\" is already locked."; | 660 << "\" is already locked."; |
| 659 return false; | 661 return false; |
| 660 } | 662 } |
| 661 if (render_surfaces_enabled()) { | 663 if (render_surfaces_enabled()) { |
| 662 O3D_ERROR(service_locator()) | 664 O3D_ERROR(service_locator()) |
| 663 << "Attempting to lock a render-target texture: " << name(); | 665 << "Attempting to lock a render-target texture: " << name(); |
| 664 return false; | 666 return false; |
| 665 } | 667 } |
| 666 if (resize_to_pot_) { | 668 if (resize_to_pot_) { |
| 667 DCHECK(backing_bitmap_.image_data()); | 669 DCHECK(backing_bitmap_->image_data()); |
| 668 *texture_data = backing_bitmap_.GetMipData(level, face); | 670 *texture_data = backing_bitmap_->GetMipData(level, face); |
| 669 locked_levels_[face] |= 1 << level; | 671 locked_levels_[face] |= 1 << level; |
| 670 return true; | 672 return true; |
| 671 } else { | 673 } else { |
| 672 RECT rect = {0, 0, edge_length(), edge_length()}; | 674 RECT rect = {0, 0, edge_length(), edge_length()}; |
| 673 D3DLOCKED_RECT out_rect = {0}; | 675 D3DLOCKED_RECT out_rect = {0}; |
| 674 | 676 |
| 675 if (HR(d3d_cube_texture_->LockRect(DX9CubeFace(face), level, | 677 if (HR(d3d_cube_texture_->LockRect(DX9CubeFace(face), level, |
| 676 &out_rect, &rect, 0))) { | 678 &out_rect, &rect, 0))) { |
| 677 *texture_data = out_rect.pBits; | 679 *texture_data = out_rect.pBits; |
| 678 locked_levels_[face] |= 1 << level; | 680 locked_levels_[face] |= 1 << level; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 } | 726 } |
| 725 | 727 |
| 726 bool TextureCUBED3D9::OnResetDevice() { | 728 bool TextureCUBED3D9::OnResetDevice() { |
| 727 if (render_surfaces_enabled()) { | 729 if (render_surfaces_enabled()) { |
| 728 DCHECK(d3d_cube_texture_ == NULL); | 730 DCHECK(d3d_cube_texture_ == NULL); |
| 729 Renderer* renderer = service_locator()->GetService<Renderer>(); | 731 Renderer* renderer = service_locator()->GetService<Renderer>(); |
| 730 RendererD3D9 *renderer_d3d9 = down_cast<RendererD3D9*>(renderer); | 732 RendererD3D9 *renderer_d3d9 = down_cast<RendererD3D9*>(renderer); |
| 731 bool resize_to_pot; | 733 bool resize_to_pot; |
| 732 unsigned int mip_edge; | 734 unsigned int mip_edge; |
| 733 return HR(CreateTextureCUBED3D9(renderer_d3d9, | 735 return HR(CreateTextureCUBED3D9(renderer_d3d9, |
| 734 &backing_bitmap_, | 736 backing_bitmap_, |
| 735 render_surfaces_enabled(), | 737 render_surfaces_enabled(), |
| 736 &resize_to_pot, | 738 &resize_to_pot, |
| 737 &mip_edge, | 739 &mip_edge, |
| 738 &d3d_cube_texture_)); | 740 &d3d_cube_texture_)); |
| 739 } | 741 } |
| 740 return true; | 742 return true; |
| 741 } | 743 } |
| 742 | 744 |
| 743 const Texture::RGBASwizzleIndices& TextureCUBED3D9::GetABGR32FSwizzleIndices() { | 745 const Texture::RGBASwizzleIndices& TextureCUBED3D9::GetABGR32FSwizzleIndices() { |
| 744 return g_d3d_abgr32f_swizzle_indices; | 746 return g_d3d_abgr32f_swizzle_indices; |
| 745 } | 747 } |
| 746 | 748 |
| 747 } // namespace o3d | 749 } // namespace o3d |
| OLD | NEW |