Jump to content

  • Log In with Google      Sign In   
  • Create Account


Binding a specific Texture Level/Mip-Map


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 30 June 2013 - 03:35 PM

Hey Guys,
 
I'm trying to bind a specific Level of an offscreen-render-texture to let's say texture target 0.
 
Now the default way of binding a texture doesn't allow that, so this is my workaround.
It's ugly, inconsistent and I don't like it.
 

public void bind(int textureId) {
    glActiveTexture(GL_TEXTURE0 + textureId);
    glBindTexture(GL_TEXTURE_2D, textureHandle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, baseLevel);
} 

So I found this function "glBindImageTexture", which I still dont' understand.
 

public void bind(int textureId, int level) {
    glBindImageTexture(textureId, textureHandle, level, false, 0, GL_READ_ONLY, GL_RGBA32F);
}

 
 Is this what I want? Do I use it right? Also I can't use formats like GL_RGB32F - without the Alpha channel.
All I get is a grey Rect, when I render this texture with "glBindImageTexture".


Edited by stefthedrummer, 30 June 2013 - 03:35 PM.


Sponsor:

#2 dpadam450   Members   -  Reputation: 886

Like
0Likes
Like

Posted 01 July 2013 - 11:54 PM

This will bias your textures to use mip maps 2 levels closer to level 0 (it will use 2x higher resolution compared to what it should be using).

GLfloat bias = -2.0;
glTexEnvfv(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, &bias);

 

glTexParameter takes these as inputs, you can push the lowest and highest resolution you want to use. I assume if they are = , it will only use that mip-map level no matter what.

GL_TEXTURE_MIN_LOD,
GL_TEXTURE_MAX_LOD

 

You can also write a shader and call texture2dLod(texture, uv_coords, mipMapLevel)



#3 dpadam450   Members   -  Reputation: 886

Like
0Likes
Like

Posted 01 July 2013 - 11:55 PM

It may also depend what you want to do. I don't believe that you can pick a specific level to render to, but the above makes it so you can choose which level to actually sample and texture from.



#4 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 02 July 2013 - 02:14 PM

Ok, now I tried these functions:

texelFetch(texture, coord, level);
textureLod(texture, coord, level);

and I also set my filters via "glTexParameter()" to

MAG -> GL_LINEAR
MIN -> GL_LINEAR_MIPMAP_NEAREST

but all I get is black pixels.

 

 

I'am absolutely shure that my textures are all-right, because when I render them with with:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, level);

It views the right level. (I have different colors on each level of my test texture).

		OpenGL.setTexture(0, texture); //(texture unit, textureHandle)
		OpenGL.setProgram(blitProgram);

		blitProgram.setInt("level", level);

		OpenGL.setDepthTest(false);

		glBegin(GL_QUADS);
		glVertexAttrib2f(1, 0.0f, 0.0f);
		glVertexAttrib3f(0, left, bottom, 0.0f);
		glVertexAttrib2f(1, 1.0f, 0.0f);
		glVertexAttrib3f(0, right, bottom, 0.0f);
		glVertexAttrib2f(1, 1.0f, 1.0f);
		glVertexAttrib3f(0, right, top, 0.0f);
		glVertexAttrib2f(1, 0.0f, 1.0f);
		glVertexAttrib3f(0, left, top, 0.0f);
		glEnd();

		OpenGL.setDepthTest(true);
#version 420 core

in  vec2 passCoord;

out vec3 outColor;

uniform sampler2D source;
uniform int       level;

void main()
{
	outColor = textureLod(source, passCoord, level).rgb + vec3(0.1f);
}

#version 420 core

in vec3 inPos;
in vec2 inCoord;
out vec2 passCoord;

void main()
{
	gl_Position = vec4(inPos, 1.0f);

	passCoord = inCoord;
}

Thanks in advance


Edited by stefthedrummer, 02 July 2013 - 02:21 PM.


#5 dpadam450   Members   -  Reputation: 886

Like
0Likes
Like

Posted 03 July 2013 - 01:53 PM

I missed it. If you can set it to view the proper levels what is your issue? Sampling them from a shader? If you want to use textureLod, try it without changing the texture parameters. I have used a shader to pick a specific texture level without changing texture parameters.



#6 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 03 July 2013 - 02:49 PM

Sry, I ment it works when rendering with "texture()" [without Lod] and chaching its base level but it doesn't when using "textureLod" without the baselevel midification. Tomorrow I will try commenting out all parameter changes and see what happens.



#7 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 04 July 2013 - 09:56 AM

Tomorrow I will try commenting out all parameter changes and see what happens.

 

Doesn't Work.

 

I also just read that you can only use "textureLod" in vertex buffers. Isn't that nonsense?



#8 dpadam450   Members   -  Reputation: 886

Like
0Likes
Like

Posted 04 July 2013 - 11:29 AM

No you can only use textureLod , and not texture in vertex shaders. Because you dont use mip-map/ anisotropic filtering when sampling a texture in a vertex shader.

 

You can though use textureLod in a pixel shader.



#9 stefthedrummer   Members   -  Reputation: 139

Like
0Likes
Like

Posted 04 July 2013 - 01:47 PM

... ok, but still - as long as I use "textureLod" all I get is black pixels ...






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS