shdinterface.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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 : WWSHADE *
  23. * *
  24. * $Archive:: wwshade/shdinterface.h $*
  25. * *
  26. * $Org Author:: Jani_p
  27. *
  28. * $Author:: Kenny_m
  29. *
  30. * $Modtime:: 6/05/02 3:12p $*
  31. * *
  32. * $Revision:: 2 $*
  33. * *
  34. * 6/05/02 KJM : Added texture info functions
  35. *---------------------------------------------------------------------------------------------*
  36. * Functions: *
  37. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  38. #ifndef SHDINTERFACE_H
  39. #define SHDINTERFACE_H
  40. #include "always.h"
  41. #include "refcount.h"
  42. #include "dx8wrapper.h"
  43. class ShdDefClass;
  44. class ShdMeshClass;
  45. class RenderInfoClass;
  46. class TextureClass;
  47. /*
  48. ** Maximum passes allowed for any shader implementation!
  49. */
  50. const int SHD_MAX_PASSES = 4;
  51. /**
  52. ** Utility structure for passing in streams to the shader. Those streams that are not available will be NULL,
  53. ** and the shader should ASSERT that it is passed everything it needs in its Copy_Vertex_Stream() function.
  54. ** The caller of the Copy_Vertex_Stream() should use query functions (such as Requires_Normals()) in the definition
  55. ** to determine which streams the shader needs.
  56. */
  57. struct VertexStreamStruct
  58. {
  59. VertexStreamStruct()
  60. : Locations(0),
  61. Normals(0),
  62. DiffuseInt(0),
  63. DiffuseFloat(0)
  64. {
  65. for (int i=0;i<MAX_TEXTURE_STAGES;++i)
  66. {
  67. UV[i]=0;
  68. }
  69. }
  70. const Vector3* Locations;
  71. const Vector3* Normals;
  72. const Vector2* UV[MAX_TEXTURE_STAGES];
  73. const unsigned* DiffuseInt;
  74. const Vector4* DiffuseFloat;
  75. const Vector3* S;
  76. const Vector3* T;
  77. const Vector3* SxT;
  78. };
  79. /**
  80. ** ShdInterfaceClass - This class is the virtual interface for all shaders. A derived shader's job is to
  81. ** set up the D3D render states for a particular rendering operation. Instances of shaders are
  82. ** are created by an associated ShdDefClass.
  83. */
  84. class ShdInterfaceClass : public RefCountClass
  85. {
  86. public:
  87. ShdInterfaceClass(const ShdDefClass * def,int class_id);
  88. virtual ~ShdInterfaceClass(void);
  89. const ShdDefClass * Peek_Definition(void);
  90. WWINLINE int Get_Class_ID() const { return ClassID; }
  91. // For rendering efficiency, all shaders should implement comparison operator that the renderer
  92. // can use to sort the meshes.
  93. virtual bool Greater_Than (const ShdInterfaceClass& s,int pass) const { return true; }
  94. virtual bool Similar_Enough (const ShdInterfaceClass& s,int pass) const { return true; }
  95. virtual int Get_Pass_Count(void) = 0;
  96. virtual bool Pass_Selection(ShdMeshClass*, RenderInfoClass*,int) { return true; }
  97. virtual void Apply_Shared(int cur_pass, RenderInfoClass& rinfo) = 0;
  98. virtual void Apply_Instance(int cur_pass, RenderInfoClass& rinfo) = 0;
  99. // The shader needs to tell how many vertex streams it needs and what are the sizes of vertices
  100. // in each stream.
  101. virtual unsigned Get_Vertex_Stream_Count() const = 0;
  102. virtual unsigned Get_Vertex_Size(unsigned stream) const = 0;
  103. virtual bool Use_HW_Vertex_Processing() const = 0;
  104. virtual int Get_Texture_Count() const = 0;
  105. virtual TextureClass* Peek_Texture(int idx) const = 0;
  106. // The shader needs to construct each vertex stream as requested. The data comes in a standard
  107. // VertexStreamStruct, and the shader can format it as it wishes (nothing else will be using
  108. // the buffer than the shader itself.
  109. virtual void Copy_Vertex_Stream(unsigned stream, void* dest_buffer, const VertexStreamStruct& vss, unsigned vertex_count) = 0;
  110. // Return whether this shader is opaque. This property is used to determine whether
  111. // geometric shadows should be cast from an object for example. Alpha-Test shaders should
  112. // return false to Is_Opaque.
  113. virtual bool Is_Opaque(void) const { return true; }
  114. protected:
  115. const ShdDefClass * Definition;
  116. int ClassID;
  117. };
  118. #endif //SHDINTERFACE_H