Fixed packed map shader.

This commit is contained in:
2025-03-02 19:38:09 -06:00
parent 122997c58c
commit 7c150a9a7c
6 changed files with 27 additions and 34 deletions

View File

@ -6,32 +6,37 @@
*/
#include "map.h"
#include "assert/assert.h"
#include "util/memory.h"
shaderbuffer_t MAP_BUFFER;
mapdata_t MAP_DATA;
void mapInit() {
memset(&MAP_DATA, 0, sizeof(mapdata_t));
memoryZero(&MAP_DATA, sizeof(mapdata_t));
shaderBufferInit(&MAP_BUFFER, sizeof(mapdata_t));
assertTrue(
sizeof(MAP_DATA.tileIds) == sizeof(OVERWORLD.tileIds),
"Map shader tile data and Overworld tile data are not the same size."
);
}
void mapUpdate() {
// Copy tile ids.
memoryCopyRangeSafe(
&MAP_DATA.tileIds,
&OVERWORLD.tileIds[0],
&OVERWORLD.tileIds[OVERWORLD.mapWidth * OVERWORLD.mapHeight],
sizeof(MAP_DATA.tileIds)
);
// Copy map size.
memoryCopyRangeSafe(
&MAP_DATA.mapSize,
&OVERWORLD.mapWidth,
&OVERWORLD.mapHeight + sizeof(uint8_t),
sizeof(uint_t)
);
// Copy tile ids.
memoryCopyRangeSafe(
&MAP_DATA.tileIds,
&OVERWORLD.tileIds[0],
&OVERWORLD.tileIds[OVERWORLD.mapWidth * OVERWORLD.mapHeight],
OVERWORLD_TILE_COUNT_MAX * sizeof(tileid_t)
sizeof(MAP_DATA.mapSize)
);
shaderBufferBind(&MAP_BUFFER);

View File

@ -7,17 +7,9 @@
#include "../fragments/packed.glsl"
#include "../fragments/quad.glsl"
#define MAP_PACKED_SIZE 4
struct TileData {
uint nothing;
uvec3 _padding0;
};
layout(std140) uniform b_Map {
uvec4 mapTileIds[OVERWORLD_TILE_COUNT_MAX / PACKED_U8_PER_UVEC4];
uint mapSize;
uint mapTileIds[OVERWORLD_TILE_COUNT_MAX / MAP_PACKED_SIZE];
TileData mapTileData[OVERWORLD_TILE_COUNT_MAX];
uvec3 _padding0;
};

View File

@ -10,19 +10,12 @@
#include "overworld/overworld.h"
#define MAP_BLOCK_NAME "b_Map"
#define MAP_PACKED_SIZE 4
typedef struct {
uint32_t nothing;
uvec3_t _padding0;
} maptiledata_t;
#define MAP_TILE_PACK_SIZE sizeof(uvec4_t) / sizeof(tileid_t)
typedef struct {
uvec4_t tileIds[OVERWORLD_TILE_COUNT_MAX / MAP_TILE_PACK_SIZE];
uint_t mapSize;
uvec3_t _padding0;
uint32_t tileIds[OVERWORLD_TILE_COUNT_MAX / MAP_PACKED_SIZE];
maptiledata_t tileData[OVERWORLD_TILE_COUNT_MAX];
} mapdata_t;
extern shaderbuffer_t MAP_BUFFER;