コード例 #1
0
ファイル: Mesh.cs プロジェクト: prepare/SharpBgfx
        public Mesh (MemoryBlock vertices, VertexLayout decl, ushort[] indices) {
            var group = new MeshGroup();
            group.VertexBuffer = new VertexBuffer(vertices, decl);
            group.IndexBuffer = new IndexBuffer(MemoryBlock.FromArray(indices));

            vertexDecl = decl;
            groups = new List<MeshGroup> { group };
        }
コード例 #2
0
ファイル: Bgfx.cs プロジェクト: PowerStateFailure/SharpBgfx
        /// <summary>
        /// Welds vertices that are close together.
        /// </summary>
        /// <param name="layout">The layout of the vertex stream.</param>
        /// <param name="data">A pointer to the vertex data stream.</param>
        /// <param name="count">The number of vertices in the stream.</param>
        /// <param name="remappingTable">An output remapping table from the original vertices to the welded ones.</param>
        /// <param name="epsilon">The tolerance for welding vertex positions.</param>
        /// <returns>
        /// The number of unique vertices after welding.
        /// </returns>
        public static int WeldVertices(VertexLayout layout, IntPtr data, int count, out int[] remappingTable, float epsilon = 0.001f)
        {
            var output = stackalloc ushort[count];
            var result = NativeMethods.bgfx_weld_vertices(output, ref layout.data, data, (ushort)count, epsilon);

            remappingTable = new int[count];
            for (int i = 0; i < count; i++)
            {
                remappingTable[i] = output[i];
            }

            return(result);
        }
コード例 #3
0
        private void Init()
        {
            _imguiContext = ImGui.CreateContext();
            var io = ImGui.GetIO();

            // load the shaders for imgui
            _imguiProgram   = ResourceLoader.LoadProgram("vs_ocornut_imgui", "fs_ocornut_imgui");
            _textureProgram = ResourceLoader.LoadProgram("vs_imgui_image", "fs_imgui_image");

            _vertexLayout = new VertexLayout();
            _vertexLayout.Begin()
            .Add(VertexAttributeUsage.Position, 2, VertexAttributeType.Float)
            .Add(VertexAttributeUsage.TexCoord0, 2, VertexAttributeType.Float)
            .Add(VertexAttributeUsage.Color0, 4, VertexAttributeType.UInt8, true)
            .End();

            _texUniform = new Uniform("s_tex", UniformType.Sampler);

            _fonts.Add("default", io.Fonts.AddFontDefault());

            // Fonts: All fonts need to be known here, because we compile the fontatlas only once
            // Example code:

            /*foreach (var font in fonts)
             * {
             *      _fonts.Add(font.name, io.Fonts.AddFontFromFileTTF(font.path, font.size));
             * }*/

            // Build and save the fontatlas
            unsafe
            {
                io.Fonts.GetTexDataAsRGBA32(out var data, out var width, out var height, out var bytesPerPixel);

                FontAtlas = Texture.Create2D(width, height, false, 1, TextureFormat.BGRA8, 0,
                                             new MemoryBlock((IntPtr)data, width * height * bytesPerPixel));

                _textures.Add((IntPtr)FontAtlas.GetHashCode(), FontAtlas);
            }

            io.Fonts.SetTexID((IntPtr)FontAtlas.GetHashCode());

            // ToDo: Set KeyMappings
            // -> Engine specific
        }
コード例 #4
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern ushort bgfx_create_dynamic_vertex_buffer(int vertexCount, ref VertexLayout.Data decl, BufferFlags flags);
コード例 #5
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_unpack(float* output, VertexAttributeUsage attribute, ref VertexLayout.Data decl, IntPtr data, int index);
コード例 #6
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern bool bgfx_check_avail_transient_buffers(int numVertices, ref VertexLayout.Data decl, int numIndices);
コード例 #7
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_decl_begin(ref VertexLayout.Data decl, RendererBackend backend);
コード例 #8
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_decl_skip(ref VertexLayout.Data decl, byte count);
コード例 #9
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern bool bgfx_alloc_transient_buffers(out TransientVertexBuffer tvb, ref VertexLayout.Data decl, ushort numVertices, out TransientIndexBuffer tib, ushort numIndices);
コード例 #10
0
 /// <summary>
 /// Gets the available space in the global transient vertex buffer.
 /// </summary>
 /// <param name="count">The number of vertices required.</param>
 /// <param name="layout">The layout of each vertex.</param>
 /// <returns>The number of available vertices.</returns>
 public static int GetAvailableSpace(int count, VertexLayout layout)
 {
     return(NativeMethods.bgfx_get_avail_transient_vertex_buffer(count, ref layout.data));
 }
コード例 #11
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
 /// <summary>
 /// Packs a vector into vertex stream format.
 /// </summary>
 /// <param name="input">The four element vector to pack.</param>
 /// <param name="inputNormalized"><c>true</c> if the input vector is normalized.</param>
 /// <param name="attribute">The attribute usage of the vector data.</param>
 /// <param name="layout">The layout of the vertex stream.</param>
 /// <param name="data">The pointer to the vertex data stream.</param>
 /// <param name="index">The index of the vertex within the stream.</param>
 public static void VertexPack(float* input, bool inputNormalized, VertexAttributeUsage attribute, VertexLayout layout, IntPtr data, int index = 0)
 {
     NativeMethods.bgfx_vertex_pack(input, inputNormalized, attribute, ref layout.data, data, index);
 }
コード例 #12
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
 /// <summary>
 /// Unpack a vector from a vertex stream.
 /// </summary>
 /// <param name="output">A pointer to four floats that will receive the unpacked vector.</param>
 /// <param name="attribute">The usage of the vertex attribute.</param>
 /// <param name="layout">The layout of the vertex stream.</param>
 /// <param name="data">A pointer to the vertex data stream.</param>
 /// <param name="index">The index of the vertex within the stream.</param>
 public static void VertexUnpack(float* output, VertexAttributeUsage attribute, VertexLayout layout, IntPtr data, int index = 0)
 {
     NativeMethods.bgfx_vertex_unpack(output, attribute, ref layout.data, data, index);
 }
コード例 #13
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
 /// <summary>
 /// Converts a stream of vertex data from one format to another.
 /// </summary>
 /// <param name="destinationLayout">The destination format.</param>
 /// <param name="destinationData">A pointer to the output location.</param>
 /// <param name="sourceLayout">The source format.</param>
 /// <param name="sourceData">A pointer to the source vertex data to convert.</param>
 /// <param name="count">The number of vertices to convert.</param>
 public static void VertexConvert(VertexLayout destinationLayout, IntPtr destinationData, VertexLayout sourceLayout, IntPtr sourceData, int count = 1)
 {
     NativeMethods.bgfx_vertex_convert(ref destinationLayout.data, destinationData, ref sourceLayout.data, sourceData, count);
 }
コード例 #14
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
 /// <summary>
 /// Checks for available space to allocate transient index and vertex buffers.
 /// </summary>
 /// <param name="vertexCount">The number of vertices to allocate.</param>
 /// <param name="layout">The layout of each vertex.</param>
 /// <param name="indexCount">The number of indices to allocate.</param>
 /// <returns><c>true</c> if there is sufficient space for both vertex and index buffers.</returns>
 public static bool CheckAvailableTransientBufferSpace(int vertexCount, VertexLayout layout, int indexCount)
 {
     return NativeMethods.bgfx_check_avail_transient_buffers(vertexCount, ref layout.data, indexCount);
 }
コード例 #15
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
 /// <summary>
 /// Attempts to allocate both a transient vertex buffer and index buffer.
 /// </summary>
 /// <param name="vertexCount">The number of vertices to allocate.</param>
 /// <param name="layout">The layout of each vertex.</param>
 /// <param name="indexCount">The number of indices to allocate.</param>
 /// <param name="vertexBuffer">Returns the allocated transient vertex buffer.</param>
 /// <param name="indexBuffer">Returns the allocated transient index buffer.</param>
 /// <returns><c>true</c> if both space requirements are satisfied and the buffers were allocated.</returns>
 public static bool AllocateTransientBuffers(int vertexCount, VertexLayout layout, int indexCount, out TransientVertexBuffer vertexBuffer, out TransientIndexBuffer indexBuffer)
 {
     return NativeMethods.bgfx_alloc_transient_buffers(out vertexBuffer, ref layout.data, (ushort)vertexCount, out indexBuffer, (ushort)indexCount);
 }
コード例 #16
0
ファイル: Bgfx.cs プロジェクト: PowerStateFailure/SharpBgfx
 /// <summary>
 /// Converts a stream of vertex data from one format to another.
 /// </summary>
 /// <param name="destinationLayout">The destination format.</param>
 /// <param name="destinationData">A pointer to the output location.</param>
 /// <param name="sourceLayout">The source format.</param>
 /// <param name="sourceData">A pointer to the source vertex data to convert.</param>
 /// <param name="count">The number of vertices to convert.</param>
 public static void VertexConvert(VertexLayout destinationLayout, IntPtr destinationData, VertexLayout sourceLayout, IntPtr sourceData, int count = 1)
 {
     NativeMethods.bgfx_vertex_convert(ref destinationLayout.data, destinationData, ref sourceLayout.data, sourceData, count);
 }
コード例 #17
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_convert(ref VertexLayout.Data destDecl, IntPtr destData, ref VertexLayout.Data srcDecl, IntPtr srcData, int num);
コード例 #18
0
ファイル: Bgfx.cs プロジェクト: prepare/SharpBgfx
        /// <summary>
        /// Welds vertices that are close together.
        /// </summary>
        /// <param name="layout">The layout of the vertex stream.</param>
        /// <param name="data">A pointer to the vertex data stream.</param>
        /// <param name="count">The number of vertices in the stream.</param>
        /// <param name="remappingTable">An output remapping table from the original vertices to the welded ones.</param>
        /// <param name="epsilon">The tolerance for welding vertex positions.</param>
        /// <returns>
        /// The number of unique vertices after welding.
        /// </returns>
        public static int WeldVertices(VertexLayout layout, IntPtr data, int count, out int[] remappingTable, float epsilon = 0.001f)
        {
            var output = stackalloc ushort[count];
            var result = NativeMethods.bgfx_weld_vertices(output, ref layout.data, data, (ushort)count, epsilon);

            remappingTable = new int[count];
            for (int i = 0; i < count; i++)
                remappingTable[i] = output[i];

            return result;
        }
コード例 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransientVertexBuffer"/> struct.
 /// </summary>
 /// <param name="vertexCount">The number of vertices that fit in the buffer.</param>
 /// <param name="layout">The layout of the vertex data.</param>
 public TransientVertexBuffer(int vertexCount, VertexLayout layout)
 {
     NativeMethods.bgfx_alloc_transient_vertex_buffer(out this, vertexCount, ref layout.data);
 }
コード例 #20
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_alloc_transient_vertex_buffer(out TransientVertexBuffer tvb, int num, ref VertexLayout.Data decl);
コード例 #21
0
ファイル: Bgfx.cs プロジェクト: zachlungu/SharpBgfx
 /// <summary>
 /// Checks for available space to allocate transient index and vertex buffers.
 /// </summary>
 /// <param name="vertexCount">The number of vertices to allocate.</param>
 /// <param name="layout">The layout of each vertex.</param>
 /// <param name="indexCount">The number of indices to allocate.</param>
 /// <returns><c>true</c> if there is sufficient space for both vertex and index buffers.</returns>
 public static bool CheckAvailableTransientBufferSpace(int vertexCount, VertexLayout layout, int indexCount)
 {
     return(NativeMethods.bgfx_check_avail_transient_buffers(vertexCount, ref layout.data, indexCount));
 }
コード例 #22
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_decl_add(ref VertexLayout.Data decl, VertexAttributeUsage attribute, byte count, VertexAttributeType type, [MarshalAs(UnmanagedType.U1)] bool normalized, [MarshalAs(UnmanagedType.U1)] bool asInt);
コード例 #23
0
ファイル: VertexBuffer.cs プロジェクト: sweep3r/SharpBgfx
 /// <summary>
 /// Initializes a new instance of the <see cref="VertexBuffer"/> struct.
 /// </summary>
 /// <param name="memory">The vertex data with which to populate the buffer.</param>
 /// <param name="layout">The layout of the vertex data.</param>
 /// <param name="flags">Flags used to control buffer behavior.</param>
 public VertexBuffer(MemoryBlock memory, VertexLayout layout, BufferFlags flags = BufferFlags.None)
 {
     handle = NativeMethods.bgfx_create_vertex_buffer(memory.ptr, ref layout.data, flags);
 }
コード例 #24
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_decl_end(ref VertexLayout.Data decl);
コード例 #25
0
ファイル: Mesh.cs プロジェクト: prepare/SharpBgfx
 internal Mesh (VertexLayout decl, List<MeshGroup> groups) {
     vertexDecl = decl;
     this.groups = groups;
 }
コード例 #26
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern void bgfx_vertex_pack(float* input, [MarshalAs(UnmanagedType.U1)] bool inputNormalized, VertexAttributeUsage attribute, ref VertexLayout.Data decl, IntPtr data, int index);
コード例 #27
0
ファイル: Bgfx.cs プロジェクト: PowerStateFailure/SharpBgfx
 /// <summary>
 /// Attempts to allocate both a transient vertex buffer and index buffer.
 /// </summary>
 /// <param name="vertexCount">The number of vertices to allocate.</param>
 /// <param name="layout">The layout of each vertex.</param>
 /// <param name="indexCount">The number of indices to allocate.</param>
 /// <param name="vertexBuffer">Returns the allocated transient vertex buffer.</param>
 /// <param name="indexBuffer">Returns the allocated transient index buffer.</param>
 /// <returns><c>true</c> if both space requirements are satisfied and the buffers were allocated.</returns>
 public static bool AllocateTransientBuffers(int vertexCount, VertexLayout layout, int indexCount, out TransientVertexBuffer vertexBuffer, out TransientIndexBuffer indexBuffer)
 {
     return(NativeMethods.bgfx_alloc_transient_buffers(out vertexBuffer, ref layout.data, (ushort)vertexCount, out indexBuffer, (ushort)indexCount));
 }
コード例 #28
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern ushort bgfx_weld_vertices(ushort* output, ref VertexLayout.Data decl, IntPtr data, ushort num, float epsilon);
コード例 #29
0
ファイル: Bgfx.cs プロジェクト: PowerStateFailure/SharpBgfx
 /// <summary>
 /// Packs a vector into vertex stream format.
 /// </summary>
 /// <param name="input">The four element vector to pack.</param>
 /// <param name="inputNormalized"><c>true</c> if the input vector is normalized.</param>
 /// <param name="attribute">The attribute usage of the vector data.</param>
 /// <param name="layout">The layout of the vertex stream.</param>
 /// <param name="data">The pointer to the vertex data stream.</param>
 /// <param name="index">The index of the vertex within the stream.</param>
 public static void VertexPack(float *input, bool inputNormalized, VertexAttributeUsage attribute, VertexLayout layout, IntPtr data, int index = 0)
 {
     NativeMethods.bgfx_vertex_pack(input, inputNormalized, attribute, ref layout.data, data, index);
 }
コード例 #30
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern bool bgfx_check_avail_transient_vertex_buffer(int num, ref VertexLayout.Data decl);
コード例 #31
0
ファイル: Bgfx.cs プロジェクト: PowerStateFailure/SharpBgfx
 /// <summary>
 /// Unpack a vector from a vertex stream.
 /// </summary>
 /// <param name="output">A pointer to four floats that will receive the unpacked vector.</param>
 /// <param name="attribute">The usage of the vertex attribute.</param>
 /// <param name="layout">The layout of the vertex stream.</param>
 /// <param name="data">A pointer to the vertex data stream.</param>
 /// <param name="index">The index of the vertex within the stream.</param>
 public static void VertexUnpack(float *output, VertexAttributeUsage attribute, VertexLayout layout, IntPtr data, int index = 0)
 {
     NativeMethods.bgfx_vertex_unpack(output, attribute, ref layout.data, data, index);
 }
コード例 #32
0
ファイル: NativeMethods.cs プロジェクト: prepare/SharpBgfx
 public static extern ushort bgfx_create_dynamic_vertex_buffer_mem(MemoryBlock.DataPtr* memory, ref VertexLayout.Data decl, BufferFlags flags);
コード例 #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicVertexBuffer"/> struct.
 /// </summary>
 /// <param name="vertexCount">The number of vertices that fit in the buffer.</param>
 /// <param name="layout">The layout of the vertex data.</param>
 /// <param name="flags">Flags used to control buffer behavior.</param>
 public DynamicVertexBuffer(int vertexCount, VertexLayout layout, BufferFlags flags = BufferFlags.None)
 {
     handle = NativeMethods.bgfx_create_dynamic_vertex_buffer(vertexCount, ref layout.data, flags);
 }