private void setTexture(Texture2D texture) { if(texture != null) texture.Apply(); }
/// <summary> /// Lazily computes derived parameter values immediately before applying the effect. /// </summary> protected internal override void OnApply() { // Recompute the shader index? // if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0) { int shaderIndex = 0; if (!fogEnabled) { shaderIndex += 1; } if (vertexColorEnabled) { shaderIndex += 2; } if (textureEnabled) { shaderIndex += 4; } if (lightingEnabled) { if (preferPerPixelLighting) { shaderIndex += 24; } else if (oneLight) { shaderIndex += 16; } else { shaderIndex += 8; } } // // //shaderIndexParam.SetValue (shaderIndex); // // dirtyFlags &= ~EffectDirtyFlags.ShaderIndex; if (oldIndex != shaderIndex) { int vertexShader = VSArray[VSIndices[shaderIndex]]; int fragmentShader = PSArray[PSIndices[shaderIndex]]; UpdateTechnique("BasicEffect", "", vertexShader, fragmentShader); oldIndex = shaderIndex; // Update here } // } // These are the states that work GLStateManager.Projection(Projection); GLStateManager.WorldView(world, view); // Override this for now for testing purposes dirtyFlags |= EffectDirtyFlags.World | EffectDirtyFlags.WorldViewProj; dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.EyePosition; dirtyFlags &= ~EffectDirtyFlags.FogEnable; // turn off fog for now dirtyFlags |= EffectDirtyFlags.MaterialColor; GLStateManager.Textures2D(TextureEnabled); GLStateManager.ColorArray(VertexColorEnabled); // Recompute the world+view+projection matrix or fog vector? dirtyFlags = EffectHelpers.SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam); // Recompute the diffuse/emissive/alpha material color parameters? if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0) { EffectHelpers.SetMaterialColor(lightingEnabled, alpha, ref diffuseColor, ref emissiveColor, ref ambientLightColor, diffuseColorParam, emissiveColorParam); dirtyFlags &= ~EffectDirtyFlags.MaterialColor; } if (TextureEnabled) { _texture.Apply(); textureParam.SetValue(_texture); //System.Console.WriteLine("Texture set"); } // // if (lightingEnabled) { // // Recompute the world inverse transpose and eye position? // dirtyFlags = EffectHelpers.SetLightingMatrices (dirtyFlags, ref world, ref view, worldParam, worldInverseTransposeParam, eyePositionParam); // // // Check if we can use the only-bother-with-the-first-light shader optimization. // bool newOneLight = !light1.Enabled && !light2.Enabled; // // if (oneLight != newOneLight) { // oneLight = newOneLight; // dirtyFlags |= EffectDirtyFlags.ShaderIndex; // } // } }