Esempio n. 1
0
void render( base::ContextPtr context, base::CameraPtr cam )
{
	// render to texture
	glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
	glClearStencil( 0 );
	multisampleFBO->begin( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

	glDisable( GL_DEPTH_TEST );

	// initialize stencil buffer ---
	glEnable(GL_STENCIL_TEST);
	glEnable( GL_MULTISAMPLE );
	glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
	glEnable(GL_SAMPLE_MASK);
	for(int i = 0; i < 4; ++i)
	{
		glStencilFunc(GL_ALWAYS, i + 1, 0xff);
		glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
		glSampleMaski(0, 0x1 << i);
		context->renderScreen(initializeStencilShader);
	}
	glSampleMaski(0, 0xFFFFFF);
	glDisable(GL_SAMPLE_MASK);
	glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
	glDisable( GL_MULTISAMPLE );


	// now render geometry using stencil routing ---
	glStencilFunc(GL_EQUAL, 1, 0xff);
	glStencilOp(GL_DECR, GL_DECR, GL_DECR );

	context->setCamera( cam );
	context->render( geometry, shader );

	glDisable(GL_STENCIL_TEST);

	multisampleFBO->end();





	//  final render the shader
	// NB: the multisampleTestShader in its pixel section fetches a single sample for each fragment. change the sample index in the
	// fetchTexture function to check the values for the different samples
	glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
	glClearStencil( 0 );

	//we also clear the stencil buffer
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

	context->renderScreen( multisampleTestShader );



}
Esempio n. 2
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
    modelViewMatrix.Translate(0.0f, 0.8f, 0.0f);
    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.3f, 0.f, 0.0f);
        modelViewMatrix.Scale(0.40, 0.8, 0.40);
        modelViewMatrix.Rotate(50.0, 0.0, 10.0, 0.0);
        glSampleMaski(0, 0x02);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtYellow);
        glass1Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.4f, 0.0f, 0.0f);
        modelViewMatrix.Scale(0.5, 0.8, 1.0);
        modelViewMatrix.Rotate(-20.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x04);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtGreen);
        glass2Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(1.0f, 0.0f, -0.6f);
        modelViewMatrix.Scale(0.3, 0.9, 1.0);
        modelViewMatrix.Rotate(-40.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x08);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtMagenta);
        glass3Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.8f, 0.0f, -0.60f);
        modelViewMatrix.Scale(0.6, 0.9, 0.40);
        modelViewMatrix.Rotate(60.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x10);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtBlue);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.1f, 0.0f, 0.50f);
        modelViewMatrix.Scale(0.4, 0.9, 0.4);
        modelViewMatrix.Rotate(205.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x20);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtPink);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();
}
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
	modelViewMatrix.moveTo(0.0f, 0.8f, 0.0f);
	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.3f, 0.f, 0.0f);
	modelViewMatrix.scaleTo(0.40, 0.8, 0.40);
	modelViewMatrix.rotateTo(50.0, 0.0, 10.0, 0.0);
	glSampleMaski(0, 0x02);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtYellow);
	glass1Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.4f, 0.0f, 0.0f);
	modelViewMatrix.scaleTo(0.5, 0.8, 1.0);
	modelViewMatrix.rotateTo(-20.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x04);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtGreen);
	glass2Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(1.0f, 0.0f, -0.6f);
	modelViewMatrix.scaleTo(0.3, 0.9, 1.0);
	modelViewMatrix.rotateTo(-40.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x08);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtMagenta);
	glass3Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.8f, 0.0f, -0.60f);
	modelViewMatrix.scaleTo(0.6, 0.9, 0.40);
	modelViewMatrix.rotateTo(60.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x10);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtBlue);
	glass4Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.1f, 0.0f, 0.50f);
	modelViewMatrix.scaleTo(0.4, 0.9, 0.4);
	modelViewMatrix.rotateTo(205.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x20);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtPink);
	glass4Batch.draw();
	modelViewMatrix.pop();
}
	bool begin()
	{
		bool Validated = true;

		if(Validated)
			Validated = initProgram();
		if(Validated)
			Validated = initBuffer();
		if(Validated)
			Validated = initVertexArray();
		if(Validated)
			Validated = initTexture();
		if(Validated)
			Validated = initFramebuffer();

		GLint MaxMasks = 0;
		glGetIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &MaxMasks);
		Validated = Validated && (MaxMasks > 0);
		
		GLint Masks = 0;
		glGetIntegeri_v(GL_SAMPLE_MASK_VALUE, 0, &Masks);

		glEnable(GL_SAMPLE_MASK);
		glSampleMaski(0, 0xf);

		return Validated && this->checkError("begin");
	}
bool initBlend()
{
	glEnable(GL_SAMPLE_MASK);
	glSampleMaski(0, 0xFF);

	glEnablei(GL_BLEND, 0);
	glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
	glBlendEquationSeparatei(0, GL_FUNC_REVERSE_SUBTRACT, GL_FUNC_ADD);
	glBlendFuncSeparatei(0, GL_SRC_COLOR, GL_ONE, GL_ZERO, GL_ZERO);

	glEnablei(GL_BLEND, 1);
	glColorMaski(1, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
	glBlendEquationSeparatei(1, GL_FACTOR_MIN_AMD, GL_FUNC_ADD);
	glBlendFuncSeparatei(1, GL_SRC_COLOR, GL_SRC_COLOR, GL_ZERO, GL_ZERO);

	glEnablei(GL_BLEND, 2);
	glColorMaski(2, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
	glBlendEquationSeparatei(2, GL_FACTOR_MAX_AMD, GL_FUNC_ADD);
	glBlendFuncSeparatei(2, GL_SRC_COLOR, GL_SRC_COLOR, GL_ZERO, GL_ZERO);

	glEnablei(GL_BLEND, 3);
	glColorMaski(3, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
	glBlendEquationSeparatei(3, GL_FUNC_ADD, GL_FUNC_ADD);
	glBlendFuncSeparatei(3, GL_SRC_COLOR, GL_SRC_COLOR, GL_ZERO, GL_ZERO);

	return glf::checkError("initBlend");
}
Esempio n. 6
0
static int SampleMask(lua_State *L)
    {
    GLuint maskNumber = luaL_checkinteger(L, 1);
    GLbitfield mask = luaL_checkinteger(L, 2);
    glSampleMaski(maskNumber, mask);
    CheckError(L);
    return 0;
    }
void OGLBlendState::Enable ()
{
	if (m_EnableAlphaToCoverage)
		glEnable (GL_SAMPLE_COVERAGE);
	else
		glDisable (GL_SAMPLE_COVERAGE);

	if (m_EnableIndependentBlend)
	{
		for (int i = 0; i < BlendState::NUM_TARGETS; i++)
		{
			Target& target = m_Target[i];
			if (target.enable)
			{
				glEnable (GL_BLEND);
				glBlendFuncSeparate (target.srcColor, target.dstColor, target.srcAlpha, target.dstAlpha);
				glBlendEquationSeparate (target.opColor, target.opAlpha);
			}
			else
			{
				glDisable (GL_BLEND);
			}
			glColorMaski (i, target.rMask, target.gMask, target.bMask, target.aMask);
			glSampleMaski (i, m_SampleMask);
		}
	}
	else
	{
		Target& target = m_Target[0];
			if (target.enable)
			{
				glEnable (GL_BLEND);
				glBlendFuncSeparate (target.srcColor, target.dstColor, target.srcAlpha, target.dstAlpha);
				glBlendEquationSeparate (target.opColor, target.opAlpha);
			}
			else
			{
				glDisable (GL_BLEND);
			}
			glColorMask (target.rMask, target.gMask, target.bMask, target.aMask);
			glSampleMaski (0, m_SampleMask);
	}

	glBlendColor (m_BlendColor.x, m_BlendColor.y, m_BlendColor.z, m_BlendColor.w);
}
Esempio n. 8
0
void StateSystem::SampleState::applyGL() const
{
  glSampleCoverage(coverage,invert);
  glSampleMaski(0,mask);
}
Esempio n. 9
0
void GLWrapper::SampleMaski(GLuint param0, GLbitfield param1)
{
	GLLOG(glSampleMaski(param0, param1));ERROR_CHECK;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL32_nglSampleMaski(JNIEnv *env, jclass clazz, jint index, jint mask, jlong function_pointer) {
	glSampleMaskiPROC glSampleMaski = (glSampleMaskiPROC)((intptr_t)function_pointer);
	glSampleMaski(index, mask);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBTextureMultisample_glSampleMaski(JNIEnv *__env, jclass clazz, jint index, jint mask) {
    glSampleMaskiPROC glSampleMaski = (glSampleMaskiPROC)tlsGetFunction(656);
    UNUSED_PARAM(clazz)
    glSampleMaski(index, mask);
}
Esempio n. 12
0
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
    // Bind the FBO with multisample buffers
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msFBO);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// User selected order independant transparency
    if (mode == USER_OIT)
    {
        // Use OIT, setup sample masks
        glSampleMaski(0, 0x01);
        glEnable(GL_SAMPLE_MASK);

		// Prevent depth test from culling covered surfaces
        glDepthFunc(GL_ALWAYS);
    }
    
    modelViewMatrix.PushMatrix();	
      M3DMatrix44f mCamera;
      cameraFrame.GetCameraMatrix(mCamera);
      modelViewMatrix.MultMatrix(mCamera);

      modelViewMatrix.PushMatrix();	
        modelViewMatrix.Translate(0.0f, -0.4f, -4.0f);
        modelViewMatrix.Rotate(worldAngle, 0.0, 1.0, 0.0);

		// Draw the background and disk to the first sample
        modelViewMatrix.PushMatrix();
          modelViewMatrix.Translate(0.0f, 3.0f, 0.0f);
          modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0);
          modelViewMatrix.Rotate(90.0, 0.0, 0.0, 1.0);
          glBindTexture(GL_TEXTURE_2D, textures[1]); 
          shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
          bckgrndCylBatch.Draw();
        modelViewMatrix.PopMatrix();
        
        modelViewMatrix.Translate(0.0f, -0.3f, 0.0f);
        modelViewMatrix.PushMatrix();
            modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0);
            shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey);
            diskBatch.Draw();
        modelViewMatrix.PopMatrix();
		modelViewMatrix.Translate(0.0f, 0.1f, 0.0f);

		// User selected blending
        if (mode == USER_BLEND)
        {
            // Setup blend state
			glDisable(GL_DEPTH_TEST);
            glEnable(GL_BLEND);
            switch (blendMode)
            {
            case 1:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 2:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
                break;
            case 3:
                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 4:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
                break;
            case 5:
                glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
                break;
            case 6:
                glBlendFuncSeparate(GL_SRC_ALPHA, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 7:
                glBlendFuncSeparate(GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            default:
                glDisable(GL_BLEND);
            }
        }
   
		// Now draw the glass pieces
        DrawWorld();
    
      modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();
    
    // Clean up all state 
    glDepthFunc(GL_LEQUAL);
    glDisable(GL_BLEND);
    glDisable(GL_SAMPLE_MASK);
    glSampleMaski(0, 0xffffffff);

    // Resolve multisample buffer
    projectionMatrix.PushMatrix();
      projectionMatrix.LoadMatrix(orthoMatrix);
      modelViewMatrix.PushMatrix();
        modelViewMatrix.LoadIdentity();
		// Setup and Clear the default framebuffer
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
        glViewport(0, 0, screenWidth, screenHeight);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        if (mode == USER_OIT)
            SetupOITResolveProg();
        else if (mode == USER_BLEND)
            SetupResolveProg();

		// Draw a full-size quad to resolve the multisample surfaces
        screenQuad.Draw();
      modelViewMatrix.PopMatrix();
    projectionMatrix.PopMatrix();
    
	// Reset texture state
    glEnable(GL_DEPTH_TEST);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
               
    // Do the buffer Swap
    glutSwapBuffers();
        
    // Do it again
    glutPostRedisplay();
}