Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Troubles with Mipmap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    79

    Question Troubles with Mipmap

    Hi, All!

    I try to start working with mipmap.
    First of all I try to render depth map to mipmap texture (only 0 level at the first step) instead of simple one.

    When I change my working render tools for using mipmap, I have empty result:
    Click image for larger version. 

Name:	mipmap.jpg 
Views:	53 
Size:	8.1 KB 
ID:	2661


    mipmap code:
    Code :
        glBindTexture(GL_TEXTURE_2D, id);
     
        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, this.width, this.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, (ByteBuffer) null);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glGenerateMipmap(GL_TEXTURE_2D);
     
        ....
        glBindFramebuffer(GL_FRAMEBUFFER, depthMapFBO);
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthMap.getId(), 0);
        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {  // Here all is ok - have no errors
          throw new IllegalStateException("Could not create FrameBuffer");
        }
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        ....
     
        // rendering of mipmap:
        shaderProgram.bind();
     
        shaderProgram.setUniform("depthTexture", 0);
        shaderProgram.setUniform("prevFrameInvertedProjViewMatrix", prevFrameInvertedProjViewMatrix);
        shaderProgram.setUniform("currFrameProjViewMatrix", currFrameProjViewMatrix);
     
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D_ARRAY, depthBuffer.getTexture().getId());
     
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, reprojectedDepthBuffer.getTexture().getId(), 0);
        quadMesh.render();
     
        shaderProgram.unbind();
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        ....
     
        // try to show it on display:
     
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, reference);
     
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
     
        quadMesh.render();
        glBindTexture(type.getGlType(), 0);

    Who knows where the problem might be?
    Thanks for answer!

  2. #2
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    79
    Is there some difference between rendering to mipmap and rendering to simple texture?

    When I replace mipmap by simple texture rendering is works.
    But for mipmap I have empty result.

    Where could be problem?
    Last edited by nimelord; 02-08-2018 at 04:02 AM.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,829
    Quote Originally Posted by nimelord View Post
    Is there some difference between rendering to mipmap and rendering to simple texture?
    Well, you only bind a specific level of a texture to a framebuffer. If the texture has more than one level, then you need to generate the other levels e.g. with glGenerateMipmap(). If you select a minification filter which uses mipmaps but haven't generated all of the levels, then texture sampling returns zeros. However, as you appear to be setting the maximum level to zero, this shouldn't matter.

  4. #4
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    79
    Quote Originally Posted by GClements View Post
    Well, you only bind a specific level of a texture to a framebuffer. If the texture has more than one level, then you need to generate the other levels e.g. with glGenerateMipmap(). If you select a minification filter which uses mipmaps but haven't generated all of the levels, then texture sampling returns zeros. However, as you appear to be setting the maximum level to zero, this shouldn't matter.
    GClements, you helped me so mauch!

    I used glGenerateMipmap next after rendering - it did not get any result.
    But when I called it before using mipmap texture, mipmap became - ok.

    I wasted a week with other details which didn't get me any results.
    You made me look at glGenerateMipmap more carefully and I gueesed solution at the moment.
    But I found out that also I need more learning about using mipmaps.

    Thank you!

  5. #5
    Intern Contributor
    Join Date
    Nov 2017
    Posts
    79
    I have another one problem.

    I rendered base level of mipmap (it is redered ok).

    And then I render other levels and have result only in last rendered level.
    All previous levels (including base level) became empty.
    Why it can be?

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,829
    Quote Originally Posted by nimelord View Post
    Why it can be?
    It's impossible to say with so little information.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •