dx8polygonrenderer.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : ww3d *
  23. * *
  24. * $Archive:: /Commando/Code/ww3d2/dx8polygonrenderer.h $*
  25. * *
  26. * Original Author:: Greg Hjelstrom *
  27. * *
  28. * $Author:: Greg_h $*
  29. * *
  30. * $Modtime:: 2/12/02 2:29p $*
  31. * *
  32. * $Revision:: 23 $*
  33. * *
  34. *---------------------------------------------------------------------------------------------*
  35. * Functions: *
  36. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  37. #if defined(_MSC_VER)
  38. #pragma once
  39. #endif
  40. #ifndef DX8_POLYGON_RENDERER_H
  41. #define DX8_POLYGON_RENDERER_H
  42. #include "always.h"
  43. #include "meshmdl.h"
  44. #include "dx8list.h"
  45. #include "sortingrenderer.h"
  46. #include "mesh.h"
  47. #include "dx8wrapper.h"
  48. class DX8PolygonRendererClass;
  49. class DX8TextureCategoryClass;
  50. /**
  51. ** DX8PolygonRendererClass
  52. ** This is a record of a batch/range of polygons to be rendered. These hang off of the DX8TextureCategoryClass's
  53. ** and are rendered after the system installs a vertex buffer and textures in the DX8 wrapper.
  54. */
  55. class DX8PolygonRendererClass : public MultiListObjectClass
  56. {
  57. MeshClass * mesh;
  58. DX8TextureCategoryClass * texture_category;
  59. unsigned index_offset; // absolute index of index 0 for our parent mesh
  60. unsigned vertex_offset; // absolute index of vertex 0 for our parent mesh
  61. unsigned index_count; // number of indices
  62. unsigned min_vertex_index; // relative index of the first vertex our polys reference
  63. unsigned vertex_index_range; // range to the last vertex our polys reference
  64. bool strip; // is this a strip?
  65. public:
  66. DX8PolygonRendererClass(
  67. unsigned index_count,
  68. MeshClass* mesh_,
  69. DX8TextureCategoryClass* tex_cat,
  70. unsigned vertex_offset,
  71. unsigned index_offset,
  72. bool strip);
  73. DX8PolygonRendererClass(const DX8PolygonRendererClass& src,MeshClass * mesh_);
  74. ~DX8PolygonRendererClass();
  75. void Render(/*const Matrix3D & tm,*/int base_vertex_offset);
  76. void Render_Sorted(/*const Matrix3D & tm,*/int base_vertex_offset,const SphereClass & bounding_sphere);
  77. void Set_Vertex_Index_Range(unsigned min_vertex_index_,unsigned vertex_index_range_);
  78. unsigned Get_Vertex_Offset(void) { return vertex_offset; }
  79. unsigned Get_Index_Offset(void) { return index_offset; }
  80. MeshClass* Get_Mesh_Class() { return mesh; }
  81. // MeshModelClass* Get_Mesh_Model_Class() { return mesh->Peek_Model(); }
  82. DX8TextureCategoryClass* Get_Texture_Category() { return texture_category; }
  83. void Set_Texture_Category(DX8TextureCategoryClass* tc) { texture_category=tc; }
  84. void Log();
  85. };
  86. // ----------------------------------------------------------------------------
  87. inline void DX8PolygonRendererClass::Set_Vertex_Index_Range(unsigned min_vertex_index_,unsigned vertex_index_range_)
  88. {
  89. // WWDEBUG_SAY(("Set_Vertex_Index_Range - min: %d, range: %d\n",min_vertex_index_,vertex_index_range_));
  90. // if (vertex_index_range_>30000) {
  91. // int a=0;
  92. // a++;
  93. // }
  94. min_vertex_index=min_vertex_index_;
  95. vertex_index_range=vertex_index_range_;
  96. }
  97. // ----------------------------------------------------------------------------
  98. inline void DX8PolygonRendererClass::Render(/*const Matrix3D & tm,*/int base_vertex_offset)
  99. {
  100. // DX8Wrapper::Set_Transform(D3DTS_WORLD,tm);
  101. // SNAPSHOT_SAY(("Set_Transform\n"));
  102. SNAPSHOT_SAY(("Set_Index_Buffer_Index_Offset(%d)\n",base_vertex_offset));
  103. DX8Wrapper::Set_Index_Buffer_Index_Offset(base_vertex_offset);
  104. if (strip) {
  105. SNAPSHOT_SAY(("Draw_Strip(%d,%d,%d,%d)\n",index_offset,index_count-2,min_vertex_index,vertex_index_range));
  106. DX8Wrapper::Draw_Strip(
  107. index_offset,
  108. index_count-2,
  109. min_vertex_index,
  110. vertex_index_range);
  111. }
  112. else {
  113. SNAPSHOT_SAY(("Draw_Triangles(%d,%d,%d,%d)\n",index_offset,index_count-2,min_vertex_index,vertex_index_range));
  114. DX8Wrapper::Draw_Triangles(
  115. index_offset,
  116. index_count/3,
  117. min_vertex_index,
  118. vertex_index_range);
  119. }
  120. }
  121. inline void DX8PolygonRendererClass::Render_Sorted(/*const Matrix3D & tm,*/int base_vertex_offset,const SphereClass & bounding_sphere)
  122. {
  123. WWASSERT(!strip); // Strips can't be sorted for now
  124. // DX8Wrapper::Set_Transform(D3DTS_WORLD,tm);
  125. // SNAPSHOT_SAY(("Set_Transform\n"));
  126. SNAPSHOT_SAY(("Set_Index_Buffer_Index_Offset(%d)\n",base_vertex_offset));
  127. SNAPSHOT_SAY(("Insert_Sorting_Triangles(%d,%d,%d,%d)\n",index_offset,index_count-2,min_vertex_index,vertex_index_range));
  128. DX8Wrapper::Set_Index_Buffer_Index_Offset(base_vertex_offset);
  129. SortingRendererClass::Insert_Triangles(
  130. bounding_sphere,
  131. index_offset,
  132. index_count/3,
  133. min_vertex_index,
  134. vertex_index_range);
  135. }
  136. #endif