Exemplo n.º 1
0
 public static void Unbind()
 {
     State.Gl.BindVertexArray(0);
     ActiveVAO = null;
 }
Exemplo n.º 2
0
        public RenderBuffer(Shape shape, bool masked, bool supportAnimations, bool layered, bool noTexture = false)
        {
            Shape  = shape;
            Masked = masked;
            this.supportAnimations = supportAnimations;

            if (noTexture)
            {
                vertexArrayObject = new VertexArrayObject(ColorShader.Instance.ShaderProgram);
            }
            else if (masked)
            {
                if (shape == Shape.Triangle)
                {
                    vertexArrayObject = new VertexArrayObject(MaskedTriangleShader.Instance.ShaderProgram);
                }
                else
                {
                    vertexArrayObject = new VertexArrayObject(MaskedTextureShader.Instance.ShaderProgram);
                }
            }
            else
            {
                vertexArrayObject = new VertexArrayObject(TextureShader.Instance.ShaderProgram);
            }

            positionBuffer = new PositionBuffer(false);
            indexBuffer    = new IndexBuffer();

            if (noTexture)
            {
                colorBuffer = new ColorBuffer(true);
                layerBuffer = new LayerBuffer(true);

                vertexArrayObject.AddBuffer(ColorShader.DefaultColorName, colorBuffer);
                vertexArrayObject.AddBuffer(ColorShader.DefaultLayerName, layerBuffer);
            }
            else if (shape == Shape.Triangle)
            {
                // map rendering will change the texture offsets often to change the terrain so use non-static buffers
                textureAtlasOffsetBuffer = new PositionBuffer(false);
            }
            else
            {
                textureAtlasOffsetBuffer = new PositionBuffer(!supportAnimations);

                if (layered)
                {
                    layerBuffer = new LayerBuffer(true);

                    vertexArrayObject.AddBuffer(ColorShader.DefaultLayerName, layerBuffer);
                }
                else
                {
                    baseLineBuffer = new BaseLineBuffer(false);

                    vertexArrayObject.AddBuffer(ColorShader.DefaultLayerName, baseLineBuffer);
                }
            }

            if (masked && !noTexture)
            {
                maskTextureAtlasOffsetBuffer = new PositionBuffer(shape != Shape.Triangle && !supportAnimations);

                vertexArrayObject.AddBuffer(MaskedTextureShader.DefaultMaskTexCoordName, maskTextureAtlasOffsetBuffer);
            }

            vertexArrayObject.AddBuffer(ColorShader.DefaultPositionName, positionBuffer);
            vertexArrayObject.AddBuffer("index", indexBuffer);

            if (!noTexture)
            {
                vertexArrayObject.AddBuffer(TextureShader.DefaultTexCoordName, textureAtlasOffsetBuffer);
            }
        }
Exemplo n.º 3
0
        void InternalBind(bool bindOnly)
        {
            lock (vaoLock)
            {
                if (ActiveVAO != this)
                {
                    State.Gl.BindVertexArray(index);
                    program.Use();
                }

                if (!bindOnly)
                {
                    bool buffersChanged = false;

                    // ensure that all buffers are up to date
                    foreach (var buffer in positionBuffers)
                    {
                        if (buffer.Value.RecreateUnbound())
                        {
                            buffersChanged = true;
                        }
                    }

                    foreach (var buffer in baseLineBuffers)
                    {
                        if (buffer.Value.RecreateUnbound())
                        {
                            buffersChanged = true;
                        }
                    }

                    foreach (var buffer in colorBuffers)
                    {
                        if (buffer.Value.RecreateUnbound())
                        {
                            buffersChanged = true;
                        }
                    }

                    foreach (var buffer in layerBuffers)
                    {
                        if (buffer.Value.RecreateUnbound())
                        {
                            buffersChanged = true;
                        }
                    }

                    foreach (var buffer in indexBuffers)
                    {
                        if (buffer.Value.RecreateUnbound())
                        {
                            buffersChanged = true;
                        }
                    }

                    if (buffersChanged)
                    {
                        UnbindBuffers();
                        BindBuffers();
                    }
                }

                ActiveVAO = this;
            }
        }