MLRTexture.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. //#############################################################################
  6. //############################ MLRTexture ###############################
  7. //#############################################################################
  8. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. //
  10. MLRTexture::MLRTexture(MemoryStream *stream)
  11. {
  12. Verify(gos_GetCurrentHeap() == Heap);
  13. Check_Pointer(this);
  14. Check_Object(stream);
  15. hint = 0;
  16. }
  17. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18. //
  19. MLRTexture::MLRTexture(
  20. MLRTexturePool *tp,
  21. const char* texName,
  22. int _instance,
  23. int handle,
  24. int _hint
  25. )
  26. {
  27. Verify(gos_GetCurrentHeap() == Heap);
  28. thePool = tp;
  29. textureHandle = handle;
  30. textureName = texName;
  31. textureNameHashValue = textureName.GetHashValue();
  32. instance = _instance;
  33. textureMatrix = AffineMatrix4D::Identity;
  34. textureMatrixIsIdentity = true;
  35. image = thePool->GetImage(textureName);
  36. hint = _hint;
  37. }
  38. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. //
  40. MLRTexture::MLRTexture(
  41. MLRTexturePool *tp,
  42. GOSImage *_image,
  43. int handle,
  44. int _hint
  45. )
  46. {
  47. Verify(gos_GetCurrentHeap() == Heap);
  48. thePool = tp;
  49. textureHandle = handle;
  50. image = _image;
  51. textureName = image->GetName();
  52. textureNameHashValue = textureName.GetHashValue();
  53. instance = 0;
  54. textureMatrix = AffineMatrix4D::Identity;
  55. textureMatrixIsIdentity = true;
  56. hint = _hint;
  57. }
  58. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. //
  60. void
  61. MLRTexture::TestInstance() const
  62. {
  63. Verify((*thePool)[textureHandle]);
  64. Check_Object(image);
  65. }
  66. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. //
  68. MLRTexture::MLRTexture(const MLRTexture& tex)
  69. {
  70. Check_Object(&tex);
  71. Verify(gos_GetCurrentHeap() == Heap);
  72. }
  73. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. //
  75. MLRTexture::~MLRTexture()
  76. {
  77. if(NULL==thePool->GetImage(image->GetName()))
  78. {
  79. Unregister_Object(image);
  80. delete image;
  81. }
  82. }
  83. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84. //
  85. MLRTexture*
  86. MLRTexture::Make(MemoryStream *stream)
  87. {
  88. Check_Object(stream);
  89. gos_PushCurrentHeap(Heap);
  90. MLRTexture *texture = new MLRTexture(stream);
  91. gos_PopCurrentHeap();
  92. return texture;
  93. }
  94. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. //
  96. void
  97. MLRTexture::Save(MemoryStream *stream)
  98. {
  99. }
  100. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. //
  102. int
  103. MLRTexture::GetImageNumber()
  104. {
  105. Check_Object(this);
  106. return ((textureHandle-1) >> (thePool->GetInstanceDepth()));
  107. }
  108. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109. //
  110. int
  111. MLRTexture::GetInstanceNumber()
  112. {
  113. Check_Object(this);
  114. return ((textureHandle-1) & ~((1<<thePool->GetInstanceDepth())-1));
  115. }