From 05758ef7de37bf7b37b01238bbe8d45ac5ea6043 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Tue, 16 Apr 2019 12:37:58 -0700
Subject: [PATCH] added shaderTextureLod compat

---
 src/mol-gl/shader-code.ts   | 10 ++++++++++
 src/mol-gl/webgl/compat.ts  |  7 +++++++
 src/mol-gl/webgl/context.ts | 11 +++++++++--
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/mol-gl/shader-code.ts b/src/mol-gl/shader-code.ts
index a7e3386a3..3778ba8ff 100644
--- a/src/mol-gl/shader-code.ts
+++ b/src/mol-gl/shader-code.ts
@@ -19,6 +19,7 @@ export interface ShaderExtensions {
     readonly standardDerivatives?: boolean
     readonly fragDepth?: boolean
     readonly drawBuffers?: boolean
+    readonly shaderTextureLod?: boolean
 }
 
 export interface ShaderCode {
@@ -115,6 +116,14 @@ function getGlsl100FragPrefix(extensions: WebGLExtensions, shaderExtensions: Sha
             throw new Error(`requested 'GL_EXT_draw_buffers' extension is unavailable`)
         }
     }
+    if (shaderExtensions.shaderTextureLod) {
+        if (extensions.shaderTextureLod) {
+            prefix.push('#extension GL_EXT_shader_texture_lod : enable')
+            prefix.push('#define enabledShaderTextureLod')
+        } else {
+            throw new Error(`requested 'GL_EXT_shader_texture_lod' extension is unavailable`)
+        }
+    }
     return prefix.join('\n') + '\n'
 }
 
@@ -136,6 +145,7 @@ layout(location = 7) out highp vec4 out_FragData7;
 
 #define varying in
 #define texture2D texture
+#define texture2DLodEXT textureLod
 
 #define gl_FragColor out_FragData0
 #define gl_FragDepthEXT gl_FragDepth
diff --git a/src/mol-gl/webgl/compat.ts b/src/mol-gl/webgl/compat.ts
index 8b1dff34a..9021af77e 100644
--- a/src/mol-gl/webgl/compat.ts
+++ b/src/mol-gl/webgl/compat.ts
@@ -213,4 +213,11 @@ export function getDrawBuffers(gl: GLRenderingContext): COMPAT_draw_buffers | nu
             MAX_DRAW_BUFFERS: ext.MAX_DRAW_BUFFERS_WEBGL,
         }
     }
+}
+
+export interface COMPAT_shader_texture_lod {
+}
+
+export function getShaderTextureLod(gl: GLRenderingContext): COMPAT_shader_texture_lod | null {
+    return isWebGL2(gl) ? {} : gl.getExtension('EXT_shader_texture_lod')
 }
\ No newline at end of file
diff --git a/src/mol-gl/webgl/context.ts b/src/mol-gl/webgl/context.ts
index 52e957e04..aca8e579d 100644
--- a/src/mol-gl/webgl/context.ts
+++ b/src/mol-gl/webgl/context.ts
@@ -6,7 +6,7 @@
 
 import { createProgramCache, ProgramCache } from './program'
 import { createShaderCache, ShaderCache } from './shader'
-import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, getVertexArrayObject, isWebGL2, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers } from './compat';
+import { GLRenderingContext, COMPAT_instanced_arrays, COMPAT_standard_derivatives, COMPAT_vertex_array_object, getInstancedArrays, getStandardDerivatives, getVertexArrayObject, isWebGL2, COMPAT_element_index_uint, getElementIndexUint, COMPAT_texture_float, getTextureFloat, COMPAT_texture_float_linear, getTextureFloatLinear, COMPAT_blend_minmax, getBlendMinMax, getFragDepth, COMPAT_frag_depth, COMPAT_color_buffer_float, getColorBufferFloat, COMPAT_draw_buffers, getDrawBuffers, getShaderTextureLod, COMPAT_shader_texture_lod } from './compat';
 import { createFramebufferCache, FramebufferCache, checkFramebufferStatus } from './framebuffer';
 import { Scheduler } from 'mol-task';
 import { isDebugMode } from 'mol-util/debug';
@@ -158,6 +158,7 @@ export type WebGLExtensions = {
     fragDepth: COMPAT_frag_depth | null
     colorBufferFloat: COMPAT_color_buffer_float | null
     drawBuffers: COMPAT_draw_buffers | null
+    shaderTextureLod: COMPAT_shader_texture_lod | null
 }
 
 function createExtensions(gl: GLRenderingContext): WebGLExtensions {
@@ -201,6 +202,11 @@ function createExtensions(gl: GLRenderingContext): WebGLExtensions {
     if (drawBuffers === null) {
         console.log('Could not find support for "draw_buffers"')
     }
+    const shaderTextureLod = getShaderTextureLod(gl)
+    if (shaderTextureLod === null) {
+        console.log('Could not find support for "shader_texture_lod"')
+    }
+    
 
     return {
         instancedArrays,
@@ -212,7 +218,8 @@ function createExtensions(gl: GLRenderingContext): WebGLExtensions {
         vertexArrayObject,
         fragDepth,
         colorBufferFloat,
-        drawBuffers
+        drawBuffers,
+        shaderTextureLod
     }
 }
 
-- 
GitLab