More layout editor improvements.

Fixed texture coordinate transformations from materials.
Window panes of all types, horizinal, around, and 1,4, and 8 frames are all supported.
Note window pane uv coordinates are very wip, and need proper flipping and transformation from the flags.
Fix bflim editor issues with filling contents.
This commit is contained in:
KillzXGaming 2019-09-16 19:56:41 -04:00
parent 42c5b22d5c
commit 1198e3de6d
13 changed files with 560 additions and 270 deletions

View file

@ -17,7 +17,7 @@ namespace LayoutBXLYT
{
switch (wrapMode)
{
case WrapMode.Clamp: return (int)TextureWrapMode.Clamp;
case WrapMode.Clamp: return (int)TextureWrapMode.ClampToEdge;
case WrapMode.Mirror: return (int)TextureWrapMode.MirroredRepeat;
case WrapMode.Repeat: return (int)TextureWrapMode.Repeat;
default: return (int)TextureWrapMode.Clamp;
@ -258,192 +258,434 @@ namespace LayoutBXLYT
BxlytToGL.DrawRectangle(pane, pane.Rectangle, TexCoords, Colors, false, effectiveAlpha);
}
//Huge thanks to layout studio for the window pane rendering code
//https://github.com/Treeki/LayoutStudio/blob/master/layoutgl/widget.cpp
//Note i still need to fix UV coordinates being flips and transformed!
public static void DrawWindowPane(BasePane pane, byte effectiveAlpha, Dictionary<string, STGenericTexture> Textures)
{
if (!Runtime.LayoutEditor.DisplayWindowPane)
return;
uint sizeX = (uint)pane.Width;
uint sizeY = (uint)pane.Height;
var window = (IWindowPane)pane;
ushort FrameRight = window.FrameElementRight;
ushort FrameLeft = window.FrameElementLeft;
ushort FrameBottom = window.FrameElementBottm;
ushort FrameTop = window.FrameElementTop;
if (FrameRight == 0) FrameRight = 1;
if (FrameLeft == 0) FrameLeft = 1;
if (FrameBottom == 0) FrameBottom = 1;
if (FrameTop == 0) FrameTop = 1;
float dX = DrawnVertexX(pane.Width, pane.originX);
float dY = DrawnVertexY(pane.Height, pane.originY);
switch (window.WindowKind)
float frameLeft = 0;
float frameRight = 0;
float frameTop = 0;
float frameBottom = 0;
switch (window.FrameCount)
{
case WindowKind.Around:
if (window.FrameCount == 1) //1 texture for all
{
var mat = window.WindowFrames[0].Material;
if (mat.TextureMaps.Length == 0)
RenderWindowContent(pane, sizeX, sizeY, window.Content, effectiveAlpha, Textures);
else
{
var texture = mat.TextureMaps[0].Name;
if (!Textures.ContainsKey(texture))
{
RenderWindowContent(pane, sizeX, sizeY, window.Content, effectiveAlpha, Textures);
break;
}
var image = Textures[texture];
FrameRight = (ushort)image.Width;
FrameLeft = (ushort)image.Width;
FrameTop = (ushort)image.Height;
FrameBottom = (ushort)image.Height;
uint contentWidth = sizeX - (uint)FrameRight - (uint)FrameLeft;
uint contentHeight = sizeY - (uint)FrameTop - (uint)FrameBottom;
RenderWindowContent(pane,
contentWidth,
contentHeight,
window.Content, effectiveAlpha, Textures);
// _________
//|______| |
//| | | |
//| |___|__|
//|__|______|
//Top Left
SetupShaders(mat, Textures);
mat.Shader.SetInt("flipTexture", (int)window.WindowFrames[0].TextureFlip);
CustomRectangle rect;
GL.PushMatrix();
{
uint pieceWidth = sizeX - FrameRight;
uint pieceHeight = FrameTop;
int pieceX = (int)-(FrameRight / 2);
int pieceY = (int)((sizeY / 2) - (pieceHeight / 2));
GL.Translate(pieceX, pieceY, 0);
rect = pane.CreateRectangle(pieceWidth, pieceHeight);
GL.Begin(PrimitiveType.Quads);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 1);
GL.Vertex2(rect.LeftPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, pieceWidth / FrameRight, 1);
GL.Vertex2(rect.RightPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, pieceWidth / FrameRight, 0);
GL.Vertex2(rect.RightPoint, rect.TopPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 0);
GL.Vertex2(rect.LeftPoint, rect.TopPoint);
GL.End();
}
GL.PopMatrix();
//Top Right
GL.PushMatrix();
{
uint pieceWidth = FrameRight;
uint pieceHeight = sizeY - FrameBottom;
int pieceX = (int)((contentWidth / 2) + (pieceWidth / 2));
int pieceY = (int)(FrameBottom / 2);
GL.Translate(pieceX, pieceY, 0);
rect = pane.CreateRectangle(pieceWidth, pieceHeight);
GL.Begin(PrimitiveType.Quads);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, pieceHeight / FrameBottom);
GL.Vertex2(rect.LeftPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 1, pieceHeight / FrameBottom);
GL.Vertex2(rect.RightPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 0);
GL.Vertex2(rect.RightPoint, rect.TopPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 1, 0);
GL.Vertex2(rect.LeftPoint, rect.TopPoint);
GL.End();
}
GL.PopMatrix();
//Bottom Right
GL.PushMatrix();
{
uint pieceWidth = FrameLeft;
uint pieceHeight = sizeY - FrameTop;
int pieceX = (int)-((contentWidth / 2) + (pieceWidth / 2));
int pieceY = (int)-(FrameTop / 2);
GL.Translate(pieceX, pieceY, 0);
rect = pane.CreateRectangle(pieceWidth, pieceHeight);
GL.Begin(PrimitiveType.Quads);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 0);
GL.Vertex2(rect.LeftPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 1, 0);
GL.Vertex2(rect.RightPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 1, pieceHeight / FrameTop);
GL.Vertex2(rect.RightPoint, rect.TopPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, pieceHeight / FrameTop);
GL.Vertex2(rect.LeftPoint, rect.TopPoint);
GL.End();
}
GL.PopMatrix();
//Bottom Right
GL.PushMatrix();
{
uint pieceWidth = sizeX - FrameLeft;
uint pieceHeight = FrameBottom;
int pieceX = (int)(FrameLeft / 2);
int pieceY = (int)(-(sizeY / 2) + (pieceHeight / 2));
GL.Translate(pieceX, pieceY, 0);
rect = pane.CreateRectangle(pieceWidth, pieceHeight);
GL.Begin(PrimitiveType.Quads);
GL.MultiTexCoord2(TextureUnit.Texture0, pieceWidth / FrameLeft, 1);
GL.Vertex2(rect.LeftPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 1);
GL.Vertex2(rect.RightPoint, rect.BottomPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, 0, 0);
GL.Vertex2(rect.RightPoint, rect.TopPoint);
GL.MultiTexCoord2(TextureUnit.Texture0, pieceWidth / FrameLeft, 0);
GL.Vertex2(rect.LeftPoint, rect.TopPoint);
GL.End();
}
GL.PopMatrix();
}
}
else if (window.FrameCount == 4) //4 corners with specific texture mapping
{
// _________
//|______| |
//| | | |
//| |___|__|
//|__|______|
var frame1 = window.WindowFrames[0];
var frame2 = window.WindowFrames[0];
var frame3 = window.WindowFrames[0];
var frame4 = window.WindowFrames[0];
uint contentWidth = sizeX - (uint)FrameRight - (uint)FrameLeft;
uint contentHeight = sizeY - (uint)FrameTop - (uint)FrameBottom;
RenderWindowContent(pane,
contentWidth,
contentHeight,
window.Content, effectiveAlpha, Textures);
}
case 1:
float oneW, oneH;
GetTextureSize(window.WindowFrames[0].Material, Textures, out oneW, out oneH);
frameLeft = frameRight = oneW;
frameTop = frameBottom = oneH;
break;
case WindowKind.Horizontal:
break;
case WindowKind.HorizontalNoContent:
case 4:
case 8:
GetTextureSize(window.WindowFrames[0].Material, Textures, out frameLeft, out frameTop);
GetTextureSize(window.WindowFrames[3].Material, Textures, out frameRight, out frameBottom);
break;
}
GL.UseProgram(0);
if (frameLeft == 0) frameLeft = window.FrameElementLeft;
if (frameRight == 0) frameRight = window.FrameElementRight;
if (frameTop == 0) frameTop = window.FrameElementTop;
if (frameBottom == 0) frameBottom = window.FrameElementBottm;
Vector2[] texCoords = new Vector2[] {
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(1, 1),
new Vector2(0, 1),
};
if (window.Content.TexCoords.Count > 0)
{
texCoords = new Vector2[] {
window.Content.TexCoords[0].BottomLeft.ToTKVector2(),
window.Content.TexCoords[0].BottomRight.ToTKVector2(),
window.Content.TexCoords[0].TopRight.ToTKVector2(),
window.Content.TexCoords[0].TopLeft.ToTKVector2(),
};
}
//Setup vertex colors
Color[] colors = new Color[] {
window.Content.ColorBottomLeft.Color,
window.Content.ColorBottomRight.Color,
window.Content.ColorTopRight.Color,
window.Content.ColorTopLeft.Color,
};
float contentWidth = ((window.StretchLeft + (pane.Width - frameLeft)) - frameRight) + window.StretchRight;
float contentHeight = ((window.StretchTop + (pane.Height - frameTop)) - frameBottom) + window.StretchBottm;
if (!window.NotDrawnContent)
{
SetupShaders(window.Content.Material, Textures);
DrawQuad(dX + frameLeft - window.StretchLeft,
dY - frameTop + window.StretchTop,
contentWidth,
contentHeight,
texCoords, colors);
}
//After the content is draw, check this
//If it's disabled, frames do not use vertex color
if (!window.UseVertexColorForAll)
{
colors = new Color[] {
Color.White, Color.White,
Color.White, Color.White,
};
}
//Apply pane alpha
for (int i = 0; i < colors.Length; i++)
{
uint setalpha = (uint)((colors[i].A * effectiveAlpha) / 255);
colors[i] = Color.FromArgb((int)setalpha, colors[i]);
}
switch (window.FrameCount)
{
case 1: //1 frame. 1 texture for corners (around) or sides (horizontal)
{
var windowFrame = window.WindowFrames[0];
SetupShaders(windowFrame.Material, Textures);
//2 sides, no corners
if (window.WindowKind == WindowKind.Horizontal ||
window.WindowKind == WindowKind.HorizontalNoContent)
{
texCoords = new Vector2[]
{
new Vector2(1, 0),
new Vector2(0, 0),
new Vector2(0, 1),
new Vector2(1, 1),
};
DrawQuad(dX + frameRight + contentWidth, dY, frameRight, pane.Height, texCoords, colors);
texCoords = new Vector2[]
{
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(1, 1),
new Vector2(0, 1),
};
DrawQuad(dX, dY, frameLeft, pane.Height, texCoords, colors);
}
else if (window.WindowKind == WindowKind.Around)
{
// top left
float pieceWidth = pane.Width - frameRight;
float pieceHeight = frameTop;
texCoords = new Vector2[]
{
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
};
DrawQuad(dX, dY, pieceWidth, pieceHeight, texCoords, colors);
// top right
pieceWidth = frameRight;
pieceHeight = pane.Height - frameBottom;
texCoords = new Vector2[]
{
new Vector2(1, 0),
new Vector2(0, 0),
new Vector2(0,(pane.Height - frameTop) / frameTop),
new Vector2(1,(pane.Height - frameTop) / frameTop),
};
DrawQuad(dX + pane.Width - frameRight, dY, pieceWidth, pieceHeight, texCoords, colors);
// bottom left
pieceWidth = frameLeft;
pieceHeight = pane.Height - frameTop;
texCoords = new Vector2[]
{
new Vector2(0,(pane.Height - frameBottom) / frameBottom),
new Vector2(1,(pane.Height - frameBottom) / frameBottom),
new Vector2(1, 0),
new Vector2(0, 0),
};
DrawQuad(dX, dY - frameTop, pieceWidth, pieceHeight, texCoords, colors);
// bottom right
pieceWidth = pane.Width - frameLeft;
pieceHeight = frameBottom;
texCoords = new Vector2[]
{
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
};
DrawQuad(dX + frameLeft, dY - pane.Height + frameBottom, pieceWidth, pieceHeight, texCoords, colors);
}
}
break;
//4 or more will always be around types
case 4: //4 each corner
{
var matTL = window.WindowFrames[0].Material;
var matTR = window.WindowFrames[1].Material;
var matBL = window.WindowFrames[2].Material;
var matBR = window.WindowFrames[3].Material;
if (matTL.TextureMaps.Length > 0)
{
SetupShaders(matTL, Textures);
float pieceWidth = pane.Width - frameRight;
float pieceHeight = frameTop;
texCoords = new Vector2[]
{
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
};
DrawQuad(dX, dY, pieceWidth, pieceHeight, texCoords, colors);
}
if (matTR.TextureMaps.Length > 0)
{
SetupShaders(matTR, Textures);
float pieceWidth = frameRight;
float pieceHeight = pane.Height - frameBottom;
texCoords = new Vector2[]
{
new Vector2(1, 0),
new Vector2(0, 0),
new Vector2(0,(pane.Height - frameTop) / frameTop),
new Vector2(1,(pane.Height - frameTop) / frameTop),
};
DrawQuad(dX + pane.Width - frameRight, dY, pieceWidth, pieceHeight, texCoords, colors);
}
if (matBL.TextureMaps.Length > 0)
{
SetupShaders(matBL, Textures);
float pieceWidth = frameLeft;
float pieceHeight = pane.Height - frameTop;
texCoords = new Vector2[]
{
new Vector2(0,(pane.Height - frameBottom) / frameBottom),
new Vector2(1,(pane.Height - frameBottom) / frameBottom),
new Vector2(1, 0),
new Vector2(0, 0),
};
DrawQuad(dX, dY - frameTop, pieceWidth, pieceHeight, texCoords, colors);
}
if (matBR.TextureMaps.Length > 0)
{
SetupShaders(matBR, Textures);
float pieceWidth = pane.Width - frameLeft;
float pieceHeight = frameBottom;
texCoords = new Vector2[]
{
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
};
DrawQuad(dX + frameLeft, dY - pane.Height + frameBottom, pieceWidth, pieceHeight, texCoords, colors);
}
}
break;
case 8: //4 per corner, 4 per side
{
var matTL = window.WindowFrames[0].Material;
var matTR = window.WindowFrames[1].Material;
var matBL = window.WindowFrames[2].Material;
var matBR = window.WindowFrames[3].Material;
var matT = window.WindowFrames[4].Material;
var matB = window.WindowFrames[5].Material;
var matL = window.WindowFrames[6].Material;
var matR = window.WindowFrames[7].Material;
if (matTL.TextureMaps.Length > 0)
{
SetupShaders(matTL, Textures);
DrawQuad(dX, dY, frameLeft, frameTop, texCoords, colors);
}
if (matTR.TextureMaps.Length > 0)
{
SetupShaders(matTR, Textures);
DrawQuad(dX + pane.Width - frameRight, dY, frameRight, frameTop, texCoords, colors);
}
if (matBL.TextureMaps.Length > 0)
{
SetupShaders(matBL, Textures);
DrawQuad(dX, dY - pane.Height + frameTop, frameLeft, frameBottom, texCoords, colors);
}
if (matBR.TextureMaps.Length > 0)
{
SetupShaders(matBR, Textures);
DrawQuad(dX + pane.Width - frameLeft, dY - pane.Height + frameBottom, frameRight, frameBottom, texCoords, colors);
}
if (matT.TextureMaps.Length > 0)
{
SetupShaders(matT, Textures);
texCoords = new Vector2[]
{
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
};
DrawQuad(dX + frameLeft, dY, contentWidth, frameTop, texCoords, colors);
}
if (matB.TextureMaps.Length > 0)
{
SetupShaders(matB, Textures);
texCoords = new Vector2[]
{
new Vector2((pane.Width - frameLeft) / frameLeft, 1),
new Vector2(0, 1),
new Vector2(0, 0),
new Vector2((pane.Width - frameLeft) / frameLeft, 0),
};
DrawQuad(dX + frameRight, dY - (pane.Height - frameBottom), contentWidth, frameTop, texCoords, colors);
}
if (matL.TextureMaps.Length > 0)
{
SetupShaders(matL, Textures);
texCoords = new Vector2[]
{
new Vector2(0,(pane.Height - frameTop) / frameTop),
new Vector2(1,(pane.Height - frameTop) / frameTop),
new Vector2(1, 0),
new Vector2(0, 0),
};
DrawQuad(dX, dY - frameTop, frameLeft, contentHeight, texCoords, colors);
}
if (matR.TextureMaps.Length > 0)
{
SetupShaders(matR, Textures);
texCoords = new Vector2[]
{
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(1,(pane.Height - frameBottom) / frameBottom),
new Vector2(0,(pane.Height - frameBottom) / frameBottom),
};
DrawQuad(dX + (pane.Width - frameRight), dY - frameTop, frameRight, contentHeight, texCoords, colors);
}
}
break;
}
}
private static void GetTextureSize(BxlytMaterial pane, Dictionary<string, STGenericTexture> Textures, out float width, out float height)
{
width = 0;
height = 0;
if (pane.TextureMaps.Length > 0)
{
if (Textures.ContainsKey(pane.TextureMaps[0].Name))
{
var tex = Textures[pane.TextureMaps[0].Name];
width = tex.Width;
height = tex.Height;
}
}
}
private static float DrawnVertexX(float width, OriginX originX)
{
switch (originX)
{
case OriginX.Center: return -width / 2.0f;
case OriginX.Right: return -width;
default: return 0.0f;
}
}
private static float DrawnVertexY(float height, OriginY originX)
{
switch (originX)
{
case OriginY.Center: return height / 2.0f;
case OriginY.Bottom: return height;
default: return 0.0f;
}
}
private static void DrawQuad(float x, float y, float w, float h, Vector2[] texCoords, Color[] colors)
{
GL.Disable(EnableCap.AlphaTest);
GL.Disable(EnableCap.Blend);
GL.LineWidth(0.5f);
GL.Begin(PrimitiveType.LineLoop);
GL.Color4(Color.Green);
GL.Vertex2(x, y);
GL.Vertex2(x + w, y);
GL.Vertex2(x + w, y - h);
GL.Vertex2(x, y - h);
GL.End();
GL.LineWidth(1f);
GL.Enable(EnableCap.AlphaTest);
GL.Enable(EnableCap.Blend);
GL.Begin(PrimitiveType.Quads);
GL.Color4(colors[0]);
GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[0].X, texCoords[0].Y);
GL.Vertex2(x, y);
GL.Color4(colors[1]);
GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[1].X, texCoords[1].Y);
GL.Vertex2(x + w, y);
GL.Color4(colors[2]);
GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[2].X, texCoords[2].Y);
GL.Vertex2(x + w, y - h);
GL.Color4(colors[3]);
GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[3].X, texCoords[3].Y);
GL.Vertex2(x, y - h);
GL.End();
}
enum FrameType

View file

@ -241,11 +241,6 @@ namespace LayoutBXLYT.Cafe
{
if (header != null)
{
foreach (var mat in header.GetMaterials())
{
if (mat.Shader != null)
mat.Shader.Dispose();
}
}
}
@ -926,9 +921,57 @@ namespace LayoutBXLYT.Cafe
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowContent Content { get; set; }
[TypeConverter(typeof(ExpandableObjectConverter))]
[Browsable(false)]
public List<BxlytWindowFrame> WindowFrames { get; set; }
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame TopLeftFrame
{
get { return WindowFrames.Count >= 1 ? WindowFrames[0] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame TopRightFrame
{
get { return WindowFrames.Count >= 2 ? WindowFrames[1] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame BottomLeftFrame
{
get { return WindowFrames.Count >= 3 ? WindowFrames[2] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame BottomRightFrame
{
get { return WindowFrames.Count >= 4 ? WindowFrames[3] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame TopFrame
{
get { return WindowFrames.Count >= 5 ? WindowFrames[4] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame BottomFrame
{
get { return WindowFrames.Count >= 6 ? WindowFrames[5] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame LeftFrame
{
get { return WindowFrames.Count >= 7 ? WindowFrames[6] : null; }
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public BxlytWindowFrame RightFrame
{
get { return WindowFrames.Count >= 8 ? WindowFrames[7] : null; }
}
public WND1(FileReader reader, Header header) : base(reader)
{
WindowFrames = new List<BxlytWindowFrame>();

View file

@ -28,7 +28,10 @@ namespace LayoutBXLYT
SetInt("hasTexture0", 0);
SetInt("numTextureMaps", 0);
SetInt("flipTexture", 0);
SetInt("textures0", 0);
SetInt("textures1", 0);
SetInt("textures2", 0);
SetVec2("uvScale0", new Vector2(1,1));
SetFloat("uvRotate0", 0);
SetVec2("uvTranslate0", new Vector2(0, 0));
@ -51,15 +54,19 @@ namespace LayoutBXLYT
if (material.TextureMaps.Length > 0)
textureMap0 = material.GetTexture(0);
if (textures.ContainsKey(textureMap0))
for (int i = 0; i < material.TextureMaps.Length; i++)
{
GL.ActiveTexture(TextureUnit.Texture0);
SetInt("textures0", 0);
bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]);
if (isBinded)
SetInt("hasTexture0", 1);
if (textures.ContainsKey(material.TextureMaps[i].Name))
{
GL.ActiveTexture(TextureUnit.Texture0 + i);
SetInt($"textures{i}", 0);
bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[textureMap0]);
if (isBinded)
SetInt($"hasTexture{i}", 1);
}
}
if (material.TextureTransforms.Length > 0)
{
var transform = material.TextureTransforms[0];

View file

@ -4,8 +4,8 @@ namespace LayoutBXLYT.Cafe
{
public class AlphaCompare
{
public byte CompareMode;
public uint Value;
public byte CompareMode { get; set; }
public uint Value { get; set; }
public AlphaCompare(FileReader reader, BFLYT.Header header)
{

View file

@ -4,9 +4,9 @@ namespace LayoutBXLYT.Cafe
{
public class TevStage
{
byte RGBMode;
byte AlphaMode;
ushort unk;
public byte RGBMode { get; set; }
public byte AlphaMode { get; set; }
public ushort unk { get; set; }
public TevStage(FileReader reader, BFLYT.Header header)
{

View file

@ -4,8 +4,8 @@ namespace LayoutBXLYT.Cafe
{
public class TexCoordGen
{
public MatrixType GenType;
public TextureGenerationType Source;
public MatrixType GenType { get; set; }
public TextureGenerationType Source { get; set; }
byte[] unkData;

View file

@ -5,9 +5,9 @@ namespace LayoutBXLYT.Cafe
{
public class TextureTransform
{
public Vector2F Translate;
public float Rotate;
public Vector2F Scale;
public Vector2F Translate { get; set; }
public float Rotate { get; set; }
public Vector2F Scale { get; set; }
public TextureTransform() { }

View file

@ -93,7 +93,8 @@ namespace LayoutBXLYT
}
}
private void UpdateRectangle() {
private void UpdateRectangle()
{
rectangle = CreateRectangle();
}
@ -163,7 +164,7 @@ namespace LayoutBXLYT
else if (originY == OriginY.Bottom)
y = -(Height / 2);
return new Vector2(x,y);
return new Vector2(x, y);
}
private static Vector4 TransformOrientation(int Width, int Height, OriginX originX, OriginY originY)
@ -456,6 +457,7 @@ namespace LayoutBXLYT
BxlytWindowContent Content { get; set; }
[Browsable(false)]
List<BxlytWindowFrame> WindowFrames { get; set; }
}
@ -571,7 +573,7 @@ namespace LayoutBXLYT
public class BxlanHeader : LayoutHeader
{
}
public class BxlytHeader : LayoutHeader
@ -610,7 +612,7 @@ namespace LayoutBXLYT
public BxlytTextureRef[] TextureMaps { get; set; }
}
public class SectionCommon
public class SectionCommon
{
[Browsable(false)]
public virtual string Signature { get; }

View file

@ -74,27 +74,7 @@ namespace FirstPlugin
public ImageEditorBase OpenForm()
{
bool IsDialog = IFileInfo != null && IFileInfo.InArchive;
Properties prop = new Properties();
prop.Width = Width;
prop.Height = Height;
prop.Depth = Depth;
prop.MipCount = MipCount;
prop.ArrayCount = ArrayCount;
prop.ImageSize = (uint)ImageData.Length;
prop.Format = Format;
prop.TileMode = image.TileMode;
prop.Swizzle = image.Swizzle;
form = new ImageEditorBase();
form.Text = Text;
form.Dock = DockStyle.Fill;
form.AddFileContextEvent("Save", Save);
form.AddFileContextEvent("Replace", Replace);
form.LoadProperties(prop);
form.LoadImage(this);
return form;
}
@ -107,8 +87,7 @@ namespace FirstPlugin
public void FillEditor(UserControl control)
{
form = (ImageEditorBase)control;
UpdateForm();
UpdateForm((ImageEditorBase)control);
}
private void UpdateForm(ImageEditorBase form)
@ -125,7 +104,11 @@ namespace FirstPlugin
prop.Format = Format;
prop.TileMode = image.TileMode;
prop.Swizzle = image.Swizzle;
form.Text = Text;
form.Dock = DockStyle.Fill;
form.AddFileContextEvent("Save", Save);
form.AddFileContextEvent("Replace", Replace);
form.LoadProperties(prop);
form.LoadImage(this);
}
@ -606,7 +589,6 @@ namespace FirstPlugin
public void Unload()
{
form.Dispose();
}
public void Save(System.IO.Stream stream)

View file

@ -114,7 +114,7 @@ namespace LayoutBXLYT
GL.ClearColor(BackgroundColor);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// GL.Disable(EnableCap.CullFace);
// GL.Disable(EnableCap.CullFace);
GL.Enable(EnableCap.Blend);
GL.Enable(EnableCap.AlphaTest);
GL.AlphaFunc(AlphaFunction.Always, 0f);
@ -186,6 +186,13 @@ namespace LayoutBXLYT
}
else
{
/*Matrix4 translate = Matrix4.CreateTranslation(pane.Translate.X, pane.Translate.Y, 0);
Matrix4 rotateX = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pane.Rotate.X));
Matrix4 rotateY = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pane.Rotate.Y));
Matrix4 rotateZ = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(pane.Rotate.Z));
Matrix4 scale = Matrix4.CreateScale(pane.Scale.X, pane.Scale.Y, 0);
Matrix4 transform = scale * (rotateX * rotateY * rotateZ) * translate;*/
GL.Translate(pane.Translate.X, pane.Translate.Y, 0);
GL.Rotate(pane.Rotate.X, 1, 0, 0);
GL.Rotate(pane.Rotate.Y, 0, 1, 0);
@ -307,56 +314,56 @@ namespace LayoutBXLYT
{
if (backgroundTex == null)
{
/* backgroundTex = RenderableTex.FromBitmap(Properties.Resources.GridBackground);
backgroundTex.TextureWrapR = TextureWrapMode.Repeat;
backgroundTex.TextureWrapT = TextureWrapMode.Repeat;
/* backgroundTex = RenderableTex.FromBitmap(Properties.Resources.GridBackground);
backgroundTex.TextureWrapR = TextureWrapMode.Repeat;
backgroundTex.TextureWrapT = TextureWrapMode.Repeat;
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, backgroundTex.TexID);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)backgroundTex.TextureWrapR);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)backgroundTex.TextureWrapT);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)backgroundTex.TextureMagFilter);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)backgroundTex.TextureMinFilter);
GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, backgroundTex.TexID);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (float)backgroundTex.TextureWrapR);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (float)backgroundTex.TextureWrapT);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)backgroundTex.TextureMagFilter);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)backgroundTex.TextureMinFilter);
float UVscale = 15;
float UVscale = 15;
int PanelWidth = 9000;
int PanelWHeight = 9000;
int PanelWidth = 9000;
int PanelWHeight = 9000;
Vector2 scaleCenter = new Vector2(0.5f, 0.5f);
Vector2 scaleCenter = new Vector2(0.5f, 0.5f);
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,0),
};
Vector2[] TexCoords = new Vector2[] {
new Vector2(1,1),
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,0),
};
for (int i = 0; i < TexCoords.Length; i++)
TexCoords[i] = (TexCoords[i] - scaleCenter) * 20 + scaleCenter;
for (int i = 0; i < TexCoords.Length; i++)
TexCoords[i] = (TexCoords[i] - scaleCenter) * 20 + scaleCenter;
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.PushMatrix();
GL.Scale(1, 1, 1);
GL.Translate(0, 0, 0);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.PushMatrix();
GL.Scale(1, 1, 1);
GL.Translate(0, 0, 0);
GL.Color4(Color.White);
GL.Color4(Color.White);
GL.Begin(PrimitiveType.Quads);
GL.TexCoord2(TexCoords[0]);
GL.Vertex3(PanelWidth, PanelWHeight, 0);
GL.TexCoord2(TexCoords[1]);
GL.Vertex3(-PanelWidth, PanelWHeight, 0);
GL.TexCoord2(TexCoords[2]);
GL.Vertex3(-PanelWidth, -PanelWHeight, 0);
GL.TexCoord2(TexCoords[3]);
GL.Vertex3(PanelWidth, -PanelWHeight, 0);
GL.End();
GL.Begin(PrimitiveType.Quads);
GL.TexCoord2(TexCoords[0]);
GL.Vertex3(PanelWidth, PanelWHeight, 0);
GL.TexCoord2(TexCoords[1]);
GL.Vertex3(-PanelWidth, PanelWHeight, 0);
GL.TexCoord2(TexCoords[2]);
GL.Vertex3(-PanelWidth, -PanelWHeight, 0);
GL.TexCoord2(TexCoords[3]);
GL.Vertex3(PanelWidth, -PanelWHeight, 0);
GL.End();
GL.BindTexture(TextureTarget.Texture2D, 0);
GL.PopMatrix();*/
GL.BindTexture(TextureTarget.Texture2D, 0);
GL.PopMatrix();*/
}
}
@ -461,13 +468,14 @@ namespace LayoutBXLYT
private void SearchHit(BasePane pane, int X, int Y, ref BasePane SelectedPane)
{
if (pane.IsHit(X, Y)){
if (pane.IsHit(X, Y))
{
SelectedPane = pane;
return;
}
foreach (var childPane in pane.Childern)
SearchHit(childPane, X, Y, ref SelectedPane);
SearchHit(childPane, X, Y, ref SelectedPane);
}
private void glControl1_MouseUp(object sender, MouseEventArgs e)

View file

@ -59,7 +59,6 @@ namespace Toolbox.Library
if (format == TEX_FORMAT.L8 || format == TEX_FORMAT.LA8)
compSel = new byte[4] { 2, 2, 2, 3 };
for (int Y = 0; Y < height; Y++)
{
for (int X = 0; X < width; X++)

View file

@ -1,10 +1,17 @@
uniform vec4 blackColor;
uniform vec4 whiteColor;
uniform int hasTexture0;
uniform int debugShading;
uniform int numTextureMaps;
uniform sampler2D textures0;
uniform sampler2D textures1;
uniform sampler2D textures2;
uniform int hasTexture0;
uniform int hasTexture1;
uniform int hasTexture2;
uniform sampler2D uvTestPattern;
void main()

View file

@ -33,7 +33,7 @@ vec2 SetFlip(vec2 tex)
void main()
{
gl_FrontColor = gl_Color;
vec2 texCoord0 = uvScale0 * gl_MultiTexCoord0.xy + uvTranslate0;
vec2 texCoord0 = uvScale0 * (gl_MultiTexCoord0.xy + uvTranslate0);
gl_TexCoord[0].st = SetFlip(texCoord0);
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}