MCPcopy Create free account
hub / github.com/carbonengine/trinity / AdjustTextureCoordsToViewport

Function AdjustTextureCoordsToViewport

trinity/Tr2Renderer.cpp:267–290  ·  view source on GitHub ↗

To deal with the adjusted viewport that D3D9 forces us to create when viewport extends beyond the screen

Source from the content-addressed store, hash-verified

265// To deal with the adjusted viewport that D3D9 forces us to create when viewport
266// extends beyond the screen
267void AdjustTextureCoordsToViewport( Tr2RenderContext& renderContext, Vector2& topLeft, Vector2& bottomRight )
268{
269 Vector2 tlTexCoordAdjusted = topLeft;
270
271 auto& viewportOnDevice = renderContext.m_esm.GetDeviceViewport();
272 auto& viewport = renderContext.m_esm.GetViewport();
273
274 int deltaX = (int)viewportOnDevice.m_x - viewport.x;
275 int deltaY = (int)viewportOnDevice.m_y - viewport.y;
276
277 float xOffset = float( deltaX ) / viewport.width;
278 float yOffset = float( deltaY ) / viewport.height;
279
280 tlTexCoordAdjusted.x += xOffset * bottomRight.x;
281 tlTexCoordAdjusted.y += yOffset * bottomRight.y;
282
283 Vector2 brTexCoordAdjusted;
284 brTexCoordAdjusted = bottomRight;
285 brTexCoordAdjusted.x *= float( viewportOnDevice.m_width + deltaX ) / viewport.width;
286 brTexCoordAdjusted.y *= float( viewportOnDevice.m_height + deltaY ) / viewport.height;
287
288 topLeft = tlTexCoordAdjusted;
289 bottomRight = brTexCoordAdjusted;
290}
291
292
293template <typename T>

Callers 1

DrawTextureMethod · 0.85

Calls 1

GetViewportMethod · 0.45

Tested by

no test coverage detected