mirror of
https://github.com/zeldaret/Z64Utils.git
synced 2026-10-01 07:30:33 -04:00
add bom swap to VertexAttrib
This commit is contained in:
@@ -14,6 +14,7 @@ using Z64;
|
||||
using RDP;
|
||||
|
||||
using DList = System.Collections.Generic.List<System.Tuple<uint, F3DZEX.Command.CommandInfo>>;
|
||||
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<Command.GVtx>();
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,8 @@ namespace Z64.Forms
|
||||
|
||||
_oldAnglePos = e.Location;
|
||||
}
|
||||
Render();
|
||||
if (e.Button != MouseButtons.None)
|
||||
Render();
|
||||
}
|
||||
protected override void OnPaint(PaintEventArgs e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user