lines.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright (c) 2018 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, GraphicsRenderVariant } from '../webgl/render-item';
  9. import { GlobalUniformSchema, BaseSchema, AttributeSpec, DefineSpec, Values, InternalSchema, SizeSchema, ElementsSpec, InternalValues, GlobalTextureSchema, UniformSpec } from './schema';
  10. import { ValueCell } from '../../mol-util';
  11. import { LinesShaderCode } from '../shader-code';
  12. export const LinesSchema = {
  13. ...BaseSchema,
  14. ...SizeSchema,
  15. aGroup: AttributeSpec('float32', 1, 0),
  16. aMapping: AttributeSpec('float32', 2, 0),
  17. aStart: AttributeSpec('float32', 3, 0),
  18. aEnd: AttributeSpec('float32', 3, 0),
  19. elements: ElementsSpec('uint32'),
  20. dLineSizeAttenuation: DefineSpec('boolean'),
  21. uDoubleSided: UniformSpec('b'),
  22. dFlipSided: DefineSpec('boolean'),
  23. };
  24. export type LinesSchema = typeof LinesSchema
  25. export type LinesValues = Values<LinesSchema>
  26. export function LinesRenderable(ctx: WebGLContext, id: number, values: LinesValues, state: RenderableState, materialId: number, variants: GraphicsRenderVariant[]): Renderable<LinesValues> {
  27. const schema = { ...GlobalUniformSchema, ...GlobalTextureSchema, ...InternalSchema, ...LinesSchema };
  28. const internalValues: InternalValues = {
  29. uObjectId: ValueCell.create(id),
  30. };
  31. const shaderCode = LinesShaderCode;
  32. const renderItem = createGraphicsRenderItem(ctx, 'triangles', shaderCode, schema, { ...values, ...internalValues }, materialId, variants);
  33. return createRenderable(renderItem, values, state);
  34. }