瀏覽代碼

webgl tweaks

- export getBuffer
- add glEnumToString helper
Alexander Rose 1 年之前
父節點
當前提交
f264e4d6b8
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 1 1
      src/mol-gl/webgl/buffer.ts
  2. 10 0
      src/mol-gl/webgl/context.ts

+ 1 - 1
src/mol-gl/webgl/buffer.ts

@@ -102,7 +102,7 @@ export interface Buffer {
     destroy: () => void
 }
 
-function getBuffer(gl: GLRenderingContext) {
+export function getBuffer(gl: GLRenderingContext) {
     const buffer = gl.createBuffer();
     if (buffer === null) {
         throw new Error('Could not create WebGL buffer');

+ 10 - 0
src/mol-gl/webgl/context.ts

@@ -52,6 +52,16 @@ export function checkError(gl: GLRenderingContext) {
     }
 }
 
+export function glEnumToString(gl: GLRenderingContext, value: number) {
+    const keys: string[] = [];
+    for (const key in gl) {
+        if ((gl as any)[key] === value) {
+            keys.push(key);
+        }
+    }
+    return keys.length ? keys.join(' | ') : `0x${value.toString(16)}`;
+}
+
 function unbindResources(gl: GLRenderingContext) {
     // bind null to all texture units
     const maxTextureImageUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);