diff --git a/Z64Utils/F3DZEX/Render/Renderer.cs b/Z64Utils/F3DZEX/Render/Renderer.cs index 0ec79bd..0980815 100644 --- a/Z64Utils/F3DZEX/Render/Renderer.cs +++ b/Z64Utils/F3DZEX/Render/Renderer.cs @@ -14,6 +14,7 @@ using Z64; using RDP; using DList = System.Collections.Generic.List>; +using System.Diagnostics; namespace F3DZEX.Render { @@ -282,7 +283,6 @@ namespace F3DZEX.Render // color/normal _rdpVtxAttrs.LayoutAddFloat(4, VertexAttribPointerType.UnsignedByte, true); - /* Init simple vertex attributes */ /*_colorVtxAttrs = new VertexAttribs(); // position @@ -299,7 +299,7 @@ namespace F3DZEX.Render { if (_reqDecodeTex) { - Console.WriteLine($"Decoding texture... {TexDecodeCount}"); + Debug.WriteLine($"Decoding texture... {TexDecodeCount++}"); GL.BindTexture(TextureTarget.Texture2D, _curTexID); _renderTex = N64Texture.Decode(_curTexW * _curTexH, _renderTexFmt, _renderTexSiz, _loadTex, _curTLUT); @@ -325,33 +325,6 @@ namespace F3DZEX.Render var cmd = info.Convert(); byte[] data = Memory.ReadBytes(cmd.vaddr, Vertex.SIZE * cmd.numv); - - // BOM swap - for (int i = 0; i < data.Length;) - { - // X - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - // Y - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - // Z - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - - // flag - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - - // tex X - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - // tex Y - (data[i + 0], data[i + 1]) = (data[i + 1], data[i + 0]); - i += 2; - // color - i += 4; - } System.Buffer.BlockCopy(data, 0, _vtxBuffer, cmd.vbidx * Vertex.SIZE, data.Length); diff --git a/Z64Utils/F3DZEX/Render/VertexAttribs.cs b/Z64Utils/F3DZEX/Render/VertexAttribs.cs index 4f49da8..8ec40c6 100644 --- a/Z64Utils/F3DZEX/Render/VertexAttribs.cs +++ b/Z64Utils/F3DZEX/Render/VertexAttribs.cs @@ -143,13 +143,30 @@ namespace F3DZEX.Render _built = true; } - // todo : endian swap public void SetData(byte[] buffer, bool bigEndian = false, BufferUsageHint hint = BufferUsageHint.StaticDraw) { if (!_built) BuldLayout(); // endian swap + if (bigEndian) + { + int off = 0; + while (off < buffer.Length) + { + foreach (var attr in _attribs) + { + int fieldSize = attr.GetSize() / attr.count; + + for (int i = 0; i < attr.count; i++) + { + for (int j = 0; j < fieldSize/2; j++) + (buffer[off + j], buffer[off + fieldSize - j - 1]) = (buffer[off + fieldSize - j - 1], buffer[off + j]); + off += fieldSize; + } + } + } + } GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo); GL.BufferData(BufferTarget.ArrayBuffer, buffer.Length, buffer, hint); diff --git a/Z64Utils/F3DZEX/Render/VertexDrawer.cs b/Z64Utils/F3DZEX/Render/VertexDrawer.cs index 08425ff..12bf981 100644 --- a/Z64Utils/F3DZEX/Render/VertexDrawer.cs +++ b/Z64Utils/F3DZEX/Render/VertexDrawer.cs @@ -1,4 +1,5 @@ using OpenTK; +using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; using System.Text; @@ -24,9 +25,31 @@ namespace F3DZEX.Render _shader.Send("u_Projection", proj); _shader.Send("u_View", view); } - public void SendTexture() + public void SendModelMatrix(Matrix4 model) { + _shader.Send("u_Model", model); + } + public void SendTexture(int tex) + { + _shader.Send("u_Tex", tex); + } + public void SetVertexData(byte[] buffer, bool bigEndian = false, BufferUsageHint hint = BufferUsageHint.StaticDraw) + => _attrs.SetData(buffer, bigEndian, hint); + + public void SetVertexData(T[] buffer, int size, BufferUsageHint hint = BufferUsageHint.StaticDraw) + where T : struct, IComparable + => _attrs.SetData(buffer, size, hint); + + public void Draw(PrimitiveType type, byte[] indices) + { + _shader.Use(); + _attrs.Draw(type, indices); + } + public void Draw(PrimitiveType type, uint[] indices) + { + _shader.Use(); + _attrs.Draw(type, indices); } } } diff --git a/Z64Utils/Forms/ModelViewerControl.cs b/Z64Utils/Forms/ModelViewerControl.cs index d37c89a..021c8c3 100644 --- a/Z64Utils/Forms/ModelViewerControl.cs +++ b/Z64Utils/Forms/ModelViewerControl.cs @@ -93,7 +93,8 @@ namespace Z64.Forms _oldAnglePos = e.Location; } - Render(); + if (e.Button != MouseButtons.None) + Render(); } protected override void OnPaint(PaintEventArgs e) {