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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 unsigned blocks_down = (src_height + 3) / 4; | 253 unsigned blocks_down = (src_height + 3) / 4; |
254 unsigned bytes_per_block = format == Texture::DXT1 ? 8 : 16; | 254 unsigned bytes_per_block = format == Texture::DXT1 ? 8 : 16; |
255 unsigned bytes_per_row = bytes_per_block * blocks_across; | 255 unsigned bytes_per_row = bytes_per_block * blocks_across; |
256 for (unsigned yy = 0; yy < blocks_down; ++yy) { | 256 for (unsigned yy = 0; yy < blocks_down; ++yy) { |
257 memcpy(dst, src, bytes_per_row); | 257 memcpy(dst, src, bytes_per_row); |
258 src += bytes_per_row; | 258 src += bytes_per_row; |
259 dst += dst_pitch; | 259 dst += dst_pitch; |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 void SetTextureRect( | 263 bool SetTextureRect( |
264 ServiceLocator* service_locator, | 264 ServiceLocator* service_locator, |
265 IDirect3DTexture9* d3d_texture, | 265 IDirect3DTexture9* d3d_texture, |
266 Texture::Format format, | 266 Texture::Format format, |
267 int level, | 267 int level, |
268 unsigned dst_left, | 268 unsigned dst_left, |
269 unsigned dst_top, | 269 unsigned dst_top, |
270 unsigned src_width, | 270 unsigned src_width, |
271 unsigned src_height, | 271 unsigned src_height, |
272 const void* src_data, | 272 const void* src_data, |
273 int src_pitch) { | 273 int src_pitch) { |
274 DCHECK(src_data); | 274 DCHECK(src_data); |
275 bool compressed = Texture::IsCompressedFormat(format); | 275 bool compressed = Texture::IsCompressedFormat(format); |
276 | 276 |
277 RECT rect = {dst_left, dst_top, dst_left + src_width, dst_top + src_height}; | 277 RECT rect = {dst_left, dst_top, dst_left + src_width, dst_top + src_height}; |
278 D3DLOCKED_RECT out_rect = {0}; | 278 D3DLOCKED_RECT out_rect = {0}; |
279 | 279 |
280 if (!HR(d3d_texture->LockRect( | 280 if (!HR(d3d_texture->LockRect( |
281 level, &out_rect, compressed ? NULL : &rect, 0))) { | 281 level, &out_rect, compressed ? NULL : &rect, 0))) { |
282 O3D_ERROR(service_locator) << "Failed to Lock Texture2D (D3D9)"; | 282 O3D_ERROR(service_locator) << "Failed to Lock Texture2D (D3D9)"; |
283 return; | 283 return false; |
284 } | 284 } |
285 | 285 |
286 const uint8* src = static_cast<const uint8*>(src_data); | 286 const uint8* src = static_cast<const uint8*>(src_data); |
287 uint8* dst = static_cast<uint8*>(out_rect.pBits); | 287 uint8* dst = static_cast<uint8*>(out_rect.pBits); |
288 if (!compressed) { | 288 if (!compressed) { |
289 SetTextureRectUncompressed(format, src, src_pitch, src_width, src_height, | 289 SetTextureRectUncompressed(format, src, src_pitch, src_width, src_height, |
290 dst, out_rect.Pitch); | 290 dst, out_rect.Pitch); |
291 } else { | 291 } else { |
292 SetTextureRectCompressed( | 292 SetTextureRectCompressed( |
293 format, src, src_width, src_height, dst, out_rect.Pitch); | 293 format, src, src_width, src_height, dst, out_rect.Pitch); |
294 } | 294 } |
295 if (!HR(d3d_texture->UnlockRect(level))) { | 295 if (!HR(d3d_texture->UnlockRect(level))) { |
296 O3D_ERROR(service_locator) << "Failed to Unlock Texture2D (D3D9)"; | 296 O3D_ERROR(service_locator) << "Failed to Unlock Texture2D (D3D9)"; |
297 return; | 297 return false; |
298 } | 298 } |
| 299 return true; |
299 } | 300 } |
300 | 301 |
301 void SetTextureFaceRect( | 302 bool SetTextureFaceRect( |
302 ServiceLocator* service_locator, | 303 ServiceLocator* service_locator, |
303 IDirect3DCubeTexture9* d3d_texture, | 304 IDirect3DCubeTexture9* d3d_texture, |
304 Texture::Format format, | 305 Texture::Format format, |
305 TextureCUBE::CubeFace face, | 306 TextureCUBE::CubeFace face, |
306 int level, | 307 int level, |
307 unsigned dst_left, | 308 unsigned dst_left, |
308 unsigned dst_top, | 309 unsigned dst_top, |
309 unsigned src_width, | 310 unsigned src_width, |
310 unsigned src_height, | 311 unsigned src_height, |
311 const void* src_data, | 312 const void* src_data, |
312 int src_pitch) { | 313 int src_pitch) { |
313 DCHECK(src_data); | 314 DCHECK(src_data); |
314 bool compressed = Texture::IsCompressedFormat(format); | 315 bool compressed = Texture::IsCompressedFormat(format); |
315 | 316 |
316 RECT rect = {dst_left, dst_top, dst_left + src_width, dst_top + src_height}; | 317 RECT rect = {dst_left, dst_top, dst_left + src_width, dst_top + src_height}; |
317 D3DLOCKED_RECT out_rect = {0}; | 318 D3DLOCKED_RECT out_rect = {0}; |
318 | 319 |
319 D3DCUBEMAP_FACES d3d_face = DX9CubeFace(face); | 320 D3DCUBEMAP_FACES d3d_face = DX9CubeFace(face); |
320 | 321 |
321 if (!HR(d3d_texture->LockRect( | 322 if (!HR(d3d_texture->LockRect( |
322 d3d_face, level, &out_rect, compressed ? NULL : &rect, 0))) { | 323 d3d_face, level, &out_rect, compressed ? NULL : &rect, 0))) { |
323 O3D_ERROR(service_locator) << "Failed to Lock TextureCUBE (D3D9)"; | 324 O3D_ERROR(service_locator) << "Failed to Lock TextureCUBE (D3D9)"; |
324 return; | 325 return false; |
325 } | 326 } |
326 | 327 |
327 const uint8* src = static_cast<const uint8*>(src_data); | 328 const uint8* src = static_cast<const uint8*>(src_data); |
328 uint8* dst = static_cast<uint8*>(out_rect.pBits); | 329 uint8* dst = static_cast<uint8*>(out_rect.pBits); |
329 if (!compressed) { | 330 if (!compressed) { |
330 SetTextureRectUncompressed(format, src, src_pitch, src_width, src_height, | 331 SetTextureRectUncompressed(format, src, src_pitch, src_width, src_height, |
331 dst, out_rect.Pitch); | 332 dst, out_rect.Pitch); |
332 } else { | 333 } else { |
333 SetTextureRectCompressed( | 334 SetTextureRectCompressed( |
334 format, src, src_width, src_height, dst, out_rect.Pitch); | 335 format, src, src_width, src_height, dst, out_rect.Pitch); |
335 } | 336 } |
336 if (!HR(d3d_texture->UnlockRect(d3d_face, level))) { | 337 if (!HR(d3d_texture->UnlockRect(d3d_face, level))) { |
337 O3D_ERROR(service_locator) << "Failed to Unlock TextureCUBE (D3D9)"; | 338 O3D_ERROR(service_locator) << "Failed to Unlock TextureCUBE (D3D9)"; |
338 return; | 339 return false; |
339 } | 340 } |
| 341 return true; |
340 } | 342 } |
341 | 343 |
342 } // unnamed namespace | 344 } // unnamed namespace |
343 | 345 |
344 // Constructs a 2D texture object from the given (existing) D3D 2D texture. | 346 // Constructs a 2D texture object from the given (existing) D3D 2D texture. |
345 Texture2DD3D9::Texture2DD3D9(ServiceLocator* service_locator, | 347 Texture2DD3D9::Texture2DD3D9(ServiceLocator* service_locator, |
346 IDirect3DTexture9* tex, | 348 IDirect3DTexture9* tex, |
347 Texture::Format format, | 349 Texture::Format format, |
348 int levels, | 350 int levels, |
349 int width, | 351 int width, |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 bool entire_rect = dst_left == 0 && dst_top == 0 && | 545 bool entire_rect = dst_left == 0 && dst_top == 0 && |
544 src_width == mip_width && src_height == mip_height; | 546 src_width == mip_width && src_height == mip_height; |
545 bool compressed = IsCompressed(); | 547 bool compressed = IsCompressed(); |
546 | 548 |
547 if (compressed && !entire_rect) { | 549 if (compressed && !entire_rect) { |
548 O3D_ERROR(service_locator()) | 550 O3D_ERROR(service_locator()) |
549 << "SetRect must be full rectangle for compressed textures"; | 551 << "SetRect must be full rectangle for compressed textures"; |
550 return; | 552 return; |
551 } | 553 } |
552 | 554 |
| 555 bool success = true; |
553 if (resize_to_pot_) { | 556 if (resize_to_pot_) { |
554 DCHECK(backing_bitmap_->image_data()); | 557 DCHECK(backing_bitmap_->image_data()); |
555 DCHECK(!compressed); | 558 DCHECK(!compressed); |
556 // We need to update the backing mipmap and then use that to update the | 559 // We need to update the backing mipmap and then use that to update the |
557 // texture. | 560 // texture. |
558 backing_bitmap_->SetRect( | 561 backing_bitmap_->SetRect( |
559 level, dst_left, dst_top, src_width, src_height, src_data, src_pitch); | 562 level, dst_left, dst_top, src_width, src_height, src_data, src_pitch); |
560 UpdateBackedMipLevel(level); | 563 UpdateBackedMipLevel(level); |
561 } else { | 564 } else { |
562 SetTextureRect(service_locator(), | 565 success = SetTextureRect(service_locator(), |
563 d3d_texture_, | 566 d3d_texture_, |
564 format(), | 567 format(), |
565 level, | 568 level, |
566 dst_left, | 569 dst_left, |
567 dst_top, | 570 dst_top, |
568 src_width, | 571 src_width, |
569 src_height, | 572 src_height, |
570 src_data, | 573 src_data, |
571 src_pitch); | 574 src_pitch); |
| 575 } |
| 576 if (success && level == 0) { |
| 577 TextureUpdated(); |
572 } | 578 } |
573 } | 579 } |
574 | 580 |
575 // Locks the given mipmap level of this texture for loading from main memory, | 581 // Locks the given mipmap level of this texture for loading from main memory, |
576 // and returns a pointer to the buffer. | 582 // and returns a pointer to the buffer. |
577 bool Texture2DD3D9::PlatformSpecificLock( | 583 bool Texture2DD3D9::PlatformSpecificLock( |
578 int level, void** texture_data, int* pitch, Texture::AccessMode mode) { | 584 int level, void** texture_data, int* pitch, Texture::AccessMode mode) { |
579 DCHECK(texture_data); | 585 DCHECK(texture_data); |
580 DCHECK(pitch); | 586 DCHECK(pitch); |
581 DCHECK_GE(level, 0); | 587 DCHECK_GE(level, 0); |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 bool entire_rect = dst_left == 0 && dst_top == 0 && | 876 bool entire_rect = dst_left == 0 && dst_top == 0 && |
871 src_width == mip_width && src_height == mip_height; | 877 src_width == mip_width && src_height == mip_height; |
872 bool compressed = IsCompressed(); | 878 bool compressed = IsCompressed(); |
873 | 879 |
874 if (compressed && !entire_rect) { | 880 if (compressed && !entire_rect) { |
875 O3D_ERROR(service_locator()) | 881 O3D_ERROR(service_locator()) |
876 << "SetRect must be full rectangle for compressed textures"; | 882 << "SetRect must be full rectangle for compressed textures"; |
877 return; | 883 return; |
878 } | 884 } |
879 | 885 |
| 886 bool success = true; |
880 if (resize_to_pot_) { | 887 if (resize_to_pot_) { |
881 Bitmap* backing_bitmap = backing_bitmaps_[face].Get(); | 888 Bitmap* backing_bitmap = backing_bitmaps_[face].Get(); |
882 DCHECK(backing_bitmap->image_data()); | 889 DCHECK(backing_bitmap->image_data()); |
883 DCHECK(!compressed); | 890 DCHECK(!compressed); |
884 // We need to update the backing mipmap and then use that to update the | 891 // We need to update the backing mipmap and then use that to update the |
885 // texture. | 892 // texture. |
886 backing_bitmap->SetRect( | 893 backing_bitmap->SetRect( |
887 level, dst_left, dst_top, src_width, src_height, src_data, src_pitch); | 894 level, dst_left, dst_top, src_width, src_height, src_data, src_pitch); |
888 UpdateBackedMipLevel(face, level); | 895 UpdateBackedMipLevel(face, level); |
889 } else { | 896 } else { |
890 SetTextureFaceRect(service_locator(), | 897 success = SetTextureFaceRect(service_locator(), |
891 d3d_cube_texture_, | 898 d3d_cube_texture_, |
892 format(), | 899 format(), |
893 face, | 900 face, |
894 level, | 901 level, |
895 dst_left, | 902 dst_left, |
896 dst_top, | 903 dst_top, |
897 src_width, | 904 src_width, |
898 src_height, | 905 src_height, |
899 src_data, | 906 src_data, |
900 src_pitch); | 907 src_pitch); |
| 908 } |
| 909 if (success && level == 0) { |
| 910 TextureUpdated(); |
901 } | 911 } |
902 } | 912 } |
903 | 913 |
904 // Locks the given face and mipmap level of this texture for loading from | 914 // Locks the given face and mipmap level of this texture for loading from |
905 // main memory, and returns a pointer to the buffer. | 915 // main memory, and returns a pointer to the buffer. |
906 bool TextureCUBED3D9::PlatformSpecificLock( | 916 bool TextureCUBED3D9::PlatformSpecificLock( |
907 CubeFace face, int level, void** texture_data, int* pitch, | 917 CubeFace face, int level, void** texture_data, int* pitch, |
908 Texture::AccessMode mode) { | 918 Texture::AccessMode mode) { |
909 DCHECK(texture_data); | 919 DCHECK(texture_data); |
910 DCHECK(pitch); | 920 DCHECK(pitch); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 &d3d_cube_texture_)); | 988 &d3d_cube_texture_)); |
979 } | 989 } |
980 return true; | 990 return true; |
981 } | 991 } |
982 | 992 |
983 const Texture::RGBASwizzleIndices& TextureCUBED3D9::GetABGR32FSwizzleIndices() { | 993 const Texture::RGBASwizzleIndices& TextureCUBED3D9::GetABGR32FSwizzleIndices() { |
984 return g_d3d_abgr32f_swizzle_indices; | 994 return g_d3d_abgr32f_swizzle_indices; |
985 } | 995 } |
986 | 996 |
987 } // namespace o3d | 997 } // namespace o3d |
OLD | NEW |