QuadRender.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #include "QuadRender.h"
  2. #include "..\..\..\..\Common_h\Render.h"
  3. #include "..\..\Utils\InterfaceUtils.h"
  4. static inline float SC2UIRC(float t)
  5. {
  6. return InterfaceUtils::ScreenCoord2UIRectCoord(t);
  7. }
  8. static inline float SS2UIRS(float t)
  9. {
  10. return InterfaceUtils::ScreenSize2UIRectSize(t);
  11. }
  12. QuadRender::QuadRender(void)
  13. {
  14. m_render = null;
  15. m_aspect = 4.0f/3.0f;
  16. m_texture = null;
  17. m_texVar = null;
  18. BlackScale = null;
  19. m_render = (IRender*)api->GetService("DX9Render");
  20. Assert(m_render);
  21. // m_render->GetShaderId("interfaceQuad", GUI_Quad_id);
  22. m_render->GetShaderId("interfaceQuad_Black", GUI_Quad_Black_id);
  23. m_aspect = m_render->GetScreenInfo2D().dwHeight/(float)m_render->GetScreenInfo2D().dwWidth;
  24. m_texVar = m_render->GetTechniqueGlobalVariable("interfaceTexture",_FL_);
  25. BlackScale = m_render->GetTechniqueGlobalVariable("interfaceBlackScale",_FL_);
  26. }
  27. QuadRender::~QuadRender(void)
  28. {
  29. if( m_texture )
  30. {
  31. m_texture->Release();
  32. m_texture = null;
  33. }
  34. m_texVar = null;
  35. BlackScale = null;
  36. }
  37. void QuadRender::SetTexture(const char *texName, bool black)
  38. {
  39. IBaseTexture *oldTex = m_texture;
  40. // m_texture = (ITexture*)m_render->CreateTexture(_FL_,texName);
  41. m_texture = (ITexture*)m_render->CreateTextureFullQuality(_FL_,texName);
  42. if( oldTex )
  43. oldTex->Release();
  44. m_black = black;
  45. }
  46. void QuadRender::CalcScreenRect(BaseGUIElement::Rect &rect, float xScaleCenter, float yScaleCenter) const
  47. {
  48. float x = rect.l;
  49. float y = rect.t;
  50. float w = rect.r - rect.l;
  51. float h = rect.b - rect.t;
  52. x -= (w*xScaleCenter - w)*0.5f;
  53. y -= (h*yScaleCenter - h)*0.5f;
  54. w *= xScaleCenter;
  55. h *= yScaleCenter;
  56. x = SC2UIRC(x*0.01f);
  57. y = SC2UIRC(y*0.01f);
  58. float x1 = x + SS2UIRS(w*0.01f);
  59. float y1 = y + SS2UIRS(h*0.01f);
  60. rect.l = x *m_render->GetViewport().Width + m_render->GetViewport().X;
  61. rect.t = y *m_render->GetViewport().Height + m_render->GetViewport().Y;
  62. rect.r = x1*m_render->GetViewport().Width + m_render->GetViewport().X;
  63. rect.b = y1*m_render->GetViewport().Height + m_render->GetViewport().Y;
  64. }
  65. void QuadRender::DrawQuad(
  66. float x, float y, float w, float h,
  67. float tu, float tv, float tw, float th, float alpha,
  68. float xScaleCenter,
  69. float yScaleCenter, bool vertical, bool invert)
  70. {
  71. x -= (w*xScaleCenter - w)*0.5f;
  72. y -= (h*yScaleCenter - h)*0.5f;
  73. w *= xScaleCenter;
  74. h *= yScaleCenter;
  75. x = /*SC2UIRC*/(x*0.01f);
  76. y = /*SC2UIRC*/(y*0.01f);
  77. float x1 = x + /*SS2UIRS*/(w*0.01f);
  78. float y1 = y + /*SS2UIRS*/(h*0.01f);
  79. float vb[] = {
  80. x *2.0f - 1.0f,1.0f - y *2.0f,1.0f,alpha,tu ,tv,
  81. x1*2.0f - 1.0f,1.0f - y *2.0f,1.0f,alpha,tu + tw,tv,
  82. x *2.0f - 1.0f,1.0f - y1*2.0f,1.0f,alpha,tu ,tv + th,
  83. x1*2.0f - 1.0f,1.0f - y1*2.0f,1.0f,alpha,tu + tw,tv + th};
  84. /* if( vertical )
  85. {
  86. if( invert )
  87. {
  88. vb[ 5] += th;
  89. vb[10] -= tw;
  90. vb[16] += tw;
  91. vb[23] -= th;
  92. }
  93. else
  94. {
  95. vb[ 4] += tw;
  96. vb[11] += th;
  97. vb[17] -= th;
  98. vb[22] -= tw;
  99. }
  100. }*/
  101. if( m_texVar )
  102. m_texVar->SetTexture(m_texture ? m_texture : m_render->getWhiteTexture());
  103. if( BlackScale )
  104. BlackScale->SetFloat(m_black ? 1.0f : 0.0f);
  105. // m_render->DrawPrimitiveUP(
  106. // m_black ? GUI_Quad_Black_id : GUI_Quad_id,PT_TRIANGLESTRIP,2,vb,6*sizeof(float));
  107. m_render->DrawPrimitiveUP(
  108. GUI_Quad_Black_id,PT_TRIANGLESTRIP,2,vb,6*sizeof(float));
  109. }