@holoscript/core 1.0.0-alpha.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/HoloScript2DParser.js +227 -0
- package/src/HoloScript2DParser.ts +5 -0
- package/src/HoloScriptCodeParser.js +1102 -0
- package/src/HoloScriptCodeParser.ts +145 -20
- package/src/HoloScriptDebugger.js +458 -0
- package/src/HoloScriptParser.js +338 -0
- package/src/HoloScriptPlusParser.js +371 -0
- package/src/HoloScriptPlusParser.ts +543 -0
- package/src/HoloScriptRuntime.js +1399 -0
- package/src/HoloScriptRuntime.test.js +351 -0
- package/src/HoloScriptRuntime.ts +17 -3
- package/src/HoloScriptTypeChecker.js +356 -0
- package/src/__tests__/GraphicsServices.test.js +357 -0
- package/src/__tests__/GraphicsServices.test.ts +427 -0
- package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
- package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
- package/src/__tests__/integration.test.js +336 -0
- package/src/__tests__/performance.bench.js +218 -0
- package/src/__tests__/type-checker.test.js +60 -0
- package/src/__tests__/type-checker.test.ts +73 -0
- package/src/index.js +217 -0
- package/src/index.ts +158 -18
- package/src/interop/Interoperability.js +413 -0
- package/src/interop/Interoperability.ts +494 -0
- package/src/logger.js +42 -0
- package/src/parser/EnhancedParser.js +205 -0
- package/src/parser/EnhancedParser.ts +251 -0
- package/src/parser/HoloScriptPlusParser.js +928 -0
- package/src/parser/HoloScriptPlusParser.ts +1089 -0
- package/src/runtime/HoloScriptPlusRuntime.js +674 -0
- package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
- package/src/runtime/PerformanceTelemetry.js +323 -0
- package/src/runtime/PerformanceTelemetry.ts +467 -0
- package/src/runtime/RuntimeOptimization.js +361 -0
- package/src/runtime/RuntimeOptimization.ts +416 -0
- package/src/services/HololandGraphicsPipelineService.js +506 -0
- package/src/services/HololandGraphicsPipelineService.ts +662 -0
- package/src/services/PlatformPerformanceOptimizer.js +356 -0
- package/src/services/PlatformPerformanceOptimizer.ts +503 -0
- package/src/state/ReactiveState.js +427 -0
- package/src/state/ReactiveState.ts +572 -0
- package/src/tools/DeveloperExperience.js +376 -0
- package/src/tools/DeveloperExperience.ts +438 -0
- package/src/traits/AIDriverTrait.js +322 -0
- package/src/traits/AIDriverTrait.test.js +329 -0
- package/src/traits/AIDriverTrait.test.ts +357 -0
- package/src/traits/AIDriverTrait.ts +474 -0
- package/src/traits/LightingTrait.js +313 -0
- package/src/traits/LightingTrait.test.js +410 -0
- package/src/traits/LightingTrait.test.ts +462 -0
- package/src/traits/LightingTrait.ts +505 -0
- package/src/traits/MaterialTrait.js +194 -0
- package/src/traits/MaterialTrait.test.js +286 -0
- package/src/traits/MaterialTrait.test.ts +329 -0
- package/src/traits/MaterialTrait.ts +324 -0
- package/src/traits/RenderingTrait.js +356 -0
- package/src/traits/RenderingTrait.test.js +363 -0
- package/src/traits/RenderingTrait.test.ts +427 -0
- package/src/traits/RenderingTrait.ts +555 -0
- package/src/traits/VRTraitSystem.js +740 -0
- package/src/traits/VRTraitSystem.ts +1040 -0
- package/src/traits/VoiceInputTrait.js +284 -0
- package/src/traits/VoiceInputTrait.test.js +226 -0
- package/src/traits/VoiceInputTrait.test.ts +252 -0
- package/src/traits/VoiceInputTrait.ts +401 -0
- package/src/types/AdvancedTypeSystem.js +226 -0
- package/src/types/AdvancedTypeSystem.ts +494 -0
- package/src/types/HoloScriptPlus.d.ts +853 -0
- package/src/types.js +6 -0
- package/src/types.ts +96 -1
- package/tsconfig.json +1 -1
- package/tsup.config.d.ts +2 -0
- package/tsup.config.js +18 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hololand Graphics Pipeline Service
|
|
3
|
+
*
|
|
4
|
+
* Core service for managing graphics rendering pipeline in Hololand.
|
|
5
|
+
* Integrates HoloScript graphics traits with Hololand's rendering backend.
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Material management and asset pipeline
|
|
9
|
+
* - Light management and shadow mapping
|
|
10
|
+
* - GPU memory optimization
|
|
11
|
+
* - Performance monitoring and profiling
|
|
12
|
+
* - Cross-platform optimization (mobile/VR/desktop)
|
|
13
|
+
*/
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Hololand Graphics Pipeline Service
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export class HololandGraphicsPipelineService {
|
|
18
|
+
constructor(platform = 'desktop') {
|
|
19
|
+
this.materialCache = new Map();
|
|
20
|
+
this.textureCache = new Map();
|
|
21
|
+
this.shaderCache = new Map();
|
|
22
|
+
this.memoryBudget = 512; // MB default
|
|
23
|
+
this.memoryUsed = 0;
|
|
24
|
+
this.platformConfig = this.getPlatformConfig(platform);
|
|
25
|
+
this.metrics = this.initializeMetrics();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Initialize graphics pipeline with configuration
|
|
29
|
+
*/
|
|
30
|
+
initialize(config) {
|
|
31
|
+
if (config.material) {
|
|
32
|
+
this.initializeMaterials(config.material);
|
|
33
|
+
}
|
|
34
|
+
if (config.lighting) {
|
|
35
|
+
this.initializeLighting(config.lighting);
|
|
36
|
+
}
|
|
37
|
+
if (config.rendering) {
|
|
38
|
+
this.initializeRendering(config.rendering);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize materials from configuration
|
|
43
|
+
*/
|
|
44
|
+
initializeMaterials(materialConfig) {
|
|
45
|
+
// Create material assets
|
|
46
|
+
const material = this.createMaterialAsset(materialConfig);
|
|
47
|
+
this.materialCache.set(material.id, material);
|
|
48
|
+
// Pre-compile shaders
|
|
49
|
+
material.shaders.forEach((shader) => {
|
|
50
|
+
this.compileShader(shader);
|
|
51
|
+
});
|
|
52
|
+
// Load textures
|
|
53
|
+
material.textures.forEach((texture) => {
|
|
54
|
+
this.loadTexture(texture);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Initialize lighting from configuration
|
|
59
|
+
*/
|
|
60
|
+
initializeLighting(lightingConfig) {
|
|
61
|
+
// Configure shadow mapping
|
|
62
|
+
if (lightingConfig.shadows) {
|
|
63
|
+
this.setupShadowMapping(lightingConfig);
|
|
64
|
+
}
|
|
65
|
+
// Configure global illumination
|
|
66
|
+
if (lightingConfig.globalIllumination) {
|
|
67
|
+
this.setupGlobalIllumination(lightingConfig.globalIllumination);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Initialize rendering from configuration
|
|
72
|
+
*/
|
|
73
|
+
initializeRendering(renderingConfig) {
|
|
74
|
+
// Apply quality preset
|
|
75
|
+
if (renderingConfig.quality) {
|
|
76
|
+
this.applyQualityPreset(renderingConfig.quality);
|
|
77
|
+
}
|
|
78
|
+
// Configure platform-specific settings
|
|
79
|
+
if (renderingConfig.platform) {
|
|
80
|
+
this.platformConfig = this.getPlatformConfig(renderingConfig.platform);
|
|
81
|
+
}
|
|
82
|
+
// Enable optimizations
|
|
83
|
+
if (renderingConfig.lod !== false) {
|
|
84
|
+
this.enableLOD();
|
|
85
|
+
}
|
|
86
|
+
if (renderingConfig.culling !== false) {
|
|
87
|
+
this.enableCulling();
|
|
88
|
+
}
|
|
89
|
+
if (renderingConfig.instancing !== false) {
|
|
90
|
+
this.platformConfig.instancingEnabled = true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Create material asset from configuration
|
|
95
|
+
*/
|
|
96
|
+
createMaterialAsset(config) {
|
|
97
|
+
const id = `mat_${Date.now()}_${Math.random()}`;
|
|
98
|
+
const asset = {
|
|
99
|
+
id,
|
|
100
|
+
name: config.name || 'Material',
|
|
101
|
+
material: null, // Would be actual MaterialTrait
|
|
102
|
+
shaders: this.generateShaders(config),
|
|
103
|
+
textures: this.loadTexturesFromConfig(config),
|
|
104
|
+
instances: 0,
|
|
105
|
+
gpuMemory: 0,
|
|
106
|
+
lastUsed: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
// Estimate GPU memory
|
|
109
|
+
asset.gpuMemory = this.estimateMaterialMemory(asset);
|
|
110
|
+
this.memoryUsed += asset.gpuMemory;
|
|
111
|
+
return asset;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generate shaders from material configuration
|
|
115
|
+
*/
|
|
116
|
+
generateShaders(config) {
|
|
117
|
+
const shaders = [];
|
|
118
|
+
// Generate PBR shader
|
|
119
|
+
if (config.type === 'pbr' || config.pbr) {
|
|
120
|
+
shaders.push(this.generatePBRShader(config));
|
|
121
|
+
}
|
|
122
|
+
return shaders;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Generate PBR shader program
|
|
126
|
+
*/
|
|
127
|
+
generatePBRShader(config) {
|
|
128
|
+
const vertexShader = `
|
|
129
|
+
#version 300 es
|
|
130
|
+
precision highp float;
|
|
131
|
+
|
|
132
|
+
in vec3 aPosition;
|
|
133
|
+
in vec3 aNormal;
|
|
134
|
+
in vec2 aTexCoord;
|
|
135
|
+
in vec3 aTangent;
|
|
136
|
+
|
|
137
|
+
uniform mat4 uMatrix;
|
|
138
|
+
uniform mat4 uNormalMatrix;
|
|
139
|
+
uniform mat4 uProjectionMatrix;
|
|
140
|
+
|
|
141
|
+
out vec3 vPosition;
|
|
142
|
+
out vec3 vNormal;
|
|
143
|
+
out vec2 vTexCoord;
|
|
144
|
+
out mat3 vTBN;
|
|
145
|
+
|
|
146
|
+
void main() {
|
|
147
|
+
vPosition = (uMatrix * vec4(aPosition, 1.0)).xyz;
|
|
148
|
+
vNormal = normalize((uNormalMatrix * vec4(aNormal, 0.0)).xyz);
|
|
149
|
+
vTexCoord = aTexCoord;
|
|
150
|
+
|
|
151
|
+
vec3 T = normalize((uNormalMatrix * vec4(aTangent, 0.0)).xyz);
|
|
152
|
+
vec3 B = cross(vNormal, T);
|
|
153
|
+
vTBN = mat3(T, B, vNormal);
|
|
154
|
+
|
|
155
|
+
gl_Position = uProjectionMatrix * uMatrix * vec4(aPosition, 1.0);
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
const fragmentShader = `
|
|
159
|
+
#version 300 es
|
|
160
|
+
precision highp float;
|
|
161
|
+
|
|
162
|
+
in vec3 vPosition;
|
|
163
|
+
in vec3 vNormal;
|
|
164
|
+
in vec2 vTexCoord;
|
|
165
|
+
in mat3 vTBN;
|
|
166
|
+
|
|
167
|
+
uniform sampler2D uBaseColorMap;
|
|
168
|
+
uniform sampler2D uNormalMap;
|
|
169
|
+
uniform sampler2D uRoughnessMap;
|
|
170
|
+
uniform sampler2D uMetallicMap;
|
|
171
|
+
uniform sampler2D uAOMap;
|
|
172
|
+
|
|
173
|
+
uniform vec3 uViewPos;
|
|
174
|
+
uniform float uMetallic;
|
|
175
|
+
uniform float uRoughness;
|
|
176
|
+
|
|
177
|
+
out vec4 FragColor;
|
|
178
|
+
|
|
179
|
+
const float PI = 3.14159265359;
|
|
180
|
+
|
|
181
|
+
vec3 fresnelSchlick(float cosTheta, vec3 F0) {
|
|
182
|
+
return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void main() {
|
|
186
|
+
vec3 baseColor = texture(uBaseColorMap, vTexCoord).rgb;
|
|
187
|
+
vec3 normal = normalize(vTBN * (texture(uNormalMap, vTexCoord).rgb * 2.0 - 1.0));
|
|
188
|
+
float roughness = texture(uRoughnessMap, vTexCoord).r;
|
|
189
|
+
float metallic = texture(uMetallicMap, vTexCoord).r;
|
|
190
|
+
float ao = texture(uAOMap, vTexCoord).r;
|
|
191
|
+
|
|
192
|
+
vec3 N = normalize(normal);
|
|
193
|
+
vec3 V = normalize(uViewPos - vPosition);
|
|
194
|
+
|
|
195
|
+
vec3 F0 = vec3(0.04);
|
|
196
|
+
F0 = mix(F0, baseColor, metallic);
|
|
197
|
+
|
|
198
|
+
// Simplified lighting (full PBR in production)
|
|
199
|
+
vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));
|
|
200
|
+
float NdotL = max(dot(N, lightDir), 0.0);
|
|
201
|
+
|
|
202
|
+
vec3 result = baseColor * NdotL * ao;
|
|
203
|
+
|
|
204
|
+
// Tone mapping
|
|
205
|
+
result = result / (result + vec3(1.0));
|
|
206
|
+
result = pow(result, vec3(1.0 / 2.2));
|
|
207
|
+
|
|
208
|
+
FragColor = vec4(result, 1.0);
|
|
209
|
+
}
|
|
210
|
+
`;
|
|
211
|
+
return {
|
|
212
|
+
id: `shader_pbr_${Date.now()}`,
|
|
213
|
+
name: 'PBRShader',
|
|
214
|
+
vertexShader,
|
|
215
|
+
fragmentShader,
|
|
216
|
+
uniforms: {
|
|
217
|
+
uMatrix: 'mat4',
|
|
218
|
+
uNormalMatrix: 'mat4',
|
|
219
|
+
uProjectionMatrix: 'mat4',
|
|
220
|
+
uViewPos: 'vec3',
|
|
221
|
+
uMetallic: 'float',
|
|
222
|
+
uRoughness: 'float',
|
|
223
|
+
uBaseColorMap: 'sampler2D',
|
|
224
|
+
uNormalMap: 'sampler2D',
|
|
225
|
+
uRoughnessMap: 'sampler2D',
|
|
226
|
+
uMetallicMap: 'sampler2D',
|
|
227
|
+
uAOMap: 'sampler2D',
|
|
228
|
+
},
|
|
229
|
+
compiled: false,
|
|
230
|
+
compilationTime: 0,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Load textures from configuration
|
|
235
|
+
*/
|
|
236
|
+
loadTexturesFromConfig(config) {
|
|
237
|
+
const textures = [];
|
|
238
|
+
if (config.textures) {
|
|
239
|
+
config.textures.forEach((tex) => {
|
|
240
|
+
textures.push({
|
|
241
|
+
id: `tex_${Date.now()}_${Math.random()}`,
|
|
242
|
+
path: tex.path,
|
|
243
|
+
format: this.selectTextureFormat(config.compression),
|
|
244
|
+
width: 2048,
|
|
245
|
+
height: 2048,
|
|
246
|
+
mipLevels: 8,
|
|
247
|
+
gpuMemory: this.estimateTextureMemory(2048, 2048, this.selectTextureFormat(config.compression)),
|
|
248
|
+
loaded: false,
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
return textures;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Select appropriate texture format based on compression type
|
|
256
|
+
*/
|
|
257
|
+
selectTextureFormat(compression) {
|
|
258
|
+
switch (compression) {
|
|
259
|
+
case 'dxt':
|
|
260
|
+
return 'BC3';
|
|
261
|
+
case 'astc':
|
|
262
|
+
return 'ASTC';
|
|
263
|
+
case 'basis':
|
|
264
|
+
return 'PVRTC';
|
|
265
|
+
default:
|
|
266
|
+
return 'RGBA8';
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Estimate texture memory usage
|
|
271
|
+
*/
|
|
272
|
+
estimateTextureMemory(width, height, format) {
|
|
273
|
+
const pixels = width * height;
|
|
274
|
+
let bytesPerPixel = 4; // RGBA8
|
|
275
|
+
switch (format) {
|
|
276
|
+
case 'RGB565':
|
|
277
|
+
bytesPerPixel = 2;
|
|
278
|
+
break;
|
|
279
|
+
case 'BC1':
|
|
280
|
+
case 'BC3':
|
|
281
|
+
case 'ASTC':
|
|
282
|
+
bytesPerPixel = 0.5; // Compressed
|
|
283
|
+
break;
|
|
284
|
+
case 'PVRTC':
|
|
285
|
+
bytesPerPixel = 0.25; // Highly compressed
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
// Account for mipmaps (roughly 1.33x base size)
|
|
289
|
+
return (pixels * bytesPerPixel * 1.33) / (1024 * 1024);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Estimate material GPU memory
|
|
293
|
+
*/
|
|
294
|
+
estimateMaterialMemory(asset) {
|
|
295
|
+
let total = 0;
|
|
296
|
+
// Shader memory (typically negligible, but count)
|
|
297
|
+
total += 0.1; // 100KB per shader
|
|
298
|
+
// Texture memory
|
|
299
|
+
asset.textures.forEach((tex) => {
|
|
300
|
+
total += tex.gpuMemory;
|
|
301
|
+
});
|
|
302
|
+
return total;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Compile shader program
|
|
306
|
+
*/
|
|
307
|
+
compileShader(shader) {
|
|
308
|
+
const start = performance.now();
|
|
309
|
+
// In real implementation, this would compile to WebGL/WebGPU
|
|
310
|
+
// For now, just mark as compiled
|
|
311
|
+
shader.compiled = true;
|
|
312
|
+
shader.compilationTime = performance.now() - start;
|
|
313
|
+
this.shaderCache.set(shader.id, shader);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Load texture into GPU memory
|
|
317
|
+
*/
|
|
318
|
+
loadTexture(texture) {
|
|
319
|
+
// In real implementation, this would load from disk/network
|
|
320
|
+
// For now, just mark as loaded
|
|
321
|
+
texture.loaded = true;
|
|
322
|
+
this.textureCache.set(texture.id, texture);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Setup shadow mapping
|
|
326
|
+
*/
|
|
327
|
+
setupShadowMapping(config) {
|
|
328
|
+
// Configure shadow map resolution and filtering
|
|
329
|
+
const shadowQuality = this.platformConfig.shadowQuality;
|
|
330
|
+
const shadowResolution = this.shadowResolutionForQuality(shadowQuality);
|
|
331
|
+
// Create shadow map textures
|
|
332
|
+
// This would allocate GPU memory for shadow maps
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Get shadow map resolution for quality level
|
|
336
|
+
*/
|
|
337
|
+
shadowResolutionForQuality(quality) {
|
|
338
|
+
switch (quality) {
|
|
339
|
+
case 'none':
|
|
340
|
+
return 0;
|
|
341
|
+
case 'low':
|
|
342
|
+
return 512;
|
|
343
|
+
case 'medium':
|
|
344
|
+
return 1024;
|
|
345
|
+
case 'high':
|
|
346
|
+
return 2048;
|
|
347
|
+
default:
|
|
348
|
+
return 1024;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Setup global illumination
|
|
353
|
+
*/
|
|
354
|
+
setupGlobalIllumination(config) {
|
|
355
|
+
// Create light probes for indirect lighting
|
|
356
|
+
const probeCount = config.probes || 16;
|
|
357
|
+
// Allocate GPU memory for probes
|
|
358
|
+
// Each probe stores 6 faces of cubemap
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Apply quality preset
|
|
362
|
+
*/
|
|
363
|
+
applyQualityPreset(quality) {
|
|
364
|
+
switch (quality) {
|
|
365
|
+
case 'low':
|
|
366
|
+
this.platformConfig.maxTextureResolution = 512;
|
|
367
|
+
this.platformConfig.shadowQuality = 'none';
|
|
368
|
+
this.platformConfig.targetFPS = 30;
|
|
369
|
+
break;
|
|
370
|
+
case 'medium':
|
|
371
|
+
this.platformConfig.maxTextureResolution = 1024;
|
|
372
|
+
this.platformConfig.shadowQuality = 'low';
|
|
373
|
+
this.platformConfig.targetFPS = 60;
|
|
374
|
+
break;
|
|
375
|
+
case 'high':
|
|
376
|
+
this.platformConfig.maxTextureResolution = 2048;
|
|
377
|
+
this.platformConfig.shadowQuality = 'medium';
|
|
378
|
+
this.platformConfig.targetFPS = 60;
|
|
379
|
+
break;
|
|
380
|
+
case 'ultra':
|
|
381
|
+
this.platformConfig.maxTextureResolution = 4096;
|
|
382
|
+
this.platformConfig.shadowQuality = 'high';
|
|
383
|
+
this.platformConfig.targetFPS = 120;
|
|
384
|
+
break;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Enable LOD system
|
|
389
|
+
*/
|
|
390
|
+
enableLOD() {
|
|
391
|
+
// Configure automatic LOD switching based on screen coverage
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Enable culling
|
|
395
|
+
*/
|
|
396
|
+
enableCulling() {
|
|
397
|
+
// Enable frustum culling and occlusion culling
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Get platform-specific configuration
|
|
401
|
+
*/
|
|
402
|
+
getPlatformConfig(platform) {
|
|
403
|
+
switch (platform) {
|
|
404
|
+
case 'mobile':
|
|
405
|
+
return {
|
|
406
|
+
platform: 'mobile',
|
|
407
|
+
maxGPUMemory: 256,
|
|
408
|
+
maxDrawCalls: 200,
|
|
409
|
+
maxTextureResolution: 512,
|
|
410
|
+
targetFPS: 30,
|
|
411
|
+
shadowQuality: 'none',
|
|
412
|
+
textureCompression: 'astc',
|
|
413
|
+
instancingEnabled: true,
|
|
414
|
+
maxLights: 2,
|
|
415
|
+
maxShadowCasters: 0,
|
|
416
|
+
};
|
|
417
|
+
case 'vr':
|
|
418
|
+
return {
|
|
419
|
+
platform: 'vr',
|
|
420
|
+
maxGPUMemory: 512,
|
|
421
|
+
maxDrawCalls: 500,
|
|
422
|
+
maxTextureResolution: 2048,
|
|
423
|
+
targetFPS: 90,
|
|
424
|
+
shadowQuality: 'low',
|
|
425
|
+
textureCompression: 'basis',
|
|
426
|
+
instancingEnabled: true,
|
|
427
|
+
maxLights: 4,
|
|
428
|
+
maxShadowCasters: 2,
|
|
429
|
+
};
|
|
430
|
+
case 'desktop':
|
|
431
|
+
return {
|
|
432
|
+
platform: 'desktop',
|
|
433
|
+
maxGPUMemory: 2048,
|
|
434
|
+
maxDrawCalls: 2000,
|
|
435
|
+
maxTextureResolution: 4096,
|
|
436
|
+
targetFPS: 120,
|
|
437
|
+
shadowQuality: 'high',
|
|
438
|
+
textureCompression: 'none',
|
|
439
|
+
instancingEnabled: true,
|
|
440
|
+
maxLights: 8,
|
|
441
|
+
maxShadowCasters: 4,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Initialize performance metrics
|
|
447
|
+
*/
|
|
448
|
+
initializeMetrics() {
|
|
449
|
+
return {
|
|
450
|
+
drawCalls: 0,
|
|
451
|
+
trianglesRendered: 0,
|
|
452
|
+
gpuFrameTime: 0,
|
|
453
|
+
cpuFrameTime: 0,
|
|
454
|
+
fps: 60,
|
|
455
|
+
gpuMemoryUsed: 0,
|
|
456
|
+
textureBinds: 0,
|
|
457
|
+
shaderSwitches: 0,
|
|
458
|
+
batchCount: 0,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Get current GPU memory estimate
|
|
463
|
+
*/
|
|
464
|
+
getGPUMemoryEstimate() {
|
|
465
|
+
let textureMemory = 0;
|
|
466
|
+
let geometryMemory = 0;
|
|
467
|
+
let bufferMemory = 0;
|
|
468
|
+
this.textureCache.forEach((tex) => {
|
|
469
|
+
if (tex.loaded) {
|
|
470
|
+
textureMemory += tex.gpuMemory;
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
this.materialCache.forEach((mat) => {
|
|
474
|
+
geometryMemory += mat.gpuMemory;
|
|
475
|
+
});
|
|
476
|
+
const total = textureMemory + geometryMemory + bufferMemory;
|
|
477
|
+
return {
|
|
478
|
+
textureMemory,
|
|
479
|
+
geometryMemory,
|
|
480
|
+
bufferMemory,
|
|
481
|
+
estimatedTotal: total,
|
|
482
|
+
budget: this.platformConfig.maxGPUMemory,
|
|
483
|
+
utilization: (total / this.platformConfig.maxGPUMemory) * 100,
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Get performance metrics
|
|
488
|
+
*/
|
|
489
|
+
getPerformanceMetrics() {
|
|
490
|
+
return { ...this.metrics };
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Set memory budget
|
|
494
|
+
*/
|
|
495
|
+
setMemoryBudget(budget) {
|
|
496
|
+
this.memoryBudget = budget;
|
|
497
|
+
this.platformConfig.maxGPUMemory = budget;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Optimize for specific platform
|
|
501
|
+
*/
|
|
502
|
+
optimizePlatform(platform) {
|
|
503
|
+
this.platformConfig = this.getPlatformConfig(platform);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
export default HololandGraphicsPipelineService;
|