示例#1
0
        internal override void Apply()
        {
            // May need to be moved elsewhere within this method
            OnApply();

            GLStateManager.Projection(Projection);
            GLStateManager.World(World);
            GLStateManager.View(View);

            base.Apply();

            GLStateManager.Textures2D(Texture != null);

            GLStateManager.ColorArray(VertexColorEnabled);
        }
        internal override void Apply()
        {
            // May need to be moved elsewhere within this method
            OnApply();

            GLStateManager.Viewport(Game.Instance.Window.ClientBounds);
            GLStateManager.Projection(Projection);
            GLStateManager.WorldView(World, View);

            base.Apply();

            GLStateManager.Textures2D(Texture != null);

            GLStateManager.ColorArray(VertexColorEnabled);
        }
示例#3
0
        internal override void Apply()
        {
            // May need to be moved elsewhere within this method
            OnApply();

            GLStateManager.Projection(Projection);
            GLStateManager.WorldView(World, View);

            // this should probably not be here.
            // this should probably be set immediately on assignment.
            GLStateManager.Cull(this.graphicsDevice.RasterizerState.CullMode);

            base.Apply();

            GLStateManager.Textures2D(Texture != null);

            GLStateManager.ColorArray(VertexColorEnabled);
        }
示例#4
0
        /// <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;
//				}
//			}
        }
示例#5
0
        public void End()
        {
            // set up camera
            switch (this.graphicsDevice.PresentationParameters.DisplayOrientation)
            {
            case DisplayOrientation.LandscapeLeft:
            case DisplayOrientation.LandscapeRight:
            case DisplayOrientation.PortraitUpsideDown:
                throw new NotImplementedException();

            default:
                if (this.graphicsDevice.RenderTarget != null)
                {
                    Matrix4.CreateOrthographicOffCenter(0, this.graphicsDevice.RenderTarget.Width, this.graphicsDevice.RenderTarget.Height, 0, -1, 1, out GLStateManager.Projection);
                    break;
                }
                else
                {
                    Matrix4.CreateOrthographicOffCenter(0, this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height, 0, -1, 1, out GLStateManager.Projection);
                    break;
                }
            }

            GL.Viewport(this.graphicsDevice.Viewport.X, this.graphicsDevice.Viewport.Y,
                        this.graphicsDevice.Viewport.Width, this.graphicsDevice.Viewport.Height);

            // Enable Scissor Tests if necessary
            if (this.graphicsDevice.RenderState.ScissorTestEnable)
            {
                GL.Enable(EnableCap.ScissorTest);
                GL.Scissor(this.graphicsDevice.ScissorRectangle.X, this.graphicsDevice.ScissorRectangle.Y, this.graphicsDevice.ScissorRectangle.Width, this.graphicsDevice.ScissorRectangle.Height);
            }

            GLStateManager.ModelView = _matrix.ToMatrix4();

            // Initialize OpenGL states (ideally move this to initialize somewhere else)
            GLStateManager.DepthTest(false);
            GLStateManager.Textures2D(true);

            // Enable Culling for better performance
            GLStateManager.Cull(FrontFaceDirection.Cw);

            switch (_sortMode)
            {
            case SpriteSortMode.Immediate:
                break;

            default:
                this.graphicsDevice.RenderState.SourceBlend      = _blendState.ColorSourceBlend;
                this.graphicsDevice.RenderState.DestinationBlend = _blendState.ColorDestinationBlend;
                break;
            }

            GLStateManager.BlendFunc((BlendingFactorSrc)this.graphicsDevice.RenderState.SourceBlend, (BlendingFactorDest)this.graphicsDevice.RenderState.DestinationBlend);

            _batcher.DrawBatch(_sortMode);

            // GG EDIT always disable scissor test after drawing a batch
            if (this.graphicsDevice.RenderState.ScissorTestEnable)
            {
                GL.Disable(EnableCap.ScissorTest);
            }
        }