void opengl_state::StencilOpSeparate(GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass) {
	if (face == GL_FRONT_AND_BACK) {
		StencilOpSeparate(GL_FRONT, sfail, dpfail, dppass);
		StencilOpSeparate(GL_BACK, sfail, dpfail, dppass);
		return;
	}

	if (face == GL_FRONT) {
		if (stencilOpFrontStencilFail == sfail && stencilOpFrontDepthFail == dpfail && stencilOpFrontPass == dppass) {
			return;
		}

		glStencilOpSeparate(GL_FRONT, sfail, dpfail, dppass);

		stencilOpFrontStencilFail = sfail;
		stencilOpFrontDepthFail = dpfail;
		stencilOpFrontPass = dppass;
	} else {
		if (stencilOpBackStencilFail == sfail && stencilOpBackDepthFail == dpfail && stencilOpBackPass == dppass) {
			return;
		}

		glStencilOpSeparate(GL_BACK, sfail, dpfail, dppass);

		stencilOpBackStencilFail = sfail;
		stencilOpBackDepthFail = dpfail;
		stencilOpBackPass = dppass;
	}
}
Пример #2
0
void renderer_bind_stencil(struct renderer *r)
{
	GLuint prog;

	prog = r->null.prog;
	glDepthMask(GL_FALSE);
	glEnable(GL_STENCIL_TEST);
	glDrawBuffer(GL_NONE);
	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glClear(GL_STENCIL_BUFFER_BIT);
	glStencilFunc(GL_ALWAYS, 0, 0);
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

	glUseProgram(prog);
	glUniformMatrix4fv(
		glGetUniformLocation(prog, "ModelViewProjectionMatrix"),
		1,
		GL_FALSE,
		r->mvp.a
	);
	
	glBindBuffer(GL_ARRAY_BUFFER, r->cube_attr);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, r->cube_idx);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(
		0,
		3,
		GL_FLOAT,
		GL_FALSE,
		sizeof(struct attribs),
		0
	);
}
Пример #3
0
void VRSim::DSStencilPass(unsigned int PointLightIndex){
  m_nullTech.enable();

  // Disable color/depth write and enable stencil
  m_gbuffer.BindForStencilPass();
  glEnable(GL_DEPTH_TEST);

  glDisable(GL_CULL_FACE);

  glClear(GL_STENCIL_BUFFER_BIT);

  // We need the stencil test to be enabled but we want it
  // to succeed always. Only the depth test matters.
  glStencilFunc(GL_ALWAYS, 0, 0);

  glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
  glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

  float BSphereScale = CalcPointLightBSphere(m_pointLight[PointLightIndex]);
  sphere.model = cavr::math::mat4f::translate(m_pointLight[PointLightIndex].Position) * cavr::math::mat4f::scale(BSphereScale);

  auto mvp = (cavr::gfx::getProjection() * cavr::gfx::getView() * sphere.model);
  m_nullTech.set("gWVP", mvp);

  sphere.renderModel();
}
Пример #4
0
void DeferredShading::mark_frustums(Slice<const Frustum> fs)
{
	glEnable(GL_STENCIL_TEST);
	glDisable(GL_CULL_FACE);
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glDepthMask(GL_FALSE);
	DEFER {
		glDisable(GL_STENCIL_TEST);
		glEnable(GL_CULL_FACE);
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		glDepthMask(GL_TRUE);
	};
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_REPLACE, GL_KEEP);
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_KEEP);

	sun_shadow.bind();
	glClear(GL_STENCIL_BUFFER_BIT);

	BIND_SHADER(stencil);
	for (int i = fs.length-1; i >= 0; i--) {
		const Frustum &f = fs[i];
		glStencilFunc(GL_ALWAYS, i+1, 0xFF);
		draw_frustum(f);
	}
}
Пример #5
0
	void DSStencilPass(unsigned int PointLightIndex)
	{
		m_nullTech.Enable();

		// Disable color/depth write and enable stencil
		m_gbuffer.BindForStencilPass();
		glEnable(GL_DEPTH_TEST);

        glDisable(GL_CULL_FACE);

		glClear(GL_STENCIL_BUFFER_BIT);

		// We need the stencil test to be enabled but we want it
		// to succeed always. Only the depth test matters.
		glStencilFunc(GL_ALWAYS, 0, 0);

		glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
		glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

		Pipeline p;
		p.WorldPos(m_pointLight[PointLightIndex].Position);
        float BBoxScale = CalcPointLightBSphere(m_pointLight[PointLightIndex]);
		p.Scale(BBoxScale, BBoxScale, BBoxScale);		
        p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp());
        p.SetPerspectiveProj(m_persProjInfo);

		m_nullTech.SetWVP(p.GetWVPTrans());
		m_bsphere.Render();  
	}
Пример #6
0
HQ_FORCE_INLINE void HQStateManagerGL::ActiveDepthStencilState(const HQSharedPtr<HQDepthStencilStateGL> &state)
{
	if (state->depthEnable != this->dsState->depthEnable)
	{
		if (state->depthEnable)
			glEnable(GL_DEPTH_TEST);
		else
			glDisable(GL_DEPTH_TEST);
	}
	if (state->depthFunc != this->dsState->depthFunc)
		glDepthFunc(state->depthFunc);
	if (state->depthWriteEnable != this->dsState->depthWriteEnable)
		glDepthMask(state->depthWriteEnable);

	if (state->stencilEnable != this->dsState->stencilEnable)
	{
		if (state->stencilEnable)
			glEnable(GL_STENCIL_TEST);
		else
			glDisable(GL_STENCIL_TEST);
	}
	if (state->stencilEnable)
	{
		if (state->stwoSide)//two sided stencil
		{
			glStencilFuncSeparate(GL_FRONT ,
				state->sfront.stencilFunc ,
				state->sref,
				state->sreadMask);

			glStencilFuncSeparate(GL_BACK ,
				state->sback.stencilFunc ,
				state->sref,
				state->sreadMask);

			glStencilOpSeparate(GL_FRONT ,
				state->sfront.stencilFailOp,
				state->sfront.depthFailOp,
				state->sfront.passOp);


			glStencilOpSeparate(GL_BACK ,
				state->sback.stencilFailOp,
				state->sback.depthFailOp,
				state->sback.passOp);
		}//if (state->stwoSide)
		else
		{
			glStencilFunc(state->sfront.stencilFunc ,
				state->sref,
				state->sreadMask);

			glStencilOp(state->sfront.stencilFailOp,
				state->sfront.depthFailOp,
				state->sfront.passOp);
		}
	}//if (state->stencilEnable)
	if (state->swriteMask != this->dsState->swriteMask)
		glStencilMask(state->swriteMask);
}
Пример #7
0
void StateSystem::StencilState::applyGL() const
{
  glStencilFuncSeparate(GL_FRONT, funcs[FACE_FRONT].func, funcs[FACE_FRONT].refvalue, funcs[FACE_FRONT].mask);
  glStencilFuncSeparate(GL_BACK,  funcs[FACE_BACK ].func, funcs[FACE_BACK ].refvalue, funcs[FACE_BACK ].mask);
  glStencilOpSeparate(GL_FRONT,   ops[FACE_FRONT].fail,   ops[FACE_FRONT].zfail,      ops[FACE_FRONT].zpass);
  glStencilOpSeparate(GL_BACK,    ops[FACE_BACK ].fail,   ops[FACE_BACK ].zfail,      ops[FACE_BACK ].zpass);
}
Пример #8
0
//creates a stencil which will determine how light is applied to fragments
//needs to be called before every light pass to ensure proper work
void DefRenderer::StencilPass(Camera *cam, Renderer *r)
{
	ShaderProgram *temp = r->GetProgram();
	r->SetShaderProgram(nullProg);

	//only updating the stencil - no fragments drawn
	glDrawBuffer(GL_NONE);
	glEnable(GL_DEPTH_TEST);

	//all the fragments need to be processed by the rasterizer
	glDisable(GL_CULL_FACE);

	glClear(GL_STENCIL_BUFFER_BIT);

	glStencilFunc(GL_ALWAYS, 0, 0);

	//if light is blocked - stencil 0
	//if we pass through the light's front face and back face - stencil will be 0
	//otherwise, something in the light area blocked from leaving the area, so it's 1
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

	r->Ready();
	mat4 mvp = cam->Get() * r->GetParentGO()->GetModelMatrix();
	r->GetProgram()->SetUniform("MVP", value_ptr(mvp));
	r->Render();
	r->SetShaderProgram(temp);
}
Пример #9
0
void apply_Rstate_stencil( const Rstate_stencil* stencil ) {

	if( stencil->enabled ) {

		glEnable( GL_STENCIL_TEST );
		glStencilFuncSeparate( GL_FRONT, 
		                       stencil->frontFunc,
		                       stencil->frontRef,
		                       stencil->frontMask );
		glStencilFuncSeparate( GL_BACK, 
		                       stencil->backFunc,
		                       stencil->backRef,
		                       stencil->backMask );

		glStencilOpSeparate( GL_FRONT,
		                     stencil->frontFail,
		                     stencil->frontZpass,
		                     stencil->frontZfail );

		glStencilOpSeparate( GL_BACK,
		                     stencil->backFail,
		                     stencil->backZpass,
		                     stencil->backZfail );

	} else
		glDisable( GL_STENCIL_TEST );

}
Пример #10
0
void renderShadowInfoStencil(const MVP &boxMVP)
{
    glDrawBuffer(GL_NONE);
    glDepthMask(GL_FALSE);
    glEnable(GL_DEPTH_CLAMP);        
    glDisable(GL_CULL_FACE);
    glEnable(GL_POLYGON_OFFSET_FILL);
    glPolygonOffset(1.0, 1.0);
    
    glStencilFunc(GL_ALWAYS, 0, 0xff);
    glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
    glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);       

    glUseProgram(shadowProgram.program);

    glUniformMatrix4fv(shadowProgram.MVPMatrix, 1, GL_FALSE,  boxMVP.modelViewProjMatrix.const_value_ptr());
    glUniform3fv(shadowProgram.lightPosition, 1, pointLight.position.const_value_ptr());

    pBoxMesh->Render();

    glUseProgram(0);

    glDisable(GL_DEPTH_CLAMP);
    glEnable(GL_CULL_FACE);                  
    glDepthMask(GL_TRUE);
    glDisable(GL_POLYGON_OFFSET_FILL);
    glDrawBuffer(GL_BACK);
}
Пример #11
0
//
// This is a static function used to A) turn on the stencil buffer and B) to
// set it's tests based on different front and back tests.
//
void Renderer::setStencilOp(const GLenum& frontDepthFail,
    const GLenum& frontDepthPass, const GLenum& backDepthFail,
    const GLenum& backDepthPass)
{
  // Stencil operations for front and back faces differ.
  glStencilOpSeparate(GL_FRONT, GL_KEEP, frontDepthFail, frontDepthPass);
  glStencilOpSeparate(GL_BACK, GL_KEEP, backDepthFail, backDepthPass);
}
Пример #12
0
// GL 2.0 1-pass version
static void ss_GL2_1pass()
{
	glDisable(GL_CULL_FACE);
	glStencilMask(~0);
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
	glStencilFunc(GL_ALWAYS, 0, ~0);

	pie_ShadowDrawLoop();
}
Пример #13
0
void ShadowVolume::draw(Vector4<float> lightPos, Vector3<float> cameraPos, const Vector3<float> *ownerVertex) {
	Vector3<double> cameraPosD;
	cameraPosD.x = (double)cameraPos.x;
	cameraPosD.y = (double)cameraPos.y;
	cameraPosD.z = (double)cameraPos.z;

	calcShadowVolume(lightPos, ownerVertex, shadowPos, 8);

	glDisable(GL_LIGHTING);
	glDisable(GL_LIGHT0);

        
	//ここからステンシルシャドウの処理
	glEnable(GL_STENCIL_TEST);
	glDepthMask(GL_FALSE);
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

	glStencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS, 0, ~0);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);//表面は「+1」
	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);//裏面は「-1」
	
	//シャドーボリュームを描画する
	glBegin(GL_TRIANGLE_FAN);
	glVertex3f(lightPos.x, lightPos.y, lightPos.z);
	for(int loop = 0; loop < 3;++loop) {
		glVertex3f(shadowPos[loop].x, shadowPos[loop].y, shadowPos[loop].z);
	}
	glVertex3f(shadowPos[0].x, shadowPos[0].y, shadowPos[0].z);
	glEnd();



	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glDepthMask(GL_TRUE);
	glStencilFunc(GL_NOTEQUAL, 0, ~0); //ステンシル値が0じゃない部分が影
	glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );

	////ステンシルバッファを可視化
	glPushMatrix();
		//Tracball::getInstance().applyOfShadow();
		glDepthMask(GL_FALSE);
		glEnable(GL_BLEND);  //ブレンド有効化
		glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
		drawScreen(30, cameraPosD, 1); //スクリーン描画(fovy,znearをわたす)
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		glDisable(GL_BLEND);  //ブレンド無効化
		glDepthMask(GL_TRUE);
	glPopMatrix();

	glDisable(GL_STENCIL_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
}
Пример #14
0
void PipelineImpl::setDepthStencilState(GlState& state) const
{
	if(state.m_stateHashes.m_depthStencil == m_hashes.m_depthStencil)
	{
		return;
	}

	state.m_stateHashes.m_depthStencil = m_hashes.m_depthStencil;

	// Depth
	glDepthMask(m_in.m_depthStencil.m_depthWriteEnabled);
	state.m_depthWriteMask = m_in.m_depthStencil.m_depthWriteEnabled;

	if(m_cache.m_depthCompareFunction == GL_ALWAYS && !m_in.m_depthStencil.m_depthWriteEnabled)
	{
		glDisable(GL_DEPTH_TEST);
	}
	else
	{
		glEnable(GL_DEPTH_TEST);
	}

	glDepthFunc(m_cache.m_depthCompareFunction);

	// Stencil
	if(m_stencilTestEnabled)
	{
		glEnable(GL_STENCIL_TEST);
	}
	else
	{
		glDisable(GL_STENCIL_TEST);
	}

	glStencilOpSeparate(
		GL_FRONT, m_cache.m_stencilFailOp[0], m_cache.m_stencilPassDepthFailOp[0], m_cache.m_stencilPassDepthPassOp[0]);

	glStencilOpSeparate(
		GL_BACK, m_cache.m_stencilFailOp[1], m_cache.m_stencilPassDepthFailOp[1], m_cache.m_stencilPassDepthPassOp[1]);

	if(state.m_stencilCompareFunc[0] != m_cache.m_stencilCompareFunc[0])
	{
		state.m_stencilCompareFunc[0] = m_cache.m_stencilCompareFunc[0];
		state.m_glStencilFuncSeparateDirtyMask |= 1 << 0;
	}

	if(state.m_stencilCompareFunc[1] != m_cache.m_stencilCompareFunc[1])
	{
		state.m_stencilCompareFunc[1] = m_cache.m_stencilCompareFunc[1];
		state.m_glStencilFuncSeparateDirtyMask |= 1 << 1;
	}
}
Пример #15
0
void LightPass::StencilTest()
{
	m_gbuffer->BindForStencilPass();

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glClear(GL_STENCIL_BUFFER_BIT);

	glStencilFunc(GL_ALWAYS, 0, 0);

	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
}
//-----------------------------------------------------------------------------
void CPUTRenderStateBlockOGL::SetRenderStates( CPUTRenderParameters &renderParams )
{
    //
    // Set Depth and Stencil render states
    //
    mStateDesc.DepthStencilDesc.DepthEnable   ? glEnable(GL_DEPTH_TEST)   : glDisable(GL_DEPTH_TEST);
    mStateDesc.DepthStencilDesc.StencilEnable ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST);
    GL_CHECK("Set Depth Stencil States");

    GL_CHECK(glDepthMask(mStateDesc.DepthStencilDesc.DepthWriteMask));
    GL_CHECK(glDepthFunc(mStateDesc.DepthStencilDesc.DepthFunc));
    
    GL_CHECK(glStencilMaskSeparate(GL_FRONT_AND_BACK, mStateDesc.DepthStencilDesc.StencilWriteMask));
    GL_CHECK(glStencilOpSeparate(GL_FRONT, mStateDesc.DepthStencilDesc.FrontFaceStencilFailOp, mStateDesc.DepthStencilDesc.FrontFaceStencilDepthFailOp, mStateDesc.DepthStencilDesc.FrontFaceStencilPassOp));
    GL_CHECK(glStencilOpSeparate(GL_BACK, mStateDesc.DepthStencilDesc.BackFaceStencilFailOp, mStateDesc.DepthStencilDesc.BackFaceStencilDepthFailOp, mStateDesc.DepthStencilDesc.BackFaceStencilPassOp));
    GL_CHECK(glStencilFuncSeparate(GL_FRONT, mStateDesc.DepthStencilDesc.FrontFaceStencilFunc, mStateDesc.DepthStencilDesc.FrontFaceStencilFuncRef, mStateDesc.DepthStencilDesc.FrontFaceStencilFuncMask));
    GL_CHECK(glStencilFuncSeparate(GL_BACK, mStateDesc.DepthStencilDesc.BackFaceStencilFunc, mStateDesc.DepthStencilDesc.BackFaceStencilFuncRef, mStateDesc.DepthStencilDesc.BackFaceStencilFuncMask));
    
    //
    // Set Rasterization states
    //
#ifndef CPUT_FOR_OGLES
    GL_CHECK(glPolygonMode(GL_FRONT_AND_BACK, mStateDesc.RasterizerDesc.FillMode));
#endif
    GL_CHECK(glCullFace(mStateDesc.RasterizerDesc.CullMode));
    GL_CHECK(glFrontFace(mStateDesc.RasterizerDesc.FrontCounterClockwise));
    //GL_CHECK(glPolygonOffset()); // used for depth bias
    mStateDesc.RasterizerDesc.CullingEnabled        ? glEnable(GL_CULL_FACE)    : glDisable(GL_CULL_FACE);
    mStateDesc.RasterizerDesc.ScissorEnable         ? glEnable(GL_SCISSOR_TEST) : glDisable(GL_SCISSOR_TEST); // is glScissor needed here as well?
#ifndef CPUT_FOR_OGLES
    mStateDesc.RasterizerDesc.DepthClipEnable       ? glDisable(GL_DEPTH_CLAMP) : glEnable(GL_DEPTH_CLAMP);
    mStateDesc.RasterizerDesc.MultisampleEnable     ? glEnable(GL_MULTISAMPLE)  : glDisable(GL_MULTISAMPLE);  // is glSampleCoverage() needed here as well?
    mStateDesc.RasterizerDesc.AntialiasedLineEnable ? glEnable(GL_LINE_SMOOTH)  : glDisable(GL_LINE_SMOOTH);
    
    //NOTE: Could not find the rendertarget being set to SRGB anywhere else; this might not be the best place
    GL_CHECK(glEnable(GL_FRAMEBUFFER_SRGB));
#endif
    GL_CHECK("Set Rasterization States");
    //glDisable(GL_CULL_FACE);

    //
    // Set Blend states
    //

	mStateDesc.RenderTargetBlendDesc.BlendEnable ? glEnable(GL_BLEND): glDisable(GL_BLEND);
    GL_CHECK(glBlendFuncSeparate(mStateDesc.RenderTargetBlendDesc.SrcBlend,mStateDesc.RenderTargetBlendDesc.DestBlend,mStateDesc.RenderTargetBlendDesc.SrcBlendAlpha,mStateDesc.RenderTargetBlendDesc.DestBlendAlpha));
	GL_CHECK(glBlendEquationSeparate(mStateDesc.RenderTargetBlendDesc.BlendOp,mStateDesc.RenderTargetBlendDesc.BlendOpAlpha));
    GL_CHECK("Set Blend States");


 } // CPUTRenderStateBlockOGL::SetRenderState()
Пример #17
0
void CG3DGraphicsGL::ApplyStencil(CG3DStencilSet* set)
{
	GLenum face;
	switch (set->m_Face) {
		case CG3DStencilSet::FRONT: face = GL_FRONT; break;
		case CG3DStencilSet::BACK: face = GL_BACK; break;
		case CG3DStencilSet::FRONT_AND_BACK: face = GL_FRONT_AND_BACK; break;
	}

	glStencilMaskSeparate(face, set->m_Mask);
	
	switch (set->m_Func) {
		case CG3DStencilSet::ALWAYS: glDisable(GL_STENCIL_TEST); break;
		case CG3DStencilSet::NEVER: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_NEVER, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::LESS: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_LESS, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::LEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_LEQUAL, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::EQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_EQUAL, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::GREATER: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_GREATER, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::GEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_GEQUAL, set->m_FuncRef, set->m_FuncMask); break;
		case CG3DStencilSet::NOTEQUAL: glEnable(GL_STENCIL_TEST); glStencilFuncSeparate(face, GL_NOTEQUAL, set->m_FuncRef, set->m_FuncMask); break;
	}
	glStencilOpSeparate(face, GetOp(set->m_StencilFail), GetOp(set->m_DepthFail), GetOp(set->m_DepthPass));

	if (set->m_OtherFace != NULL)
		ApplyStencil(set->m_OtherFace);
}
Пример #18
0
/*************************************************************//**
 *
 *  @brief  ステンシルの関数の設定を行う
 *  @param  関数の種類
 *  @param  比較値
 *  @param  マスク
 *  @param  面
 *  @return なし
 *
 ****************************************************************/
void C_OpenGlManager::SetStencilProcess(StencilEnum stencilFail,
                                        StencilEnum stencilPassAndDepthFail,
                                        StencilEnum stencilPassAndDepthPass,
                                        FaceEnum face)
{
    glStencilOpSeparate(face, stencilFail, stencilPassAndDepthFail, stencilPassAndDepthPass);
}
Пример #19
0
//--------------------------------------------------------------
// start drawing decal background.  draw=false just sets depth
void mgGL33Services::decalBackground(
  BOOL draw)
{
  CHECK_THREAD();
  // set the stencil buffer based on depth test
  glEnable(GL_STENCIL_TEST);
  glStencilFunc(GL_ALWAYS, 1, 1);
  glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_ZERO, GL_REPLACE);
  glStencilOpSeparate(GL_BACK, GL_ZERO, GL_ZERO, GL_ZERO);

  // if we shouldn't draw the background, turn off write of color
  if (!draw)
  {
    glDepthFunc(GL_LEQUAL);
    glColorMask(false, false, false, false);
  }
}
Пример #20
0
void GBuffer::bindForStencilPass() {
    glDrawBuffer(GL_NONE); // disable draw buffer as we don't want to be drawing to the depth buffer or anything else
    // we only want to affect the stencil buffer

    glEnable(GL_STENCIL_TEST);
    glEnable(GL_DEPTH_TEST);

    glDisable(GL_CULL_FACE);

    glStencilFunc(GL_ALWAYS, 0, 0); // always pass stencil

    // first param (GL_KEEP) is when stencil test fails - it's set to always pass, so is irrelevant
    // second param is when stencil passes, but depth test fails - we want to increment/decrement
    // third param is when stencil passes and depth test passes (means vertex is completely outside of volume (behind)
    glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR, GL_KEEP);
    glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR, GL_KEEP);
}
Пример #21
0
void NGLScene::renderLightPass(const std::string &_shader)
{
  // get the VBO instance and draw the built in teapot
 ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
 ngl::ShaderLib *shader = ngl::ShaderLib::instance();
 glDrawBuffer(GL_NONE);
 glEnable(GL_DEPTH_TEST);
 glDisable(GL_CULL_FACE);
 glClear(GL_STENCIL_BUFFER_BIT);
 glStencilFunc(GL_ALWAYS, 0, 0);
 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);


 shader->use(_shader);
  for(float z=-5.0; z<5.0; z+=0.5)
  {
    for(float x=-5.0; x<5.0; x+=0.5)
    {
      m_transform.reset();

      m_transform.setPosition(x,sin(x),z);
      ngl::Mat4 MV;
      ngl::Mat4 MVP;
      ngl::Mat4 M;

      M=m_transform.getMatrix()*m_mouseGlobalTX;
      MV=  M*m_cam.getViewMatrix();
      MVP=  MV*m_cam.getProjectionMatrix();
      ngl::Mat4 globalMV = MV.transpose();
      ngl::Vec4 p(x,sin(x),z,1.0f);
      p=globalMV*p;
      shader->setShaderParam3f("lightPos",p.m_x,p.m_y,p.m_z);

      shader->setShaderParamFromMat4("MVP",MVP);
      prim->draw("lightSphere");

    }
  }

	glDisable(GL_BLEND);
	glDisable(GL_CULL_FACE);

}
Пример #22
0
static void glnvg__fill(GLNVGcontext* gl, GLNVGcall* call)
{
    PROFILER_CPU_TIMESLICE("NVG backend fill");

    GLNVGpath* paths = &gl->paths[call->pathOffset];
    int i, npaths = call->pathCount;

    // Draw shapes
    glEnable(GL_STENCIL_TEST);
    glStencilMask(0xff);
    glStencilFunc(GL_ALWAYS, 0, 0xff);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

    // set bindpoint for solid loc
    glnvg__setUniforms(gl, call->uniformOffset, 0);

    glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
    glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
    glDisable(GL_CULL_FACE);
    for (i = 0; i < npaths; i++)
        glDrawArrays(GL_TRIANGLE_FAN, paths[i].fillOffset, paths[i].fillCount);
    glEnable(GL_CULL_FACE);

    // Draw anti-aliased pixels
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

    glnvg__setUniforms(gl, call->uniformOffset + gl->fragSize, call->image);

    if (gl->flags & NVG_ANTIALIAS) {
        glStencilFunc(GL_EQUAL, 0x00, 0xff);
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
        // Draw fringes
        for (i = 0; i < npaths; i++)
            glDrawArrays(GL_TRIANGLE_STRIP, paths[i].strokeOffset, paths[i].strokeCount);
    }

    // Draw fill
    glStencilFunc(GL_NOTEQUAL, 0x0, 0xff);
    glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
    glDrawArrays(GL_TRIANGLES, call->triangleOffset, call->triangleCount);

    glDisable(GL_STENCIL_TEST);
}
 inline void VL_glStencilOpSeparate( GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass)
 {
   if (glStencilOpSeparate)
     glStencilOpSeparate( face, sfail, dpfail, dppass );
   else
     VL_UNSUPPORTED_FUNC();
   // NOT SUPPORTED
   // see also http://www.opengl.org/registry/specs/ATI/separate_stencil.txt
   /*else
   if ( Has_GL_ATI_separate_stencil )
     glStencilOpSeparateATI( GLenum face, GLenum sfail, GLenum dpfail, GLenum dppass )*/
 }
Пример #24
0
void StencilPass::startPass(CGraphics* it, PointLight* Light) {
	m_shaderProg.useProgram();

	// Disable color/depth write and enable stencil
	glEnable(GL_DEPTH_TEST);

	glDisable(GL_CULL_FACE);

	glClear(GL_STENCIL_BUFFER_BIT);
	// We need the stencil test to be enabled but we want it
	// to succeed always. Only the depth test matters.
	glStencilFunc(GL_ALWAYS, 0, 0);

	glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
	glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

	Pipeline::position(it->getOwner()->GetTransform()->getPosition().x, it->getOwner()->GetTransform()->getPosition().y, it->getOwner()->GetTransform()->getPosition().z);
	float BSphereScale = CalcPointLightBSphere(Light);
	Pipeline::scale(BSphereScale, BSphereScale, BSphereScale);	

	glUniformMatrix4fv(m_MVPLocation, 1, GL_FALSE, &Pipeline::getTransformationMatrix()[0][0]);
}
Пример #25
0
void device_stencilop(device_t device, enum gs_stencil_side side,
		enum gs_stencil_op fail, enum gs_stencil_op zfail,
		enum gs_stencil_op zpass)
{
	GLenum gl_side  = convert_gs_stencil_side(side);
	GLenum gl_fail  = convert_gs_stencil_op(fail);
	GLenum gl_zfail = convert_gs_stencil_op(zfail);
	GLenum gl_zpass = convert_gs_stencil_op(zpass);

	glStencilOpSeparate(gl_side, gl_fail, gl_zfail, gl_zpass);
	if (!gl_success("glStencilOpSeparate"))
		blog(LOG_ERROR, "device_stencilop (GL) failed");
}
Пример #26
0
 void GLState::glsStencilOpSeparate(const GLenum face, const GLenum sfail, 
   const GLenum dpfail, const GLenum dppass) {
   switch (face) {
   case GL_FRONT_AND_BACK:
     /*
     if (setGLenumGLenum(GL_STENCIL_FAIL, sfail) ||  // Front
       setGLenumGLenum(GL_STENCIL_PASS_DEPTH_FAIL, dpfail) ||  // Front
       setGLenumGLenum(GL_STENCIL_PASS_DEPTH_PASS, dppass) ||  // Front
       setGLenumGLenum(GL_STENCIL_BACK_FAIL, sfail) ||  // back
       setGLenumGLenum(GL_STENCIL_BACK_PASS_DEPTH_FAIL, sfail) ||  // back
       setGLenumGLenum(GL_STENCIL_BACK_PASS_DEPTH_PASS, sfail)) {  // back
       glStencilOpSeparate(GL_FRONT_AND_BACK, sfail, dpfail, dppass);
       ERROR_CHECK;
     }
     */
     glsStencilOpSeparate(GL_FRONT, sfail, dpfail, dppass);
     glsStencilOpSeparate(GL_BACK, sfail, dpfail, dppass);
     break;
   case GL_FRONT:
     if (setGLenum(GL_STENCIL_FAIL, &sfail, GLTYPE_ENUM_SIZE, GLTYPE_ENUM) || 
       setGLenum(GL_STENCIL_PASS_DEPTH_FAIL, &dpfail, GLTYPE_ENUM_SIZE, GLTYPE_ENUM) ||
       setGLenum(GL_STENCIL_PASS_DEPTH_PASS, &dppass, GLTYPE_ENUM_SIZE, GLTYPE_ENUM)) { 
       glStencilOpSeparate(GL_FRONT, sfail, dpfail, dppass);
       ERROR_CHECK;
     }
     break;
   case GL_BACK:
     if (setGLenum(GL_STENCIL_BACK_FAIL, &sfail, GLTYPE_ENUM_SIZE, GLTYPE_ENUM) ||
       setGLenum(GL_STENCIL_BACK_PASS_DEPTH_FAIL, &dpfail, GLTYPE_ENUM_SIZE, GLTYPE_ENUM) ||
       setGLenum(GL_STENCIL_BACK_PASS_DEPTH_PASS, &dppass, GLTYPE_ENUM_SIZE, GLTYPE_ENUM)) {
       glStencilOpSeparate(GL_BACK, sfail, dpfail, dppass);
       ERROR_CHECK;
     }
     break;
   default:
     throw std::runtime_error("GLState::glsStencilOpSeparate() - face"
       " invalid");
   }
 }
	void OpenGLDepthStencilState::apply()
	{
		if (changed_desc)
		{
			changed_desc = false;

			if (glStencilFuncSeparate)
			{
				CompareFunction front; int front_ref; int front_mask;
				CompareFunction back; int back_ref; int back_mask;
				unsigned char front_facing_mask, back_facing_mask;

				StencilOp fail_front, pass_depth_fail_front, pass_depth_pass_front;
				StencilOp fail_back, pass_depth_fail_back, pass_depth_pass_back;
				desc.get_stencil_compare_front(front, front_ref, front_mask);
				desc.get_stencil_compare_back(back, back_ref, back_mask);
				desc.get_stencil_write_mask(front_facing_mask, back_facing_mask);
				desc.get_stencil_op_front(fail_front, pass_depth_fail_front, pass_depth_pass_front);
				desc.get_stencil_op_back(fail_back, pass_depth_fail_back, pass_depth_pass_back);

				desc.is_stencil_test_enabled() ? glEnable(GL_STENCIL_TEST) : glDisable(GL_STENCIL_TEST);

				glStencilFuncSeparate(GL_FRONT, OpenGL::to_enum(front), front_ref, front_mask);
				glStencilFuncSeparate(GL_BACK, OpenGL::to_enum(back), back_ref, back_mask);
				glStencilMaskSeparate(GL_FRONT, front_facing_mask);
				glStencilMaskSeparate(GL_BACK, back_facing_mask);

				glStencilOpSeparate(GL_FRONT, OpenGL::to_enum(fail_front), OpenGL::to_enum(pass_depth_fail_front), OpenGL::to_enum(pass_depth_pass_front));
				glStencilOpSeparate(GL_BACK, OpenGL::to_enum(fail_back), OpenGL::to_enum(pass_depth_fail_back), OpenGL::to_enum(pass_depth_pass_back));
			}
			desc.is_depth_test_enabled() ? glEnable(GL_DEPTH_TEST) : glDisable(GL_DEPTH_TEST);
			glDepthMask(desc.is_depth_write_enabled() ? 1 : 0);
			glDepthFunc(OpenGL::to_enum(desc.get_depth_compare_function()));

		}
	}
Пример #28
0
void device_stencil_op(gs_device_t device, enum gs_stencil_side side,
		enum gs_stencil_op_type fail, enum gs_stencil_op_type zfail,
		enum gs_stencil_op_type zpass)
{
	GLenum gl_side  = convert_gs_stencil_side(side);
	GLenum gl_fail  = convert_gs_stencil_op(fail);
	GLenum gl_zfail = convert_gs_stencil_op(zfail);
	GLenum gl_zpass = convert_gs_stencil_op(zpass);

	glStencilOpSeparate(gl_side, gl_fail, gl_zfail, gl_zpass);
	if (!gl_success("glStencilOpSeparate"))
		blog(LOG_ERROR, "device_stencil_op (GL) failed");

	UNUSED_PARAMETER(device);
}
Пример #29
0
static int StencilOp(lua_State *L)
    {
    GLenum face;
    GLenum sfail = checkstencilop(L, 1);
    GLenum dpfail = checkstencilop(L, 2);
    GLenum dppass = checkstencilop(L, 3);
    if(lua_isstring(L, 4))
        {
        face = checkface(L, 4);
        glStencilOpSeparate(face, sfail, dpfail, dppass);
        }
    else
        glStencilOp(sfail, dpfail, dppass);
    CheckError(L);
    return 0;
    }
Пример #30
0
void OpenGLES2Context::setStencilActions(TriangleFace triangleFace, CompareMode compareMode, StencilAction actionOnBothPass, StencilAction actionOnDepthFail, StencilAction actionOnDepthPassStencilFail)
{
	if (compareMode != m_curStencilFunc)
	{
		m_curStencilFunc = compareMode;
		glStencilFuncSeparate(m_triangleFaces[triangleFace], m_compareFuncs[compareMode], m_curStencilRef, m_curStencilMask);
	}

	if (actionOnBothPass != m_curStencilBothPassOp || actionOnDepthFail != m_curStencilDepthFailOp || actionOnDepthPassStencilFail != m_curStencilDepthPassStencilFailOp)
	{
		m_curStencilBothPassOp = actionOnBothPass;
		m_curStencilDepthFailOp = actionOnDepthFail;
		m_curStencilDepthPassStencilFailOp = actionOnDepthPassStencilFail;
		glStencilOpSeparate(m_triangleFaces[triangleFace], m_stencilActions[actionOnDepthFail], m_stencilActions[actionOnDepthPassStencilFail], m_stencilActions[actionOnBothPass]);
	}
}