setupTexture method
Creates a texture and compiles the shaders. Safe to call multiple times – resources are recreated if needed.
Implementation
Future<void> setupTexture({
required double width,
required double height,
required String vertexShaderCode,
required String fragmentShaderCode,
bool enableProfiling = false,
}) async {
assert(width > 0 && height > 0, 'Viewport must be non‑zero');
_vertexShaderSource = vertexShaderCode;
_fragmentShaderSource = fragmentShaderCode;
_targetTexture = await _angle.createTexture(
AngleOptions(
width: width.toInt(),
height: height.toInt(),
dpr: 1, // TODO(jesper): support dpr?
alpha: true,
useSurfaceProducer: true,
),
);
_gl = _targetTexture.getContext();
await _compileShaders();
await _createBuffers();
_updateProjectionMatrix();
if (enableProfiling) {
_perf = PerfProfiler.auto(_gl);
// Determine profiler type for display
if (_perf is DisjointQueryGpuProfiler) {
_profilerType = 'GPU';
} else if (_perf is GlFinishSamplerProfiler) {
_profilerType = 'Sampled';
} else {
_profilerType = 'CPU';
}
} else {
_perf = null;
_profilerType = null;
}
}