1. dbacchet
  2. dbsdev

Commits

dbacchet  committed b847e4d

started restructuring OpenGL rid
removed srgb texture support (and complication…)

  • Participants
  • Parent commits df8beea
  • Branches default

Comments (0)

Files changed (17)

File temp/test_hordefiles/egCom.cpp

View file
 	trilinearFiltering = true;
 	maxAnisotropy = 1;
 	texCompression = false;
-	sRGBLinearization = false;
 	loadTextures = true;
 	fastAnimation = true;
 	shadowMapSize = 1024;
 		return (float)maxAnisotropy;
 	case EngineOptions::TexCompression:
 		return texCompression ? 1.0f : 0.0f;
-	case EngineOptions::SRGBLinearization:
-		return sRGBLinearization ? 1.0f : 0.0f;
 	case EngineOptions::LoadTextures:
 		return loadTextures ? 1.0f : 0.0f;
 	case EngineOptions::FastAnimation:
 	case EngineOptions::TexCompression:
 		texCompression = (value != 0);
 		return true;
-	case EngineOptions::SRGBLinearization:
-		sRGBLinearization = (value != 0);
-		return true;
 	case EngineOptions::LoadTextures:
 		loadTextures = (value != 0);
 		return true;
 		
 		if( !Modules::renderer().createShadowRB( size, size ) )
 		{
-			Modules::log().warning( "Failed to create shadow map" );
+			Modules::log().warning( "Failed to create shadow map GGG" );
 			// Restore old buffer
 			Modules::renderer().createShadowRB( shadowMapSize, shadowMapSize );
 			return false;

File temp/test_hordefiles/egCom.h

View file
 	MaxAnisotropy       - Sets the maximum quality for anisotropic filtering. (Values: 1, 2, 4, 8; Default: 1)
 	TexCompression      - Enables or disables texture compression; only affects textures that are
 	                      loaded after setting the option. (Values: 0, 1; Default: 0)
-	SRGBLinearization   - Eanbles or disables gamma-to-linear-space conversion of input textures that are tagged as sRGB (Values: 0, 1; Default: 0)
 	LoadTextures        - Enables or disables loading of textures referenced by materials; this can be useful to reduce
 	                      loading times for testing. (Values: 0, 1; Default: 1)
 	FastAnimation       - Disables or enables inter-frame interpolation for animations. (Values: 0, 1; Default: 1)
 		TrilinearFiltering,
 		MaxAnisotropy,
 		TexCompression,
-		SRGBLinearization,
 		LoadTextures,
 		FastAnimation,
 		ShadowMapSize,
 	int   shadowMapSize;
 	int   sampleCount;
 	bool  texCompression;
-	bool  sRGBLinearization;
 	bool  loadTextures;
 	bool  fastAnimation;
 	bool  trilinearFiltering;

File temp/test_hordefiles/egGeometry.cpp

View file
-// *************************************************************************************************
-//
-// Horde3D
-//   Next-Generation Graphics Engine
-// --------------------------------------
-// Copyright (C) 2006-2011 Nicolas Schulz
-//
-// This software is distributed under the terms of the Eclipse Public License v1.0.
-// A copy of the license may be obtained at: http://www.eclipse.org/legal/epl-v10.html
-//
-// *************************************************************************************************
+// // *************************************************************************************************
+// //
+// // Horde3D
+// //   Next-Generation Graphics Engine
+// // --------------------------------------
+// // Copyright (C) 2006-2011 Nicolas Schulz
+// //
+// // This software is distributed under the terms of the Eclipse Public License v1.0.
+// // A copy of the license may be obtained at: http://www.eclipse.org/legal/epl-v10.html
+// //
+// // *************************************************************************************************
 
 #include "engine_logger.h"
 #include "egGeometry.h"
 #include "egResource.h"
-#include "egAnimation.h"
+// #include "egAnimation.h"
 #include "egModules.h"
-#include "egCom.h"
-#include "egRenderer.h"
-#include <cstring>
+// #include "egCom.h"
+// #include "egRenderer.h"
+#include "engine_renderdevice_opengl.h"
+// #include <cstring>
 
 
 

File temp/test_hordefiles/egMaterial.cpp

View file
 			_stricmp( node1.getAttribute( "mipmaps", "1" ), "0" ) == 0 )
 			flags |= TextureFlags::TexNoMipmaps;
 
-		if( _stricmp( node1.getAttribute( "sRGB", "false" ), "true" ) == 0 ||
-			_stricmp( node1.getAttribute( "sRGB", "0" ), "1" ) == 0 )
-			flags |= TextureFlags::TexSRGB;
-
 		texMap = Modules::resMan().addResource(
 			ResourceTypes::Texture, node1.getAttribute( "map" ), flags );
 

File temp/test_hordefiles/egModules.cpp

View file
 #include "egLight.h"
 #include "egCamera.h"
 #include "egResource.h"
-#include "egRendererBase.h"
+#include "engine_renderdevice_opengl.h"
 #include "egRenderer.h"
 #include "egPipeline.h"
 

File temp/test_hordefiles/egPrerequisites.h

View file
 
 
 
+// ---------------------------------------------------------
+// Textures
+// ---------------------------------------------------------
+
+struct TextureTypes
+{
+	enum List
+	{
+		Tex2D,
+		Tex3D,
+		TexCube,
+		TextureTypesNum
+	};
+};
+
+struct TextureFormats
+{
+	enum List
+	{
+		Unknown,
+		BGRA8,
+		DXT1,
+		DXT3,
+		DXT5,
+		RGBA16F,
+		RGBA32F,
+		DEPTH
+	};
+};
 
 
 

File temp/test_hordefiles/egRenderer.cpp

View file
 
 	// Create default shadow map
 	float shadowTex[16] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
-	_defShadowMap = gRDI->createTexture( TextureTypes::Tex2D, 4, 4, 1, TextureFormats::DEPTH, false, false, false );
+	_defShadowMap = gRDI->createTexture( TextureTypes::Tex2D, 4, 4, 1, TextureFormats::DEPTH, false, false );
 	gRDI->uploadTextureData( _defShadowMap, 0, 0, shadowTex );
 
 	// Create index buffer used for drawing quads

File temp/test_hordefiles/egRenderer.h

View file
 #define _egRenderer_H_
 
 #include "egPrerequisites.h"
-#include "egRendererBase.h"
+#include "engine_renderdevice_opengl.h"
 // #include "egPrimitives.h"
 #include "egModel.h"
 #include <vector>

File temp/test_hordefiles/egRendererBase.cpp

-// *************************************************************************************************
-//
-// Horde3D
-//   Next-Generation Graphics Engine
-// --------------------------------------
-// Copyright (C) 2006-2011 Nicolas Schulz
-//
-// This software is distributed under the terms of the Eclipse Public License v1.0.
-// A copy of the license may be obtained at: http://www.eclipse.org/legal/epl-v10.html
-//
-// *************************************************************************************************
-
-#include "engine_logger.h"
-#include "egRendererBase.h"
-#include "egModules.h"
-#include "egCom.h"
-#include "utOpenGL.h"
-
-
-
-namespace Horde3D {
-
-#ifdef H3D_VALIDATE_DRAWCALLS
-#	define CHECK_GL_ERROR checkGLError();
-#else
-#	define CHECK_GL_ERROR
-#endif
-
-static const char *defaultShaderVS =
-	"uniform mat4 viewProjMat;\n"
-	"uniform mat4 worldMat;\n"
-	"attribute vec3 vertPos;\n"
-	"void main() {\n"
-	"	gl_Position = viewProjMat * worldMat * vec4( vertPos, 1.0 );\n"
-	"}\n";
-
-static const char *defaultShaderFS =
-	"uniform vec4 color;\n"
-	"void main() {\n"
-	"	gl_FragColor = color;\n"
-	"}\n";
-
-
-
-
-// =================================================================================================
-// RenderDevice
-// =================================================================================================
-
-RenderDevice::RenderDevice()
-{
-	_numVertexLayouts = 0;
-	
-	_vpX = 0; _vpY = 0; _vpWidth = 320; _vpHeight = 240;
-	_scX = 0; _scY = 0; _scWidth = 320; _scHeight = 240;
-	_prevShaderId = _curShaderId = 0;
-	_curRendBuf = 0; _outputBufferIndex = 0;
-	_textureMem = 0; _bufferMem = 0;
-	_curRasterState.hash = _newRasterState.hash = 0;
-	_curBlendState.hash = _newBlendState.hash = 0;
-	_curDepthStencilState.hash = _newDepthStencilState.hash = 0;
-	_curVertLayout = _newVertLayout = 0;
-	_curIndexBuf = _newIndexBuf = 0;
-	_defaultFBO = 0;
-	_indexFormat = (uint32_t)IDXFMT_16;
-	_pendingMask = 0;
-}
-
-
-RenderDevice::~RenderDevice()
-{
-}
-
-
-void RenderDevice::initStates()
-{
-	glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
-}
-
-
-bool RenderDevice::init()
-{
-	bool failed = false;
-
-	char *vendor = (char *)glGetString( GL_VENDOR );
-	char *renderer = (char *)glGetString( GL_RENDERER );
-	char *version = (char *)glGetString( GL_VERSION );
-	
-	Modules::log().info( "Initializing GL2 backend using OpenGL driver '%s' by '%s' on '%s'",
-	                          version, vendor, renderer );
-	
-	// Init extensions
-	if( !initOpenGLExtensions() )
-	{	
-		Modules::log().error( "Could not find all required OpenGL function entry points" );
-		failed = true;
-	}
-
-	// Check that OpenGL 2.0 is available
-	if( glExt::majorVersion * 10 + glExt::minorVersion < 20 )
-	{
-		Modules::log().error( "OpenGL 2.0 not available" );
-		failed = true;
-	}
-	
-	// Check that required extensions are supported
-	if( !glExt::EXT_framebuffer_object )
-	{
-		Modules::log().error( "Extension EXT_framebuffer_object not supported" );
-		failed = true;
-	}
-	if( !glExt::EXT_texture_filter_anisotropic )
-	{
-		Modules::log().error( "Extension EXT_texture_filter_anisotropic not supported" );
-		failed = true;
-	}
-	if( !glExt::EXT_texture_compression_s3tc )
-	{
-		Modules::log().error( "Extension EXT_texture_compression_s3tc not supported" );
-		failed = true;
-	}
-	if( !glExt::EXT_texture_sRGB )
-	{
-		Modules::log().error( "Extension EXT_texture_sRGB not supported" );
-		failed = true;
-	}
-	
-	if( failed )
-	{
-		Modules::log().error( "Failed to init renderer backend, debug info following" );
-		char *exts = (char *)glGetString( GL_EXTENSIONS );
-		Modules::log().info( "Supported extensions: '%s'", exts );
-
-		return false;
-	}
-	
-	// Get capabilities
-	_caps.texFloat = glExt::ARB_texture_float ? 1 : 0;
-	_caps.texNPOT = glExt::ARB_texture_non_power_of_two ? 1 : 0;
-	_caps.rtMultisampling = glExt::EXT_framebuffer_multisample ? 1 : 0;
-
-	// Find supported depth format (some old ATI cards only support 16 bit depth for FBOs)
-	_depthFormat = GL_DEPTH_COMPONENT24;
-	uint32_t testBuf = createRenderBuffer( 32, 32, TextureFormats::BGRA8, true, 1, 0 ); 
-	if( testBuf == 0 )
-	{	
-		_depthFormat = GL_DEPTH_COMPONENT16;
-		Modules::log().warning( "Render target depth precision limited to 16 bit" );
-	}
-	else
-		destroyRenderBuffer( testBuf );
-	
-	initStates();
-	resetStates();
-
-	return true;
-}
-
-
-// =================================================================================================
-// Vertex layouts
-// =================================================================================================
-
-uint32_t RenderDevice::registerVertexLayout( uint32_t numAttribs, VertexLayoutAttrib *attribs )
-{
-	if( _numVertexLayouts == MaxNumVertexLayouts )
-		return 0;
-	
-	_vertexLayouts[_numVertexLayouts].numAttribs = numAttribs;
-
-	for( uint32_t i = 0; i < numAttribs; ++i )
-		_vertexLayouts[_numVertexLayouts].attribs[i] = attribs[i];
-
-	return ++_numVertexLayouts;
-}
-
-
-// =================================================================================================
-// Buffers
-// =================================================================================================
-
-void RenderDevice::beginRendering()
-{	
-	//	Get the currently bound frame buffer object. 
-	glGetIntegerv( GL_FRAMEBUFFER_BINDING_EXT, &_defaultFBO );
-	resetStates();
-}
-
-uint32_t RenderDevice::createVertexBuffer( uint32_t size, const void *data )
-{
-	RDIBuffer buf;
-
-	buf.type = GL_ARRAY_BUFFER;
-	buf.size = size;
-	glGenBuffers( 1, &buf.glObj );
-	glBindBuffer( buf.type, buf.glObj );
-	glBufferData( buf.type, size, data, GL_DYNAMIC_DRAW );
-	glBindBuffer( buf.type, 0 );
-	
-	_bufferMem += size;
-	return _buffers.add( buf );
-}
-
-
-uint32_t RenderDevice::createIndexBuffer( uint32_t size, const void *data )
-{
-	RDIBuffer buf;
-
-	buf.type = GL_ELEMENT_ARRAY_BUFFER;
-	buf.size = size;
-	glGenBuffers( 1, &buf.glObj );
-	glBindBuffer( buf.type, buf.glObj );
-	glBufferData( buf.type, size, data, GL_DYNAMIC_DRAW );
-	glBindBuffer( buf.type, 0 );
-	
-	_bufferMem += size;
-	return _buffers.add( buf );
-}
-
-
-void RenderDevice::destroyBuffer( uint32_t bufObj )
-{
-	if( bufObj == 0 ) return;
-	
-	RDIBuffer &buf = _buffers.getRef( bufObj );
-	glDeleteBuffers( 1, &buf.glObj );
-
-	_bufferMem -= buf.size;
-	_buffers.remove( bufObj );
-}
-
-
-void RenderDevice::updateBufferData( uint32_t bufObj, uint32_t offset, uint32_t size, void *data )
-{
-	const RDIBuffer &buf = _buffers.getRef( bufObj );
-	ASSERT( offset + size <= buf.size );
-	
-	glBindBuffer( buf.type, buf.glObj );
-	
-	if( offset == 0 &&  size == buf.size )
-	{
-		// Replacing the whole buffer can help the driver to avoid pipeline stalls
-		glBufferData( buf.type, size, data, GL_DYNAMIC_DRAW );
-		return;
-	}
-
-	glBufferSubData( buf.type, offset, size, data );
-}
-
-
-// =================================================================================================
-// Textures
-// =================================================================================================
-
-uint32_t RenderDevice::calcTextureSize( TextureFormats::List format, int width, int height, int depth )
-{
-	switch( format )
-	{
-	case TextureFormats::BGRA8:
-		return width * height * depth * 4;
-	case TextureFormats::DXT1:
-		return std::max( width / 4, 1 ) * std::max( height / 4, 1 ) * depth * 8;
-	case TextureFormats::DXT3:
-		return std::max( width / 4, 1 ) * std::max( height / 4, 1 ) * depth * 16;
-	case TextureFormats::DXT5:
-		return std::max( width / 4, 1 ) * std::max( height / 4, 1 ) * depth * 16;
-	case TextureFormats::RGBA16F:
-		return width * height * depth * 8;
-	case TextureFormats::RGBA32F:
-		return width * height * depth * 16;
-	default:
-		return 0;
-	}
-}
-
-
-uint32_t RenderDevice::createTexture( TextureTypes::List type, int width, int height, int depth,
-                                    TextureFormats::List format,
-                                    bool hasMips, bool genMips, bool sRGB )
-{
-	ASSERT( depth > 0 );
-
-	if( !_caps.texNPOT )
-	{
-		// Check if texture is NPOT
-		if( (width & (width-1)) != 0 || (height & (height-1)) != 0 )
-			Modules::log().warning( "Texture has non-power-of-two dimensions although NPOT is not supported by GPU" );
-	}
-	
-	RDITexture tex;
-	tex.type = type;
-	tex.format = format;
-	tex.width = width;
-	tex.height = height;
-	tex.depth = depth;
-	tex.sRGB = sRGB && Modules::config().sRGBLinearization;
-	tex.genMips = genMips;
-	tex.hasMips = hasMips;
-	
-	switch( format )
-	{
-	case TextureFormats::BGRA8:
-		tex.glFmt = tex.sRGB ? GL_SRGB8_ALPHA8_EXT : GL_RGBA8;
-		break;
-	case TextureFormats::DXT1:
-		tex.glFmt = tex.sRGB ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT : GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
-		break;
-	case TextureFormats::DXT3:
-		tex.glFmt = tex.sRGB ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT : GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
-		break;
-	case TextureFormats::DXT5:
-		tex.glFmt = tex.sRGB ? GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT : GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
-		break;
-	case TextureFormats::RGBA16F:
-		tex.glFmt = GL_RGBA16F_ARB;
-		break;
-	case TextureFormats::RGBA32F:
-		tex.glFmt = GL_RGBA32F_ARB;
-		break;
-	case TextureFormats::DEPTH:
-		tex.glFmt = _depthFormat;
-		break;
-	default:
-		ASSERT( 0 );
-		break;
-	};
-	
-	glGenTextures( 1, &tex.glObj );
-	glActiveTexture( GL_TEXTURE15 );
-	glBindTexture( tex.type, tex.glObj );
-	
-	float borderColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
-	glTexParameterfv( GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor );
-	
-	tex.samplerState = 0;
-	applySamplerState( tex );
-	
-	glBindTexture( tex.type, 0 );
-	if( _texSlots[15].texObj )
-		glBindTexture( _textures.getRef( _texSlots[15].texObj ).type, _textures.getRef( _texSlots[15].texObj ).glObj );
-
-	// Calculate memory requirements
-	tex.memSize = calcTextureSize( format, width, height, depth );
-	if( hasMips || genMips ) tex.memSize += ftoi_r( tex.memSize * 1.0f / 3.0f );
-	if( type == TextureTypes::TexCube ) tex.memSize *= 6;
-	_textureMem += tex.memSize;
-	
-	return _textures.add( tex );
-}
-
-
-void RenderDevice::uploadTextureData( uint32_t texObj, int slice, int mipLevel, const void *pixels )
-{
-	const RDITexture &tex = _textures.getRef( texObj );
-	TextureFormats::List format = tex.format;
-
-	glActiveTexture( GL_TEXTURE15 );
-	glBindTexture( tex.type, tex.glObj );
-	
-	int inputFormat = GL_BGRA, inputType = GL_UNSIGNED_BYTE;
-	bool compressed = (format == TextureFormats::DXT1) || (format == TextureFormats::DXT3) ||
-	                  (format == TextureFormats::DXT5);
-	
-	switch( format )
-	{
-	case TextureFormats::RGBA16F:
-		inputFormat = GL_RGBA;
-		inputType = GL_FLOAT;
-		break;
-	case TextureFormats::RGBA32F:
-		inputFormat = GL_RGBA;
-		inputType = GL_FLOAT;
-		break;
-	case TextureFormats::DEPTH:
-		inputFormat = GL_DEPTH_COMPONENT;
-		inputType = GL_FLOAT;
-	};
-	
-	// Calculate size of next mipmap using "floor" convention
-	int width = std::max( tex.width >> mipLevel, 1 ), height = std::max( tex.height >> mipLevel, 1 );
-	
-	if( tex.type == TextureTypes::Tex2D || tex.type == TextureTypes::TexCube )
-	{
-		int target = (tex.type == TextureTypes::Tex2D) ?
-			GL_TEXTURE_2D : (GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice);
-		
-		if( compressed )
-			glCompressedTexImage2D( target, mipLevel, tex.glFmt, width, height, 0,
-			                        calcTextureSize( format, width, height, 1 ), pixels );
-		else
-			glTexImage2D( target, mipLevel, tex.glFmt, width, height, 0, inputFormat, inputType, pixels );
-	}
-	else if( tex.type == TextureTypes::Tex3D )
-	{
-		int depth = std::max( tex.depth >> mipLevel, 1 );
-		
-		if( compressed )
-			glCompressedTexImage3D( GL_TEXTURE_3D, mipLevel, tex.glFmt, width, height, depth, 0,
-			                        calcTextureSize( format, width, height, depth ), pixels );	
-		else
-			glTexImage3D( GL_TEXTURE_3D, mipLevel, tex.glFmt, width, height, depth, 0,
-			              inputFormat, inputType, pixels );
-	}
-
-	if( tex.genMips && (tex.type != GL_TEXTURE_CUBE_MAP || slice == 5) )
-	{
-		// Note: for cube maps mips are only generated when the side with the highest index is uploaded
-		glEnable( tex.type );  // Workaround for ATI driver bug
-		glGenerateMipmapEXT( tex.type );
-		glDisable( tex.type );
-	}
-
-	glBindTexture( tex.type, 0 );
-	if( _texSlots[15].texObj )
-		glBindTexture( _textures.getRef( _texSlots[15].texObj ).type, _textures.getRef( _texSlots[15].texObj ).glObj );
-}
-
-
-void RenderDevice::destroyTexture( uint32_t texObj )
-{
-	if( texObj == 0 ) return;
-	
-	const RDITexture &tex = _textures.getRef( texObj );
-	glDeleteTextures( 1, &tex.glObj );
-
-	_textureMem -= tex.memSize;
-	_textures.remove( texObj );
-}
-
-
-void RenderDevice::updateTextureData( uint32_t texObj, int slice, int mipLevel, const void *pixels )
-{
-	uploadTextureData( texObj, slice, mipLevel, pixels );
-}
-
-
-bool RenderDevice::getTextureData( uint32_t texObj, int slice, int mipLevel, void *buffer )
-{
-	const RDITexture &tex = _textures.getRef( texObj );
-	
-	int target = tex.type == TextureTypes::TexCube ? GL_TEXTURE_CUBE_MAP : GL_TEXTURE_2D;
-	if( target == GL_TEXTURE_CUBE_MAP ) target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + slice;
-	
-	int fmt, type, compressed = 0;
-	glActiveTexture( GL_TEXTURE15 );
-	glBindTexture( tex.type, tex.glObj );
-
-	switch( tex.format )
-	{
-	case TextureFormats::BGRA8:
-		fmt = GL_BGRA;
-		type = GL_UNSIGNED_BYTE;
-		break;
-	case TextureFormats::DXT1:
-	case TextureFormats::DXT3:
-	case TextureFormats::DXT5:
-		compressed = 1;
-		break;
-	case TextureFormats::RGBA16F:
-	case TextureFormats::RGBA32F:
-		fmt = GL_RGBA;
-		type = GL_FLOAT;
-		break;
-	default:
-		return false;
-	};
-
-	if( compressed )
-		glGetCompressedTexImage( target, mipLevel, buffer );
-	else
-		glGetTexImage( target, mipLevel, fmt, type, buffer );
-
-	glBindTexture( tex.type, 0 );
-	if( _texSlots[15].texObj )
-		glBindTexture( _textures.getRef( _texSlots[15].texObj ).type, _textures.getRef( _texSlots[15].texObj ).glObj );
-
-	return true;
-}
-
-
-// =================================================================================================
-// Shaders
-// =================================================================================================
-
-uint32_t RenderDevice::createShaderProgram( const char *vertexShaderSrc, const char *fragmentShaderSrc )
-{
-	int infologLength = 0;
-	int charsWritten = 0;
-	char *infoLog = 0x0;
-	int status;
-
-	_shaderLog = "";
-
-	// Vertex shader
-	uint32_t vs = glCreateShader( GL_VERTEX_SHADER );
-	glShaderSource( vs, 1, &vertexShaderSrc, 0x0 );
-	glCompileShader( vs );
-	glGetShaderiv( vs, GL_COMPILE_STATUS, &status );
-	if( !status )
-	{	
-		// Get info
-		glGetShaderiv( vs, GL_INFO_LOG_LENGTH, &infologLength );
-		if( infologLength > 1 )
-		{
-			infoLog = new char[infologLength];
-			glGetShaderInfoLog( vs, infologLength, &charsWritten, infoLog );
-			_shaderLog = _shaderLog + "[Vertex Shader]\n" + infoLog;
-			delete[] infoLog; infoLog = 0x0;
-		}
-
-		glDeleteShader( vs );
-		return 0;
-	}
-
-	// Fragment shader
-	uint32_t fs = glCreateShader( GL_FRAGMENT_SHADER );
-	glShaderSource( fs, 1, &fragmentShaderSrc, 0x0 );
-	glCompileShader( fs );
-	glGetShaderiv( fs, GL_COMPILE_STATUS, &status );
-	if( !status )
-	{	
-		glGetShaderiv( fs, GL_INFO_LOG_LENGTH, &infologLength );
-		if( infologLength > 1 )
-		{
-			infoLog = new char[infologLength];
-			glGetShaderInfoLog( fs, infologLength, &charsWritten, infoLog );
-			_shaderLog = _shaderLog + "[Fragment Shader]\n" + infoLog;
-			delete[] infoLog; infoLog = 0x0;
-		}
-
-		glDeleteShader( vs );
-		glDeleteShader( fs );
-		return 0;
-	}
-
-	// Shader program
-	uint32_t program = glCreateProgram();
-	glAttachShader( program, vs );
-	glAttachShader( program, fs );
-	glDeleteShader( vs );
-	glDeleteShader( fs );
-
-	return program;
-}
-
-
-bool RenderDevice::linkShaderProgram( uint32_t programObj )
-{
-	int infologLength = 0;
-	int charsWritten = 0;
-	char *infoLog = 0x0;
-	int status;
-
-	_shaderLog = "";
-	
-	glLinkProgram( programObj );
-	glGetProgramiv( programObj, GL_INFO_LOG_LENGTH, &infologLength );
-	if( infologLength > 1 )
-	{
-		infoLog = new char[infologLength];
-		glGetProgramInfoLog( programObj, infologLength, &charsWritten, infoLog );
-		_shaderLog = _shaderLog + "[Linking]\n" + infoLog;
-		delete[] infoLog; infoLog = 0x0;
-	}
-	
-	glGetProgramiv( programObj, GL_LINK_STATUS, &status );
-	if( !status ) return false;
-
-	return true;
-}
-
-
-uint32_t RenderDevice::createShader( const char *vertexShaderSrc, const char *fragmentShaderSrc )
-{
-	// Compile and link shader
-	uint32_t programObj = createShaderProgram( vertexShaderSrc, fragmentShaderSrc );
-	if( programObj == 0 ) return 0;
-	if( !linkShaderProgram( programObj ) ) return 0;
-	
-	uint32_t shaderId = _shaders.add( RDIShader() );
-	RDIShader &shader = _shaders.getRef( shaderId );
-	shader.oglProgramObj = programObj;
-	
-	int attribCount;
-	glGetProgramiv( programObj, GL_ACTIVE_ATTRIBUTES, &attribCount );
-	
-	for( uint32_t i = 0; i < _numVertexLayouts; ++i )
-	{
-		RDIVertexLayout &vl = _vertexLayouts[i];
-		bool allAttribsFound = true;
-		
-		for( uint32_t j = 0; j < 16; ++j )
-			shader.inputLayouts[i].attribIndices[j] = -1;
-		
-		for( int j = 0; j < attribCount; ++j )
-		{
-			char name[32];
-			uint32_t size, type;
-			glGetActiveAttrib( programObj, j, 32, 0x0, (int *)&size, &type, name );
-
-			bool attribFound = false;
-			for( uint32_t k = 0; k < vl.numAttribs; ++k )
-			{
-				if( vl.attribs[k].semanticName.compare(name) == 0 )
-				{
-					shader.inputLayouts[i].attribIndices[k] = glGetAttribLocation( programObj, name );
-					attribFound = true;
-				}
-			}
-
-			if( !attribFound )
-			{
-				allAttribsFound = false;
-				break;
-			}
-		}
-
-		shader.inputLayouts[i].valid = allAttribsFound;
-	}
-
-	return shaderId;
-}
-
-
-void RenderDevice::destroyShader( uint32_t shaderId )
-{
-	if( shaderId == 0 ) return;
-
-	RDIShader &shader = _shaders.getRef( shaderId );
-	glDeleteProgram( shader.oglProgramObj );
-	_shaders.remove( shaderId );
-}
-
-
-void RenderDevice::bindShader( uint32_t shaderId )
-{
-	if( shaderId != 0 )
-	{
-		RDIShader &shader = _shaders.getRef( shaderId );
-		glUseProgram( shader.oglProgramObj );
-	}
-	else
-	{
-		glUseProgram( 0 );
-	}
-	
-	_curShaderId = shaderId;
-	_pendingMask |= PM_VERTLAYOUT;
-} 
-
-
-int RenderDevice::getShaderConstLoc( uint32_t shaderId, const char *name )
-{
-	RDIShader &shader = _shaders.getRef( shaderId );
-	return glGetUniformLocation( shader.oglProgramObj, name );
-}
-
-
-int RenderDevice::getShaderSamplerLoc( uint32_t shaderId, const char *name )
-{
-	RDIShader &shader = _shaders.getRef( shaderId );
-	return glGetUniformLocation( shader.oglProgramObj, name );
-}
-
-
-void RenderDevice::setShaderConst( int loc, RDIShaderConstType type, void *values, uint32_t count )
-{
-	switch( type )
-	{
-	case CONST_FLOAT:
-		glUniform1fv( loc, count, (float *)values );
-		break;
-	case CONST_FLOAT2:
-		glUniform2fv( loc, count, (float *)values );
-		break;
-	case CONST_FLOAT3:
-		glUniform3fv( loc, count, (float *)values );
-		break;
-	case CONST_FLOAT4:
-		glUniform4fv( loc, count, (float *)values );
-		break;
-	case CONST_FLOAT44:
-		glUniformMatrix4fv( loc, count, false, (float *)values );
-		break;
-	case CONST_FLOAT33:
-		glUniformMatrix3fv( loc, count, false, (float *)values );
-		break;
-	}
-}
-
-
-void RenderDevice::setShaderSampler( int loc, uint32_t texUnit )
-{
-	glUniform1i( loc, (int)texUnit );
-}
-
-
-const char *RenderDevice::getDefaultVSCode()
-{
-	return defaultShaderVS;
-}
-
-
-const char *RenderDevice::getDefaultFSCode()
-{
-	return defaultShaderFS;
-}
-
-
-// =================================================================================================
-// Renderbuffers
-// =================================================================================================
-
-uint32_t RenderDevice::createRenderBuffer( uint32_t width, uint32_t height, TextureFormats::List format,
-                                         bool depth, uint32_t numColBufs, uint32_t samples )
-{
-	if( (format == TextureFormats::RGBA16F || format == TextureFormats::RGBA32F) && !_caps.texFloat )
-	{
-		return 0;
-	}
-
-	if( numColBufs > RDIRenderBuffer::MaxColorAttachmentCount ) return 0;
-
-	uint32_t maxSamples = 0;
-	if( _caps.rtMultisampling )
-	{
-		GLint value;
-		glGetIntegerv( GL_MAX_SAMPLES_EXT, &value );
-		maxSamples = (uint32_t)value;
-	}
-	if( samples > maxSamples )
-	{
-		samples = maxSamples;
-		Modules::log().warning( "GPU does not support desired multisampling quality for render target" );
-	}
-
-	RDIRenderBuffer rb;
-	rb.width = width;
-	rb.height = height;
-	rb.samples = samples;
-
-	// Create framebuffers
-	glGenFramebuffersEXT( 1, &rb.fbo );
-	if( samples > 0 ) glGenFramebuffersEXT( 1, &rb.fboMS );
-
-	if( numColBufs > 0 )
-	{
-		// Attach color buffers
-		for( uint32_t j = 0; j < numColBufs; ++j )
-		{
-			glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-			// Create a color texture
-			uint32_t texObj = createTexture( TextureTypes::Tex2D, rb.width, rb.height, 1, format, false, false, false );
-			ASSERT( texObj != 0 );
-			uploadTextureData( texObj, 0, 0, 0x0 );
-			rb.colTexs[j] = texObj;
-			RDITexture &tex = _textures.getRef( texObj );
-			// Attach the texture
-			glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + j, GL_TEXTURE_2D, tex.glObj, 0 );
-
-			if( samples > 0 )
-			{
-				glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS );
-				// Create a multisampled renderbuffer
-				glGenRenderbuffersEXT( 1, &rb.colBufs[j] );
-				glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rb.colBufs[j] );
-				glRenderbufferStorageMultisampleEXT( GL_RENDERBUFFER_EXT, rb.samples, tex.glFmt, rb.width, rb.height );
-				// Attach the renderbuffer
-				glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + j,
-				                              GL_RENDERBUFFER_EXT, rb.colBufs[j] );
-			}
-		}
-
-		uint32_t buffers[] = { GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT,
-		                     GL_COLOR_ATTACHMENT2_EXT, GL_COLOR_ATTACHMENT3_EXT };
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-		glDrawBuffers( numColBufs, buffers );
-		
-		if( samples > 0 )
-		{
-			glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS );
-			glDrawBuffers( numColBufs, buffers );
-		}
-	}
-	else
-	{	
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-		glDrawBuffer( GL_NONE );
-		glReadBuffer( GL_NONE );
-		
-		if( samples > 0 )
-		{
-			glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS );
-			glDrawBuffer( GL_NONE );
-			glReadBuffer( GL_NONE );
-		}
-	}
-
-	// Attach depth buffer
-	if( depth )
-	{
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-		// Create a depth texture
-		uint32_t texObj = createTexture( TextureTypes::Tex2D, rb.width, rb.height, 1, TextureFormats::DEPTH, false, false, false );
-		ASSERT( texObj != 0 );
-		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE );
-		uploadTextureData( texObj, 0, 0, 0x0 );
-		rb.depthTex = texObj;
-		RDITexture &tex = _textures.getRef( texObj );
-		// Attach the texture
-		glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, tex.glObj, 0 );
-
-		if( samples > 0 )
-		{
-			glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS );
-			// Create a multisampled renderbuffer
-			glGenRenderbuffersEXT( 1, &rb.depthBuf );
-			glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, rb.depthBuf );
-			glRenderbufferStorageMultisampleEXT( GL_RENDERBUFFER_EXT, rb.samples, _depthFormat, rb.width, rb.height );
-			// Attach the renderbuffer
-			glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
-			                              GL_RENDERBUFFER_EXT, rb.depthBuf );
-		}
-	}
-
-	uint32_t rbObj = _rendBufs.add( rb );
-	
-	// Check if FBO is complete
-	bool valid = true;
-	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-	uint32_t status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
-	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-	if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) valid = false;
-	
-	if( samples > 0 )
-	{
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS );
-		status = glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT );
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-		if( status != GL_FRAMEBUFFER_COMPLETE_EXT ) valid = false;
-	}
-
-	if( !valid )
-	{
-		destroyRenderBuffer( rbObj );
-		return 0;
-	}
-	
-	return rbObj;
-}
-
-
-void RenderDevice::destroyRenderBuffer( uint32_t rbObj )
-{
-	RDIRenderBuffer &rb = _rendBufs.getRef( rbObj );
-	
-	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-	
-	if( rb.depthTex != 0 ) destroyTexture( rb.depthTex );
-	if( rb.depthBuf != 0 ) glDeleteRenderbuffersEXT( 1, &rb.depthBuf );
-	rb.depthTex = rb.depthBuf = 0;
-		
-	for( uint32_t i = 0; i < RDIRenderBuffer::MaxColorAttachmentCount; ++i )
-	{
-		if( rb.colTexs[i] != 0 ) destroyTexture( rb.colTexs[i] );
-		if( rb.colBufs[i] != 0 ) glDeleteRenderbuffersEXT( 1, &rb.colBufs[i] );
-		rb.colTexs[i] = rb.colBufs[i] = 0;
-	}
-
-	if( rb.fbo != 0 ) glDeleteFramebuffersEXT( 1, &rb.fbo );
-	if( rb.fboMS != 0 ) glDeleteFramebuffersEXT( 1, &rb.fboMS );
-	rb.fbo = rb.fboMS = 0;
-
-	_rendBufs.remove( rbObj );
-}
-
-
-uint32_t RenderDevice::getRenderBufferTex( uint32_t rbObj, uint32_t bufIndex )
-{
-	RDIRenderBuffer &rb = _rendBufs.getRef( rbObj );
-	
-	if( bufIndex < RDIRenderBuffer::MaxColorAttachmentCount ) return rb.colTexs[bufIndex];
-	else if( bufIndex == 32 ) return rb.depthTex;
-	else return 0;
-}
-
-
-void RenderDevice::resolveRenderBuffer( uint32_t rbObj )
-{
-	RDIRenderBuffer &rb = _rendBufs.getRef( rbObj );
-	
-	if( rb.fboMS == 0 ) return;
-	
-	glBindFramebufferEXT( GL_READ_FRAMEBUFFER_EXT, rb.fboMS );
-	glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, rb.fbo );
-
-	bool depthResolved = false;
-	for( uint32_t i = 0; i < RDIRenderBuffer::MaxColorAttachmentCount; ++i )
-	{
-		if( rb.colBufs[i] != 0 )
-		{
-			glReadBuffer( GL_COLOR_ATTACHMENT0_EXT + i );
-			glDrawBuffer( GL_COLOR_ATTACHMENT0_EXT + i );
-			
-			int mask = GL_COLOR_BUFFER_BIT;
-			if( !depthResolved && rb.depthBuf != 0 )
-			{
-				mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
-				depthResolved = true;
-			}
-			glBlitFramebufferEXT( 0, 0, rb.width, rb.height, 0, 0, rb.width, rb.height, mask, GL_NEAREST );
-		}
-	}
-
-	if( !depthResolved && rb.depthBuf != 0 )
-	{
-		glReadBuffer( GL_NONE );
-		glDrawBuffer( GL_NONE );
-		glBlitFramebufferEXT( 0, 0, rb.width, rb.height, 0, 0, rb.width, rb.height,
-							  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST );
-	}
-
-	glBindFramebufferEXT( GL_READ_FRAMEBUFFER_EXT, _defaultFBO );
-	glBindFramebufferEXT( GL_DRAW_FRAMEBUFFER_EXT, _defaultFBO );
-}
-
-
-void RenderDevice::setRenderBuffer( uint32_t rbObj )
-{
-	// Resolve render buffer if necessary
-	if( _curRendBuf != 0 ) resolveRenderBuffer( _curRendBuf );
-	
-	// Set new render buffer
-	_curRendBuf = rbObj;
-	
-	if( rbObj == 0 )
-	{
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-		if( _defaultFBO == 0 ) glDrawBuffer( _outputBufferIndex == 1 ? GL_BACK_RIGHT : GL_BACK_LEFT );
-		_fbWidth = _vpWidth + _vpX;
-		_fbHeight = _vpHeight + _vpY;
-		glDisable( GL_MULTISAMPLE );
-	}
-	else
-	{
-		// Unbind all textures to make sure that no FBO attachment is bound any more
-		for( uint32_t i = 0; i < 16; ++i ) setTexture( i, 0, 0 );
-		commitStates( PM_TEXTURES );
-		
-		RDIRenderBuffer &rb = _rendBufs.getRef( rbObj );
-
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fboMS != 0 ? rb.fboMS : rb.fbo );
-		ASSERT( glCheckFramebufferStatusEXT( GL_FRAMEBUFFER_EXT ) == GL_FRAMEBUFFER_COMPLETE_EXT );
-		_fbWidth = rb.width;
-		_fbHeight = rb.height;
-
-		if( rb.fboMS != 0 ) glEnable( GL_MULTISAMPLE );
-		else glDisable( GL_MULTISAMPLE );
-	}
-}
-
-
-bool RenderDevice::getRenderBufferData( uint32_t rbObj, int bufIndex, int *width, int *height,
-                                        int *compCount, void *dataBuffer, int bufferSize )
-{
-	int x, y, w, h;
-	int format = GL_RGBA;
-	int type = GL_FLOAT;
-	beginRendering();
-	glPixelStorei( GL_PACK_ALIGNMENT, 4 );
-	
-	if( rbObj == 0 )
-	{
-		if( bufIndex != 32 && bufIndex != 0 ) return false;
-		if( width != 0x0 ) *width = _vpWidth;
-		if( height != 0x0 ) *height = _vpHeight;
-		
-		x = _vpX; y = _vpY; w = _vpWidth; h = _vpHeight;
-
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-		if( bufIndex != 32 ) glReadBuffer( GL_BACK_LEFT );
-		//format = GL_BGRA;
-		//type = GL_UNSIGNED_BYTE;
-	}
-	else
-	{
-		resolveRenderBuffer( rbObj );
-		RDIRenderBuffer &rb = _rendBufs.getRef( rbObj );
-		
-		if( bufIndex == 32 && rb.depthTex == 0 ) return false;
-		if( bufIndex != 32 )
-		{
-			if( (unsigned)bufIndex >= RDIRenderBuffer::MaxColorAttachmentCount || rb.colTexs[bufIndex] == 0 )
-				return false;
-		}
-		if( width != 0x0 ) *width = rb.width;
-		if( height != 0x0 ) *height = rb.height;
-
-		x = 0; y = 0; w = rb.width; h = rb.height;
-		
-		glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, rb.fbo );
-		if( bufIndex != 32 ) glReadBuffer( GL_COLOR_ATTACHMENT0_EXT + bufIndex );
-	}
-
-	if( bufIndex == 32 )
-	{	
-		format = GL_DEPTH_COMPONENT;
-		type = GL_FLOAT;
-	}
-	
-	int comps = (bufIndex == 32 ? 1 : 4);
-	if( compCount != 0x0 ) *compCount = comps;
-	
-	bool retVal = false;
-	if( dataBuffer != 0x0 &&
-	    bufferSize >= w * h * comps * (type == GL_FLOAT ? 4 : 1) ) 
-	{
-		glFinish();
-		glReadPixels( x, y, w, h, format, type, dataBuffer );
-		retVal = true;
-	}
-	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-
-	return retVal;
-}
-
-
-// =================================================================================================
-// Queries
-// =================================================================================================
-
-uint32_t RenderDevice::createOcclusionQuery()
-{
-	uint32_t queryObj;
-	glGenQueries( 1, &queryObj );
-	return queryObj;
-}
-
-
-void RenderDevice::destroyQuery( uint32_t queryObj )
-{
-	if( queryObj == 0 ) return;
-	
-	glDeleteQueries( 1, &queryObj );
-}
-
-
-void RenderDevice::beginQuery( uint32_t queryObj )
-{
-	glBeginQuery( GL_SAMPLES_PASSED, queryObj );
-}
-
-
-void RenderDevice::endQuery( uint32_t /*queryObj*/ )
-{
-	glEndQuery( GL_SAMPLES_PASSED );
-}
-
-
-uint32_t RenderDevice::getQueryResult( uint32_t queryObj )
-{
-	uint32_t samples = 0;
-	glGetQueryObjectuiv( queryObj, GL_QUERY_RESULT, &samples );
-	return samples;
-}
-
-
-// =================================================================================================
-// Internal state management
-// =================================================================================================
-
-void RenderDevice::checkGLError()
-{
-	uint32_t error = glGetError();
-	ASSERT( error != GL_INVALID_ENUM );
-	ASSERT( error != GL_INVALID_VALUE );
-	ASSERT( error != GL_INVALID_OPERATION );
-	ASSERT( error != GL_OUT_OF_MEMORY );
-	ASSERT( error != GL_STACK_OVERFLOW && error != GL_STACK_UNDERFLOW );
-}
-
-
-bool RenderDevice::applyVertexLayout()
-{
-	uint32_t newVertexAttribMask = 0;
-	
-	if( _newVertLayout != 0 )
-	{
-		if( _curShaderId == 0 ) return false;
-		
-		RDIVertexLayout &vl = _vertexLayouts[_newVertLayout - 1];
-		RDIShader &shader = _shaders.getRef( _curShaderId );
-		RDIInputLayout &inputLayout = shader.inputLayouts[_newVertLayout - 1];
-		
-		if( !inputLayout.valid )
-			return false;
-
-		// Set vertex attrib pointers
-		for( uint32_t i = 0; i < vl.numAttribs; ++i )
-		{
-			int8_t attribIndex = inputLayout.attribIndices[i];
-			if( attribIndex >= 0 )
-			{
-				VertexLayoutAttrib &attrib = vl.attribs[i];
-				const RDIVertBufSlot &vbSlot = _vertBufSlots[attrib.vbSlot];
-				
-				ASSERT( _buffers.getRef( _vertBufSlots[attrib.vbSlot].vbObj ).glObj != 0 &&
-						_buffers.getRef( _vertBufSlots[attrib.vbSlot].vbObj ).type == GL_ARRAY_BUFFER );
-				
-				glBindBuffer( GL_ARRAY_BUFFER, _buffers.getRef( _vertBufSlots[attrib.vbSlot].vbObj ).glObj );
-				glVertexAttribPointer( attribIndex, attrib.size, GL_FLOAT, GL_FALSE,
-									   vbSlot.stride, (char *)0 + vbSlot.offset + attrib.offset );
-
-				newVertexAttribMask |= 1 << attribIndex;
-			}
-		}
-	}
-	
-	for( uint32_t i = 0; i < 16; ++i )
-	{
-		uint32_t curBit = 1 << i;
-		if( (newVertexAttribMask & curBit) != (_activeVertexAttribsMask & curBit) )
-		{
-			if( newVertexAttribMask & curBit ) glEnableVertexAttribArray( i );
-			else glDisableVertexAttribArray( i );
-		}
-	}
-	_activeVertexAttribsMask = newVertexAttribMask;
-
-	return true;
-}
-
-
-void RenderDevice::applySamplerState( RDITexture &tex )
-{
-	uint32_t state = tex.samplerState;
-	uint32_t target = tex.type;
-	
-	const uint32_t magFilters[] = { GL_LINEAR, GL_LINEAR, GL_NEAREST };
-	const uint32_t minFiltersMips[] = { GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_NEAREST };
-	const uint32_t maxAniso[] = { 1, 2, 4, 0, 8, 0, 0, 0, 16 };
-	const uint32_t wrapModes[] = { GL_CLAMP_TO_EDGE, GL_REPEAT, GL_CLAMP_TO_BORDER };
-
-	if( tex.hasMips )
-		glTexParameteri( target, GL_TEXTURE_MIN_FILTER, minFiltersMips[(state & SS_FILTER_MASK) >> SS_FILTER_START] );
-	else
-		glTexParameteri( target, GL_TEXTURE_MIN_FILTER, magFilters[(state & SS_FILTER_MASK) >> SS_FILTER_START] );
-
-	glTexParameteri( target, GL_TEXTURE_MAG_FILTER, magFilters[(state & SS_FILTER_MASK) >> SS_FILTER_START] );
-	glTexParameteri( target, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAniso[(state & SS_ANISO_MASK) >> SS_ANISO_START] );
-	glTexParameteri( target, GL_TEXTURE_WRAP_S, wrapModes[(state & SS_ADDRU_MASK) >> SS_ADDRU_START] );
-	glTexParameteri( target, GL_TEXTURE_WRAP_T, wrapModes[(state & SS_ADDRV_MASK) >> SS_ADDRV_START] );
-	glTexParameteri( target, GL_TEXTURE_WRAP_R, wrapModes[(state & SS_ADDRW_MASK) >> SS_ADDRW_START] );
-	
-	if( !(state & SS_COMP_LEQUAL) )
-	{
-		glTexParameteri( target, GL_TEXTURE_COMPARE_MODE, GL_NONE );
-	}
-	else
-	{
-		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
-		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
-	}
-}
-
-
-void RenderDevice::applyRenderStates()
-{
-	// Rasterizer state
-	if( _newRasterState.hash != _curRasterState.hash )
-	{
-		if( _newRasterState.params.fillMode == RS_FILL_SOLID ) glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-		else glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-
-		if( _newRasterState.params.cullMode == RS_CULL_BACK )
-		{
-			glEnable( GL_CULL_FACE );
-			glCullFace( GL_BACK );
-		}
-		else if( _newRasterState.params.cullMode == RS_CULL_FRONT )
-		{
-			glEnable( GL_CULL_FACE );
-			glCullFace( GL_FRONT );
-		}
-		else
-		{
-			glDisable( GL_CULL_FACE );
-		}
-
-		if( !_newRasterState.params.scissorEnable ) glDisable( GL_SCISSOR_TEST );
-		else glEnable( GL_SCISSOR_TEST );
-
-		if( _newRasterState.params.renderTargetWriteMask ) glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
-		else glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
-		
-		_curRasterState.hash = _newRasterState.hash;
-	}
-
-	// Blend state
-	if( _newBlendState.hash != _curBlendState.hash )
-	{
-		if( !_newBlendState.params.alphaToCoverageEnable ) glDisable( GL_SAMPLE_ALPHA_TO_COVERAGE );
-		else glEnable( GL_SAMPLE_ALPHA_TO_COVERAGE );
-
-		if( !_newBlendState.params.blendEnable )
-		{
-			glDisable( GL_BLEND );
-		}
-		else
-		{
-			uint32_t oglBlendFuncs[8] = { GL_ZERO, GL_ONE, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_COLOR, GL_ZERO, GL_ZERO };
-			
-			glEnable( GL_BLEND );
-			glBlendFunc( oglBlendFuncs[_newBlendState.params.srcBlendFunc], oglBlendFuncs[_newBlendState.params.destBlendFunc] );
-		}
-		
-		_curBlendState.hash = _newBlendState.hash;
-	}
-
-	// Depth-stencil state
-	if( _newDepthStencilState.hash != _curDepthStencilState.hash )
-	{
-		if( _newDepthStencilState.params.depthWriteMask ) glDepthMask( GL_TRUE );
-		else glDepthMask( GL_FALSE);
-
-		if( _newDepthStencilState.params.depthEnable )
-		{
-			uint32_t oglDepthFuncs[8] = { GL_LEQUAL, GL_LESS, GL_EQUAL, GL_GREATER, GL_GEQUAL, GL_ALWAYS, GL_ALWAYS, GL_ALWAYS };
-			
-			glEnable( GL_DEPTH_TEST );
-			glDepthFunc( oglDepthFuncs[_newDepthStencilState.params.depthFunc] );
-		}
-		else
-		{
-			glDisable( GL_DEPTH_TEST );
-		}
-		
-		_curDepthStencilState.hash = _newDepthStencilState.hash;
-	}
-}
-
-
-bool RenderDevice::commitStates( uint32_t filter )
-{
-	if( _pendingMask & filter )
-	{
-		uint32_t mask = _pendingMask & filter;
-	
-		// Set viewport
-		if( mask & PM_VIEWPORT )
-		{
-			glViewport( _vpX, _vpY, _vpWidth, _vpHeight );
-			_pendingMask &= ~PM_VIEWPORT;
-		}
-
-		if( mask & PM_RENDERSTATES )
-		{
-			applyRenderStates();
-			_pendingMask &= ~PM_RENDERSTATES;
-		}
-
-		// Set scissor rect
-		if( mask & PM_SCISSOR )
-		{
-			glScissor( _scX, _scY, _scWidth, _scHeight );
-			_pendingMask &= ~PM_SCISSOR;
-		}
-		
-		// Bind index buffer
-		if( mask & PM_INDEXBUF )
-		{
-			if( _newIndexBuf != _curIndexBuf )
-			{
-				if( _newIndexBuf != 0 )
-					glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, _buffers.getRef( _newIndexBuf ).glObj );
-				else
-					glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );
-				
-				_curIndexBuf = _newIndexBuf;
-				_pendingMask &= ~PM_INDEXBUF;
-			}
-		}
-
-		// Bind textures and set sampler state
-		if( mask & PM_TEXTURES )
-		{
-			for( uint32_t i = 0; i < 16; ++i )
-			{
-				glActiveTexture( GL_TEXTURE0 + i );
-
-				if( _texSlots[i].texObj != 0 )
-				{
-					RDITexture &tex = _textures.getRef( _texSlots[i].texObj );
-					glBindTexture( tex.type, tex.glObj );
-
-					// Apply sampler state
-					if( tex.samplerState != _texSlots[i].samplerState )
-					{
-						tex.samplerState = _texSlots[i].samplerState;
-						applySamplerState( tex );
-					}
-				}
-				else
-				{
-					glBindTexture( GL_TEXTURE_CUBE_MAP, 0 );
-					glBindTexture( GL_TEXTURE_3D, 0 );
-					glBindTexture( GL_TEXTURE_2D, 0 );
-				}
-			}
-			
-			_pendingMask &= ~PM_TEXTURES;
-		}
-
-		// Bind vertex buffers
-		if( mask & PM_VERTLAYOUT )
-		{
-			//if( _newVertLayout != _curVertLayout || _curShader != _prevShader )
-			{
-				if( !applyVertexLayout() )
-					return false;
-				_curVertLayout = _newVertLayout;
-				_prevShaderId = _curShaderId;
-				_pendingMask &= ~PM_VERTLAYOUT;
-			}
-		}
-
-		CHECK_GL_ERROR
-	}
-
-	return true;
-}
-
-
-void RenderDevice::resetStates()
-{
-	_curIndexBuf = 1; _newIndexBuf = 0;
-	_curVertLayout = 1; _newVertLayout = 0;
-	_curRasterState.hash = 0xFFFFFFFF; _newRasterState.hash = 0;
-	_curBlendState.hash = 0xFFFFFFFF; _newBlendState.hash = 0;
-	_curDepthStencilState.hash = 0xFFFFFFFF; _newDepthStencilState.hash = 0;
-
-	for( uint32_t i = 0; i < 16; ++i )
-		setTexture( i, 0, 0 );
-
-	setColorWriteMask( true );
-	_pendingMask = 0xFFFFFFFF;
-	commitStates();
-
-	glBindBuffer( GL_ARRAY_BUFFER, 0 );
-	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, _defaultFBO );
-}
-
-
-// =================================================================================================
-// Draw calls and clears
-// =================================================================================================
-
-void RenderDevice::clear( uint32_t flags, float *colorRGBA, float depth )
-{
-	uint32_t prevBuffers[4] = { 0 };
-
-	if( _curRendBuf != 0x0 )
-	{
-		RDIRenderBuffer &rb = _rendBufs.getRef( _curRendBuf );
-		
-		if( (flags & CLR_DEPTH) && rb.depthTex == 0 ) flags &= ~CLR_DEPTH;
-		
-		// Store state of glDrawBuffers
-		for( uint32_t i = 0; i < 4; ++i )
-			glGetIntegerv( GL_DRAW_BUFFER0 + i, (int *)&prevBuffers[i] );
-		
-		uint32_t buffers[4], cnt = 0;
-		
-		if( (flags & CLR_COLOR_RT0) && rb.colTexs[0] != 0 ) buffers[cnt++] = GL_COLOR_ATTACHMENT0_EXT;
-		if( (flags & CLR_COLOR_RT1) && rb.colTexs[1] != 0 ) buffers[cnt++] = GL_COLOR_ATTACHMENT1_EXT;
-		if( (flags & CLR_COLOR_RT2) && rb.colTexs[2] != 0 ) buffers[cnt++] = GL_COLOR_ATTACHMENT2_EXT;
-		if( (flags & CLR_COLOR_RT3) && rb.colTexs[3] != 0 ) buffers[cnt++] = GL_COLOR_ATTACHMENT3_EXT;
-
-		if( cnt == 0 )
-			flags &= ~(CLR_COLOR_RT0 | CLR_COLOR_RT1 | CLR_COLOR_RT2 | CLR_COLOR_RT3);
-		else
-			glDrawBuffers( cnt, buffers );
-	}
-	
-	uint32_t oglClearMask = 0;
-	
-	if( flags & CLR_DEPTH )
-	{
-		oglClearMask |= GL_DEPTH_BUFFER_BIT;
-		glClearDepth( depth );
-	}
-	if( flags & (CLR_COLOR_RT0 | CLR_COLOR_RT1 | CLR_COLOR_RT2 | CLR_COLOR_RT3) )
-	{
-		oglClearMask |= GL_COLOR_BUFFER_BIT;
-		if( colorRGBA ) glClearColor( colorRGBA[0], colorRGBA[1], colorRGBA[2], colorRGBA[3] );
-		else glClearColor( 0, 0, 0, 0 );
-	}
-	
-	if( oglClearMask )
-	{	
-		commitStates( PM_VIEWPORT | PM_SCISSOR | PM_RENDERSTATES );
-		glClear( oglClearMask );
-	}
-
-	// Restore state of glDrawBuffers
-	if( _curRendBuf != 0x0 )
-		glDrawBuffers( 4, prevBuffers );
-
-	CHECK_GL_ERROR
-}
-
-
-void RenderDevice::draw( RDIPrimType primType, uint32_t firstVert, uint32_t numVerts )
-{
-	if( commitStates() )
-	{
-		glDrawArrays( (uint32_t)primType, firstVert, numVerts );
-	}
-
-	CHECK_GL_ERROR
-}
-
-
-void RenderDevice::drawIndexed( RDIPrimType primType, uint32_t firstIndex, uint32_t numIndices,
-                                uint32_t firstVert, uint32_t numVerts )
-{
-	if( commitStates() )
-	{
-		firstIndex *= (_indexFormat == IDXFMT_16) ? sizeof( short ) : sizeof( int );
-		
-		glDrawRangeElements( (uint32_t)primType, firstVert, firstVert + numVerts,
-		                     numIndices, _indexFormat, (char *)0 + firstIndex );
-	}
-
-	CHECK_GL_ERROR
-}
-
-}  // namespace

File temp/test_hordefiles/egRendererBase.h

-// *************************************************************************************************
-//
-// Horde3D
-//   Next-Generation Graphics Engine
-// --------------------------------------
-// Copyright (C) 2006-2011 Nicolas Schulz
-//
-// This software is distributed under the terms of the Eclipse Public License v1.0.
-// A copy of the license may be obtained at: http://www.eclipse.org/legal/epl-v10.html
-//
-// *************************************************************************************************
-
-#ifndef _egRendererBase_H_
-#define _egRendererBase_H_
-
-#include "egPrerequisites.h"
-#include "utMath.h"
-#include "utOpenGL.h"
-#include <string>
-#include <vector>
-
-
-namespace Horde3D {
-
-const uint32_t MaxNumVertexLayouts = 16;
-
-
-
-// =================================================================================================
-// Render Device Interface
-// =================================================================================================
-
-// ---------------------------------------------------------
-// General
-// ---------------------------------------------------------
-
-template< class T > class RDIObjects
-{
-public:
-
-	uint32_t add( const T &obj )
-	{
-		if( !_freeList.empty() )
-		{
-			uint32_t index = _freeList.back();
-			_freeList.pop_back();
-			_objects[index] = obj;
-			return index + 1;
-		}
-		else
-		{
-			_objects.push_back( obj );
-			return (uint32_t)_objects.size();
-		}
-	}
-
-	void remove( uint32_t handle )
-	{
-		ASSERT( handle > 0 && handle <= _objects.size() );
-		
-		_objects[handle - 1] = T();  // Destruct and replace with default object
-		_freeList.push_back( handle - 1 );
-	}
-
-	T &getRef( uint32_t handle )
-	{
-		ASSERT( handle > 0 && handle <= _objects.size() );
-		
-		return _objects[handle - 1];
-	}
-
-	friend class RenderDevice;
-
-private:
-	std::vector< T >       _objects;
-	std::vector< uint32_t >  _freeList;
-};
-
-
-struct DeviceCaps
-{
-	bool  texFloat;
-	bool  texNPOT;
-	bool  rtMultisampling;
-};
-
-
-// ---------------------------------------------------------
-// Vertex layout
-// ---------------------------------------------------------
-
-struct VertexLayoutAttrib
-{
-	std::string  semanticName;
-	uint32_t       vbSlot;
-	uint32_t       size;
-	uint32_t       offset;
-};
-
-struct RDIVertexLayout
-{
-	uint32_t              numAttribs;
-	VertexLayoutAttrib  attribs[16];
-};
-
-
-// ---------------------------------------------------------
-// Buffers
-// ---------------------------------------------------------
-
-struct RDIBuffer
-{
-	uint32_t  type;
-	uint32_t  glObj;
-	uint32_t  size;
-};
-
-struct RDIVertBufSlot
-{
-	uint32_t  vbObj;
-	uint32_t  offset;
-	uint32_t  stride;
-
-	RDIVertBufSlot() : vbObj( 0 ), offset( 0 ), stride( 0 ) {}
-	RDIVertBufSlot( uint32_t vbObj, uint32_t offset, uint32_t stride ) :
-		vbObj( vbObj ), offset( offset ), stride( stride ) {}
-};
-
-
-// ---------------------------------------------------------
-// Textures
-// ---------------------------------------------------------
-
-struct TextureTypes
-{
-	enum List
-	{
-		Tex2D = GL_TEXTURE_2D,
-		Tex3D = GL_TEXTURE_3D,
-		TexCube = GL_TEXTURE_CUBE_MAP
-	};
-};
-
-struct TextureFormats
-{
-	enum List
-	{
-		Unknown,
-		BGRA8,
-		DXT1,
-		DXT3,
-		DXT5,
-		RGBA16F,
-		RGBA32F,
-		DEPTH
-	};
-};
-
-struct RDITexture
-{
-	uint32_t                glObj;
-	uint32_t                glFmt;
-	int                   type;
-	TextureFormats::List  format;
-	int                   width, height, depth;
-	int                   memSize;
-	uint32_t                samplerState;
-	bool                  sRGB;
-	bool                  hasMips, genMips;
-};
-
-struct RDITexSlot
-{
-	uint32_t  texObj;
-	uint32_t  samplerState;
-
-	RDITexSlot() : texObj( 0 ), samplerState( 0 ) {}
-	RDITexSlot( uint32_t texObj, uint32_t samplerState ) :
-		texObj( texObj ), samplerState( samplerState ) {}
-};
-
-
-// ---------------------------------------------------------
-// Shaders
-// ---------------------------------------------------------
-
-enum RDIShaderConstType
-{
-	CONST_FLOAT,
-	CONST_FLOAT2,
-	CONST_FLOAT3,
-	CONST_FLOAT4,
-	CONST_FLOAT44,
-	CONST_FLOAT33
-};
-
-struct RDIInputLayout
-{
-	bool  valid;
-	int8_t  attribIndices[16];
-};
-
-struct RDIShader
-{
-	uint32_t          oglProgramObj;
-	RDIInputLayout  inputLayouts[MaxNumVertexLayouts];
-};
-
-
-// ---------------------------------------------------------
-// Render buffers
-// ---------------------------------------------------------
-
-struct RDIRenderBuffer
-{
-	static const uint32_t MaxColorAttachmentCount = 4;
-
-	uint32_t  fbo, fboMS;  // fboMS: Multisampled FBO used when samples > 0
-	uint32_t  width, height;
-	uint32_t  samples;
-
-	uint32_t  depthTex, colTexs[MaxColorAttachmentCount];
-	uint32_t  depthBuf, colBufs[MaxColorAttachmentCount];  // Used for multisampling
-
-	RDIRenderBuffer() : fbo( 0 ), fboMS( 0 ), width( 0 ), height( 0 ), depthTex( 0 ), depthBuf( 0 )
-	{
-		for( uint32_t i = 0; i < MaxColorAttachmentCount; ++i ) colTexs[i] = colBufs[i] = 0;
-	}
-};
-
-
-// ---------------------------------------------------------
-// Render states
-// ---------------------------------------------------------
-
-// Note: Render states use unions to provide a hash value. Writing to and reading from different members of a
-//       union is not guaranteed to work by the C++ standard but is common practice and supported by many compilers.
-
-enum RDISamplerState
-{
-	SS_FILTER_BILINEAR   = 0x0,
-	SS_FILTER_TRILINEAR  = 0x0001,
-	SS_FILTER_POINT      = 0x0002,
-	SS_ANISO1            = 0x0,
-	SS_ANISO2            = 0x0004,
-	SS_ANISO4            = 0x0008,
-	SS_ANISO8            = 0x0010,
-	SS_ANISO16           = 0x0020,
-	SS_ADDRU_CLAMP       = 0x0,
-	SS_ADDRU_WRAP        = 0x0040,
-	SS_ADDRU_CLAMPCOL    = 0x0080,
-	SS_ADDRV_CLAMP       = 0x0,
-	SS_ADDRV_WRAP        = 0x0100,
-	SS_ADDRV_CLAMPCOL    = 0x0200,
-	SS_ADDRW_CLAMP       = 0x0,
-	SS_ADDRW_WRAP        = 0x0400,
-	SS_ADDRW_CLAMPCOL    = 0x0800,
-	SS_ADDR_CLAMP        = SS_ADDRU_CLAMP | SS_ADDRV_CLAMP | SS_ADDRW_CLAMP,
-	SS_ADDR_WRAP         = SS_ADDRU_WRAP | SS_ADDRV_WRAP | SS_ADDRW_WRAP,
-	SS_ADDR_CLAMPCOL     = SS_ADDRU_CLAMPCOL | SS_ADDRV_CLAMPCOL | SS_ADDRW_CLAMPCOL,
-	SS_COMP_LEQUAL       = 0x1000
-};
-
-const uint32_t SS_FILTER_START = 0;
-const uint32_t SS_FILTER_MASK = SS_FILTER_BILINEAR | SS_FILTER_TRILINEAR | SS_FILTER_POINT;
-const uint32_t SS_ANISO_START = 2;
-const uint32_t SS_ANISO_MASK = SS_ANISO1 | SS_ANISO2 | SS_ANISO4 | SS_ANISO8 | SS_ANISO16;
-const uint32_t SS_ADDRU_START = 6;
-const uint32_t SS_ADDRU_MASK = SS_ADDRU_CLAMP | SS_ADDRU_WRAP | SS_ADDRU_CLAMPCOL;
-const uint32_t SS_ADDRV_START = 8;
-const uint32_t SS_ADDRV_MASK = SS_ADDRV_CLAMP | SS_ADDRV_WRAP | SS_ADDRV_CLAMPCOL;
-const uint32_t SS_ADDRW_START = 10;
-const uint32_t SS_ADDRW_MASK = SS_ADDRW_CLAMP | SS_ADDRW_WRAP | SS_ADDRW_CLAMPCOL;
-const uint32_t SS_ADDR_START = 6;
-const uint32_t SS_ADDR_MASK = SS_ADDR_CLAMP | SS_ADDR_WRAP | SS_ADDR_CLAMPCOL;
-
-
-enum RDIFillMode
-{
-	RS_FILL_SOLID = 0,
-	RS_FILL_WIREFRAME = 1
-};
-
-enum RDICullMode
-{
-	RS_CULL_BACK = 0,
-	RS_CULL_FRONT,
-	RS_CULL_NONE,
-};
-
-struct RDIRasterState
-{
-	union
-	{
-		uint32_t  hash;
-		struct
-		{
-			uint32_t  fillMode : 1;  // RDIFillMode
-			uint32_t  cullMode : 2;  // RDICullMode
-			uint32_t  scissorEnable : 1;
-			uint32_t  multisampleEnable : 1;
-			uint32_t  renderTargetWriteMask : 1;
-		} params;
-	};
-};
-
-enum RDIBlendFunc
-{
-	BS_BLEND_ZERO = 0,
-	BS_BLEND_ONE,
-	BS_BLEND_SRC_ALPHA,
-	BS_BLEND_INV_SRC_ALPHA,
-	BS_BLEND_DEST_COLOR
-};
-
-struct RDIBlendState
-{
-	union
-	{
-		uint32_t  hash;
-		struct
-		{
-			uint32_t  alphaToCoverageEnable : 1;
-			uint32_t  blendEnable : 1;
-			uint32_t  srcBlendFunc : 4;
-			uint32_t  destBlendFunc : 4;
-		} params;
-	};
-};
-
-enum RDIDepthFunc
-{
-	DSS_DEPTHFUNC_LESS_EQUAL = 0,
-	DSS_DEPTHFUNC_LESS,
-	DSS_DEPTHFUNC_EQUAL,
-	DSS_DEPTHFUNC_GREATER,
-	DSS_DEPTHFUNC_GREATER_EQUAL,
-	DSS_DEPTHFUNC_ALWAYS
-};
-
-struct RDIDepthStencilState
-{
-	union
-	{
-		uint32_t  hash;
-		struct
-		{
-			uint32_t  depthWriteMask : 1;
-			uint32_t  depthEnable : 1;
-			uint32_t  depthFunc : 4;  // RDIDepthFunc
-		} params;
-	};
-};
-
-// ---------------------------------------------------------
-// Draw calls and clears
-// ---------------------------------------------------------
-
-enum RDIClearFlags
-{
-	CLR_COLOR_RT0 = 0x00000001,
-	CLR_COLOR_RT1 = 0x00000002,
-	CLR_COLOR_RT2 = 0x00000004,
-	CLR_COLOR_RT3 = 0x00000008,
-	CLR_DEPTH = 0x00000010
-};
-
-enum RDIIndexFormat
-{
-	IDXFMT_16 = GL_UNSIGNED_SHORT,
-	IDXFMT_32 = GL_UNSIGNED_INT
-};
-
-enum RDIPrimType
-{
-	PRIM_TRILIST = GL_TRIANGLES,
-	PRIM_TRISTRIP = GL_TRIANGLE_STRIP
-};
-
-// =================================================================================================
-
-
-class RenderDevice
-{
-public:
-
-	RenderDevice();
-	~RenderDevice();
-