/* * /// <summary> * /// * /// </summary> * /// <param name="mode"></param> * /// <returns></returns> #if !(XBOX || XBOX360 || SILVERLIGHT) * public static XFG.FogMode Convert( Axiom.Graphics.FogMode mode ) * { * // convert the fog mode value * switch ( mode ) * { * case Axiom.Graphics.FogMode.Exp: * return XFG.FogMode.Exponent; * * case Axiom.Graphics.FogMode.Exp2: * return XFG.FogMode.ExponentSquared; * * case Axiom.Graphics.FogMode.Linear: * return XFG.FogMode.Linear; * } // switch * * return 0; * } #endif */ /* public static XFG.LockFlags Convert( BufferLocking locking ) * { * //no lock in xna * XFG.LockFlags d3dLockFlags = 0; * * if ( locking == BufferLocking.Discard ) * d3dLockFlags |= XFG.LockFlags.Discard; * if ( locking == BufferLocking.ReadOnly ) * d3dLockFlags |= XFG.LockFlags.ReadOnly; * if ( locking == BufferLocking.NoOverwrite ) * d3dLockFlags |= XFG.LockFlags.NoOverwrite; * * return 0; * }*/ public static int Convert(TexCoordCalcMethod method) { /* * switch ( method ) * { * case TexCoordCalcMethod.None: * return (int)XFG.TextureCoordinateIndex.PassThru; * * case TexCoordCalcMethod.EnvironmentMapReflection: * return TexCoordCalcMethod.EnvironmentMapPlanar;// (int)XFG.TextureCoordinateIndex.CameraSpaceReflectionVector; * * case TexCoordCalcMethod.EnvironmentMapPlanar: * //return (int)XFG.TextureCoordinateIndex.CameraSpacePosition; * if ( caps.VertexProcessingCaps.SupportsTextureGenerationSphereMap ) * { * // use sphere map if available * return TexCoordCalcMethod.EnvironmentMapPlanar;// (int)XFG.TextureCoordinateIndex.SphereMap; * } * else * { * // If not, fall back on camera space reflection vector which isn't as good * return TexCoordCalcMethod.EnvironmentMapReflection;// (int)XFG.TextureCoordinateIndex.CameraSpaceReflectionVector; * } * * case TexCoordCalcMethod.EnvironmentMapNormal: * return TexCoordCalcMethod.EnvironmentMapNormal;// (int)XFG.TextureCoordinateIndex.CameraSpaceNormal; * * case TexCoordCalcMethod.EnvironmentMap: * if ( caps.VertexProcessingCaps.SupportsTextureGenerationSphereMap ) * { * return TexCoordCalcMethod.EnvironmentMap;// (int)XFG.TextureCoordinateIndex.SphereMap; * } * else * { * // fall back on camera space normal if sphere map isnt supported * return TexCoordCalcMethod.None;// (int)XFG.TextureCoordinateIndex.CameraSpaceNormal; * } * * case TexCoordCalcMethod.ProjectiveTexture: * return TexCoordCalcMethod.None;// (int)XFG.TextureCoordinateIndex.CameraSpacePosition; * } // switch */ return(1); }
public static int ConvertEnum(TexCoordCalcMethod method, D3D9.Capabilities caps) { switch (method) { case TexCoordCalcMethod.None: return((int)D3D9.TextureCoordIndex.PassThru); case TexCoordCalcMethod.EnvironmentMapReflection: return((int)D3D9.TextureCoordIndex.CameraSpaceReflectionVector); case TexCoordCalcMethod.EnvironmentMapPlanar: if ((caps.VertexProcessingCaps & D3D9.VertexProcessingCaps.TexGenSphereMap) == D3D9.VertexProcessingCaps.TexGenSphereMap) { // use sphere map if available return((int)D3D9.TextureCoordIndex.SphereMap); } else { // If not, fall back on camera space reflection vector which isn't as good return((int)D3D9.TextureCoordIndex.CameraSpaceReflectionVector); } case TexCoordCalcMethod.EnvironmentMapNormal: return((int)D3D9.TextureCoordIndex.CameraSpaceNormal); case TexCoordCalcMethod.EnvironmentMap: if ((caps.VertexProcessingCaps & D3D9.VertexProcessingCaps.TexGenSphereMap) == D3D9.VertexProcessingCaps.TexGenSphereMap) { return((int)D3D9.TextureCoordIndex.SphereMap); } else { // fall back on camera space normal if sphere map isnt supported return((int)D3D9.TextureCoordIndex.CameraSpaceNormal); } case TexCoordCalcMethod.ProjectiveTexture: return((int)D3D9.TextureCoordIndex.CameraSpacePosition); } // switch return(0); }
public override void SetTextureCoordCalculation( int stage, TexCoordCalcMethod method, Frustum frustum ) { // save this for texture matrix calcs later _texStageDesc[ stage ].autoTexCoordType = method; _texStageDesc[ stage ].frustum = frustum; SetTextureStageState( stage, TextureStage.TexCoordIndex, D3DHelper.ConvertEnum( method, _deviceManager.ActiveDevice.D3D9DeviceCaps ) | _texStageDesc[ stage ].coordIndex ); }
public override void SetTextureCoordCalculation( int unit, TexCoordCalcMethod method, Core.Frustum frustum ) { //Ogre: not supported }
/// <summary> /// Sets a method for automatically calculating texture coordinates for a stage. /// </summary> /// <param name="unit">Texture stage to modify.</param> /// <param name="method">Calculation method to use</param> /// <param name="frustum">Frustum, only used for projective effects</param> public override void SetTextureCoordCalculation(int stage, TexCoordCalcMethod method, Frustum frustum) { texStageDesc[stage].autoTexCoordType = method; texStageDesc[stage].frustum = frustum; //texStageDesc[stage].Enabled = true; //if (frustum != null) MessageBox.Show(texStageDesc[stage].Enabled.ToString()); }
public override void SetTextureCoordCalculation( int stage, TexCoordCalcMethod method, Frustum frustum ) { if ( stage > _fixedFunctionTextureUnits ) { // Can't do this return; } float[] m = new float[ 16 ]; Matrix4 projectionBias = Matrix4.Identity; // Default to no extra auto texture matrix _useAutoTextureMatrix = false; if ( !ActivateGLTextureUnit( stage ) ) return; switch ( method ) { case TexCoordCalcMethod.None: break; case TexCoordCalcMethod.EnvironmentMap: _useAutoTextureMatrix = true; _autoTextureMatrix = new float[ 16 ]; _autoTextureMatrix[ 0 ] = _autoTextureMatrix[ 10 ] = _autoTextureMatrix[ 15 ] = 1.0f; _autoTextureMatrix[ 5 ] = -1.0f; break; case TexCoordCalcMethod.EnvironmentMapPlanar: // TODO not implemented break; case TexCoordCalcMethod.EnvironmentMapReflection: // We need an extra texture matrix here // This sets the texture matrix to be the inverse of the view matrix _useAutoTextureMatrix = true; MakeGLMatrix( ref m, _ViewMatrix ); if ( _autoTextureMatrix == null ) _autoTextureMatrix = new float[ 16 ]; // Transpose 3x3 in order to invert matrix (rotation) // Note that we need to invert the Z _before_ the rotation // No idea why we have to invert the Z at all, but reflection is wrong without it _autoTextureMatrix[ 0 ] = m[ 0 ]; _autoTextureMatrix[ 1 ] = m[ 4 ]; _autoTextureMatrix[ 2 ] = -m[ 8 ]; _autoTextureMatrix[ 4 ] = m[ 1 ]; _autoTextureMatrix[ 5 ] = m[ 5 ]; _autoTextureMatrix[ 6 ] = -m[ 9 ]; _autoTextureMatrix[ 8 ] = m[ 2 ]; _autoTextureMatrix[ 9 ] = m[ 6 ]; _autoTextureMatrix[ 10 ] = -m[ 10 ]; _autoTextureMatrix[ 3 ] = _autoTextureMatrix[ 7 ] = _autoTextureMatrix[ 11 ] = 0.0f; _autoTextureMatrix[ 12 ] = _autoTextureMatrix[ 13 ] = _autoTextureMatrix[ 14 ] = 0.0f; _autoTextureMatrix[ 15 ] = 1.0f; break; case TexCoordCalcMethod.EnvironmentMapNormal: break; case TexCoordCalcMethod.ProjectiveTexture: _useAutoTextureMatrix = true; if ( _autoTextureMatrix == null ) _autoTextureMatrix = new float[ 16 ]; // Set scale and translation matrix for projective textures projectionBias = Matrix4.ClipSpace2DToImageSpace; projectionBias = projectionBias * frustum.ProjectionMatrix; projectionBias = projectionBias * frustum.ViewMatrix; projectionBias = projectionBias * _worldMatrix; MakeGLMatrix( ref _autoTextureMatrix, projectionBias ); break; default: break; } ActivateGLTextureUnit( 0 ); }
/* /// <summary> /// /// </summary> /// <param name="mode"></param> /// <returns></returns> #if !(XBOX || XBOX360 || SILVERLIGHT) public static XFG.FogMode Convert( Axiom.Graphics.FogMode mode ) { // convert the fog mode value switch ( mode ) { case Axiom.Graphics.FogMode.Exp: return XFG.FogMode.Exponent; case Axiom.Graphics.FogMode.Exp2: return XFG.FogMode.ExponentSquared; case Axiom.Graphics.FogMode.Linear: return XFG.FogMode.Linear; } // switch return 0; } #endif */ /* public static XFG.LockFlags Convert( BufferLocking locking ) { //no lock in xna XFG.LockFlags d3dLockFlags = 0; if ( locking == BufferLocking.Discard ) d3dLockFlags |= XFG.LockFlags.Discard; if ( locking == BufferLocking.ReadOnly ) d3dLockFlags |= XFG.LockFlags.ReadOnly; if ( locking == BufferLocking.NoOverwrite ) d3dLockFlags |= XFG.LockFlags.NoOverwrite; return 0; }*/ public static int Convert( TexCoordCalcMethod method ) { /* switch ( method ) { case TexCoordCalcMethod.None: return (int)XFG.TextureCoordinateIndex.PassThru; case TexCoordCalcMethod.EnvironmentMapReflection: return TexCoordCalcMethod.EnvironmentMapPlanar;// (int)XFG.TextureCoordinateIndex.CameraSpaceReflectionVector; case TexCoordCalcMethod.EnvironmentMapPlanar: //return (int)XFG.TextureCoordinateIndex.CameraSpacePosition; if ( caps.VertexProcessingCaps.SupportsTextureGenerationSphereMap ) { // use sphere map if available return TexCoordCalcMethod.EnvironmentMapPlanar;// (int)XFG.TextureCoordinateIndex.SphereMap; } else { // If not, fall back on camera space reflection vector which isn't as good return TexCoordCalcMethod.EnvironmentMapReflection;// (int)XFG.TextureCoordinateIndex.CameraSpaceReflectionVector; } case TexCoordCalcMethod.EnvironmentMapNormal: return TexCoordCalcMethod.EnvironmentMapNormal;// (int)XFG.TextureCoordinateIndex.CameraSpaceNormal; case TexCoordCalcMethod.EnvironmentMap: if ( caps.VertexProcessingCaps.SupportsTextureGenerationSphereMap ) { return TexCoordCalcMethod.EnvironmentMap;// (int)XFG.TextureCoordinateIndex.SphereMap; } else { // fall back on camera space normal if sphere map isnt supported return TexCoordCalcMethod.None;// (int)XFG.TextureCoordinateIndex.CameraSpaceNormal; } case TexCoordCalcMethod.ProjectiveTexture: return TexCoordCalcMethod.None;// (int)XFG.TextureCoordinateIndex.CameraSpacePosition; } // switch */ return 1; }
/// <summary> /// Sets a method for automatically calculating texture coordinates for a stage. /// </summary> /// <param name="stage">Texture stage to modify.</param> /// <param name="method">Calculation method to use</param> public void SetTextureCoordCalculation(int stage, TexCoordCalcMethod method) { SetTextureCoordCalculation(stage, method, null); }
/// <summary> /// Sets a method for automatically calculating texture coordinates for a stage. /// </summary> /// <param name="stage">Texture stage to modify.</param> /// <param name="method">Calculation method to use</param> /// <param name="frustum">Frustum, only used for projective effects</param> public abstract void SetTextureCoordCalculation(int stage, TexCoordCalcMethod method, Frustum frustum);
public static int ConvertEnum( TexCoordCalcMethod method, D3D.Capabilities caps ) { switch ( method ) { case TexCoordCalcMethod.None: return (int)D3D.TextureCoordIndex.PassThru; case TexCoordCalcMethod.EnvironmentMapReflection: return (int)D3D.TextureCoordIndex.CameraSpaceReflectionVector; case TexCoordCalcMethod.EnvironmentMapPlanar: //return (int)D3D.TextureCoordinateIndex.CameraSpacePosition; if ( ( caps.VertexProcessingCaps & D3D.VertexProcessingCaps.TexGenSphereMap ) == D3D.VertexProcessingCaps.TexGenSphereMap ) { // use sphere map if available return (int)D3D.TextureCoordIndex.SphereMap; } else { // If not, fall back on camera space reflection vector which isn't as good return (int)D3D.TextureCoordIndex.CameraSpaceReflectionVector; } case TexCoordCalcMethod.EnvironmentMapNormal: return (int)D3D.TextureCoordIndex.CameraSpaceNormal; case TexCoordCalcMethod.EnvironmentMap: if ( ( caps.VertexProcessingCaps & D3D.VertexProcessingCaps.TexGenSphereMap ) == D3D.VertexProcessingCaps.TexGenSphereMap ) { return (int)D3D.TextureCoordIndex.SphereMap; } else { // fall back on camera space normal if sphere map isnt supported return (int)D3D.TextureCoordIndex.CameraSpaceNormal; } case TexCoordCalcMethod.ProjectiveTexture: return (int)D3D.TextureCoordIndex.CameraSpacePosition; } // switch return 0; }
public override void SetTextureCoordCalculation( int stage, TexCoordCalcMethod method, Frustum frustum ) { if (stage >= _fixedFunctionTextureUnits) { // Can't do this return; } // Default to no extra auto texture matrix useAutoTextureMatrix = false; float[] eyePlaneS = { 1.0f, 0.0f, 0.0f, 0.0f }; float[] eyePlaneT = { 0.0f, 1.0f, 0.0f, 0.0f }; float[] eyePlaneR = { 0.0f, 0.0f, 1.0f, 0.0f }; float[] eyePlaneQ = { 0.0f, 0.0f, 0.0f, 1.0f }; if (!ActivateGLTextureUnit(stage)) return; switch ( method ) { case TexCoordCalcMethod.None: Gl.glDisable( Gl.GL_TEXTURE_GEN_S ); Gl.glDisable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); break; case TexCoordCalcMethod.EnvironmentMap: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); // Need to use a texture matrix to flip the spheremap useAutoTextureMatrix = true; Array.Clear( autoTextureMatrix, 0, 16 ); autoTextureMatrix[ 0 ] = autoTextureMatrix[ 10 ] = autoTextureMatrix[ 15 ] = 1.0f; autoTextureMatrix[ 5 ] = -1.0f; break; case TexCoordCalcMethod.EnvironmentMapPlanar: // XXX This doesn't seem right?! if ( GL_VERSION_1_3 ) { Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); } else { Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); } break; case TexCoordCalcMethod.EnvironmentMapReflection: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); // We need an extra texture matrix here // This sets the texture matrix to be the inverse of the modelview matrix useAutoTextureMatrix = true; MakeGLMatrix(ref viewMatrix, _tempMatrix); // Transpose 3x3 in order to invert matrix (rotation) // Note that we need to invert the Z _before_ the rotation // No idea why we have to invert the Z at all, but reflection is wrong without it autoTextureMatrix[ 0 ] = _tempMatrix[ 0 ]; autoTextureMatrix[ 1 ] = _tempMatrix[ 4 ]; autoTextureMatrix[ 2 ] = -_tempMatrix[ 8 ]; autoTextureMatrix[ 4 ] = _tempMatrix[ 1 ]; autoTextureMatrix[ 5 ] = _tempMatrix[ 5 ]; autoTextureMatrix[ 6 ] = -_tempMatrix[ 9 ]; autoTextureMatrix[ 8 ] = _tempMatrix[ 2 ]; autoTextureMatrix[ 9 ] = _tempMatrix[ 6 ]; autoTextureMatrix[ 10 ] = -_tempMatrix[ 10 ]; autoTextureMatrix[ 3 ] = autoTextureMatrix[ 7 ] = autoTextureMatrix[ 11 ] = 0.0f; autoTextureMatrix[ 12 ] = autoTextureMatrix[ 13 ] = autoTextureMatrix[ 14 ] = 0.0f; autoTextureMatrix[ 15 ] = 1.0f; break; case TexCoordCalcMethod.EnvironmentMapNormal: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); break; case TexCoordCalcMethod.ProjectiveTexture: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR ); Gl.glTexGeni( Gl.GL_Q, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR ); Gl.glTexGenfv( Gl.GL_S, Gl.GL_EYE_PLANE, eyePlaneS ); Gl.glTexGenfv( Gl.GL_T, Gl.GL_EYE_PLANE, eyePlaneT ); Gl.glTexGenfv( Gl.GL_R, Gl.GL_EYE_PLANE, eyePlaneR ); Gl.glTexGenfv( Gl.GL_Q, Gl.GL_EYE_PLANE, eyePlaneQ ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glEnable( Gl.GL_TEXTURE_GEN_Q ); useAutoTextureMatrix = true; // Set scale and translation matrix for projective textures Matrix4 projectionBias = Matrix4.ClipSpace2DToImageSpace; //projectionBias.m00 = 0.5f; //projectionBias.m11 = -0.5f; //projectionBias.m22 = 1.0f; //projectionBias.m03 = 0.5f; //projectionBias.m13 = 0.5f; //projectionBias.m33 = 1.0f; projectionBias = projectionBias * frustum.ProjectionMatrix; if (texProjRelative) { Matrix4 tmp; frustum.CalcViewMatrixRelative(texProjRelativeOrigin, out tmp); projectionBias = projectionBias * tmp; } else { projectionBias = projectionBias*frustum.ViewMatrix; } projectionBias = projectionBias * worldMatrix; MakeGLMatrix( ref projectionBias, autoTextureMatrix ); break; default: break; } ActivateGLTextureUnit(0); }
/// <summary> /// /// </summary> /// <param name="stage"></param> /// <param name="method"></param> public override void SetTextureCoordCalculation(int stage, TexCoordCalcMethod method, Frustum frustum) { // save this for texture matrix calcs later if (texStageDesc[stage].autoTexCoordType != method || texStageDesc[stage].frustum != frustum) { // We will need ot recalculate the texture matrix cache.usingTextureMatrix[stage] = false; texStageDesc[stage].autoTexCoordType = method; texStageDesc[stage].frustum = frustum; } SetTextureCoordSetInternal(stage, texStageDesc[stage].coordIndex); }
/// <summary> /// /// </summary> /// <param name="stage"></param> /// <param name="method"></param> public override void SetTextureCoordCalculation(int stage, TexCoordCalcMethod method, Frustum frustum) { // Default to no extra auto texture matrix useAutoTextureMatrix = false; if(method == TexCoordCalcMethod.None && lastTexCalMethods[stage] == method) { return; } // store for next checking next time around lastTexCalMethods[stage] = method; float[] eyePlaneS = {1.0f, 0.0f, 0.0f, 0.0f}; float[] eyePlaneT = {0.0f, 1.0f, 0.0f, 0.0f}; float[] eyePlaneR = {0.0f, 0.0f, 1.0f, 0.0f}; float[] eyePlaneQ = {0.0f, 0.0f, 0.0f, 1.0f}; Gl.glActiveTextureARB(Gl.GL_TEXTURE0 + stage ); switch(method) { case TexCoordCalcMethod.None: Gl.glDisable( Gl.GL_TEXTURE_GEN_S ); Gl.glDisable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); break; case TexCoordCalcMethod.EnvironmentMap: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); // Need to use a texture matrix to flip the spheremap useAutoTextureMatrix = true; Array.Clear(autoTextureMatrix, 0, 16); autoTextureMatrix[0] = autoTextureMatrix[10] = autoTextureMatrix[15] = 1.0f; autoTextureMatrix[5] = -1.0f; break; case TexCoordCalcMethod.EnvironmentMapPlanar: // XXX This doesn't seem right?! if(glSupport.CheckMinVersion("1.3")) { Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); } else { Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_SPHERE_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glDisable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); } break; case TexCoordCalcMethod.EnvironmentMapReflection: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_REFLECTION_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); // We need an extra texture matrix here // This sets the texture matrix to be the inverse of the modelview matrix useAutoTextureMatrix = true; Gl.glGetFloatv(Gl.GL_MODELVIEW_MATRIX, tempMatrix); // Transpose 3x3 in order to invert matrix (rotation) // Note that we need to invert the Z _before_ the rotation // No idea why we have to invert the Z at all, but reflection is wrong without it autoTextureMatrix[0] = tempMatrix[0]; autoTextureMatrix[1] = tempMatrix[4]; autoTextureMatrix[2] = -tempMatrix[8]; autoTextureMatrix[4] = tempMatrix[1]; autoTextureMatrix[5] = tempMatrix[5]; autoTextureMatrix[6] = -tempMatrix[9]; autoTextureMatrix[8] = tempMatrix[2]; autoTextureMatrix[9] = tempMatrix[6]; autoTextureMatrix[10] = -tempMatrix[10]; autoTextureMatrix[3] = autoTextureMatrix[7] = autoTextureMatrix[11] = 0.0f; autoTextureMatrix[12] = autoTextureMatrix[13] = autoTextureMatrix[14] = 0.0f; autoTextureMatrix[15] = 1.0f; break; case TexCoordCalcMethod.EnvironmentMapNormal: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_NORMAL_MAP ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S ); Gl.glEnable( Gl.GL_TEXTURE_GEN_T ); Gl.glEnable( Gl.GL_TEXTURE_GEN_R ); Gl.glDisable( Gl.GL_TEXTURE_GEN_Q ); break; case TexCoordCalcMethod.ProjectiveTexture: Gl.glTexGeni( Gl.GL_S, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR); Gl.glTexGeni( Gl.GL_T, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR); Gl.glTexGeni( Gl.GL_R, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR); Gl.glTexGeni( Gl.GL_Q, Gl.GL_TEXTURE_GEN_MODE, Gl.GL_EYE_LINEAR); Gl.glTexGenfv( Gl.GL_S, Gl.GL_EYE_PLANE, eyePlaneS); Gl.glTexGenfv( Gl.GL_T, Gl.GL_EYE_PLANE, eyePlaneT); Gl.glTexGenfv( Gl.GL_R, Gl.GL_EYE_PLANE, eyePlaneR); Gl.glTexGenfv( Gl.GL_Q, Gl.GL_EYE_PLANE, eyePlaneQ); Gl.glEnable( Gl.GL_TEXTURE_GEN_S); Gl.glEnable( Gl.GL_TEXTURE_GEN_T); Gl.glEnable( Gl.GL_TEXTURE_GEN_R); Gl.glEnable( Gl.GL_TEXTURE_GEN_Q); useAutoTextureMatrix = true; // Set scale and translation matrix for projective textures Matrix4 projectionBias = Matrix4.Zero; projectionBias.m00 = 0.5f; projectionBias.m11 = -0.5f; projectionBias.m22 = 1.0f; projectionBias.m03 = 0.5f; projectionBias.m13 = 0.5f; projectionBias.m33 = 1.0f; projectionBias = projectionBias * frustum.ProjectionMatrix; projectionBias = projectionBias * frustum.ViewMatrix; projectionBias = projectionBias * worldMatrix; MakeGLMatrix( ref projectionBias, autoTextureMatrix ); break; default: break; } Gl.glActiveTextureARB(Gl.GL_TEXTURE0); }