Apply() private method

private Apply ( Shader shader, IntPtr offset ) : void
shader Shader
offset System.IntPtr
return void
Example #1
0
        public void DrawUserPrimitives <T>(
            PrimitiveType primitiveType,
            T[] vertexData,
            int vertexOffset,
            int primitiveCount,
            VertexDeclaration vertexDeclaration
            ) where T : struct
        {
            // Flush the GL state before moving on!
            ApplyState();

            // Unbind current VBOs.
            GLDevice.BindVertexBuffer(OpenGLDevice.OpenGLVertexBuffer.NullBuffer);

            // Pin the buffers.
            GCHandle vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(VertexShader, vbHandle.AddrOfPinnedObject());

            // Enable the appropriate vertex attributes.
            GLDevice.FlushGLVertexAttributes();

            // Draw!
            GLDevice.glDrawArrays(
                PrimitiveTypeGL(primitiveType),
                vertexOffset,
                GetElementCountArray(primitiveType, primitiveCount)
                );

            // Release the handles.
            vbHandle.Free();
        }
        private void PlatformDrawUserIndexedPrimitives(PrimitiveType primitiveType, ArrayBuffer vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration)
        {
            ApplyState(true);

            var count = GetElementCountArray(primitiveType, primitiveCount);

            var vertexBuffer = gl.createBuffer();
            var indexBuffer  = gl.createBuffer();

            gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
            GraphicsExtensions.CheckGLError();
            gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(vertexData, (vertexOffset * 4 * 6).As <uint>(), (numVertices * 4 * 6).As <uint>()), gl.STATIC_DRAW);
            GraphicsExtensions.CheckGLError();
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
            GraphicsExtensions.CheckGLError();
            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indexData.As <Int16Array>().subarray(indexOffset.As <uint>()), gl.STATIC_DRAW);
            GraphicsExtensions.CheckGLError();

            _vertexBuffersDirty = true;
            _indexBufferDirty   = true;

            var mode = GraphicsExtensions.GetPrimitiveTypeGL(primitiveType);

            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vertexOffset, ShaderProgramHash);

            GraphicsExtensions.CheckGLError();
            gl.drawElements(mode, count, gl.UNSIGNED_SHORT, 0);
            GraphicsExtensions.CheckGLError();

            gl.bindBuffer(gl.ARRAY_BUFFER, null);
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
            gl.deleteBuffer(vertexBuffer);
            gl.deleteBuffer(indexBuffer);
        }
        private void PlatformDrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, VertexDeclaration vertexDeclaration, int vertexCount) where T : struct
        {
            ApplyState(true);

            var vertexArrayBuffer = ConvertVertices(vertexData, vertexOffset, vertexCount, vertexDeclaration);

            var buffer = gl.createBuffer();

            GraphicsExtensions.CheckGLError();
            gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
            GraphicsExtensions.CheckGLError();
            gl.bufferData(gl.ARRAY_BUFFER, vertexArrayBuffer, gl.STATIC_DRAW);
            GraphicsExtensions.CheckGLError();

            var mode = (uint)GraphicsExtensions.GetPrimitiveTypeGL(primitiveType);

            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vertexOffset, ShaderProgramHash);

            GraphicsExtensions.CheckGLError();
            gl.drawArrays(mode, 0, vertexCount);
            GraphicsExtensions.CheckGLError();

            gl.bindBuffer(gl.ARRAY_BUFFER, null);
            GraphicsExtensions.CheckGLError();
            gl.deleteBuffer(buffer);
            GraphicsExtensions.CheckGLError();
        }
Example #4
0
        private void PlatformDrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
        {
            ApplyState(true);

            // Unbind current VBOs.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            _vertexBufferDirty = _indexBufferDirty = true;

            // Pin the buffers.
            var vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);
            var ibHandle = GCHandle.Alloc(indexData, GCHandleType.Pinned);

            var vertexAddr = (IntPtr)(vbHandle.AddrOfPinnedObject().ToInt64() + vertexDeclaration.VertexStride * vertexOffset);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vertexAddr);

            //Draw
            GL.DrawElements(PrimitiveTypeGL(primitiveType),
                            GetElementCountArray(primitiveType, primitiveCount),
                            DrawElementsType.UnsignedShort,
                            (IntPtr)(ibHandle.AddrOfPinnedObject().ToInt64() + (indexOffset * sizeof(short))));
            GraphicsExtensions.CheckGLError();

            // Release the handles.
            ibHandle.Free();
            vbHandle.Free();
        }
Example #5
0
        private void PlatformDrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, VertexDeclaration vertexDeclaration, int vertexCount) where T : struct
        {
            ApplyState(true);

            // Unbind current VBOs.
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GraphicsExtensions.CheckGLError();
            _vertexBufferDirty = _indexBufferDirty = true;

            // Pin the buffers.
            var vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vbHandle.AddrOfPinnedObject());

            //Draw
            GL.DrawArrays(PrimitiveTypeGL(primitiveType),
                          vertexOffset,
                          vertexCount);
            GraphicsExtensions.CheckGLError();

            // Release the handles.
            vbHandle.Free();
        }
Example #6
0
        public void DrawUserPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
        {
            int elementCountArray = GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount);

            this.ApplyState(true);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            this._vertexBufferDirty = this._indexBufferDirty = true;
            GCHandle gcHandle = GCHandle.Alloc((object)vertexData, GCHandleType.Pinned);

            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(this._vertexShader, gcHandle.AddrOfPinnedObject());
            GL.DrawArrays(GraphicsDevice.PrimitiveTypeGL(primitiveType), vertexOffset, elementCountArray);
            gcHandle.Free();
        }
Example #7
0
        public void DrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct, IVertexType
        {
            this.ApplyState(true);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            this._vertexBufferDirty = this._indexBufferDirty = true;
            GCHandle gcHandle1 = GCHandle.Alloc((object)vertexData, GCHandleType.Pinned);
            GCHandle gcHandle2 = GCHandle.Alloc((object)indexData, GCHandleType.Pinned);

            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(this._vertexShader, gcHandle1.AddrOfPinnedObject());
            GL.DrawElements(GraphicsDevice.PrimitiveTypeGL(primitiveType), GraphicsDevice.GetElementCountArray(primitiveType, primitiveCount), DrawElementsType.UnsignedInt, (IntPtr)(gcHandle2.AddrOfPinnedObject().ToInt64() + (long)(indexOffset * 4)));
            gcHandle2.Free();
            gcHandle1.Free();
        }
Example #8
0
        public void DrawUserIndexedPrimitives <T>(
            PrimitiveType primitiveType,
            T[] vertexData,
            int vertexOffset,
            int numVertices,
            int[] indexData,
            int indexOffset,
            int primitiveCount,
            VertexDeclaration vertexDeclaration
            ) where T : struct, IVertexType
        {
            // Flush the GL state before moving on!
            ApplyState();

            // Unbind current buffer objects.
            GLDevice.BindVertexBuffer(OpenGLDevice.OpenGLVertexBuffer.NullBuffer);
            GLDevice.BindIndexBuffer(OpenGLDevice.OpenGLIndexBuffer.NullBuffer);

            // Pin the buffers.
            GCHandle vbHandle = GCHandle.Alloc(vertexData, GCHandleType.Pinned);
            GCHandle ibHandle = GCHandle.Alloc(indexData, GCHandleType.Pinned);

            // Setup the vertex declaration to point at the VB data.
            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(
                VertexShader,
                (IntPtr)(vbHandle.AddrOfPinnedObject().ToInt64() + vertexDeclaration.VertexStride * vertexOffset)
                );

            // Enable the appropriate vertex attributes.
            GLDevice.FlushGLVertexAttributes();

            // Draw!
            GLDevice.glDrawRangeElements(
                PrimitiveTypeGL(primitiveType),
                0,
                numVertices - 1,
                GetElementCountArray(primitiveType, primitiveCount),
                OpenGLDevice.GLenum.GL_UNSIGNED_INT,
                (IntPtr)(ibHandle.AddrOfPinnedObject().ToInt64() + (indexOffset * sizeof(int)))
                );

            // Release the handles.
            ibHandle.Free();
            vbHandle.Free();
        }
        private void PlatformDrawUserIndexedPrimitives <T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
        {
            ApplyState(true);

            var count = GetElementCountArray(primitiveType, primitiveCount);

            var vertexArrayBuffer = ConvertVertices(vertexData, vertexOffset, numVertices, vertexDeclaration);
            var uintIndexData     = new Uint16Array(count.As <uint>());//indexData.As<Uint16Array>();

            for (uint i = 0; i < uintIndexData.length; i++)
            {
                uintIndexData[i] = indexData[indexOffset + i].As <ushort>();
            }

            var vertexBuffer = gl.createBuffer();
            var indexBuffer  = gl.createBuffer();

            gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
            GraphicsExtensions.CheckGLError();
            gl.bufferData(gl.ARRAY_BUFFER, vertexArrayBuffer, gl.STATIC_DRAW);
            GraphicsExtensions.CheckGLError();
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
            GraphicsExtensions.CheckGLError();
            gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, uintIndexData, gl.STATIC_DRAW);
            GraphicsExtensions.CheckGLError();

            _vertexBuffersDirty = true;
            _indexBufferDirty   = true;

            var mode = (uint)GraphicsExtensions.GetPrimitiveTypeGL(primitiveType);

            vertexDeclaration.GraphicsDevice = this;
            vertexDeclaration.Apply(_vertexShader, vertexOffset, ShaderProgramHash);

            GraphicsExtensions.CheckGLError();
            gl.drawElements(mode, count, gl.UNSIGNED_SHORT, 0);
            GraphicsExtensions.CheckGLError();

            gl.bindBuffer(gl.ARRAY_BUFFER, null);
            gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
            gl.deleteBuffer(vertexBuffer);
            gl.deleteBuffer(indexBuffer);
        }