What is the process for transferring a particular mip map level from one texture to another specific mip map level?

Currently, I am combining multiple 2D textures into an Array Texture in WebGL2 (using three.js) to render models with multi draw functionality. These individual textures are frequently updated and utilize mipmaps. Since generating mipmaps for a single layer in an Array Texture is not feasible, I'm interested in creating mipmaps for a 2D target and then transferring the complete mipmap chain to a specific layer within the texture.

Upon investigating the WebGL API, it appears that binding a particular mipmap level from a texture created with texStorage2D and copying it to a specific mipmap level for a layer in the 3D texture might not be achievable. Although this process occurs within three.js, the following approximate copy commands are executed:

_gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
_gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
_gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
_gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );

gl.bindTexture( _gl.TEXTURE_2D, srcTextureHandle, _gl.TEXTURE0 );
gl.copyTexSubImage3D( _gl.TEXTURE_2D_ARRAY, level, dstX, dstY, dstZ, minX, minY, width, height );

While it is possible to specify the target mip level in the parameters of copyTexSubImage3D, there doesn't seem to be a way to designate the mipmap level for the bound texture to copy.

I have come across the glCopyImageSubData function in the OpenGLES3.2 specification, which allows for specifying both source and target mip levels, but unfortunately, this feature is not available in web browsers. Is it feasible to achieve this in WebGL2?

Answer №1

Generating mipmaps for an individual layer in an Array Texture is not feasible.

However, it can be achieved by manually handling the process instead of using gl.generateMipmap.

Using draw method

canvas { border: 1px solid black; }
<canvas id="c"></canvas>
<script type="module">
import 'https://greggman.github.io/webgl-lint/webgl-lint.js';
import * as twgl from 'https://twgljs.org/dist/5.x/twgl-full.module.js';

const lerp = (a, b, t) => a + (b - a) * t;

// More code snippets here...

</script>

Using blitFramebuffer method

canvas { border: 1px solid black; }
<canvas id="c"></canvas>
<script type="module">
import 'https://greggman.github.io/webgl-lint/webgl-lint.js';
import * as twgl from 'https://twgljs.org/dist/5.x/twgl-full.module.js';

const lerp = (a, b, t) => a + (b - a) * t;
const getMipSize = (size, mipLevel) => size.map(s => Math.max(1, s >> mipLevel));

// More code snippets here...

</script>

Both methods should yield similar results. The draw method offers flexibility in customizing filtering algorithms.

To copy from one layer to another, set the mipmap/layer in the DRAW_FRAMEBUFFER using framebufferTextureLayer, then perform blit or draw operations. Ensure that if reading from and writing to the same texture, the texture parameter settings prevent any feedback loops, such as setting TEXTURE_BASE_LEVEL and TEXTURE_MAX_LEVEL appropriately to read from a single mip level only.

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

Refine keys dynamically according to the given input

I'm facing a challenge with an array wherein I need to filter out keys based on an input string. The only constant key is OLD_VAL, while the others are dynamic. Even though I attempted using a variable, it doesn't retrieve that specific key. let ...

Encountering a 401 Unauthorized error while attempting an AJAX call to an ASP.NET Web API endpoint that has Windows authentication activated

After creating a basic ASP.NET web API application, I implemented Cross-Origin Resource Sharing (CORS) using the Microsoft.AspNet.WebApi.Cors package. This is what my controller looks like: public class UserController : ApiController { [Route ...

"How can a link be created in the most nested node of jsTree to connect to a

I am currently utilizing within my asp.net mvc project. My objective is to create a tree structure where users can click on the deepest node and navigate through my site. Although the tree structure is functioning properly, I am unable to generate any li ...

Ways to update the value within an object in an array stored in a BehaviorSubject?

My initial data is: const menuItems = [{id: 1, active: false}, {id: 2, active: false}] public menuSubject$ = new BehaviorSubject<MenuItem[]>(menuItems); public menu$ = this.menuSubject$.asObservable(); I am attempting to update the element with ...

Troubleshooting Problems with jQuery's .remove() Function

I attempted to create a simple game using JS and jQuery, keeping in mind that I am new to both languages. My goal was to create a function that allows users to delete their save within the game. However, despite my efforts, I faced issues with the function ...

Trouble with Background Image Display in Internet Explorer 8

I have been attempting to set a background image for the . element, but it is not displaying correctly. The image shows up in Firefox and Chrome, but not in Internet Explorer. I have included a link to my website and relevant CSS code below. Can anyone pro ...

What are the steps to implementing the jQuery live() function in this particular code?

I am seeking assistance in applying the live() function to this particular code. The following code will be dynamically inserted using JavaScript: <a class="link" href="url"><span>This content is hidden</span></a> This is the Jav ...

Tips for updating standard JavaScript events in Rails following an Ajax call

I am in the process of developing a Rails application that utilizes ajax functionality with jQuery. I could really use some assistance from you guys. For instance, within my /public/javascripts/application.js : <!-- _item_info.html.erb --> ... < ...

Calculate the sum of values in a JSON array response

I recently received a JSON string as part of an API response, and it has the following structure: { "legend_size": 1, "data": { "series": [ "2013-05-01", "2013-05-02" ], "values": { "Sign Up": { "2013-05-05": 10, ...

Why won't the function activate on the initial click within the jQuery tabs?

When creating a UI with tabs, each tab contains a separate form. I have noticed that when I click on the tabs, all form save functions are called. However, if I fill out the first tab form and then click on the second tab, refresh the page, and go back t ...

Retrieve Javascript data from JSON only if the specified parameter is set to true

I'm currently utilizing the TMDB API for fetching movie details and I want to extract the trailer from YouTube. If my JSON data appears as follows... { id: 568124, results: [ { iso_639_1: "en", iso_3166_1: "US", ...

Mobile browser experiences video freezing when src is set through useState, yet it starts playing when triggered by a button click or when the video is set to M

Hey awesome folks at the StackOverflow Community, I'm currently encountering a perplexing issue with a video element in my web application. The video is supposed to play automatically on both desktop and mobile browsers. However, I've run into a ...

Substitute the nested object's value with a variable structure

I have an object structured like this: const obj = {a: {x: 0, y: 0}} but it can also be structured like this: const obj = {a: {x: 0, y: 0}, b: {x: 10, y: 3}, abcd: {x: -1, y: 0}} This means that the obj can contain multiple keys with variable key names. ...

Highlighting the current menu item by comparing the URL and ID

Looking to make my navigation menu items active based on URL and ID, rather than href. None of the suggested solutions (like this one, this one, or this one) have worked for me. This is how my Navigation is designed: <nav id="PageNavigation"& ...

Encountering an issue with AJAX form submission in PHP when integrating object-oriented programming principles with Sweet Alert confirmation pop-ups

I am looking to enhance my form submission process by incorporating AJAX jQuery and adding a sweet alert confirmation before submitting the form. Currently, the form functions correctly without any AJAX or JavaScript; however, I want to improve the user e ...

AngularJS select box setting selected valueIt can be accomplished by manipulating the

I am facing an issue with a selectbox populated with options from the backend. <tr> <td class="col-lg-4">Superkund</td> <td><select class="form-control input-sm2" ng-model="selectedSupercustomer" ng-options="item as item ...

Error encountered while attempting to load image through multiple window.print() functions

I am having an issue with printing a receipt containing an image in a for loop when using the code below. The image does not load when multiple prints are done using the for loop (It works fine for a single print), but if I remove the image reference, it ...

React is throwing a parsing error due to the incorrect use of braces. Remember, JSX elements must be wrapped in an enclosing tag. If you were trying to include multiple elements without a parent tag, you can use a JSX fragment

Having recently started working with React, I came across this code snippet return ( <div> dropdown ? (<li className='goal-list-item' onClick={() => setDropdown(!dropdown)}>{goal.name}</li>) : ...

Tips for retrieving data from Angular dropdown menus

How to Retrieve Selected Value in AngularJS HTML <select data-ng-model='datasource.value' ng-options='sourcetype.dataSourceType as sourcetype.dataSourceDesc for sourcetype in sourcetypes' data-ng-change="getAccountCredentials(sourc ...

Using ReactJS and Ruby on Rails to implement an AJAX delete request

There is a component named Items residing inside a parent component called ItemsContainer. A click on a button within the Items component triggers an Ajax function to delete that specific Item. However, I am encountering a 500 error message at the moment ...