omfg
unknown
csharp
9 months ago
5.1 kB
6
Indexable
Camera _camera;
int _lastBoundTexture;
Target TextureTarget;
Texture[] _textures;
Dimension[] _textureDimensions;
Shader _shader;
void CertainUnclearedMethod(int indexOffset,
int y,
int x,
int textureIndex,
out IEnumerable<float> vertices,
out IEnumerable<int> indices)
{
var textureDims = _textureDimensions[textureIndex];
float texWidth = textureDims.width;
float texHeight = textureDims.height;
GetVertices(y, x, texWidth, texHeight, out vertices);
indices = new[] {
indexOffset,
indexOffset + 1,
indexOffset + 2,
indexOffset + 2,
indexOffset + 1,
indexOffset + 3
};
}
void GetVertices(int y, int x, float texWidth, float texHeight, out IEnumerable<float> vertices)
{
const int someSize = 128; //magic numbers GTFO
float cellWidth = .1f, //why is this here?
cellHeight = .1f,
startX = -1f + x * cellWidth,
startY = .5f - y * cellHeight;
float u0, v0;
u0 = v0 = 0;
float u1 = someSize / texWidth;
float v1 = someSize / texHeight;
vertices = Enumerable.Empty<float>(); //might be overkill
vertices = AddVerticesBlock(vertices, startX, startY, u0, v0);
vertices = AddVerticesBlock(vertices, startX + cellWidth, startY, u1, v0);
vertices = AddVerticesBlock(vertices, startX, startY + cellHeight, u0, v1);
vertices = AddVerticesBlock(vertices, startX + cellWidth, startY + cellHeight, u1, v1);
}
IEnumerable<float> AddVerticesBlock(IEnumerable<float> floats, float x, float y, float u, float v)
=> floats.Append(x)
.Append(y)
.Append(0)
.Append(u)
.Append(v);
static void NotLastBoundTextureMethod(Target TextureTarget, Texture[] _textures, int textureIndex)
{
GL.BindTexture(TextureTarget.Texture2D, _textures[textureIndex]);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
(int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
(int)TextureMagFilter.Nearest);
}
void Render(int[,] grid)
{
IEnumerable<float> vertices = Enumerable.Empty<float>();
IEnumerable<int> indices = Enumerable.Empty<int>();
int xLimit, yLimit;
_shader.Use();
_shader.SetUniform("view", _camera.View);
xLimit = grid.GetLength(1);
yLimit = grid.GetLength(0);
int indexOffset = 0;
for (int y = 0; y < yLimit; y++) {
GetInformationFromX(y, xLimit, grid, ref indexOffset, ref vertices, ref indices);
}
Mesh mesh = new(vertices, indices);
mesh.Draw(indices.Count());
mesh.Cleanup();
DrawCursor();
}
void GetInformationFromX(int currentY,
int limit,
int[,] grid,
ref int indexOffset,
ref IEnumerable<float> vertices,
ref IEnumerable<int> indices)
{
for (int x = 0; x < limit; x++) {
int textureIndex = grid[currentY, x];
if (textureIndex != _lastBoundTexture) {
_lastBoundTexture = textureIndex;
NotLastBoundTextureMethod(TextureTarget, _textures, textureIndex);
}
CertainUnclearedMethod(indexOffset, currentY, x, textureIndex,
out var verticesX, out var indicesX);
vertices = vertices.Concat(verticesX);
indices = indices.Concat(indicesX);
indexOffset += 4;
}
}
void DrawCursor()
{
throw new NotImplementedException();
}
internal class Camera
{
public object View { get; internal set; }
}
internal class Dimension
{
internal float height;
internal float width;
}
internal class GL
{
internal static void BindTexture(object texture2D, object value)
{
throw new NotImplementedException();
}
internal static void TexParameter(object texture2D, object textureMinFilter, int nearest)
{
throw new NotImplementedException();
}
}
internal class Mesh
{
public Mesh(float[] floats, int[] ints)
{
}
public Mesh(IEnumerable<float> vertices, IEnumerable<int> indices)
{
}
internal void Cleanup()
{
throw new NotImplementedException();
}
internal void Draw(int count)
{
throw new NotImplementedException();
}
}
internal class Target
{
public object Texture2D { get; internal set; }
}
internal class Texture
{
}
internal class TextureMagFilter
{
public static object Nearest { get; internal set; }
}
internal class TextureMinFilter
{
public static object Nearest { get; internal set; }
}
internal class TextureParameterName
{
public static object TextureMagFilter { get; internal set; }
public static object TextureMinFilter { get; internal set; }
}Editor is loading...
Leave a Comment