Checking for WebGL or WebGL extensions with Modernizr

On my website, I have incorporated THREE.js scenes and graphic objects. It is common knowledge that THREE.js makes use of WebGL.

To ensure compatibility with WebGL, I am considering using Modernizr to check the user's browser. If the browser does not support WebGL, I plan to display a message alerting the user.

When configuring Modernizr to test for specific browser features, there are two options that align with my objective:

WebGL: Detects the presence of WebGL in the browser.

WebGL Extensions: Checks for support for OpenGL extensions within WebGL. If the WebGL extensions API is supported, it will expose the available extensions as subproperties.

In order for THREE.js to function properly, should I test for both WebGL Extensions and WebGL, or is testing for WebGL alone sufficient?

Answer №1

Whether or not you need extensions depends on the features you are using. Three.js itself does not require any extensions, but certain features like shadows may perform better with the WEBGL_depth_texture extension.

If you are unsure about which extensions you need, you can try hiding them using some code to see if your application still functions:

For example:

// disable all extensions

WebGLRenderingContext.prototype.getExtension = function() {
  return null;
}
WebGLRenderingContext.prototype.getSupportedExtensions = function() {
  return [];
}

// initialize Three.js

If you want to allow specific extensions, you can use the following approach:

var allowedExtensions = [
  "webgl_depth_texture",
  "oes_texture_float",
];

WebGLRenderingContext.prototype.getExtension = function(origFn) {
  return function(name) {
    if (allowedExtensions.indexOf(name.toLowerCase()) >= 0) {
      return origFn.call(this, name);
    }
    return null;
  };
}(WebGLRenderingContext.prototype.getExtension);

WebGLRenderingContext.prototype.getSupportedExtensions = function(origFn) {
  return function() {
    return origFn.call(this).filter(function(name) {
      return allowedExtensions.indexOf(n) >= 0;
    });
  };
}(WebGLRenderingContext.prototype.getSupportedExtensions);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enhance Vaadin 14: Automatically adjust TextArea size when window is resized

Using Vaadin 14.1.19 in a project called "My Starter Project," I attempted to create a TextArea that supports multiple lines. Initially, everything seemed fine, but upon resizing the TextArea, it failed to adjust the number of visible lines. Here is the co ...

What is the best way to eliminate the border color on a drop-down menu's bottom border?

I need help removing the border color from a dropdown with the style border-bottom: 1px solid rgba(0, 0, 0, 0.42); After debugging, I discovered that it is originating from the class MuiInput-underline-2593. However, the CSS class MuiInput-underline-2593 ...

Exploring ways to enhance the functionality of spreadsheets in GAS

It has come to my attention the potential for accessing output generated from the same dataset via various formats such as spreadsheets, a sidebar like the one in TBA, and perhaps even an HTML window using a JavaScript Library like THREE. https://i.sstatic ...

How can we use the jQuery each loop to iterate through a JSON object, compare values to another object, and ensure that no duplicate prints occur?

Hey everyone! I'm currently working on a music player and I'm utilizing JSON to store my ID3, also known as "MP3 Metadata". The issue I'm facing is that I'm extracting an object and trying to compare the values to avoid repeating the sa ...

Navigating fluently in React Native applications

Struggling to grasp the proper implementation of navigation in RN? The provided code snippet should shed light on the current scenario. HeaderConnected is equipped with a menu button component that utilizes a custom navigate prop for opening the Drawer me ...

Design an interactive quarter-circle using CSS styling

My goal is to create this element using CSS, however, the content inside needs to be dynamic. I initially attempted to use border-radius, but realized it is unable to achieve the desired outcome. If anyone has a solution or can offer assistance, I would g ...

Unable to establish session using jquery

I am trying to set a session using jQuery, but I keep encountering this error. I have looked for solutions online, but haven't been able to find one that works. Can someone please help me out? Thank you! ...

Tips for avoiding issues with double quotes when working with JavaScript and JSON

Creating a specific String format in JavaScript for JSON might be tricky. The goal is to generate a string like this: ["PNG","350x150","127 KB"] Here's the code snippet using string variables: var imgType = getImageType(); // Returns "PNG" var im ...

Issue with repeated items in Flatlist

Whenever I display my flatlist, it appears to be duplicating the items within it (the feedCache has only one index but the data for this index is rendered twice). Below is the code snippet for the flatlist: const FeedBody = React.memo(() => { return ...

A loop variable in Javascript is a function that iterates

var x = 99; while (true) { function lyrics(person) { return x + " " + "lines of code in the file " + x + " " + person + (x-1) + " lines of code" + "!"; } console.log(lyrics("John strikes one out, clears it all out ;")); x -= 1; if (x ...

Improving a lengthy TypeScript function through refactoring

Currently, I have this function that I am refactoring with the goal of making it more concise. For instance, by using a generic function. setSelectedSearchOptions(optionLabel: string) { //this.filterSection.reset(); this.selectedOption = optionLa ...

A guide on iterating through an array in vue.js and appending a new attribute to each object

To incorporate a new property or array item into an existing virtual DOM element in Vue.js, the $set function must be utilized. Attempting to do so directly can cause issues: For objects: this.myObject.newProperty = "value"; For arrays: ...

Adjust dimensions of images in Bee3D carousel

I recently utilized the Bee3d library available on the following Github link: https://github.com/lukeed/bee3d While I found everything to be truly impressive, I am curious if there is a way to adjust the image size. Whenever I attempt to change the image ...

Issue with Redirecting in React: REST requests are not successful

There's a text input that triggers a submission when the [Enter Key] is pressed. const [ query, setQuery ] = React.useState('') ... <TextField label="Search Codebase" id="queryField" onChange={ event => setQuery( ...

What could be the reason for this code returning a "module not found" error?

Within localbase.js... const fs = require("fs"); if(!fs.existsSync(__dirname + "/localbase.json")) fs.writeFileSync("./localbase.json", "{}"); let database = require("./localbase.json"); The code abov ...

Utilizing Vue.js to effectively filter within a nested array

I'm currently facing an issue with filtering a nested array within an array of objects in Vue.js. Take a look at this snippet from my component code: computed: { filteredProducts: function () { // https://codepen.io/arhey/pen/QrbxdX ...

Differences Between React Prop Types and Typescript in Front-End

I'm considering incorporating TypeScript into my project. Would this render the use of prop-types in React unnecessary? With prop-types, I find myself having to manually define types, but TypeScript would eliminate this step. Am I on the right track? ...

Building HTML elements using AngularJS and JavaScript

When I'm embedding HTML code within my JavaScript code, it's not recognizing that it's AngularJS code. How can I resolve this issue? I am experiencing trouble with the variables enclosed in {{}} as they are not being recognized as AngularJS ...

Adjust the font size based on the dimensions of the container

I'm currently working on a script that dynamically sets the font-size based on the container's dimensions and the length of the text. This is what I have implemented so far. window.onload = function () { var defaultDimensions = 300; ...

Observing the closing of a modal window from a different controller in AngularJS

Within my main controller, I have a function called $scope.showDialog: $scope.showDialog = function(ev) { $mdDialog.show({ controller: 'DialogController', templateUrl: 'partials/dialog.tmpl.ejs', targetEvent: ev ...