babylon.modelRenderCache.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module BABYLON {
  2. export const enum ShaderDataType {
  3. Vector2, Vector3, Vector4, Matrix, float, Color3, Color4
  4. }
  5. export class GroupInstanceInfo {
  6. constructor(owner: Group2D, classTreeInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>, cache: ModelRenderCacheBase) {
  7. this._owner = owner;
  8. this._classTreeInfo = classTreeInfo;
  9. this._modelCache = cache;
  10. }
  11. _owner: Group2D;
  12. _classTreeInfo: ClassTreeInfo<InstanceClassInfo, InstancePropInfo>;
  13. _modelCache: ModelRenderCacheBase;
  14. _instancesData: DynamicFloatArray;
  15. _dirtyInstancesData: boolean;
  16. _instancesBuffer: WebGLBuffer;
  17. _instancesBufferSize: number;
  18. }
  19. export class ModelRenderCacheBase {
  20. /**
  21. * Render the model instances
  22. * @param instanceInfo
  23. * @param context
  24. * @return must return true is the rendering succeed, false if the rendering couldn't be done (asset's not yet ready, like Effect)
  25. */
  26. render(instanceInfo: GroupInstanceInfo, context: Render2DContext): boolean {
  27. return true;
  28. }
  29. }
  30. export class ModelRenderCache<TInstData> extends ModelRenderCacheBase {
  31. constructor() {
  32. super();
  33. this._nextKey = 1;
  34. this._instancesData = new StringDictionary<TInstData>();
  35. }
  36. addInstanceData(data: TInstData): string {
  37. let key = this._nextKey.toString();
  38. if (!this._instancesData.add(key, data)) {
  39. throw Error(`Key: ${key} is already allocated`);
  40. }
  41. ++this._nextKey;
  42. return key;
  43. }
  44. removeInstanceData(key: string) {
  45. this._instancesData.remove(key);
  46. }
  47. _instancesData: StringDictionary<TInstData>;
  48. private _nextKey: number;
  49. }
  50. }