cylinders.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Copyright (c) 2020-2022 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, Values, InternalSchema, SizeSchema, InternalValues, ElementsSpec, ValueSpec, DefineSpec, GlobalTextureSchema, UniformSpec } from './schema';
  10. import { CylindersShaderCode } from '../shader-code';
  11. import { ValueCell } from '../../mol-util';
  12. export const CylindersSchema = {
  13. ...BaseSchema,
  14. ...SizeSchema,
  15. aGroup: AttributeSpec('float32', 1, 0),
  16. aStart: AttributeSpec('float32', 3, 0),
  17. aEnd: AttributeSpec('float32', 3, 0),
  18. aMapping: AttributeSpec('float32', 3, 0),
  19. aScale: AttributeSpec('float32', 1, 0),
  20. aCap: AttributeSpec('float32', 1, 0),
  21. elements: ElementsSpec('uint32'),
  22. padding: ValueSpec('number'),
  23. uDoubleSided: UniformSpec('b'),
  24. dIgnoreLight: DefineSpec('boolean'),
  25. dXrayShaded: DefineSpec('boolean'),
  26. dOpaqueBackfaces: DefineSpec('boolean'),
  27. uBumpFrequency: UniformSpec('f'),
  28. uBumpAmplitude: UniformSpec('f'),
  29. };
  30. export type CylindersSchema = typeof CylindersSchema
  31. export type CylindersValues = Values<CylindersSchema>
  32. export function CylindersRenderable(ctx: WebGLContext, id: number, values: CylindersValues, state: RenderableState, materialId: number, variants: GraphicsRenderVariant[]): Renderable<CylindersValues> {
  33. const schema = { ...GlobalUniformSchema, ...GlobalTextureSchema, ...InternalSchema, ...CylindersSchema };
  34. const internalValues: InternalValues = {
  35. uObjectId: ValueCell.create(id),
  36. };
  37. const shaderCode = CylindersShaderCode;
  38. const renderItem = createGraphicsRenderItem(ctx, 'triangles', shaderCode, schema, { ...values, ...internalValues }, materialId, variants);
  39. return createRenderable(renderItem, values, state);
  40. }