bool D3D9Sprite::DrawShaped( const Vector2& v2Pos, const Vector2& v2Size, const Color& color0, const Color& color1, const Color& color2, const Color& color3, const float angle) { if (v2Size == Vector2(0,0)) { return true; } // do the flip (parameters that will be send to the VS) Vector2 flipMul(1,1), flipAdd(0,0); if (m_flipX) { flipMul.x =-1; flipAdd.x = 1; } if (m_flipY) { flipMul.y =-1; flipAdd.y = 1; } // centralizes the sprite according to the origin Vector2 v2Center = m_normalizedOrigin*v2Size; Video* video = m_video.lock().get(); ShaderPtr pCurrentVS = video->GetVertexShader(); Matrix4x4 mRot; if (angle != 0.0f) mRot = RotateZ(DegreeToRadian(angle)); pCurrentVS->SetMatrixConstant(L"rotationMatrix", mRot); // rounds up the final position to avoid alpha distortion Vector2 v2FinalPos; if (video->IsRoundingUpPosition()) { v2FinalPos.x = floor(v2Pos.x); v2FinalPos.y = floor(v2Pos.y); } else { v2FinalPos = v2Pos; } // subtract 0.5 to align pixel-texel v2FinalPos -= math::constant::HALF_VECTOR2; pCurrentVS->SetConstant(L"size", v2Size); pCurrentVS->SetConstant(L"entityPos", v2FinalPos); pCurrentVS->SetConstant(L"center", v2Center); pCurrentVS->SetConstant(L"flipMul", flipMul); pCurrentVS->SetConstant(L"flipAdd", flipAdd); pCurrentVS->SetConstant(L"bitmapSize", GetBitmapSizeF()); pCurrentVS->SetConstant(L"scroll", GetScroll()); pCurrentVS->SetConstant(L"multiply", GetMultiply()); const bool setCameraPos = pCurrentVS->ConstantExist(L"cameraPos"); if (setCameraPos) pCurrentVS->SetConstant(L"cameraPos", video->GetCameraPos()); if (m_rect.size.x == 0 || m_rect.size.y == 0) { pCurrentVS->SetConstant(L"rectSize", GetBitmapSizeF()); pCurrentVS->SetConstant(L"rectPos", 0, 0); } else { pCurrentVS->SetConstant(L"rectSize", m_rect.size); pCurrentVS->SetConstant(L"rectPos", m_rect.pos); } pCurrentVS->SetConstant(L"color0", color0); pCurrentVS->SetConstant(L"color1", color1); pCurrentVS->SetConstant(L"color2", color2); pCurrentVS->SetConstant(L"color3", color3); if (pCurrentVS->ConstantExist(L"depth")) pCurrentVS->SetConstant(L"depth", video->GetSpriteDepth()); pCurrentVS->SetShader(); // apply textures according to the rendering mode (pixel shaded or not) ShaderPtr pCurrentPS = video->GetPixelShader(); if (!pCurrentPS) { m_pDevice->SetTexture(0, m_pTexture); //for (unsigned int t=1; t<GS_TEXTURE_CHANNELS; t++) // pDevice->SetTexture(t, NULL); } else { pCurrentPS->SetShader(); pCurrentPS->SetTexture(L"diffuse", GetTexture()); } // draw the one-pixel-quad applying the vertex shader m_pVideoInfo->DrawSprite(m_pDevice, m_rectMode); m_pDevice->SetVertexShader(NULL); return true; }
void GLVideo::UpdateShaderViewData(const ShaderPtr& shader, const math::Vector2& screenSize, const math::Matrix4x4& ortho) { shader->SetConstant("screenSize", screenSize); shader->SetMatrixConstant("viewMatrix", ortho); }
bool GLSprite::DrawShaped( const math::Vector2 &v2Pos, const math::Vector2 &v2Size, const Color& color0, const Color& color1, const Color& color2, const Color& color3, const float angle) { if (v2Size == math::Vector2(0,0)) { return true; } // compute flip parameters that will be sent to the VS math::Vector2 flipMul, flipAdd; GetFlipShaderParameters(flipAdd, flipMul); // centralizes the sprite according to the origin math::Vector2 v2Center = m_normalizedOrigin * v2Size; GLVideo* video = m_video.lock().get(); ShaderPtr pCurrentVS = video->GetVertexShader(); math::Matrix4x4 mRot; if (angle != 0.0f) mRot = math::RotateZ(math::DegreeToRadian(angle)); pCurrentVS->SetMatrixConstant("rotationMatrix", mRot); // rounds up the final position to avoid alpha distortion math::Vector2 v2FinalPos; if (video->IsRoundingUpPosition()) { v2FinalPos.x = floor(v2Pos.x); v2FinalPos.y = floor(v2Pos.y); } else { v2FinalPos = v2Pos; } pCurrentVS->SetConstant("size", v2Size); pCurrentVS->SetConstant("entityPos", v2FinalPos); pCurrentVS->SetConstant("center", v2Center); pCurrentVS->SetConstant("flipMul", flipMul); pCurrentVS->SetConstant("flipAdd", flipAdd); pCurrentVS->SetConstant("bitmapSize", GetBitmapSizeF()); pCurrentVS->SetConstant("scroll", GetScroll()); pCurrentVS->SetConstant("multiply", GetMultiply()); const bool setCameraPos = pCurrentVS->ConstantExist("cameraPos"); if (setCameraPos) pCurrentVS->SetConstant("cameraPos", video->GetCameraPos()); if (m_rect.size.x == 0 || m_rect.size.y == 0) { pCurrentVS->SetConstant("rectSize", GetBitmapSizeF()); pCurrentVS->SetConstant("rectPos", 0, 0); } else { pCurrentVS->SetConstant("rectSize", m_rect.size); pCurrentVS->SetConstant("rectPos", m_rect.pos); } pCurrentVS->SetConstant("color0", color0); pCurrentVS->SetConstant("color1", color1); pCurrentVS->SetConstant("color2", color2); pCurrentVS->SetConstant("color3", color3); if (pCurrentVS->ConstantExist("depth")) pCurrentVS->SetConstant("depth", video->GetSpriteDepth()); // apply textures according to the rendering mode (pixel shaded or not) ShaderPtr pCurrentPS = video->GetPixelShader(); SetDiffuseTexture(pCurrentPS); pCurrentVS->SetShader(); // draw the one-pixel-quad applying the vertex shader video->GetRectRenderer().Draw(m_rectMode); return true; }