MCPcopy Create free account
hub / github.com/ddnet/ddnet / RenderTileRectangle

Method RenderTileRectangle

src/game/map/render_map.cpp:435–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

433}
434
435void CRenderMap::RenderTileRectangle(int RectX, int RectY, int RectW, int RectH,
436 unsigned char IndexIn, unsigned char IndexOut,
437 float Scale, ColorRGBA Color, int RenderFlags)
438{
439 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
440 Graphics()->GetScreen(&ScreenX0, &ScreenY0, &ScreenX1, &ScreenY1);
441
442 // calculate the final pixelsize for the tiles
443 float TilePixelSize = 1024 / 32.0f;
444 float FinalTileSize = Scale / (ScreenX1 - ScreenX0) * Graphics()->ScreenWidth();
445 float FinalTilesetScale = FinalTileSize / TilePixelSize;
446
447 if(Graphics()->HasTextureArraysSupport())
448 Graphics()->QuadsTex3DBegin();
449 else
450 Graphics()->QuadsBegin();
451 Graphics()->SetColor(Color);
452
453 int StartY = (int)(ScreenY0 / Scale) - 1;
454 int StartX = (int)(ScreenX0 / Scale) - 1;
455 int EndY = (int)(ScreenY1 / Scale) + 1;
456 int EndX = (int)(ScreenX1 / Scale) + 1;
457
458 // adjust the texture shift according to mipmap level
459 float TexSize = 1024.0f;
460 float Frac = (1.25f / TexSize) * (1 / FinalTilesetScale);
461 float Nudge = (0.5f / TexSize) * (1 / FinalTilesetScale);
462
463 for(int y = StartY; y < EndY; y++)
464 {
465 for(int x = StartX; x < EndX; x++)
466 {
467 unsigned char Index = (x >= RectX && x < RectX + RectW && y >= RectY && y < RectY + RectH) ? IndexIn : IndexOut;
468 if(Index)
469 {
470 bool Render = false;
471 if(RenderFlags & LAYERRENDERFLAG_TRANSPARENT)
472 Render = true;
473
474 if(Render)
475 {
476 int tx = Index % 16;
477 int ty = Index / 16;
478 int Px0 = tx * (1024 / 16);
479 int Py0 = ty * (1024 / 16);
480 int Px1 = Px0 + (1024 / 16) - 1;
481 int Py1 = Py0 + (1024 / 16) - 1;
482
483 float x0 = Nudge + Px0 / TexSize + Frac;
484 float y0 = Nudge + Py0 / TexSize + Frac;
485 float x1 = Nudge + Px1 / TexSize - Frac;
486 float y1 = Nudge + Py0 / TexSize + Frac;
487 float x2 = Nudge + Px1 / TexSize - Frac;
488 float y2 = Nudge + Py1 / TexSize - Frac;
489 float x3 = Nudge + Px0 / TexSize + Frac;
490 float y3 = Nudge + Py1 / TexSize - Frac;
491
492 if(Graphics()->HasTextureArraysSupport())

Callers 1

Calls 13

GraphicsFunction · 0.85
GetScreenMethod · 0.80
ScreenWidthMethod · 0.80
QuadsTex3DBeginMethod · 0.80
QuadsBeginMethod · 0.80
QuadsSetSubsetFreeMethod · 0.80
QuadsTex3DDrawTLMethod · 0.80
QuadsDrawTLMethod · 0.80
QuadsTex3DEndMethod · 0.80
QuadsEndMethod · 0.80
SetColorMethod · 0.45

Tested by

no test coverage detected