Exemple #1
0
        private void ShowObject(ObjectState state)
        {
            touchableObject.Add(state);

            if (renderer.AvailableNewRenderer && state.Prototype.Mesh.VAO == null)
            {
                VAOExtensions.CreateVAO(ref state.Prototype.Mesh, state.Prototype.Dynamic, renderer.pickingShader.VertexLayout, renderer);
            }
        }
Exemple #2
0
        /// <summary>Renders an object based background</summary>
        /// <param name="data">The background object</param>
        private void RenderBackgroundObject(BackgroundObject data)
        {
            if (renderer.AvailableNewRenderer)
            {
                renderer.DefaultShader.Activate();
                renderer.DefaultShader.SetCurrentProjectionMatrix(renderer.CurrentProjectionMatrix);

                if (data.Object.Mesh.VAO == null)
                {
                    VAOExtensions.CreateVAO(ref data.Object.Mesh, false, renderer.DefaultShader.VertexLayout);
                }
            }

            foreach (MeshFace face in data.Object.Mesh.Faces)
            {
                OpenGlTextureWrapMode wrap = OpenGlTextureWrapMode.ClampClamp;

                if (data.Object.Mesh.Materials[face.Material].DaytimeTexture != null)
                {
                    if (data.Object.Mesh.Materials[face.Material].WrapMode == null)
                    {
                        foreach (VertexTemplate vertex in data.Object.Mesh.Vertices)
                        {
                            if (vertex.TextureCoordinates.X < 0.0f || vertex.TextureCoordinates.X > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.RepeatClamp;
                            }

                            if (vertex.TextureCoordinates.Y < 0.0f || vertex.TextureCoordinates.Y > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.ClampRepeat;
                            }
                        }

                        data.Object.Mesh.Materials[face.Material].WrapMode = wrap;
                    }
                }

                if (renderer.AvailableNewRenderer)
                {
                    renderer.RenderFace(renderer.DefaultShader, new ObjectState {
                        Prototype = data.Object
                    }, face, Matrix4D.NoTransformation, Matrix4D.Scale(1.0) * renderer.CurrentViewMatrix);
                }
                else
                {
                    renderer.RenderFaceImmediateMode(new ObjectState {
                        Prototype = data.Object
                    }, face, Matrix4D.NoTransformation, Matrix4D.Scale(1.0) * renderer.CurrentViewMatrix);
                }
            }

            if (renderer.AvailableNewRenderer)
            {
                renderer.DefaultShader.Deactivate();
            }
        }
Exemple #3
0
        private void ShowObject(ObjectState state)
        {
            objectStates.Add(state);

            if (state.Prototype.Mesh.VAO == null)
            {
                VAOExtensions.CreateVAO(ref state.Prototype.Mesh, state.Prototype.Dynamic, renderer.DefaultShader.VertexLayout);
            }

            foreach (MeshFace face in state.Prototype.Mesh.Faces)
            {
                touchFaces.Add(new FaceState(state, face));
            }
        }
Exemple #4
0
        /// <summary>Renders an object based background</summary>
        /// <param name="data">The background object</param>
        private void RenderBackgroundObject(BackgroundObject data)
        {
            if (data.Object.Mesh.VAO == null)
            {
                VAOExtensions.CreateVAO(ref data.Object.Mesh, false);
            }

            foreach (MeshFace face in data.Object.Mesh.Faces)
            {
                OpenGlTextureWrapMode wrap = OpenGlTextureWrapMode.ClampClamp;

                if (data.Object.Mesh.Materials[face.Material].DaytimeTexture != null)
                {
                    if (data.Object.Mesh.Materials[face.Material].WrapMode == null)
                    {
                        foreach (VertexTemplate vertex in data.Object.Mesh.Vertices)
                        {
                            if (vertex.TextureCoordinates.X < 0.0f || vertex.TextureCoordinates.X > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.RepeatClamp;
                            }

                            if (vertex.TextureCoordinates.Y < 0.0f || vertex.TextureCoordinates.Y > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.ClampRepeat;
                            }
                        }

                        data.Object.Mesh.Materials[face.Material].WrapMode = wrap;
                    }
                }

                renderer.DefaultShader.Activate();
                renderer.ResetShader(renderer.DefaultShader);
                renderer.RenderFace(renderer.DefaultShader, new ObjectState {
                    Prototype = data.Object
                }, face);
                renderer.DefaultShader.Deactivate();
            }
        }
Exemple #5
0
        public void ShowObject(ObjectState State, ObjectType Type)
        {
            bool result = AddObject(State);

            if (State.Prototype.Mesh.VAO == null)
            {
                VAOExtensions.CreateVAO(ref State.Prototype.Mesh, State.Prototype.Dynamic);
            }

            if (!result)
            {
                return;
            }

            foreach (MeshFace face in State.Prototype.Mesh.Faces)
            {
                OpenGlTextureWrapMode wrap = OpenGlTextureWrapMode.ClampClamp;

                if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture != null || State.Prototype.Mesh.Materials[face.Material].NighttimeTexture != null)
                {
                    if (State.Prototype.Mesh.Materials[face.Material].WrapMode == null)
                    {
                        // If the object does not have a stored wrapping mode, determine it now
                        foreach (VertexTemplate vertex in State.Prototype.Mesh.Vertices)
                        {
                            if (vertex.TextureCoordinates.X < 0.0f || vertex.TextureCoordinates.X > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.RepeatClamp;
                            }

                            if (vertex.TextureCoordinates.Y < 0.0f || vertex.TextureCoordinates.Y > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.ClampRepeat;
                            }
                        }

                        State.Prototype.Mesh.Materials[face.Material].WrapMode = wrap;
                    }
                }

                bool alpha = false;

                if (Type == ObjectType.Overlay && camera.CurrentRestriction != CameraRestrictionMode.NotAvailable)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].Color.A != 255)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].BlendMode == MeshMaterialBlendMode.Additive)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].GlowAttenuationData != 0)
                {
                    alpha = true;
                }
                else
                {
                    if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture != null)
                    {
                        currentHost.LoadTexture(State.Prototype.Mesh.Materials[face.Material].DaytimeTexture, (OpenGlTextureWrapMode)State.Prototype.Mesh.Materials[face.Material].WrapMode);

                        if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Transparency == TextureTransparencyType.Alpha)
                        {
                            alpha = true;
                        }
                        else if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Transparency == TextureTransparencyType.Partial && currentOptions.TransparencyMode == TransparencyMode.Quality)
                        {
                            alpha = true;
                        }
                    }

                    if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture != null)
                    {
                        currentHost.LoadTexture(State.Prototype.Mesh.Materials[face.Material].NighttimeTexture, (OpenGlTextureWrapMode)State.Prototype.Mesh.Materials[face.Material].WrapMode);

                        if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture.Transparency == TextureTransparencyType.Alpha)
                        {
                            alpha = true;
                        }
                        else if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture.Transparency == TextureTransparencyType.Partial && currentOptions.TransparencyMode == TransparencyMode.Quality)
                        {
                            alpha = true;
                        }
                    }
                }

                /*
                 * For all lists, insert the face at the end of the list.
                 * */
                List <FaceState> list;

                switch (Type)
                {
                case ObjectType.Static:
                case ObjectType.Dynamic:
                    list = alpha ? myAlphaFaces : myOpaqueFaces;
                    break;

                case ObjectType.Overlay:
                    list = alpha ? myOverlayAlphaFaces : myOverlayOpaqueFaces;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(Type), Type, null);
                }

                list.Add(new FaceState(State, face));
            }
        }
Exemple #6
0
        public void ShowObject(ObjectState State, ObjectType Type)
        {
            bool result = AddObject(State);

            if (!renderer.ForceLegacyOpenGL && State.Prototype.Mesh.VAO == null)
            {
                VAOExtensions.CreateVAO(ref State.Prototype.Mesh, State.Prototype.Dynamic, renderer.DefaultShader.VertexLayout);
            }

            if (!result)
            {
                return;
            }

            foreach (MeshFace face in State.Prototype.Mesh.Faces)
            {
                OpenGlTextureWrapMode wrap = OpenGlTextureWrapMode.ClampClamp;

                if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture != null || State.Prototype.Mesh.Materials[face.Material].NighttimeTexture != null)
                {
                    if (State.Prototype.Mesh.Materials[face.Material].WrapMode == null)
                    {
                        // If the object does not have a stored wrapping mode, determine it now
                        foreach (VertexTemplate vertex in State.Prototype.Mesh.Vertices)
                        {
                            if (vertex.TextureCoordinates.X < 0.0f || vertex.TextureCoordinates.X > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.RepeatClamp;
                            }

                            if (vertex.TextureCoordinates.Y < 0.0f || vertex.TextureCoordinates.Y > 1.0f)
                            {
                                wrap |= OpenGlTextureWrapMode.ClampRepeat;
                            }
                        }

                        State.Prototype.Mesh.Materials[face.Material].WrapMode = wrap;
                    }
                }

                bool alpha = false;

                if (Type == ObjectType.Overlay && camera.CurrentRestriction != CameraRestrictionMode.NotAvailable)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].Color.A != 255)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].BlendMode == MeshMaterialBlendMode.Additive)
                {
                    alpha = true;
                }
                else if (State.Prototype.Mesh.Materials[face.Material].GlowAttenuationData != 0)
                {
                    alpha = true;
                }
                else
                {
                    if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture != null)
                    {
                        currentHost.LoadTexture(State.Prototype.Mesh.Materials[face.Material].DaytimeTexture, (OpenGlTextureWrapMode)State.Prototype.Mesh.Materials[face.Material].WrapMode);

                        if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Transparency == TextureTransparencyType.Alpha)
                        {
                            alpha = true;
                        }
                        else if (State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Transparency == TextureTransparencyType.Partial && currentOptions.TransparencyMode == TransparencyMode.Quality)
                        {
                            alpha = true;
                        }
                    }

                    if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture != null)
                    {
                        currentHost.LoadTexture(State.Prototype.Mesh.Materials[face.Material].NighttimeTexture, (OpenGlTextureWrapMode)State.Prototype.Mesh.Materials[face.Material].WrapMode);

                        if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture.Transparency == TextureTransparencyType.Alpha)
                        {
                            alpha = true;
                        }
                        else if (State.Prototype.Mesh.Materials[face.Material].NighttimeTexture.Transparency == TextureTransparencyType.Partial && currentOptions.TransparencyMode == TransparencyMode.Quality)
                        {
                            alpha = true;
                        }
                    }
                }

                List <FaceState> list;

                switch (Type)
                {
                case ObjectType.Static:
                case ObjectType.Dynamic:
                    list = alpha ? myAlphaFaces : myOpaqueFaces;
                    break;

                case ObjectType.Overlay:
                    list = alpha ? myOverlayAlphaFaces : myOverlayOpaqueFaces;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(Type), Type, null);
                }

                if (!alpha)
                {
                    /*
                     * If an opaque face, itinerate through the list to see if the prototype is present in the list
                     * When the new renderer is in use, this prevents re-binding the VBO as it is simply re-drawn with
                     * a different translation matrix
                     * NOTE: The shader isn't currently smart enough to do depth discards, so if this changes may need to
                     * be revisited
                     */
                    if (list.Count == 0)
                    {
                        list.Add(new FaceState(State, face));
                    }
                    else
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (list[i].Object.Prototype == State.Prototype)
                            {
                                list.Insert(i, new FaceState(State, face));
                                break;
                            }
                            if (i == list.Count - 1)
                            {
                                list.Add(new FaceState(State, face));
                                break;
                            }
                        }
                    }
                }
                else
                {
                    /*
                     * Alpha faces should be inserted at the end of the list- We're going to sort it anyway so it makes no odds
                     */
                    list.Add(new FaceState(State, face));
                }
            }
        }