NPOT texture as render target on OGLES2

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
gtimworks
Posts: 21
Joined: Sun Nov 03, 2013 8:07 pm

NPOT texture as render target on OGLES2

Post by gtimworks »

I am still in my SSAO adventure on iOS platform. I am using prerelease 1.9 for OGLES2.

I followed tutorial 13 to draw staff to a texture. I found that if the texture is a NPOT one (a quarter of the screen resolution for example) , I just got a totally black screen.

According to Kronos (http://www.khronos.org/opengles/sdk/doc ... ameter.xml) this makes sense.
Suppose that a texture is accessed from a fragment shader or vertex shader and has set GL_TEXTURE_MIN_FILTER to one of the functions that requires mipmaps. If either the dimensions of the texture images currently defined (with previous calls to glTexImage2D, glCompressedTexImage2D, or glCopyTexImage2D) do not follow the proper sequence for mipmaps (described above), or there are fewer texture images defined than are needed, or the set of texture images were defined with different formats or types, then the texture image unit will return (R, G, B, A) = (0, 0, 0, 1).

Similarly, if the width or height of a texture image are not powers of two and either the GL_TEXTURE_MIN_FILTER is set to one of the functions that requires mipmaps or the GL_TEXTURE_WRAP_S or GL_TEXTURE_WRAP_T is not set to GL_CLAMP_TO_EDGE, then the texture image unit will return (R, G, B, A) = (0, 0, 0, 1).
In short this means you need the following lines to use NPOT texture as a rendering target. Without these lines you are going to get a black screen.

Code: Select all

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
Now the question is, what are the APIs I should use to enable these lines inside the driver in order to use a NPOT texture? Thanks.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: NPOT texture as render target on OGLES2

Post by hendu »

That's not universal, many devices support NPOT with this extension:

http://www.khronos.org/registry/gles/ex ... e_npot.txt
gtimworks
Posts: 21
Joined: Sun Nov 03, 2013 8:07 pm

Re: NPOT texture as render target on OGLES2

Post by gtimworks »

Hi hendu,

Thanks for the reply. The following is quoted from the link you gave:
This extension adds support for the REPEAT and MIRRORED_REPEAT
texture wrap modes and the minification filters supported for
non-power of two 2D textures, cubemaps and for 3D textures, if
the OES_texture_3D extension is supported.

Section 3.8.2 of the OpenGL ES 2.0 specification describes
rules for sampling from an incomplete texture. There were specific
rules added for non-power of two textures i.e. if the texture wrap
mode is not CLAMP_TO_EDGE or minification filter is not NEAREST or
LINEAR and the texture is a non-power-of-two texture, then sampling
the texture will return (0, 0, 0, 1).

These rules are no longer applied by an implementation that supports
this extension.
OGLES2 does support NPOT textures, but with conditions. The extension above just have the conditions removed. For my case I don't need REPEAT or MIRRORED_REPEAT texture wrap modes but I do want NPOT texture. As long as I setup the condition properly, I would expect it works on all OGLES2 compatible implementations, with or without the extension.

So the question here is not about whether the extension is "universal". It is about from Irrlicht point of view, do we allow NOPT texture on OGLES2 implementations that don't have this extension. If we do, then my question is still valid: what are the Irrlicht APIs I should call to setup the conditions required for NPOT texture.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: NPOT texture as render target on OGLES2

Post by hybrid »

I think we have (or had) such a correction in the ogl-es2 driver. Guess we have to go through the code again and check all reset codes.
Post Reply