spheres.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Renderable, RenderableState, createRenderable } from '../renderable'
  7. import { WebGLContext } from '../webgl/context';
  8. import { createGraphicsRenderItem } from '../webgl/render-item';
  9. import { GlobalUniformSchema, BaseSchema, AttributeSpec, Values, InternalSchema, SizeSchema, InternalValues, ElementsSpec, ValueSpec, DefineSpec } from './schema';
  10. import { SpheresShaderCode } from '../shader-code';
  11. import { ValueCell } from 'mol-util';
  12. export const SpheresSchema = {
  13. ...BaseSchema,
  14. ...SizeSchema,
  15. aPosition: AttributeSpec('float32', 3, 0),
  16. aMapping: AttributeSpec('float32', 2, 0),
  17. elements: ElementsSpec('uint32'),
  18. padding: ValueSpec('number'),
  19. dDoubleSided: DefineSpec('boolean'),
  20. }
  21. export type SpheresSchema = typeof SpheresSchema
  22. export type SpheresValues = Values<SpheresSchema>
  23. export function SpheresRenderable(ctx: WebGLContext, id: number, values: SpheresValues, state: RenderableState, materialId: number): Renderable<SpheresValues> {
  24. const schema = { ...GlobalUniformSchema, ...InternalSchema, ...SpheresSchema }
  25. const internalValues: InternalValues = {
  26. uObjectId: ValueCell.create(id),
  27. uPickable: ValueCell.create(state.pickable ? 1 : 0)
  28. }
  29. const shaderCode = SpheresShaderCode
  30. const renderItem = createGraphicsRenderItem(ctx, 'triangles', shaderCode, schema, { ...values, ...internalValues }, materialId)
  31. return createRenderable(renderItem, values, state);
  32. }