Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ARenderTargetContentByRequest.cs
Go to the documentation of this file.
1using System;
3
5
7{
9
10 protected bool _wasPrepared;
11
12 private bool _wasRequested;
13
14 public bool IsReady => _wasPrepared;
15
16 public void Request()
17 {
18 _wasRequested = true;
19 }
20
22 {
23 return _target;
24 }
25
26 public void PrepareRenderTarget(GraphicsDevice device, SpriteBatch spriteBatch)
27 {
28 _wasPrepared = false;
29 if (_wasRequested)
30 {
31 _wasRequested = false;
32 HandleUseReqest(device, spriteBatch);
33 }
34 }
35
36 protected abstract void HandleUseReqest(GraphicsDevice device, SpriteBatch spriteBatch);
37
38 protected void PrepareARenderTarget_AndListenToEvents(ref RenderTarget2D target, GraphicsDevice device, int neededWidth, int neededHeight, RenderTargetUsage usage)
39 {
40 if (target == null || target.IsDisposed || target.Width != neededWidth || target.Height != neededHeight)
41 {
42 if (target != null)
43 {
44 target.ContentLost -= target_ContentLost;
45 target.Disposing -= target_Disposing;
46 }
47 target = new RenderTarget2D(device, neededWidth, neededHeight, mipMap: false, device.PresentationParameters.BackBufferFormat, DepthFormat.None, 0, usage);
48 target.ContentLost += target_ContentLost;
49 target.Disposing += target_Disposing;
50 }
51 }
52
53 private void target_Disposing(object sender, EventArgs e)
54 {
55 _wasPrepared = false;
56 _target = null;
57 }
58
59 private void target_ContentLost(object sender, EventArgs e)
60 {
61 _wasPrepared = false;
62 }
63
64 public void Reset()
65 {
66 _wasPrepared = false;
67 _wasRequested = false;
68 _target = null;
69 }
70
71 protected void PrepareARenderTarget_WithoutListeningToEvents(ref RenderTarget2D target, GraphicsDevice device, int neededWidth, int neededHeight, RenderTargetUsage usage)
72 {
73 if (target == null || target.IsDisposed || target.Width != neededWidth || target.Height != neededHeight)
74 {
75 target = new RenderTarget2D(device, neededWidth, neededHeight, mipMap: false, device.PresentationParameters.BackBufferFormat, DepthFormat.None, 0, usage);
76 }
77 }
78}
void HandleUseReqest(GraphicsDevice device, SpriteBatch spriteBatch)
void PrepareARenderTarget_AndListenToEvents(ref RenderTarget2D target, GraphicsDevice device, int neededWidth, int neededHeight, RenderTargetUsage usage)
void PrepareRenderTarget(GraphicsDevice device, SpriteBatch spriteBatch)
void PrepareARenderTarget_WithoutListeningToEvents(ref RenderTarget2D target, GraphicsDevice device, int neededWidth, int neededHeight, RenderTargetUsage usage)