Fixed whatever was wrong with my shader

This commit is contained in:
2022-12-05 19:27:32 -08:00
parent 8059158bae
commit 5b6f9124b5
21 changed files with 284 additions and 61 deletions

View File

@ -126,10 +126,6 @@ void RenderPipeline::renderUI(
// Clear / Bind / Update the render target.
renderTarget->bind();
renderTarget->clear(
RENDER_TARGET_CLEAR_FLAG_DEPTH |
RENDER_TARGET_CLEAR_FLAG_COLOR
);
this->renderManager->setRenderFlags(
RENDER_MANAGER_RENDER_FLAG_BLEND |
RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST

View File

@ -16,12 +16,20 @@ namespace Dawn {
struct Tileset {
public:
std::vector<struct Tile> tiles;
struct Tile getTile(int32_t tile) {
assertTrue(tile >= 0);
assertTrue(tile < this->tiles.size());
return this->tiles[tile];
}
};
struct TilesetGrid : public Tileset{
public:
int32_t rows;
int32_t columns;
int32_t divX;
int32_t divY;
TilesetGrid() {
@ -30,8 +38,8 @@ namespace Dawn {
TilesetGrid(
int32_t columns,
int32_t rows,
int32_t width,
int32_t height,
int32_t w,
int32_t h,
int32_t gapX,
int32_t gapY,
int32_t borderX,
@ -39,49 +47,43 @@ namespace Dawn {
) {
assertTrue(columns >= 1);
assertTrue(rows >= 1);
assertTrue(width >= 1);
assertTrue(height >= 1);
assertTrue(w >= 1);
assertTrue(h >= 1);
assertTrue(gapX >= 0);
assertTrue(gapY >= 0);
assertTrue(borderX >= 0);
assertTrue(borderY >= 0);
assertTrue(width >= (columns + (gapX * columns) + borderX + borderX));
assertTrue(height >= (rows + (gapY * rows) + borderY + borderY));
assertTrue(w >= (columns + (gapX * columns) + borderX + borderX));
assertTrue(h >= (rows + (gapY * rows) + borderY + borderY));
this->rows = rows;
this->columns = columns;
// Calculate division sizes (pixels)
float_t divX = (
(float_t)width - ((float_t)borderX * 2.0f) -
((float_t)gapX * ((float_t)columns - 1))
) / columns;
float_t divY = (
(float_t)height - ((float_t)borderY * 2.0f) -
((float_t)gapY * ((float_t)rows - 1))
) / rows;
this->divX = (w - (borderX * 2.0f) - (gapX * (columns - 1))) / columns;
this->divY = (h - (borderY * 2.0f) - (gapY * (rows - 1))) / rows;
// Calculate the division sizes (units)
float_t tdivX = divX / (float_t)width;
float_t tdivY = divY / (float_t)height;
float_t tdivX = (float_t)this->divX / (float_t)w;
float_t tdivY = (float_t)this->divY / (float_t)h;
for(int32_t y = 0; y < rows; y++) {
for(int32_t x = 0; x < columns; x++) {
struct Tile tile;
tile.uv0.x = (borderX + (divX * x) + (gapX * x)) / width;
tile.uv0.x = (borderX + ((float_t)this->divX * x) + (gapX * x)) / w;
tile.uv1.x = tile.uv0.x + tdivX;
tile.uv0.y = (borderY + (divY * y) + (gapY * y)) / height;
tile.uv0.y = (borderY + ((float_t)this->divY * y) + (gapY * y)) / h;
tile.uv1.y = tile.uv0.y + tdivY;
this->tiles.push_back(tile);
}
}
}
struct Tile getTile(int32_t row, int32_t column) {
struct Tile getTileFromGrid(int32_t row, int32_t column) {
assertTrue(row > 0 && row < this->rows);
assertTrue(column > 0 && column < this->columns);
return this->tiles[row + (column * this->rows)];
return this->getTile(row + (column * this->rows));
}
};
}

View File

@ -50,6 +50,33 @@ void QuadMesh::bufferQuadMesh(
);
}
void QuadMesh::bufferCoordinates(
Mesh *mesh,
glm::vec2 uv0, glm::vec2 uv1,
int32_t verticeStart
) {
assertNotNull(mesh);
mesh->bufferCoordinates(verticeStart, std::array<glm::vec2, QUAD_VERTICE_COUNT>{{
uv0, glm::vec2(uv1.x, uv0.y),
glm::vec2(uv0.x, uv1.y), uv1
}});
}
void QuadMesh::bufferPositions(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 xy1,
int32_t verticeStart
) {
mesh->bufferPositions(
verticeStart, std::array<glm::vec3, QUAD_VERTICE_COUNT>{{
glm::vec3(xy0, 0),
glm::vec3(xy1.x, xy0.y, 0),
glm::vec3(xy0.x, xy1.y, 0),
glm::vec3(xy1, 0)
}}
);
}
void QuadMesh::initQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,

View File

@ -16,7 +16,7 @@ namespace Dawn {
/**
* Buffers the vertices of a quad onto a primitive.
*
* @param primitive The primitive to buffer to.
* @param mesh The primitive to buffer to.
* @param xy0 The lower X and Y coordinate.
* @param uv0 The lower Xand Y texture coordinate.
* @param xy1 The higher X and Y coordinate.
@ -35,7 +35,7 @@ namespace Dawn {
/**
* Buffers the vertices of a quad onto a primitive.
*
* @param primitive The primitive to buffer to.
* @param mesh The primitive to buffer to.
* @param xy0 The lower X and Y coordinate.
* @param uv0 The lower Xand Y texture coordinate.
* @param xy1 The higher X and Y coordinate.
@ -50,6 +50,44 @@ namespace Dawn {
int32_t verticeStart, int32_t indiceStart
);
/**
* Buffers texture coordinates on to an already initialized quad mesh.
*
* @param mesh Mesh to buffer the texture coordinates on to.
* @param uv0 Lower X and Y coordinates.
* @param uv1 Upper X and Y coordinates.
* @param verticeStart Start vertice to buffer in to.
*/
static void bufferCoordinates(
Mesh *mesh,
glm::vec2 uv0, glm::vec2 uv1,
int32_t verticeStart
);
/**
* Buffers the positions of a quad onto a primitive.
*
* @param mesh The primitive to buffer to.
* @param xy0 The lower X and Y coordinate.
* @param xy1 The higher X and Y coordinate.
* @param verticeStart Start vertice to buffer to.
*/
static void bufferPositions(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 xy1,
int32_t verticeStart
);
/**
* Initializes a mesh to be a single quad.
*
* @param mesh The primitive to buffer to.
* @param xy0 The lower X and Y coordinate.
* @param uv0 The lower Xand Y texture coordinate.
* @param xy1 The higher X and Y coordinate.
* @param uv1 The higher X and Y texture coordinate.
* @param z The Z position of the coordinates.
*/
static void initQuadMesh(
Mesh *mesh,
glm::vec2 xy0, glm::vec2 uv0,