Exemplo n.º 1
0
        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 };
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 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
        }
Exemplo n.º 4
0
 public static extern ushort bgfx_create_dynamic_vertex_buffer(int vertexCount, ref VertexLayout.Data decl, BufferFlags flags);
Exemplo n.º 5
0
 public static extern void bgfx_vertex_unpack(float* output, VertexAttributeUsage attribute, ref VertexLayout.Data decl, IntPtr data, int index);
Exemplo n.º 6
0
 public static extern bool bgfx_check_avail_transient_buffers(int numVertices, ref VertexLayout.Data decl, int numIndices);
Exemplo n.º 7
0
 public static extern void bgfx_vertex_decl_begin(ref VertexLayout.Data decl, RendererBackend backend);
Exemplo n.º 8
0
 public static extern void bgfx_vertex_decl_skip(ref VertexLayout.Data decl, byte count);
Exemplo n.º 9
0
 public static extern bool bgfx_alloc_transient_buffers(out TransientVertexBuffer tvb, ref VertexLayout.Data decl, ushort numVertices, out TransientIndexBuffer tib, ushort numIndices);
Exemplo n.º 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));
 }
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 12
0
 /// <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);
 }
Exemplo n.º 13
0
 /// <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);
 }
Exemplo n.º 14
0
 /// <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);
 }
Exemplo n.º 15
0
 /// <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);
 }
Exemplo n.º 16
0
 /// <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);
 }
Exemplo n.º 17
0
 public static extern void bgfx_vertex_convert(ref VertexLayout.Data destDecl, IntPtr destData, ref VertexLayout.Data srcDecl, IntPtr srcData, int num);
Exemplo n.º 18
0
        /// <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;
        }
Exemplo n.º 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);
 }
Exemplo n.º 20
0
 public static extern void bgfx_alloc_transient_vertex_buffer(out TransientVertexBuffer tvb, int num, ref VertexLayout.Data decl);
Exemplo n.º 21
0
 /// <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));
 }
Exemplo n.º 22
0
 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);
Exemplo n.º 23
0
 /// <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);
 }
Exemplo n.º 24
0
 public static extern void bgfx_vertex_decl_end(ref VertexLayout.Data decl);
Exemplo n.º 25
0
 internal Mesh (VertexLayout decl, List<MeshGroup> groups) {
     vertexDecl = decl;
     this.groups = groups;
 }
Exemplo n.º 26
0
 public static extern void bgfx_vertex_pack(float* input, [MarshalAs(UnmanagedType.U1)] bool inputNormalized, VertexAttributeUsage attribute, ref VertexLayout.Data decl, IntPtr data, int index);
Exemplo n.º 27
0
 /// <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));
 }
Exemplo n.º 28
0
 public static extern ushort bgfx_weld_vertices(ushort* output, ref VertexLayout.Data decl, IntPtr data, ushort num, float epsilon);
Exemplo n.º 29
0
 /// <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);
 }
Exemplo n.º 30
0
 public static extern bool bgfx_check_avail_transient_vertex_buffer(int num, ref VertexLayout.Data decl);
Exemplo n.º 31
0
 /// <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);
 }
Exemplo n.º 32
0
 public static extern ushort bgfx_create_dynamic_vertex_buffer_mem(MemoryBlock.DataPtr* memory, ref VertexLayout.Data decl, BufferFlags flags);
Exemplo n.º 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);
 }