Skip to content

Commit 7448a66

Browse files
committed
Clearing the screen before rendering
1 parent bbbfb69 commit 7448a66

10 files changed

Lines changed: 38 additions & 33 deletions

File tree

OpenTibia/Assets/Scripts/Core/Components/SplitStackWindow.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,10 @@ protected void OnGUI() {
110110
_renderTexture = new RenderTexture(Constants.FieldSize, Constants.FieldSize, 0, RenderTextureFormat.ARGB32);
111111
_renderTexture.filterMode = FilterMode.Point;
112112
_itemImage.texture = _renderTexture;
113-
} else {
114-
_renderTexture.Release();
115113
}
116114

117115
RenderTexture.active = _renderTexture;
118-
GL.Clear(false, true, new Color(0, 0, 0, 0));
119-
116+
Utils.GraphicsUtility.ClearWithTransparency();
120117
if (!!_objectType) {
121118
if (_objectInstance == null || _objectInstance.Id != _objectType._id)
122119
_objectInstance = OpenTibiaUnity.AppearanceStorage.CreateObjectInstance(_objectType._id, _objectAmount);

OpenTibia/Assets/Scripts/Core/MiniMap/Rendering/MinimapRenderer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public RenderError Render(Material material) {
6767
return RenderError.MiniMapNotValid;
6868

6969
GL.Clear(false, true, Color.black);
70-
7170
if (PositionX < Constants.MapMinX || PositionX > Constants.MapMaxX
7271
|| PositionY < Constants.MapMinY || PositionY > Constants.MapMaxY
7372
|| PositionZ < Constants.MapMinZ || PositionZ > Constants.MapMaxZ) {

OpenTibia/Assets/Scripts/Core/Utils/GraphicsUtility.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ static GraphicsUtility() {
1111
_mesh.MarkDynamic();
1212
}
1313

14+
public static void ClearWithTransparency() {
15+
GL.Clear(false, true, new Color(0, 0, 0, 0));
16+
}
17+
1418
public static void DrawRect(Rect rect, Vector3 scale, Color color) {
1519
_mesh.vertices = new Vector3[] {
1620
new Vector3(0, 0, 0),

OpenTibia/Assets/Scripts/Core/WorldMap/Rendering/MeshBasedLightmapRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public override Texture CreateLightmap() {
7373
}
7474

7575
var previousRenderTexture = RenderTexture.active;
76-
_renderTexture.Release();
7776
RenderTexture.active = _renderTexture;
77+
Utils.GraphicsUtility.ClearWithTransparency();
7878

7979
OpenTibiaUnity.GameManager.InternalColoredMaterial.SetPass(0);
8080
Graphics.DrawMeshNow(_lightMesh, _lightTransformationMatrix);

OpenTibia/Assets/Scripts/Modules/Container/ContainerWindow.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ protected void OnGUI() {
4747

4848
Vector2 zoom = new Vector2(Screen.width / (float)_slotsRenderTexture.width, Screen.height / (float)_slotsRenderTexture.height);
4949

50-
_slotsRenderTexture.Release();
5150
RenderTexture.active = _slotsRenderTexture;
51+
Core.Utils.GraphicsUtility.ClearWithTransparency();
5252
for (int i = 0; i < 4; i++) {
5353
for (int j = 0; j < _rows; j++) {
5454
int index = j * 4 + i;
@@ -69,6 +69,15 @@ protected void OnGUI() {
6969
RenderTexture.active = null;
7070
}
7171

72+
protected override void OnDestroy() {
73+
base.OnDestroy();
74+
75+
if (_slotsRenderTexture != null) {
76+
_slotsRenderTexture.Release();
77+
_slotsRenderTexture = null;
78+
}
79+
}
80+
7281
protected void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {
7382
if (publicStartMouseAction(e.mousePosition, mouseButton, true, false))
7483
e.Use();
@@ -212,15 +221,22 @@ public void UpdateProperties(ContainerView containerView) {
212221
_itemViews = null;
213222
}
214223

224+
_numberOfSlots = containerView.NumberOfSlotsPerPage;
225+
_rows = (int)Mathf.Ceil((_numberOfSlots + 1) / 4f); // extra slot for the container's icon
226+
227+
bool shouldCreateRenderTexture = true;
215228
if (_slotsRenderTexture != null) {
216-
_slotsRenderTexture.Release();
217-
_slotsRenderTexture.DiscardContents();
218-
_slotsRenderTexture = null;
229+
if (_slotsRenderTexture.height == Constants.FieldSize * _rows) {
230+
shouldCreateRenderTexture = false;
231+
} else {
232+
_slotsRenderTexture.Release();
233+
_slotsRenderTexture = null;
234+
}
219235
}
220236

221-
_numberOfSlots = containerView.NumberOfSlotsPerPage;
222-
_rows = (int)Mathf.Ceil((_numberOfSlots + 1) / 4f); // extra slot for the container's icon
223-
_slotsRenderTexture = new RenderTexture(Constants.FieldSize * 4, Constants.FieldSize * _rows, 0, RenderTextureFormat.ARGB32);
237+
if (shouldCreateRenderTexture)
238+
_slotsRenderTexture = new RenderTexture(Constants.FieldSize * 4, Constants.FieldSize * _rows, 0, RenderTextureFormat.ARGB32);
239+
224240
_itemViews = new ItemView[_numberOfSlots];
225241
_containerView = containerView;
226242

OpenTibia/Assets/Scripts/Modules/GameWindow/GameMapContainer.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.IO;
1+
using System.IO;
32
using OpenTibiaUnity.Core.Appearances;
43
using OpenTibiaUnity.Core.Components;
54
using OpenTibiaUnity.Core.Creatures;
@@ -104,8 +103,8 @@ protected void RenderWorldMap() {
104103
if (ContextMenuBase.CurrentContextMenu != null || ObjectDragImpl.AnyDraggingObject)
105104
worldMapRenderer.HighlightTile = null;
106105

107-
gameManager.WorldMapRenderTexture.Release();
108106
RenderTexture.active = gameManager.WorldMapRenderTexture;
107+
Core.Utils.GraphicsUtility.ClearWithTransparency();
109108
var error = worldMapRenderer.RenderWorldMap(worldMapRectTransform.rect);
110109
RenderTexture.active = null;
111110

@@ -115,11 +114,10 @@ protected void RenderWorldMap() {
115114
_onscreenTextRenderTexture?.Release();
116115
_onscreenTextRenderTexture = new RenderTexture(_lastScreenWidth, _lastScreenHeight, 0, RenderTextureFormat.ARGB32);
117116
_onscreenTextImage.texture = _onscreenTextRenderTexture;
118-
} else {
119-
_onscreenTextRenderTexture.Release();
120117
}
121118

122119
RenderTexture.active = _onscreenTextRenderTexture;
120+
Core.Utils.GraphicsUtility.ClearWithTransparency();
123121
worldMapRenderer.RenderOnscreenText(_cachedScreenRect);
124122
RenderTexture.active = null;
125123

OpenTibia/Assets/Scripts/Modules/Hotkeys/HotkeysWindow.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,10 @@ protected void OnGUI() {
123123
s_RenderTexture.filterMode = FilterMode.Point;
124124

125125
_objectImage.texture = s_RenderTexture;
126-
} else {
127-
s_RenderTexture.Release();
128126
}
129127

130128
RenderTexture.active = s_RenderTexture;
131-
GL.Clear(false, true, new Color(0, 0, 0, 0));
129+
Core.Utils.GraphicsUtility.ClearWithTransparency();
132130

133131
var zoom = new Vector2(Screen.width / (float)s_RenderTexture.width, Screen.height / (float)s_RenderTexture.height);
134132
_objectInstance.Draw(new Vector2(0, 0), zoom, 0, 0, 0);

OpenTibia/Assets/Scripts/Modules/Inventory/InventoryWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ private void OnGUI() {
182182

183183
Vector2 zoom = new Vector2(Screen.width / (float)_slotsRenderTexture.width, Screen.height / (float)_slotsRenderTexture.height);
184184

185-
_slotsRenderTexture.Release();
186185
RenderTexture.active = _slotsRenderTexture;
186+
Core.Utils.GraphicsUtility.ClearWithTransparency();
187187
for (int i = 0; i < (int)ClothSlots.Hip; i++) {
188188
var @object = BodyContainerView.Objects[i];
189189
if (@object) {
@@ -199,6 +199,7 @@ protected override void OnDestroy() {
199199
base.OnDestroy();
200200

201201
_slotsRenderTexture.Release();
202+
_slotsRenderTexture = null;
202203
}
203204

204205
public void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {

OpenTibia/Assets/Scripts/Modules/MiniMap/MiniMapModule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ protected void OnGUI() {
3131
if (Event.current.type != EventType.Repaint)
3232
return;
3333

34-
OpenTibiaUnity.GameManager.MiniMapRenderingTexture.Release();
3534
RenderTexture.active = OpenTibiaUnity.GameManager.MiniMapRenderingTexture;
35+
Core.Utils.GraphicsUtility.ClearWithTransparency();
3636
OpenTibiaUnity.MiniMapRenderer.Render(null);
3737
RenderTexture.active = null;
3838
}

OpenTibia/Assets/Scripts/Modules/Outfit/OutfitWindow.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,15 @@ protected void OnGUI() {
113113
return;
114114

115115
if (_renderTexture == null) {
116-
var descriptor = new RenderTextureDescriptor(Constants.FieldSize * 2 * 2, Constants.FieldSize * 2, RenderTextureFormat.ARGB32, 0);
117-
_renderTexture = new RenderTexture(descriptor);
116+
_renderTexture = new RenderTexture(Constants.FieldSize * 2 * 2, Constants.FieldSize * 2, 0, RenderTextureFormat.ARGB32);
118117
_renderTexture.filterMode = FilterMode.Point;
119118

120119
_rawImageOutfit.texture = _renderTexture;
121120
_rawImageMount.texture = _renderTexture;
122-
} else {
123-
_renderTexture.Release();
124121
}
125122

126123
RenderTexture.active = _renderTexture;
127-
GL.Clear(false, true, new Color(0, 0, 0, 0));
124+
Core.Utils.GraphicsUtility.ClearWithTransparency();
128125

129126
if (!!_currentOutfit) {
130127
var screenPosition = new Vector2(Constants.FieldSize, Constants.FieldSize);
@@ -234,11 +231,6 @@ private void OnClientVersionChange(int oldVersion, int newVersion) {
234231
_panelOutfitName.gameObject.SetActive(hasNewProtocol);
235232
_panelAddons.gameObject.SetActive(hasAddons);
236233
_panelMount.gameObject.SetActive(hasMounts);
237-
238-
if (_renderTexture) {
239-
_renderTexture.Release();
240-
_renderTexture = null;
241-
}
242234
}
243235

244236
private void OnHeadToggleValueChanged(bool value) {

0 commit comments

Comments
 (0)