Пример #1
0
void OpenGLRenderer::SetRenderState(RenderState renderState, bool enable) {
	
	switch(renderState) {
		
		case AlphaBlending: {
			setGLState(GL_BLEND, enable);
			break;
		}
		
		case AlphaTest: {
			setGLState(GL_ALPHA_TEST, enable);
			break;
		}

		case ColorKey: {
			SetRenderState(AlphaTest, enable);
			if(enable)
				SetAlphaFunc(CmpNotEqual, 0.0f);
			break;
		}
		
		case DepthTest: {
			setGLState(GL_DEPTH_TEST, enable);
			break;
		}
		
		case DepthWrite: {
			glDepthMask(enable ? GL_TRUE : GL_FALSE);
			break;
		}
		
		case Fog: {
			setGLState(GL_FOG, enable);
			break;
		}
		
		case Lighting: {
			setGLState(GL_LIGHTING, enable);
			break;
		}
		
		case ZBias: {
			setGLState(GL_POLYGON_OFFSET_FILL, enable);
			break;
		}
		
		default:
			LogWarning << "unsupported render state: " << renderState;
	}
	
	CHECK_GL;
}
Пример #2
0
void OpenGLRenderer::SetRenderState(RenderState renderState, bool enable) {
	
	switch(renderState) {
		
		case AlphaBlending: {
			if(m_hasBlend == enable) {
				return;
			}
			/*
			 * When rendering color-keyed textures with GL_BLEND enabled we still
			 * need to 'discard' transparent texels, as blending might not use the src alpha!
			 * On the other hand, we can't use GL_SAMPLE_ALPHA_TO_COVERAGE when blending
			 * as that could result in the src alpha being applied twice (e.g. for text).
			 * So we must toggle between alpha to coverage and alpha test when toggling blending.
			 * TODO Fix it so that the apha channel from the color-keyed textures is
			 *      always used as part of the blending factor.
			 */
			bool colorkey = m_hasColorKey;
			if(colorkey && m_hasMSAA) {
				SetRenderState(ColorKey, false);
			}
			m_hasBlend = enable;
			if(colorkey && m_hasMSAA) {
				SetRenderState(ColorKey, true);
			}
			setGLState(GL_BLEND, enable);
			break;
		}
		
		case ColorKey: {
			if(m_hasColorKey == enable) {
				return;
			}
			m_hasColorKey = enable;
			if(m_hasMSAA && !m_hasBlend) {
				// TODO(option-video) add a config option for this
				setGLState(GL_SAMPLE_ALPHA_TO_COVERAGE, enable);
			} else {
				setGLState(GL_ALPHA_TEST, enable);
				if(enable) {
					SetAlphaFunc(CmpNotEqual, 0.0f);
				}
			}
			break;
		}
		
		case DepthTest: {
			glDepthFunc(enable ? GL_LEQUAL : GL_ALWAYS);
			break;
		}
		
		case DepthWrite: {
			glDepthMask(enable ? GL_TRUE : GL_FALSE);
			break;
		}
		
		case Fog: {
			setGLState(GL_FOG, enable);
			break;
		}
		
		case Lighting: {
			setGLState(GL_LIGHTING, enable);
			break;
		}
		
		case ZBias: {
			setGLState(GL_POLYGON_OFFSET_FILL, enable);
			break;
		}
		
		default:
			LogWarning << "Unsupported render state: " << renderState;
	}
}