Example #1
0
// Draw the skybox
void GLSkybox::Draw(GL3DProgram * program)
{
    // Bind the vertex array object
    glBindVertexArray(vertexArrayObject);

    // If the program has changed
    if(program != previousProgram)
    {
        // Bind the vertices to the VAO
        glEnableVertexAttribArray(program->AttributeVertex());
        glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
        glVertexAttribPointer(program->AttributeVertex(), 3, GL_FLOAT, GL_FALSE, 0, 0);

        // Bind the indices to the VAO
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
    }

    // Center the skybox
    program->Model.Reset();
    program->Apply();

    // Bind the texture
    glActiveTexture(GL_TEXTURE0);
    textureCache.GetTexture<GLTextureCubeMap>(skyboxName)->Bind();

    // Draw the skybox (at the most distant distance)
    glDepthRangef(1, 1);
    glDrawElements(GL_TRIANGLES, sizeof(cube_indices) / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);
    glDepthRangef(0, 1);
}
Example #2
0
		void setOpenGLOptions(pipeline_map& pipelines)
		{

			Pipeline& mainPipeline = pipelines["main"];

			// Enabling face culling
			glEnable(GL_CULL_FACE);
			glCullFace(GL_BACK);

			//Clockwise winding order
			glFrontFace(GL_CW);

			// Enable blending (for alpha transparency)
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Linear

			// Enable Depth test --> 0.0f = near, 1.0f = far.
			glEnable(GL_DEPTH_TEST);
			glDepthMask(GL_TRUE);
			glDepthFunc(GL_LEQUAL);
			glDepthRangef(mainPipeline.fWindowZNear, mainPipeline.fWindowZFar);
			glEnable(GL_DEPTH_CLAMP);

			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
		}
Example #3
0
/*!
  The draw function for the viewport sets up all of the lighting parameters for the scene before
  iterating through the top level items in the scene and drawing them using \a painter.

  As a matter of course each item will draw its child items, and so on, until the entire image has
  been populated.
*/
void Viewport::draw(QGLPainter *painter)
{
    // Set up the initial depth, blend, and other options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif
    painter->setBlendingEnabled(d->blending);
    qt_gl_BlendColor(0, 0, 0, 0);
    qt_gl_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    qt_gl_BlendEquation(GL_FUNC_ADD);
    painter->setCullFaces(QGL::CullDisabled);
    if (!d->view)
        painter->setPicking(d->showPicking);

    painter->setObjectPickId(-1);
    QObjectList list = QObject::children();    
    bool haveLights = false;
    foreach (QObject *child, list) {
        QGLLightParameters *light = qobject_cast<QGLLightParameters *>(child);
        if (light) {
            painter->setMainLight(light, QMatrix4x4());
            break;
        }
    }
Example #4
0
/*!
    \internal
*/
void QGLView::initializeGL()
{
    d->logEnter("QGLView::initializeGL");
    QGLPainter painter;
    painter.begin();

    // Set the default depth buffer options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif

    // Set the default blend options.
    qt_gl_BlendColor(0, 0, 0, 0);
    qt_gl_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    qt_gl_BlendEquation(GL_FUNC_ADD);

    painter.setCullFaces(QGL::CullDisabled);
    initializeGL(&painter);
    d->logLeave("QGLView::initializeGL");
}
    void configure() {
        s_textureUnit = -1;
        s_validGeneration++;
        VertexLayout::clearCache();

        blending.init(GL_FALSE);
        blendingFunc.init(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        culling.init(GL_TRUE);
        cullFace.init(GL_BACK);
        frontFace.init(GL_CCW);
        depthTest.init(GL_TRUE);
        depthWrite.init(GL_TRUE);

        glDisable(GL_STENCIL_TEST);
        glDepthFunc(GL_LEQUAL);
        glClearDepthf(1.0);
        glDepthRangef(0.0, 1.0);

        static size_t max = std::numeric_limits<size_t>::max();

        clearColor.init(0.0, 0.0, 0.0, 0.0);
        shaderProgram.init(max, false);
        vertexBuffer.init(max, false);
        indexBuffer.init(max, false);
        texture.init(GL_TEXTURE_2D, max, false);
        texture.init(GL_TEXTURE_CUBE_MAP, max, false);
        textureUnit.init(max, false);
    }
void g_makeCurrent()
{
    LOGE("g_makeCurrent-->start L:366");
    LOGE("Got bwdisplay %p", bwdisplay);
    LOGE("Got bwsurface %p", bwsurface);
    LOGE("Got bwcontext %p", bwcontext);
    if (!eglMakeCurrent(bwdisplay, bwsurface, bwsurface, bwcontext)) {
        LOGI("eglMakeCurrent() returned error %d", eglGetError());
        g_destroyGL();
    }
    printGLString("Version", GL_VERSION);
    printGLString("Vendor", GL_VENDOR);
    printGLString("Renderer", GL_RENDERER);
    printGLString("Extensions", GL_EXTENSIONS);
    
    glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
    
    glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, GL_NICEST );
    
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_CULL_FACE  );
    glDisable( GL_DITHER );
    glDepthMask( GL_TRUE );
    glDepthFunc( GL_LESS );
    glDepthRangef( 0.0f, 1.0f );
    glClearDepthf( 1.0f );
    glCullFace ( GL_BACK );
    glFrontFace( GL_CCW  );
    glClearStencil( 0 );
    glStencilMask( 0xFFFFFFFF );
}
Example #7
0
/*!
    \internal
*/
void QGLView::initializeGL()
{
    d->logEnter("QGLView::initializeGL");
    QGLPainter painter;
    painter.begin();

    // Set the default depth buffer options.
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif

    // Set the default blend options.
    if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendColor))
        painter.glBlendColor(0, 0, 0, 0);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
        painter.glBlendEquation(GL_FUNC_ADD);
    else if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
        painter.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);

    glDisable(GL_CULL_FACE);
    initializeGL(&painter);
    d->logLeave("QGLView::initializeGL");
}
void MapNode::restoreDefaults(QGLPainter *painter)
{
    // Disable the effect to return control to the GL paint engine.
    painter->disableEffect();

    // Try to restore the default options
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    // Set the default depth buffer options.
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif
    // Set the default blend options.
    glDisable(GL_BLEND);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendColor))
        painter->glBlendColor(0, 0, 0, 0);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
        painter->glBlendEquation(GL_FUNC_ADD);
    else if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
        painter->glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
}
void OpenGLEngine::SetDepthRange (float nearVal, float farVal)
{
	m_DepthRange.m_Near = nearVal;
	m_DepthRange.m_Far = farVal;

	glDepthRangef (nearVal, farVal);
}
Example #10
0
//-----------------------------------------------------------------------
void GraphicsContextGL4::SetViewport(Viewport const& viewport)
{
    POMDOG_ASSERT(viewport.Width > 0);
    POMDOG_ASSERT(viewport.Height > 0);

    GLint viewportY = viewport.TopLeftY;

    if (renderTargets.empty()) {
        if (auto window = gameWindow.lock()) {
            viewportY = window->GetClientBounds().Height - (viewport.TopLeftY + viewport.Height);
        }
    }

    glViewport(viewport.TopLeftX, viewportY, viewport.Width, viewport.Height);
    POMDOG_CHECK_ERROR_GL4("glViewport");

    static_assert(std::is_same<GLfloat, decltype(viewport.MinDepth)>::value
                  && std::is_same<GLfloat, decltype(viewport.MaxDepth)>::value,
                  "NOTE: You can use glDepthRange instead of glDepthRangef");

    POMDOG_ASSERT(!std::isinf(viewport.MinDepth));
    POMDOG_ASSERT(!std::isinf(viewport.MaxDepth));
    POMDOG_ASSERT(!std::isnan(viewport.MinDepth));
    POMDOG_ASSERT(!std::isnan(viewport.MaxDepth));

    glDepthRangef(viewport.MinDepth, viewport.MaxDepth);
    POMDOG_CHECK_ERROR_GL4("glDepthRangef");
}
enum piglit_result
piglit_display(void)
{
#ifdef GL_ARB_ES2_compatibility
	GLboolean pass = GL_TRUE;
	float red[4] =   {1.0, 0.0, 0.0, 0.0};
	float green[4] = {0.0, 1.0, 0.0, 0.0};
	float blue[4] =  {0.0, 0.0, 1.0, 0.0};

	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);

	glClearColor(0.0, 0.0, 1.0, 0.0);

	glClearDepthf(0.5);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	/* Keep in mind that the ortho projection flips near and far's signs,
	 * so 1.0 to quad()'s z maps to glDepthRange's near, and -1.0 maps to
	 * glDepthRange's far.
	 */

	glColor4fv(green);
	glDepthRangef(0, 1);
	piglit_draw_rect_z(0.5,
			   0, 0,
			   piglit_width / 2, piglit_height);

	glColor4fv(red);
	glDepthRangef(1, 0);
	piglit_draw_rect_z(0.5,
			   piglit_width / 2, 0,
			   piglit_width, piglit_height);

	pass = piglit_probe_pixel_rgb(piglit_width * 1 / 4, piglit_height / 2,
				      green) && pass;
	pass = piglit_probe_pixel_rgb(piglit_width * 3 / 4, piglit_height / 2,
				      blue) && pass;

	glutSwapBuffers();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
#else
	return PIGLIT_SKIP;
#endif /* GL_ARB_ES2_compatibility */
}
void COGLGraphicsContext::InitState(void)
{
    m_pRenderStr = glGetString(GL_RENDERER);
    m_pExtensionStr = glGetString(GL_EXTENSIONS);
    m_pVersionStr = glGetString(GL_VERSION);
    m_pVendorStr = glGetString(GL_VENDOR);
    //glMatrixMode(GL_PROJECTION);
    //OPENGL_CHECK_ERRORS;
    //glLoadIdentity();
    //OPENGL_CHECK_ERRORS;

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    OPENGL_CHECK_ERRORS;
    glClearDepthf(1.0f);
    OPENGL_CHECK_ERRORS;

    //glShadeModel(GL_SMOOTH);
    //OPENGL_CHECK_ERRORS;

    //position viewer 
    //glMatrixMode(GL_MODELVIEW);
    //glLoadIdentity();

    //glDisable(GL_ALPHA_TEST);
    //OPENGL_CHECK_ERRORS;

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    OPENGL_CHECK_ERRORS;
    glDisable(GL_BLEND);
    OPENGL_CHECK_ERRORS;

    glFrontFace(GL_CCW);
    OPENGL_CHECK_ERRORS;
    glDisable(GL_CULL_FACE);
    OPENGL_CHECK_ERRORS;
    //glDisable(GL_NORMALIZE);
    //OPENGL_CHECK_ERRORS;

    glDepthFunc(GL_LEQUAL);
    OPENGL_CHECK_ERRORS;
    glEnable(GL_DEPTH_TEST);
    OPENGL_CHECK_ERRORS;

    //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    //OPENGL_CHECK_ERRORS;

    glEnable(GL_BLEND);
    OPENGL_CHECK_ERRORS;
    //glEnable(GL_ALPHA_TEST);
    //OPENGL_CHECK_ERRORS;

    //glMatrixMode(GL_PROJECTION);
    //OPENGL_CHECK_ERRORS;
    //glLoadIdentity();
    //OPENGL_CHECK_ERRORS;
    
    glDepthRangef(0.0f, 1.0f);
    OPENGL_CHECK_ERRORS;
}
void sglDepthRangef(GLclampd zNear, GLclampd zFar)
{
#ifdef GLES
   glDepthRangef(zNear, zFar);
#else
   glDepthRange(zNear, zFar);
#endif
}
Example #14
0
void KRSprite::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass) {
    
    if(m_lod_visible >= LOD_VISIBILITY_PRESTREAM && renderPass == KRNode::RENDER_PASS_PRESTREAM) {
        // Pre-stream sprites, even if the alpha is zero
        if(m_spriteTexture.size() && m_pSpriteTexture == NULL) {
            if(!m_pSpriteTexture && m_spriteTexture.size()) {
                m_pSpriteTexture = getContext().getTextureManager()->getTexture(m_spriteTexture);
            }
        }
        
        if(m_pSpriteTexture) {
            m_pSpriteTexture->resetPoolExpiry(0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
        }
    }
    
    if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
    
    KRNode::render(pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
    
    
    if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
        if(m_spriteTexture.size() && m_spriteAlpha > 0.0f) {
            

            if(!m_pSpriteTexture && m_spriteTexture.size()) {
                m_pSpriteTexture = getContext().getTextureManager()->getTexture(m_spriteTexture);
            }
            
            if(m_pSpriteTexture) {
                /*
                // Enable additive blending
                GLDEBUG(glEnable(GL_BLEND));
                GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
                
                // Disable z-buffer write
                GLDEBUG(glDepthMask(GL_FALSE));
                 */
                
                // TODO - Sprites are currently additive only.  Need to expose this and allow for multiple blending modes
                
                // Enable z-buffer test
                GLDEBUG(glEnable(GL_DEPTH_TEST));
                GLDEBUG(glDepthFunc(GL_LEQUAL));
                GLDEBUG(glDepthRangef(0.0, 1.0));
                
                // Render light sprite on transparency pass
                KRShader *pShader = getContext().getShaderManager()->getShader("sprite", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
                if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, getModelMatrix(), point_lights, directional_lights, spot_lights, 0, renderPass, KRVector3::Zero(), 0.0f, KRVector4::Zero())) {
                    pShader->setUniform(KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA, m_spriteAlpha);
                    m_pContext->getTextureManager()->selectTexture(0, m_pSpriteTexture, 0.0f, KRTexture::TEXTURE_USAGE_SPRITE);
                    m_pContext->getMeshManager()->bindVBO(&m_pContext->getMeshManager()->KRENGINE_VBO_DATA_2D_SQUARE_VERTICES, 1.0f);
                    GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
                }
            }
        }
        
    }
}
Example #15
0
void GraphicsContext3D::depthRange(GC3Dclampf zNear, GC3Dclampf zFar)
{
    makeContextCurrent();
#if defined(QT_OPENGL_ES_2)
    glDepthRangef(zNear, zFar);
#else
    glDepthRange(zNear, zFar);
#endif
}
Example #16
0
	void SetViewports(int count, T3DViewport *viewports) override {
		// TODO: Add support for multiple viewports.
		glViewport(viewports[0].TopLeftX, viewports[0].TopLeftY, viewports[0].Width, viewports[0].Height);
#if defined(USING_GLES2)
		glDepthRangef(viewports[0].MinDepth, viewports[0].MaxDepth);
#else
		glDepthRange(viewports[0].MinDepth, viewports[0].MaxDepth);
#endif
	}
Example #17
0
void RiftAppSkeleton::_resetGLState() const
{
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthRangef(0.0f, 1.0f);
    glDepthFunc(GL_LESS);

    glDisable(GL_CULL_FACE);
    glFrontFace(GL_CCW);
}
Example #18
0
void rglDepthRange(GLclampd zNear, GLclampd zFar)
{
#ifdef HAVE_OPENGLES
   glDepthRangef(zNear, zFar);
#else
   glDepthRange(zNear, zFar);
#endif
   gl_state.depthrange.used  = true;
   gl_state.depthrange.zNear = zNear;
   gl_state.depthrange.zFar  = zFar;
}
Example #19
0
    void initialize() {

        logMsg("initialize\n");

        // Create view
        if (!m_view) {
            m_view = std::make_shared<View>();
        }

        // Create a scene object
        if (!m_scene) {
            m_scene = std::make_shared<Scene>();

            m_skybox = std::shared_ptr<Skybox>(new Skybox("cubemap.png"));
            m_skybox->init();
        }

        // Create a tileManager
        if (!m_tileManager) {
            m_tileManager = TileManager::GetInstance();

            // Pass references to the view and scene into the tile manager
            m_tileManager->setView(m_view);
            m_tileManager->setScene(m_scene);
        }

        // Hard-coded setup for stuff that isn't loaded through the config file yet
        m_ftContext = std::make_shared<FontContext>();
        m_ftContext->addFont("FiraSans-Medium.ttf", "FiraSans");
        m_labels = Labels::GetInstance();
        m_labels->setFontContext(m_ftContext);
        m_labels->setView(m_view);

        SceneLoader loader;
        loader.loadScene("config.yaml", *m_scene, *m_tileManager, *m_view);

        // Set up openGL state
        glDisable(GL_BLEND);
        glDisable(GL_STENCIL_TEST);
        glEnable(GL_DEPTH_TEST);
        glClearDepthf(1.0);
        glDepthRangef(0.0, 1.0);
        glDepthMask(GL_TRUE);
        glDepthFunc(GL_LEQUAL);
        glEnable(GL_CULL_FACE);
        glFrontFace(GL_CCW);
        glCullFace(GL_BACK);
        glClearColor(0.3f, 0.3f, 0.3f, 1.0f);

        while (Error::hadGlError("Tangram::initialize()")) {}

        logMsg("finish initialize\n");

    }
void GFX_start( void )
{
	memset( &gfx, 0, sizeof( GFX ) );
	
	#ifdef __IPHONE_4_0
	
		printf("\nGL_VENDOR:      %s\n", ( char * )glGetString( GL_VENDOR     ) );
		printf("GL_RENDERER:    %s\n"  , ( char * )glGetString( GL_RENDERER   ) );
		printf("GL_VERSION:     %s\n"  , ( char * )glGetString( GL_VERSION    ) );
		printf("GL_EXTENSIONS:  %s\n"  , ( char * )glGetString( GL_EXTENSIONS ) );
	#else
	
		__android_log_print( ANDROID_LOG_INFO, "", "\nGL_VENDOR:      %s\n", ( char * )glGetString( GL_VENDOR     ) );
		__android_log_print( ANDROID_LOG_INFO, "", "GL_RENDERER:    %s\n"  , ( char * )glGetString( GL_RENDERER   ) );
		__android_log_print( ANDROID_LOG_INFO, "", "GL_VERSION:     %s\n"  , ( char * )glGetString( GL_VERSION    ) );
		__android_log_print( ANDROID_LOG_INFO, "", "GL_EXTENSIONS:  %s\n"  , ( char * )glGetString( GL_EXTENSIONS ) );
	#endif

	glHint( GL_GENERATE_MIPMAP_HINT, GL_NICEST );
	
	glHint( GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES, GL_NICEST );
	
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE  );
	glDisable( GL_DITHER );
	glDepthMask( GL_TRUE );
	glDepthFunc( GL_LESS );
	glDepthRangef( 0.0f, 1.0f );
	glCullFace ( GL_BACK );
	glFrontFace( GL_CCW  );
	glClearStencil( 0 );
	glStencilMask( 0xFFFFFFFF );
	
	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
	
	glClear( GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT );

	#ifndef __IPHONE_4_0

		glBindVertexArrayOES 	= ( PFNGLBINDVERTEXARRAYOESPROC    ) eglGetProcAddress("glBindVertexArrayOES"  );
		glGenVertexArraysOES 	= ( PFNGLGENVERTEXARRAYSOESPROC    ) eglGetProcAddress("glGenVertexArraysOES"  );
		glDeleteVertexArraysOES = ( PFNGLDELETEVERTEXARRAYSOESPROC ) eglGetProcAddress("glDeleteVertexArraysOES");
	#endif
	
	GFX_set_matrix_mode( TEXTURE_MATRIX );
	GFX_load_identity();

	GFX_set_matrix_mode( PROJECTION_MATRIX );
	GFX_load_identity();

	GFX_set_matrix_mode( MODELVIEW_MATRIX );
	GFX_load_identity();
}
	//-------------------------------------------------------------------------------------------------------
	void OpenGLGraphicSystem::OnFrameworkEntry( float time, BohgeEngine::Framework& framework )
	{
		glEnable(GL_TEXTURE_2D);//默认打开2D纹理
		glDisable(GL_DITHER);
		glDepthRangef( 0.0, 1.0 );
		glDisable(GL_DEPTH_TEST);
		glDisable(GL_CULL_FACE);
		glDepthMask(false);
		glDisable(GL_BLEND);
		glEnable(GL_PROGRAM_POINT_SIZE);
		glEnable( GL_POINT_SPRITE );
		m_pGlslopt_ctx = glslopt_initialize( kGlslTargetOpenGL );
	}
Example #22
0
void GL::GeometryBuffer::SetDepthRange(float nearDepth, float farDepth) const {
	#if 0
	if (globalRendering->supportClipSpaceControl) {
		// TODO: need to inform shaders about this, modify PM instead
		glDepthRangef(nearDepth, farDepth);
		glClearDepth(farDepth);
		glDepthFunc((nearDepth <= farDepth)? GL_LEQUAL: GL_GREATER);
	}
	#else
	glClearDepth(std::max(nearDepth, farDepth));
	glDepthFunc(GL_LEQUAL);
	#endif
}
Example #23
0
void wyDirector::setDepthTest(bool on) {
	m_enableDepthTest = on;
	if(m_surfaceCreated && isGLThread()) {
		/* 启动禁用深度测试 */
		if(on) {
			glEnable(GL_DEPTH_TEST);
			glDepthFunc(GL_LEQUAL);
			glDepthRangef(0, 1);
			glClearDepthf(1);
		} else {
			glDisable(GL_DEPTH_TEST);
		}
	}
}
Example #24
0
/*
=============
R_Clear
=============
*/
void R_Clear (void)
{
	if (r_mirroralpha.value != 1.0)
	{
		if (gl_clear.value)
			glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		else
			glClear (GL_DEPTH_BUFFER_BIT);
		gldepthmin = 0;
		gldepthmax = 0.5;
		glDepthFunc (GL_LEQUAL);
	}
	else if (gl_ztrick.value)
	{
		static int trickframe;

		if (gl_clear.value)
			glClear (GL_COLOR_BUFFER_BIT);

		trickframe++;
		if (trickframe & 1)
		{
			gldepthmin = 0;
			gldepthmax = 0.49999;
			glDepthFunc (GL_LEQUAL);
		}
		else
		{
			gldepthmin = 1;
			gldepthmax = 0.5;
			glDepthFunc (GL_GEQUAL);
		}
	}
	else
	{
		if (gl_clear.value)
			glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		else
			glClear (GL_DEPTH_BUFFER_BIT);
		gldepthmin = 0;
		gldepthmax = 1;
		glDepthFunc (GL_LEQUAL);
	}

#ifdef USE_OPENGLES
	glDepthRangef (gldepthmin, gldepthmax);
#else
	glDepthRange (gldepthmin, gldepthmax);
#endif
}
Example #25
0
void CubeWindow::initializeGL()
{
    initializeOpenGLFunctions();
    m_program = new QOpenGLShaderProgram(this);
    m_program->addShaderFromSourceCode(QOpenGLShader::Vertex, vertexShaderSrc);
    m_program->addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShaderSrc);
    m_program->link();
    m_posAtr = m_program->attributeLocation("position");
    m_colorAtr = m_program->attributeLocation("color");
    m_perspectiveMatrixUniform = m_program->uniformLocation("perspectiveMatrix");

    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LEQUAL);
    glDepthRangef(0.0f, 1.0f);
}
void Engine::GraphicsRenderer::setSkyboxState() const
{
     glBindFramebuffer(GL_FRAMEBUFFER, 0);

     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

     glEnable(GL_DEPTH_TEST);
     glDepthFunc(GL_LESS);
     glDepthMask(GL_FALSE);

     glDisable(GL_STENCIL_TEST);

     glDisable(GL_BLEND);

     glDisable(GL_CULL_FACE);

     glViewport(0, 0, _width, _height);
     glDepthRangef(0.0f, 1.0f);
}
Example #27
0
static void
flush_depth_state (CoglContext *ctx,
                   CoglDepthState *depth_state)
{
  if (ctx->depth_test_enabled_cache != depth_state->test_enabled)
    {
      if (depth_state->test_enabled == TRUE)
        GE (ctx, glEnable (GL_DEPTH_TEST));
      else
        GE (ctx, glDisable (GL_DEPTH_TEST));
      ctx->depth_test_enabled_cache = depth_state->test_enabled;
    }

  if (ctx->depth_test_function_cache != depth_state->test_function &&
      depth_state->test_enabled == TRUE)
    {
      GE (ctx, glDepthFunc (depth_state->test_function));
      ctx->depth_test_function_cache = depth_state->test_function;
    }

  if (ctx->depth_writing_enabled_cache != depth_state->write_enabled)
    {
      GE (ctx, glDepthMask (depth_state->write_enabled ?
                            GL_TRUE : GL_FALSE));
      ctx->depth_writing_enabled_cache = depth_state->write_enabled;
    }

  if (ctx->driver != COGL_DRIVER_GLES1 &&
      (ctx->depth_range_near_cache != depth_state->range_near ||
       ctx->depth_range_far_cache != depth_state->range_far))
    {
      if (ctx->private_feature_flags & COGL_PRIVATE_FEATURE_GL_EMBEDDED)
        GE (ctx, glDepthRangef (depth_state->range_near,
                                depth_state->range_far));
      else
        GE (ctx, glDepthRange (depth_state->range_near,
                               depth_state->range_far));

      ctx->depth_range_near_cache = depth_state->range_near;
      ctx->depth_range_far_cache = depth_state->range_far;
    }
}
Example #28
0
void KRAudioSource::render(KRCamera *pCamera, std::vector<KRPointLight *> &point_lights, std::vector<KRDirectionalLight *> &directional_lights, std::vector<KRSpotLight *>&spot_lights, const KRViewport &viewport, KRNode::RenderPass renderPass)
{
    
    if(m_lod_visible <= LOD_VISIBILITY_PRESTREAM) return;
    
    KRNode::render(pCamera, point_lights, directional_lights, spot_lights, viewport, renderPass);
    
    bool bVisualize = false;
    
    if(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
        Matrix4 sphereModelMatrix = getModelMatrix();
        
        KRShader *pShader = getContext().getShaderManager()->getShader("visualize_overlay", pCamera, point_lights, directional_lights, spot_lights, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
        
        if(getContext().getShaderManager()->selectShader(*pCamera, pShader, viewport, sphereModelMatrix, point_lights, directional_lights, spot_lights, 0, renderPass, Vector3::Zero(), 0.0f, Vector4::Zero())) {
            
            // Enable additive blending
            GLDEBUG(glEnable(GL_BLEND));
            GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
            
            
            // Disable z-buffer write
            GLDEBUG(glDepthMask(GL_FALSE));
            
            // Enable z-buffer test
            GLDEBUG(glEnable(GL_DEPTH_TEST));
            GLDEBUG(glDepthFunc(GL_LEQUAL));
            GLDEBUG(glDepthRangef(0.0, 1.0));
            std::vector<KRMesh *> sphereModels = getContext().getMeshManager()->getModel("__sphere");
            if(sphereModels.size()) {
                for(int i=0; i < sphereModels[0]->getSubmeshCount(); i++) {
                    sphereModels[0]->renderSubmesh(i, renderPass, getName(), "visualize_overlay", 1.0f);
                }
            }
            
            // Enable alpha blending
            GLDEBUG(glEnable(GL_BLEND));
            GLDEBUG(glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA));
        }
    }
}
Example #29
0
static void
flush_depth_state(cg_device_t *dev, cg_depth_state_t *depth_state)
{
    bool depth_writing_enabled = depth_state->write_enabled;

    if (dev->current_draw_buffer)
        depth_writing_enabled &=
            dev->current_draw_buffer->depth_writing_enabled;

    if (dev->depth_test_enabled_cache != depth_state->test_enabled) {
        if (depth_state->test_enabled == true)
            GE(dev, glEnable(GL_DEPTH_TEST));
        else
            GE(dev, glDisable(GL_DEPTH_TEST));
        dev->depth_test_enabled_cache = depth_state->test_enabled;
    }

    if (dev->depth_test_function_cache != depth_state->test_function &&
        depth_state->test_enabled == true) {
        GE(dev, glDepthFunc(depth_state->test_function));
        dev->depth_test_function_cache = depth_state->test_function;
    }

    if (dev->depth_writing_enabled_cache != depth_writing_enabled) {
        GE(dev, glDepthMask(depth_writing_enabled ? GL_TRUE : GL_FALSE));
        dev->depth_writing_enabled_cache = depth_writing_enabled;
    }

    if (dev->depth_range_near_cache != depth_state->range_near ||
        dev->depth_range_far_cache != depth_state->range_far) {
        if (_cg_has_private_feature(dev, CG_PRIVATE_FEATURE_GL_EMBEDDED))
            GE(dev,
               glDepthRangef(depth_state->range_near, depth_state->range_far));
        else
            GE(dev,
               glDepthRange(depth_state->range_near, depth_state->range_far));

        dev->depth_range_near_cache = depth_state->range_near;
        dev->depth_range_far_cache = depth_state->range_far;
    }
}
void QGLGraphicsViewportItemPrivate::setDefaults(QGLPainter *painter)
{
    // Set the default depth buffer options.
    glDepthFunc(GL_LESS);
    glDepthMask(GL_TRUE);
#if defined(QT_OPENGL_ES)
    glDepthRangef(0.0f, 1.0f);
#else
    glDepthRange(0.0f, 1.0f);
#endif

    // Set the default blend options.
    glDisable(GL_BLEND);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendColor))
        painter->glBlendColor(0, 0, 0, 0);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquation))
        painter->glBlendEquation(GL_FUNC_ADD);
    else if (painter->hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate))
        painter->glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
}