Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 02:40:33 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Depth and Stencil Buffer
Pages: [1]
Print
Author Topic: Depth and Stencil Buffer  (Read 792 times)
Sigma
Level 1
*


View Profile WWW
« on: September 29, 2017, 12:27:53 PM »

Hi all,
    I'm new to OpenGL going through depth and stencil buffers.I have a problem understanding the way stencil functions and mask works. If you can give me a simple explanation on the above it would be highly appreciated. I have added what i have understood below

point 1 : glStencilFunc(GL_ALWAYS, 1, 0xff); //always keep the fragment, i.e, set the stencil buffer bit as 1
point 2 : glStencilMask(0xff); //write the values to the stencil buffer as it is

if the above point 1 is correct, the following block should set all the bit as 1 wherever the mesh fragments are and it should be visible. And it is working as intended

        glStencilFunc(GL_ALWAYS, 1, 0xff);
        glStencilMask(0xff);
        for (int i = 0; i < MESHES_COUNT; i++)
        {
            meshes->draw();
        }
        the question here is irrespective of whether i make this ( glStencilMask(0xff) ) call or not the meshes are visible. WHY?

Second question is,
after the previous call i'm making the following call to clip the next drawn model

glStencilFunc(GL_EQUAL, 1, 0xff);
glStencilMask(0x00);
//draw inverted model
ourModel->transform->setScale(glm::vec3(-0.1f));
ourModel->draw();

there is no clipping but when i comment glStencilMask(0x00) objects are clipped properly.

need to know what glStencilMask actually do?

All helps are highly appreciated!!!

« Last Edit: September 29, 2017, 11:07:06 PM by Sigma » Logged

ALourenco
Level 0
***


View Profile WWW
« Reply #1 on: September 30, 2017, 11:38:45 AM »

glStencilMask as it's definition says: "controls the writing of individual bits in the stencil planes", so this means that it would control the bits that are written to the stencil buffer when you run a stencil operation.

You should know how bitmasks work. 0xFF means 1111 1111, that means that OpenGL could write to all 8 stencil bits. 0x00 means 0000 0000 that openGL wouldn't be able to write to any of the 8 stencil bits.

You should only use mask 0x00 when you don't want to write to the stencil buffer. So if you want to use the Stencil Test to apply the clipping, you must keep with the 0xFF mask.

I'm no pro explaining, but I hope I could help ^^.

Good Luck
Logged

GameDev Master Student.
Game Engines and Computer Graphics in free time.

@CodinGree
Sigma
Level 1
*


View Profile WWW
« Reply #2 on: October 01, 2017, 10:23:13 AM »

glStencilMask as it's definition says: "controls the writing of individual bits in the stencil planes", so this means that it would control the bits that are written to the stencil buffer when you run a stencil operation.

You should know how bitmasks work. 0xFF means 1111 1111, that means that OpenGL could write to all 8 stencil bits. 0x00 means 0000 0000 that openGL wouldn't be able to write to any of the 8 stencil bits.

You should only use mask 0x00 when you don't want to write to the stencil buffer. So if you want to use the Stencil Test to apply the clipping, you must keep with the 0xFF mask.

I'm no pro explaining, but I hope I could help ^^.

Good Luck

Hi ALourenco,
   Thanks for the reply, i understand that mask. Should i always use glStencilMask(0xFF) after the glStencilFunc then?
Logged

ALourenco
Level 0
***


View Profile WWW
« Reply #3 on: October 01, 2017, 12:33:55 PM »

glStencilMask as it's definition says: "controls the writing of individual bits in the stencil planes", so this means that it would control the bits that are written to the stencil buffer when you run a stencil operation.

You should know how bitmasks work. 0xFF means 1111 1111, that means that OpenGL could write to all 8 stencil bits. 0x00 means 0000 0000 that openGL wouldn't be able to write to any of the 8 stencil bits.

You should only use mask 0x00 when you don't want to write to the stencil buffer. So if you want to use the Stencil Test to apply the clipping, you must keep with the 0xFF mask.

I'm no pro explaining, but I hope I could help ^^.

Good Luck

Hi ALourenco,
   Thanks for the reply, i understand that mask. Should i always use glStencilMask(0xFF) after the glStencilFunc then?

Well, since glStencilFunc will set in witch situation should it write to the stencil buffer, it would make sense to have glStencilMask(0xFF) in most situations yes. Although in some situation were you want to avoid stencil writing you can use glStencilMask(0x00).
Logged

GameDev Master Student.
Game Engines and Computer Graphics in free time.

@CodinGree
Sigma
Level 1
*


View Profile WWW
« Reply #4 on: October 02, 2017, 05:02:18 AM »

glStencilMask as it's definition says: "controls the writing of individual bits in the stencil planes", so this means that it would control the bits that are written to the stencil buffer when you run a stencil operation.

You should know how bitmasks work. 0xFF means 1111 1111, that means that OpenGL could write to all 8 stencil bits. 0x00 means 0000 0000 that openGL wouldn't be able to write to any of the 8 stencil bits.

You should only use mask 0x00 when you don't want to write to the stencil buffer. So if you want to use the Stencil Test to apply the clipping, you must keep with the 0xFF mask.

I'm no pro explaining, but I hope I could help ^^.

Good Luck

Hi ALourenco,
   Thanks for the reply, i understand that mask. Should i always use glStencilMask(0xFF) after the glStencilFunc then?

Well, since glStencilFunc will set in witch situation should it write to the stencil buffer, it would make sense to have glStencilMask(0xFF) in most situations yes. Although in some situation were you want to avoid stencil writing you can use glStencilMask(0x00).

Thanks ALourenco
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic