• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: OpenGL sampler2D array

Resolved: OpenGL sampler2D array

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have an array of sampler2D that looks like so: uniform sampler2D u_Textures[2];. I want to be able to render more textures(in this case 2) in the same drawcall. In my fragment shader, if I set the color output value to somethiung like red, it does show me 2 red squares witch leads me to belive I did something wrong when binding the textures. My code:
And this is my fragment shader:
Also, it only draws the tex2 texture on the screen. This is my verticie attributes:
No matter how I chenge the texture index, it only draws 1 of those 2 textures.

Answer:

You cannot use a fragment shader input variable to index an array of texture samplers. You have to use a sampler2DArray (GL_TEXTURE_2D_ARRAY) instead of an array of sampler2D (GL_TEXTURE_2D).

int index = int(v_texIndex); vec4 texColor = texture(u_Textures[index], v_TexCoord);


is undefined behavior because v_texIndex is a fragment shader input variable and therefore not a dynamically uniform expression. See GLSL 4.60 Specification – 4.1.7. Opaque Types

[…] Texture-combined sampler types are opaque types, […]. When aggregated into arrays within a shader, they can only be indexed with a dynamically uniform integral expression, otherwise results are undefined.


Example using sampler2DArray:
texture is overloaded for all sampler types. The texture coordinates and texture layer need not to dynamically uniform, but the index into a sampler array has to be dynamically uniform.

If you have better answer, please add a comment about this, thank you!

opengl
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Azuer Service Bus SDK not receiving the specified messages

01/04/2023

Resolved: how to change date format from 201904 to Apr-19 in excel

01/04/2023

Resolved: Iterator for custom Hashtable C#

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.