Beispiel #1
0
        internal void Draw(PrimitiveType primitiveType, Matrix world)
        {
            Threading.EnsureUIThread();
            GL.FrontFace(FrontFaceDirection.Ccw);
            GL.CullFace(CullFaceMode.Back);

            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Less);
            Material.Shader.Bind();
            Material.Apply();

            VertexBuffer.BindVertexArray();
            VertexBuffer.Bind();
            IndexBuffer.Bind();
            VertexBuffer.VertexDeclaration.Apply(Material.Shader, IntPtr.Zero);

            REngine.CheckGLError();

            Material.Shader.BindSemantics(Matrix.Identity * world, REngine.camera.View, REngine.camera.Projection);
            REngine.CheckGLError();


            GL.DrawElements(primitiveType, IndexBuffer.IndexCount, DrawElementsType.UnsignedInt, IntPtr.Zero);

            Material.Shader.Unbind();
            IndexBuffer.Unbind();
            VertexBuffer.Unbind();
            VertexBuffer.UnbindVertexArray();
        }
Beispiel #2
0
        public override void Render()
        {
            if (IsDrawable)
            {
                ApplyState();
                base.Render();

                /*
                 * GL.Enable(EnableCap.CullFace);
                 * REngine.CheckGLError();
                 * GL.FrontFace(FrontFaceDirection.Ccw);
                 * REngine.CheckGLError();
                 * GL.CullFace(CullFaceMode.FrontAndBack);
                 * REngine.CheckGLError();
                 */
                _material.Shader.Bind();
                _material.Apply();
                VertexBuffer.BindVertexArray();
                VertexBuffer.Bind();

                VertexBuffer.VertexDeclaration.Apply(_material.Shader, IntPtr.Zero);

                _material.Shader.BindSemantics(matrix, REngine.camera.viewMatrix, REngine.camera.projMatrix);
                if (PrimitiveType == RPrimitiveType.Points)
                {
                    GL.PointParameter(PointParameterName.PointSizeMin, 0.0f);
                    GL.PointParameter(PointParameterName.PointSizeMax, 1024.0f);
                    GL.Enable(EnableCap.PointSprite);
                    GL.Enable(EnableCap.PointSmooth);
                    GL.Enable(EnableCap.ProgramPointSize);
                }
                if (_index != null)
                {
                    var shortIndices       = _index.IndexElementSize == RIndexElementSize.SixteenBits;
                    var indexElementType   = shortIndices ? DrawElementsType.UnsignedShort : DrawElementsType.UnsignedInt;
                    var indexElementSize   = shortIndices ? 2 : 4;
                    var indexOffsetInBytes = (IntPtr)(indexElementSize);
                    var indexElementCount  = _index.GetElementCountArray((PrimitiveType)PrimitiveType, vertCount);
                    _index.Bind();
                    REngine.CheckGLError();
                    GL.DrawRangeElements((PrimitiveType)PrimitiveType, 0, 1, _index.IndexCount, indexElementType, indexOffsetInBytes);
                    REngine.CheckGLError();
                    _index.Unbind();
                    REngine.CheckGLError();
                }
                else
                {
                    GL.DrawArrays((PrimitiveType)PrimitiveType, 0, VertexBuffer.VertexCount);
                    REngine.CheckGLError();
                }
                if (PrimitiveType == RPrimitiveType.Points)
                {
                    GL.Disable(EnableCap.PointSprite);
                    GL.Disable(EnableCap.PointSmooth);
                    GL.Disable(EnableCap.ProgramPointSize);
                }
                _material.Shader.Unbind();

                VertexBuffer.Unbind();
                VertexBuffer.UnbindVertexArray();
            }
        }