Ejemplo n.º 1
0
        /// <inheritdoc />
        public void RenderInstances(Matrix4 viewMatrix, Matrix4 projectionMatrix, ViewportCamera camera, int count)
        {
            ThrowIfDisposed();

            if (_vertexBuffer is null || _vertexIndexesBuffer is null)
            {
                return;
            }

            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);

            // Send the vertices to the shader
            _vertexBuffer.Bind();
            _vertexBuffer.EnableAttributes();

            _vertexIndexesBuffer.Bind();

            var modelViewProjection = this.ActorTransform.GetModelMatrix() * viewMatrix * projectionMatrix;

            _boxShader.Enable();
            _boxShader.SetIsInstance(true);
            _boxShader.SetMVPMatrix(modelViewProjection);
            _boxShader.SetLineColour(this.LineColour);
            _boxShader.SetViewMatrix(viewMatrix);
            _boxShader.SetProjectionMatrix(projectionMatrix);

            // Now draw the box
            GL.DrawElementsInstanced
            (
                PrimitiveType.LineLoop,
                24,
                DrawElementsType.UnsignedByte,
                new IntPtr(0),
                count
            );

            _vertexBuffer.DisableAttributes();
        }
Ejemplo n.º 2
0
        private void RenderBoundingBox(ModelGroup modelGroup, Matrix4 modelViewProjection, Color4 colour)
        {
            BoundingBoxShader boxShader = this.Cache.GetShader(EverlookShader.BoundingBox) as BoundingBoxShader;

            if (boxShader == null)
            {
                throw new ShaderNullException(typeof(BoundingBoxShader));
            }

            boxShader.Enable();
            boxShader.SetMVPMatrix(modelViewProjection);
            boxShader.SetLineColour(colour);

            GL.Disable(EnableCap.CullFace);

            // Render the object
            // Send the vertices to the shader
            GL.EnableVertexAttribArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, this.BoundingBoxVertexBufferLookup[modelGroup]);
            GL.VertexAttribPointer
            (
                0,
                3,
                VertexAttribPointerType.Float,
                false,
                0,
                0
            );

            // Bind the index buffer
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.BoundingBoxVertexIndexBufferID);

            // Now draw the box
            GL.DrawRangeElements
            (
                PrimitiveType.LineLoop,
                0,
                23,
                24,
                DrawElementsType.UnsignedByte,
                new IntPtr(0)
            );

            GL.DisableVertexAttribArray(0);
        }