Skip to content
Snippets Groups Projects
Select Git revision
  • 4a39fac4e97a191bb2f0ebd032c6669f81dc76ee
  • master default protected
  • rednatco-v2
  • base-pairs-ladder
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

text.frag

Blame
  • texture.ts 10.46 KiB
    /**
     * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    import { WebGLContext } from './context'
    import { TextureImage, TextureVolume } from '../renderable/util';
    import { ValueCell } from 'mol-util';
    import { RenderableSchema } from '../renderable/schema';
    import { idFactory } from 'mol-util/id-factory';
    import { Framebuffer } from './framebuffer';
    import { isWebGL2 } from './compat';
    import { ValueOf } from 'mol-util/type-helpers';
    
    const getNextTextureId = idFactory()
    
    export type TextureKindValue = {
        'image-uint8': TextureImage<Uint8Array>
        'image-float32': TextureImage<Float32Array>
        'volume-uint8': TextureVolume<Uint8Array>
        'volume-float32': TextureVolume<Float32Array>
        'texture': Texture
    }
    export type TextureValueType = ValueOf<TextureKindValue>
    export type TextureKind = keyof TextureKindValue
    export type TextureType = 'ubyte' | 'float'
    export type TextureFormat = 'alpha' | 'rgb' | 'rgba'
    /** Numbers are shortcuts for color attachment */
    export type TextureAttachment = 'depth' | 'stencil' | 'color0' | 'color1' | 'color2' | 'color3' | 'color4' | 'color5' | 'color6' | 'color7' | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
    export type TextureFilter = 'nearest' | 'linear'
    
    export function getTarget(ctx: WebGLContext, kind: TextureKind): number {
        const { gl } = ctx
        switch (kind) {
            case 'image-uint8': return gl.TEXTURE_2D
            case 'image-float32': return gl.TEXTURE_2D
        }
        if (isWebGL2(gl)) {
            switch (kind) {
                case 'volume-uint8': return gl.TEXTURE_3D
                case 'volume-float32': return gl.TEXTURE_3D
            }
        }
        throw new Error(`unknown texture kind '${kind}'`)
    }
    
    export function getFormat(ctx: WebGLContext, format: TextureFormat): number {
        const { gl } = ctx
        switch (format) {
            case 'alpha': return gl.ALPHA
            case 'rgb': return gl.RGB
            case 'rgba': return gl.RGBA
        }
    }
    
    export function getInternalFormat(ctx: WebGLContext, format: TextureFormat, type: TextureType): number {
        const { gl, isWebGL2 } = ctx
        if (isWebGL2) {
            switch (format) {
                case 'alpha':
                    switch (type) {
                        case 'ubyte': return gl.ALPHA
                        case 'float': throw new Error('invalid format/type combination alpha/float')
                    }
                case 'rgb':
                    switch (type) {
                        case 'ubyte': return gl.RGB
                        case 'float': return (gl as WebGL2RenderingContext).RGB32F
                    }