0
$\begingroup$

So I want to make a compute shader that uses a coarse-to-fine approach.

As I have learned about open gl mipmap levels it seems they could be very useful.

However the only binding method which I have found and used (so far) for individual mipmap levels is

glBindImageTexture

for example the call

glBindImageTexture(1, im_mvs, level, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

binds the level mipmap level of the first texture (nr 0) im_mvs to slot 1.

As far as I know I can do

glBindImageTexture(1, im_mvs, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glBindImageTexture(2, im_mvs, 1, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glBindImageTexture(3, im_mvs, 2, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

to bind three different levels at once and then when preparing my program

glUseProgram(...);
glUniform1i(Loc_mvs1,1);
glUniform1i(Loc_mvs2,2);
glUniform1i(Loc_mvs3,3);
glUniform1i(Loc_NrLevels,3);

and then inside the comp shader;

layout(rgba32f, binding = 1) uniform image2D      mvs1;
layout(rgba32f, binding = 2) uniform image2D      mvs2;
layout(rgba32f, binding = 3) uniform image2D      mvs3;
uniform int NrLayers;
...
doStuffLevel0(); // will not assume mvs2,3 are bound
if(NrLayers>1){
    someMemoryBarrier();
    doStuffLevel1(); // will not assume mvs3 is bound
}
if(NrLayers>2){
    someMemoryBarrier();
    doStuffLevel2(); 
}

First of all, will this usage be okay?

And then, how can I handle it if I only actually want to use 1 or 2 levels ?

What are the hazards of having an unbound mipmap level? For example if I prepare it with

glUseProgram(...);
glUniform1i(Loc_mvs1,1);
// here Loc_mvs2,3 could be set to anything or nothing.
glUniform1i(Loc_NrLevels,1); // we set 1 to signal that mvs2,3 should not be attempted to be read from or written to inside the shader

Will it be okay if I am just careful enough to never touch (read or write or do other functions on) it inside the shader?

I suppose I can have an extra variable coding for which of these variables to use and which to avoid. Like "NrLevels" above.

This does seem quite cumbersome especially if I need even more MipMap levels in my pyramid.

Is there some smoother way to do it ?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.