예제 #1
0
        internal override void ApplyPreRenderSettings(Material mat, bool useVertexColor)
        {
            if (mat.mainTexture != null)
            {
                Effect.TextureEnabled = true;
                Effect.Texture        = mat.mainTexture;
            }
            else
            {
                Effect.TextureEnabled = false;
            }

            Effect.DiffuseColor       = mat.color;
            Effect.Alpha              = mat.color.a;
            Effect.VertexColorEnabled = useVertexColor;
            if (supportsLights)
            {
                Effect.LightingEnabled = Light.HasLights;
                if (supportsLights && Light.HasLights)
                {
                    Light.EnableLighting(Effect, 0);
                }
            }
            else
            {
                Effect.LightingEnabled = false;
            }
        }
예제 #2
0
        internal int DoDraw(GraphicsDevice device, Camera cam)
        {
            if (currentIndexIndex == 0)
            {
                return(0);
            }

            cam.BasicEffect.World = Matrix.Identity;
            cam.BasicEffect.VertexColorEnabled = hasColors;
            cam.BasicEffect.LightingEnabled    = (!hasColors) && Light.HasLights;
            if (cam.BasicEffect.LightingEnabled)
            {
                Light.EnableLighting(cam.BasicEffect, 0.2f);
            }

            currentMaterial.SetTextureState(cam.BasicEffect);
            currentMaterial.SetBlendState(device);

#if DEBUG
            if (Camera.logRenderCalls)
            {
                Debug.LogFormat("==> Dyn batch draw: {0} RQ {4} on {1} verts {2}, indices {3}", currentMaterial.mainTexture, cam.gameObject, currentVertexIndex, currentIndexIndex, currentMaterial.finalRenderQueue);
            }
#endif

            foreach (EffectPass pass in cam.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                if (hasColors)
                {
                    device.DrawUserIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        vertexColorData,
                        0,
                        currentVertexIndex,
                        indexData,
                        0,
                        currentIndexIndex / 3
                        );
                }
                else
                {
                    device.DrawUserIndexedPrimitives(
                        PrimitiveType.TriangleList,
                        vertexData,
                        0,
                        currentVertexIndex,
                        indexData,
                        0,
                        currentIndexIndex / 3
                        );
                }
            }

            EndBatch();
            return(1);
        }
예제 #3
0
파일: Camera.cs 프로젝트: mikecrews/FFWD
        internal void doRender(GraphicsDevice device)
        {
            if (targetChanged)
            {
                CreateRenderTarget();
            }
            if (target != null)
            {
                device.SetRenderTarget(target);
                device.Clear(Microsoft.Xna.Framework.Color.Transparent);
            }
            Clear(device);

#if DEBUG
            if (logRenderCalls)
            {
                if (target == null)
                {
                    Debug.Log("**** Camera begin : ", name, "****");
                }
                else
                {
                    Debug.Log("**** Camera begin to texture : ", name, "****");
                }
            }
#endif
            RenderStats.Clear();

            if (CulledRenderQueue.Count > 0)
            {
                int rqCount = CulledRenderQueue.Count;
                for (int i = 0; i < rqCount; i++)
                {
                    CulledRenderQueue[i].Render(device, this);
                }
            }
            frustum.Matrix = view * projectionMatrix;

            int q     = 0;
            int count = oldRenderQueue.Count;

            if (count > 0)
            {
                BasicEffect.View       = view;
                BasicEffect.Projection = projectionMatrix;

                if (Light.HasLights)
                {
                    Light.EnableLighting(BasicEffect, 0);
                }
            }

            for (int i = 0; i < count; i++)
            {
                Renderer r = oldRenderQueue[i];

                if (r.gameObject == null)
                {
                    // This will happen if the game object has been destroyed in update.
                    // It is acceptable behaviour.
                    continue;
                }

                if (r.material == null)
                {
                    // We have no material, so we will skip rendering
                    continue;
                }

                if (r.isPartOfStaticBatch)
                {
                    // The object is statically batched, so we will skip it
                    continue;
                }

                if (r.material.renderQueue != q)
                {
                    if (q > 0)
                    {
                        dynamicBatchRenderer.DoDraw(device, this);
                    }
                    q = r.material.renderQueue;
                }

                if (r.gameObject.active && r.enabled)
                {
                    r.Draw(device, this);
                }
            }

            dynamicBatchRenderer.DoDraw(device, this);
        }