Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.1 KiB

  1. /**
  2. ** File : cpmesh.cxx
  3. ** Description: Implementations of CPMeshGL class
  4. **/
  5. #include "precomp.h"
  6. #pragma hdrstop
  7. #include <objbase.h>
  8. #include <initguid.h>
  9. #include "cpmesh.h"
  10. #include "pmerrors.h"
  11. /*
  12. * CPMeshGL: Constructor
  13. */
  14. CPMeshGL::CPMeshGL() : CAugGlMesh()
  15. {
  16. m_cRef = 1;
  17. m_vsarr = NULL;
  18. m_baseVertices =
  19. m_baseWedges =
  20. m_baseFaces =
  21. m_currPos =
  22. m_maxVertices =
  23. m_maxWedges =
  24. m_maxFaces =
  25. m_maxMaterials =
  26. m_maxTextures = 0;
  27. }
  28. /**************************************************************************/
  29. /*
  30. * CPMeshGL: Destructor
  31. */
  32. CPMeshGL::~CPMeshGL()
  33. {
  34. unsigned i;
  35. delete m_vsarr;
  36. }
  37. /**************************************************************************/
  38. /*
  39. * IUnknown methods
  40. */
  41. STDMETHODIMP_(ULONG) CPMeshGL::AddRef(void)
  42. {
  43. return m_cRef++;
  44. }
  45. STDMETHODIMP_(ULONG) CPMeshGL::Release(void)
  46. {
  47. if (--m_cRef != 0)
  48. return m_cRef;
  49. delete this;
  50. return 0;
  51. }
  52. STDMETHODIMP CPMeshGL::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  53. {
  54. *ppv=NULL;
  55. if (riid == IID_IUnknown)
  56. *ppv=(IUnknown*)(IPMesh*)this;
  57. else if (riid == IID_IPMesh)
  58. *ppv=(IPMesh*)this;
  59. else if (riid == IID_IPMeshGL)
  60. *ppv=(IPMeshGL*)this;
  61. else
  62. return E_NOINTERFACE;
  63. ((LPUNKNOWN)*ppv)->AddRef();
  64. return NOERROR;
  65. }
  66. /**************************************************************************/
  67. /*
  68. * IPMeshGL methods
  69. */
  70. STDMETHODIMP CPMeshGL::Initialize(void)
  71. {
  72. return S_OK;
  73. }
  74. STDMETHODIMP CPMeshGL::Render(void)
  75. {
  76. RenderMesh (GLPM_SOLID);
  77. return S_OK;
  78. }
  79. /**************************************************************************/
  80. /*
  81. * IPMesh methods
  82. */
  83. // Gets
  84. STDMETHODIMP CPMeshGL::GetNumFaces(DWORD* const nfaces)
  85. {
  86. *nfaces = GetMeshNumFaces();
  87. return S_OK;
  88. }
  89. STDMETHODIMP CPMeshGL::GetMaxFaces(DWORD* const maxfaces)
  90. {
  91. *maxfaces = m_maxFaces;
  92. return S_OK;
  93. }
  94. STDMETHODIMP CPMeshGL::GetNumVertices(DWORD* const nverts)
  95. {
  96. *nverts = GetMeshNumVerts();
  97. return S_OK;
  98. }
  99. STDMETHODIMP CPMeshGL::GetMaxVertices(DWORD* const maxverts)
  100. {
  101. *maxverts = m_maxVertices;
  102. return S_OK;
  103. }
  104. // Sets
  105. STDMETHODIMP CPMeshGL::SetNumFaces(DWORD f)
  106. {
  107. return E_NOTIMPL;
  108. }
  109. STDMETHODIMP CPMeshGL::SetNumVertices(DWORD nv)
  110. {
  111. DWORD v = nv;
  112. if (v > m_maxVertices)
  113. v = m_maxVertices;
  114. if (v < m_baseVertices)
  115. v = m_baseVertices;
  116. if (v > m_baseVertices + m_currPos)
  117. {
  118. while (m_currPos < v - m_baseVertices)
  119. {
  120. apply_vsplit (m_vsarr->elem(m_currPos++));
  121. }
  122. }
  123. else if (v < m_baseVertices + m_currPos)
  124. {
  125. while (m_currPos > v - m_baseVertices)
  126. {
  127. --m_currPos;
  128. undo_vsplit (m_vsarr->elem(m_currPos));
  129. }
  130. }
  131. else
  132. {
  133. return S_OK;
  134. }
  135. return S_OK;
  136. }
  137. /**************************************************************************\
  138. * FUNCTION: CreatePMeshGL. This function is exported *
  139. * *
  140. * ARGS: iid -> IID of the interface desired. *
  141. * ppV -> pointer to pointer to the interface. *
  142. * pUnkOuter -> Not needed yet. Dunno what for!! *
  143. * bReserved -> Shd be NULL. To be used later. *
  144. * *
  145. * DESCRIPTION: Helper function to initialize the Object. *
  146. * Use it in place of CoCreateInstance. *
  147. \**************************************************************************/
  148. HRESULT CreatePMeshGL(REFIID iid,
  149. LPVOID FAR* ppV,
  150. IUnknown* pUnkOuter,
  151. DWORD bReserved)
  152. {
  153. HRESULT hr;
  154. if (bReserved)
  155. return E_INVALIDARG;
  156. CPMeshGL* pPMGL = new CPMeshGL;
  157. if (!pPMGL)
  158. return E_OUTOFMEMORY;
  159. hr = pPMGL->QueryInterface(iid, ppV);
  160. if (SUCCEEDED(hr))
  161. hr = pPMGL->Initialize();
  162. if (FAILED(hr))
  163. {
  164. ppV = NULL;
  165. delete pPMGL;
  166. }
  167. return hr;
  168. }