Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit bc39d56

Browse files
committed
add configs for user to disable some features in their app
usecase: in Editor app, the RasterCache may should be disabled to avoid Engine errors when the RenderTexture is too big
1 parent a4ff74a commit bc39d56

File tree

5 files changed

+44
-5
lines changed

5 files changed

+44
-5
lines changed

Runtime/editor/window_config.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Unity.UIWidgets.foundation;
2+
3+
namespace Unity.UIWidgets.editor {
4+
public class WindowConfig {
5+
public readonly bool disableRasterCache;
6+
7+
static bool? _disableComputeBuffer = null;
8+
9+
public static bool disableComputeBuffer {
10+
//disable compute buffer by default for now
11+
get { return _disableComputeBuffer ?? true; }
12+
set {
13+
D.assert(_disableComputeBuffer == null
14+
|| _disableComputeBuffer == value
15+
, () => "The global settings of [disableComputeBuffer] cannot be initiated for multiple times!");
16+
17+
_disableComputeBuffer = value;
18+
}
19+
}
20+
21+
public WindowConfig(bool disableRasterCache) {
22+
this.disableRasterCache = disableRasterCache;
23+
}
24+
25+
public static readonly WindowConfig defaultConfig = new WindowConfig(
26+
disableRasterCache: false
27+
);
28+
}
29+
}

Runtime/ui/renderer/cmdbufferCanvas/rendering/canvas_shader_initializer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
using Unity.UIWidgets.editor;
12
using UnityEngine;
23
using UnityEngine.Rendering;
34

45
namespace Unity.UIWidgets.ui {
56
static partial class CanvasShader {
6-
const bool enableComputeBuffer = false;
7-
87
const bool enableDebugLog = false;
98

109
public static bool supportComputeBuffer;
@@ -22,7 +21,7 @@ static bool IsShaderSupported() {
2221
}
2322

2423
static void InitShaders() {
25-
supportComputeBuffer = enableComputeBuffer && SystemInfo.supportsComputeShaders && IsShaderSupported();
24+
supportComputeBuffer = !WindowConfig.disableComputeBuffer && SystemInfo.supportsComputeShaders && IsShaderSupported();
2625

2726
if (!supportComputeBuffer) {
2827
DebugAssert(false, "init default shaders");

Runtime/ui/renderer/compositeCanvas/flow/raster_cache.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,10 @@ static bool _canRasterizePicture(Picture picture) {
210210
return false;
211211
}
212212

213+
if (Window.instance.windowConfig.disableRasterCache) {
214+
return false;
215+
}
216+
213217
var bounds = picture.paintBounds;
214218
if (bounds.isEmpty) {
215219
return false;
@@ -223,6 +227,12 @@ static bool _canRasterizePicture(Picture picture) {
223227
return false;
224228
}
225229

230+
//https://forum.unity.com/threads/rendertexture-create-failed-rendertexture-too-big.58667/
231+
if (picture.paintBounds.size.width > 4096 ||
232+
picture.paintBounds.size.height > 4096) {
233+
return false;
234+
}
235+
226236
return true;
227237
}
228238

Runtime/ui/window.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using Unity.UIWidgets.async;
4+
using Unity.UIWidgets.editor;
45
using Unity.UIWidgets.foundation;
56
using UnityEngine;
67

@@ -148,11 +149,12 @@ public int antiAliasing {
148149

149150
protected int _antiAliasing = defaultAntiAliasing;
150151

151-
152152
public Size physicalSize {
153153
get { return this._physicalSize; }
154154
}
155155

156+
public WindowConfig windowConfig = WindowConfig.defaultConfig;
157+
156158
protected Size _physicalSize = Size.zero;
157159

158160
public WindowPadding viewInsets {

Samples/UIWidgetsGallery/GalleryMain.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using UIWidgetsGallery.gallery;
22
using Unity.UIWidgets.engine;
3-
using Unity.UIWidgets.material;
43
using Unity.UIWidgets.ui;
54
using Unity.UIWidgets.widgets;
65
using UnityEngine;

0 commit comments

Comments
 (0)