Skip to content

Commit 4ff6f03

Browse files
committed
Quad calculations stored instead of being done every frame.
1 parent 2fea6e0 commit 4ff6f03

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

PixelCamDrawer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public void DrawQuad()
2424
if (SourceCamera == null || SourceCamera.CameraMaterial == null)
2525
return;
2626

27-
Vector2 min;
28-
Vector2 max;
29-
SourceCamera.GetQuadBounds(out min, out max);
27+
Vector2 min = SourceCamera.QuadMin;
28+
Vector2 max = SourceCamera.QuadMax;
3029

3130
float zOffset = -0.1f;
3231

PixelCamera.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public bool Equals(CamSettings other)
6767
protected CamSettings lastSettings;
6868

6969
protected Vector2 quadOffset;
70+
public Vector2 QuadMin { get; protected set; }
71+
public Vector2 QuadMax { get; protected set; }
7072

7173
public Material CameraMaterial
7274
{
@@ -253,11 +255,7 @@ protected void SetupCamera()
253255
}
254256

255257
// Find the settings to be used for drawing the GL quad
256-
Vector2 pixelSize = new Vector2(pixelRenderSize[0], pixelRenderSize[1]) * zoomLevel;
257-
quadOffset = pixelSize - screenRenderSize;
258-
quadOffset /= 2;
259-
quadOffset.x /= Screen.width;
260-
quadOffset.y /= Screen.height;
258+
CalculateQuad(screenRenderSize, pixelRenderSize);
261259

262260
// Important to release current render texture
263261
cam.targetTexture = null;
@@ -315,12 +313,22 @@ protected int[] GetRenderTextureSize(Vector2 size, Vector2 aspect)
315313
return new[] {width, height};
316314
}
317315

318-
public void GetQuadBounds(out Vector2 min, out Vector2 max)
316+
private void CalculateQuad(Vector2 screenRenderSize, int[] pixelRenderSize)
319317
{
320-
min = Vector2.zero - quadOffset;
321-
max = Vector2.one + quadOffset;
318+
Vector2 pixelSize = new Vector2(pixelRenderSize[0], pixelRenderSize[1]) * zoomLevel;
319+
quadOffset = pixelSize - screenRenderSize;
320+
quadOffset /= 2;
321+
quadOffset.x /= Screen.width;
322+
quadOffset.y /= Screen.height;
323+
324+
Vector2 min = Vector2.zero - quadOffset;
325+
Vector2 max = Vector2.one + quadOffset;
322326
if (advancedSettings == null)
327+
{
328+
QuadMin = min;
329+
QuadMax = max;
323330
return;
331+
}
324332

325333
Vector2 aspectStretch = advancedSettings.aspectStretch;
326334
if (aspectStretch.x < float.Epsilon || aspectStretch.y < float.Epsilon)
@@ -329,7 +337,7 @@ public void GetQuadBounds(out Vector2 min, out Vector2 max)
329337
Vector2 center = (min + max) / 2;
330338
min -= center;
331339
max -= center;
332-
340+
333341
min.x *= aspectStretch.x;
334342
max.x *= aspectStretch.x;
335343

@@ -338,6 +346,9 @@ public void GetQuadBounds(out Vector2 min, out Vector2 max)
338346

339347
min += center;
340348
max += center;
349+
350+
QuadMin = min;
351+
QuadMax = max;
341352
}
342353

343354
public void ForceRefresh()

0 commit comments

Comments
 (0)