- core::position2d<s32> targetPos(destPos);\r
- core::position2d<s32> sourcePos(sourceRect.UpperLeftCorner);\r
- core::dimension2d<s32> sourceSize(sourceRect.getSize());\r
- if (clipRect)\r
- {\r
- if (targetPos.X < clipRect->UpperLeftCorner.X)\r
- {\r
- sourceSize.Width += targetPos.X - clipRect->UpperLeftCorner.X;\r
- if (sourceSize.Width <= 0)\r
- return;\r
-\r
- sourcePos.X -= targetPos.X - clipRect->UpperLeftCorner.X;\r
- targetPos.X = clipRect->UpperLeftCorner.X;\r
- }\r
-\r
- if (targetPos.X + sourceSize.Width > clipRect->LowerRightCorner.X)\r
- {\r
- sourceSize.Width -= (targetPos.X + sourceSize.Width) - clipRect->LowerRightCorner.X;\r
- if (sourceSize.Width <= 0)\r
- return;\r
- }\r
-\r
- if (targetPos.Y < clipRect->UpperLeftCorner.Y)\r
- {\r
- sourceSize.Height += targetPos.Y - clipRect->UpperLeftCorner.Y;\r
- if (sourceSize.Height <= 0)\r
- return;\r
-\r
- sourcePos.Y -= targetPos.Y - clipRect->UpperLeftCorner.Y;\r
- targetPos.Y = clipRect->UpperLeftCorner.Y;\r
- }\r
-\r
- if (targetPos.Y + sourceSize.Height > clipRect->LowerRightCorner.Y)\r
- {\r
- sourceSize.Height -= (targetPos.Y + sourceSize.Height) - clipRect->LowerRightCorner.Y;\r
- if (sourceSize.Height <= 0)\r
- return;\r
- }\r
- }\r
-\r
- // clip these coordinates\r
-\r
- if (targetPos.X < 0)\r
- {\r
- sourceSize.Width += targetPos.X;\r
- if (sourceSize.Width <= 0)\r
- return;\r
-\r
- sourcePos.X -= targetPos.X;\r
- targetPos.X = 0;\r
- }\r
-\r
- const core::dimension2d<u32>& renderTargetSize = getCurrentRenderTargetSize();\r
-\r
- if (targetPos.X + sourceSize.Width > (s32)renderTargetSize.Width)\r
- {\r
- sourceSize.Width -= (targetPos.X + sourceSize.Width) - renderTargetSize.Width;\r
- if (sourceSize.Width <= 0)\r
- return;\r
- }\r
-\r
- if (targetPos.Y < 0)\r
- {\r
- sourceSize.Height += targetPos.Y;\r
- if (sourceSize.Height <= 0)\r
- return;\r
-\r
- sourcePos.Y -= targetPos.Y;\r
- targetPos.Y = 0;\r
- }\r
-\r
- if (targetPos.Y + sourceSize.Height > (s32)renderTargetSize.Height)\r
- {\r
- sourceSize.Height -= (targetPos.Y + sourceSize.Height) - renderTargetSize.Height;\r
- if (sourceSize.Height <= 0)\r
- return;\r
- }\r
-\r
- // ok, we've clipped everything.\r
- // now draw it.\r
-\r
- // texcoords need to be flipped horizontally for RTTs\r
- const bool isRTT = texture->isRenderTarget();\r
- const core::dimension2d<u32>& ss = texture->getOriginalSize();\r
- const f32 invW = 1.f / static_cast<f32>(ss.Width);\r
- const f32 invH = 1.f / static_cast<f32>(ss.Height);\r
- const core::rect<f32> tcoords(\r
- sourcePos.X * invW,\r
- (isRTT ? (sourcePos.Y + sourceSize.Height) : sourcePos.Y) * invH,\r
- (sourcePos.X + sourceSize.Width) * invW,\r
- (isRTT ? sourcePos.Y : (sourcePos.Y + sourceSize.Height)) * invH);\r
-\r
- const core::rect<s32> poss(targetPos, sourceSize);\r
-\r
- chooseMaterial2D();\r
- if (!setMaterialTexture(0, texture ))\r
- return;\r
-\r
- setRenderStates2DMode(color.getAlpha() < 255, true, useAlphaChannelOfTexture);\r
-\r
- f32 left = (f32)poss.UpperLeftCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;\r
- f32 right = (f32)poss.LowerRightCorner.X / (f32)renderTargetSize.Width * 2.f - 1.f;\r
- f32 down = 2.f - (f32)poss.LowerRightCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;\r
- f32 top = 2.f - (f32)poss.UpperLeftCorner.Y / (f32)renderTargetSize.Height * 2.f - 1.f;\r
-\r
- u16 indices[] = {0, 1, 2, 3};\r
- S3DVertex vertices[4];\r
- vertices[0] = S3DVertex(left, top, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.UpperLeftCorner.Y);\r
- vertices[1] = S3DVertex(right, top, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.UpperLeftCorner.Y);\r
- vertices[2] = S3DVertex(right, down, 0, 0, 0, 1, color, tcoords.LowerRightCorner.X, tcoords.LowerRightCorner.Y);\r
- vertices[3] = S3DVertex(left, down, 0, 0, 0, 1, color, tcoords.UpperLeftCorner.X, tcoords.LowerRightCorner.Y);\r
-\r
- glEnableVertexAttribArray(EVA_POSITION);\r
- glEnableVertexAttribArray(EVA_COLOR);\r
- glEnableVertexAttribArray(EVA_TCOORD0);\r
- glVertexAttribPointer(EVA_POSITION, 3, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Pos);\r
- glVertexAttribPointer(EVA_COLOR, 4, GL_UNSIGNED_BYTE, true, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].Color);\r
- glVertexAttribPointer(EVA_TCOORD0, 2, GL_FLOAT, false, sizeof(S3DVertex), &(static_cast<const S3DVertex*>(vertices))[0].TCoords);\r
- glDrawElements(GL_TRIANGLE_FAN, 4, GL_UNSIGNED_SHORT, indices);\r
- glDisableVertexAttribArray(EVA_TCOORD0);\r
- glDisableVertexAttribArray(EVA_COLOR);\r
- glDisableVertexAttribArray(EVA_POSITION);\r