Sampling a 1D texture based on values ​​from a 2D texture

I fill in the GLubyte 2D texture from the floating point values ​​R (real numbers) displayed in (0,1) and multiply by 255 to give the values ​​(0, 255). Saving is like GL_R8, since I need only one value from the texture. This may be, for example, a mathematical function.

I also upload 1d texture to work as a color map / colorbar. Then I select from 1D texture based on the values ​​from my 2D texture.

This is how my fragment shaders work:

#version 400 in vec2 f_textureCoord; layout(location = 0) out vec4 FragColor; uniform sampler2D textureData; uniform sampler1D colorBar; void main() { /* Values in the sampler are on (0, 1) * 255 => (0, 255) */ vec3 texColor = texture2D(textureData, f_textureCoord).rgb; float s = texColor.r; /* Use the texture value as a coordinate in the 1D colorbar texture */ vec3 color = texture1D(colorBar, s).rgb; float val = color.r; FragColor = vec4(val, val, val, 1); } 

Using this, I get the following error:

glValidateProgram: validation error: samplers of different types point to the same texture unit

However, my code works as expected, at least the rendering result!

My questions:

1) Why am I getting this error / warning? --- Answered in the comments ...

2) Is this the right approach to what I'm trying to do? Should I use a different form of buffer instead of storing the values ​​of my function in a 2D texture?

3) I assume that I will have problems when my mathematical function (filling in a 2D texture) exceeds a certain size limit of the texture. Any recommendations on how I should work on this?

+4
source share
2 answers

1.) Call glValidateProgram in front of your glDraw * command to verify that you have set the attributes to be uniformly and evenly positioned. Thus, an incorrect warning is issued because both texture units of the sampler are still zero after the program is bound.

2.) If it comes to displaying the results of your function using the color index, this is normal. If I understand that the correct texture contains only gray values. If you need only one color component from the texture, you should write

 float s = texture2D(textureData, f_textureCoord).r; 

3.) If you need to display more data than you can fit into a single texture, you will have to use tiling (for example, divide the data into several textures and make several drawings).

+2
source

glValidateProgram designed to detect whether a program can be used to render with the current state of OpenGL. This includes things like current texture bindings, uniform buffers, and any other things directly related to textures (draw buffers and vertex attributes are not included in this list).

0
source

Source: https://habr.com/ru/post/1446317/


All Articles