Fixed packed map shader.
This commit is contained in:
@ -6,32 +6,37 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
|
#include "assert/assert.h"
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
shaderbuffer_t MAP_BUFFER;
|
shaderbuffer_t MAP_BUFFER;
|
||||||
mapdata_t MAP_DATA;
|
mapdata_t MAP_DATA;
|
||||||
|
|
||||||
void mapInit() {
|
void mapInit() {
|
||||||
memset(&MAP_DATA, 0, sizeof(mapdata_t));
|
memoryZero(&MAP_DATA, sizeof(mapdata_t));
|
||||||
shaderBufferInit(&MAP_BUFFER, 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() {
|
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.
|
// Copy map size.
|
||||||
memoryCopyRangeSafe(
|
memoryCopyRangeSafe(
|
||||||
&MAP_DATA.mapSize,
|
&MAP_DATA.mapSize,
|
||||||
&OVERWORLD.mapWidth,
|
&OVERWORLD.mapWidth,
|
||||||
&OVERWORLD.mapHeight + sizeof(uint8_t),
|
&OVERWORLD.mapHeight + sizeof(uint8_t),
|
||||||
sizeof(uint_t)
|
sizeof(MAP_DATA.mapSize)
|
||||||
);
|
|
||||||
|
|
||||||
// Copy tile ids.
|
|
||||||
memoryCopyRangeSafe(
|
|
||||||
&MAP_DATA.tileIds,
|
|
||||||
&OVERWORLD.tileIds[0],
|
|
||||||
&OVERWORLD.tileIds[OVERWORLD.mapWidth * OVERWORLD.mapHeight],
|
|
||||||
OVERWORLD_TILE_COUNT_MAX * sizeof(tileid_t)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
shaderBufferBind(&MAP_BUFFER);
|
shaderBufferBind(&MAP_BUFFER);
|
||||||
|
@ -7,17 +7,9 @@
|
|||||||
#include "../fragments/packed.glsl"
|
#include "../fragments/packed.glsl"
|
||||||
#include "../fragments/quad.glsl"
|
#include "../fragments/quad.glsl"
|
||||||
|
|
||||||
#define MAP_PACKED_SIZE 4
|
|
||||||
|
|
||||||
struct TileData {
|
|
||||||
uint nothing;
|
|
||||||
uvec3 _padding0;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(std140) uniform b_Map {
|
layout(std140) uniform b_Map {
|
||||||
|
uvec4 mapTileIds[OVERWORLD_TILE_COUNT_MAX / PACKED_U8_PER_UVEC4];
|
||||||
uint mapSize;
|
uint mapSize;
|
||||||
uint mapTileIds[OVERWORLD_TILE_COUNT_MAX / MAP_PACKED_SIZE];
|
|
||||||
TileData mapTileData[OVERWORLD_TILE_COUNT_MAX];
|
|
||||||
uvec3 _padding0;
|
uvec3 _padding0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,19 +10,12 @@
|
|||||||
#include "overworld/overworld.h"
|
#include "overworld/overworld.h"
|
||||||
|
|
||||||
#define MAP_BLOCK_NAME "b_Map"
|
#define MAP_BLOCK_NAME "b_Map"
|
||||||
#define MAP_PACKED_SIZE 4
|
#define MAP_TILE_PACK_SIZE sizeof(uvec4_t) / sizeof(tileid_t)
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint32_t nothing;
|
|
||||||
uvec3_t _padding0;
|
|
||||||
} maptiledata_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
uvec4_t tileIds[OVERWORLD_TILE_COUNT_MAX / MAP_TILE_PACK_SIZE];
|
||||||
uint_t mapSize;
|
uint_t mapSize;
|
||||||
uvec3_t _padding0;
|
uvec3_t _padding0;
|
||||||
|
|
||||||
uint32_t tileIds[OVERWORLD_TILE_COUNT_MAX / MAP_PACKED_SIZE];
|
|
||||||
maptiledata_t tileData[OVERWORLD_TILE_COUNT_MAX];
|
|
||||||
} mapdata_t;
|
} mapdata_t;
|
||||||
|
|
||||||
extern shaderbuffer_t MAP_BUFFER;
|
extern shaderbuffer_t MAP_BUFFER;
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
// This software is released under the MIT License.
|
// This software is released under the MIT License.
|
||||||
// https://opensource.org/licenses/MIT
|
// https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
#define PACKED_U8_PER_UI 4
|
||||||
|
#define PACKED_U8_PER_UVEC4 PACKED_U8_PER_UI / 4
|
||||||
|
|
||||||
uint packedGetU8(uint position, uint data) {
|
uint packedGetU8(uint position, uint data) {
|
||||||
return (data >> (position * 8u)) & 0xFFu;
|
return (data >> (position * 8u)) & 0xFFu;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ typedef double double_t;
|
|||||||
extern char_t EXECUTABLE_PATH[];
|
extern char_t EXECUTABLE_PATH[];
|
||||||
extern char_t EXECUTABLE_DIRECTORY[];
|
extern char_t EXECUTABLE_DIRECTORY[];
|
||||||
|
|
||||||
typedef uint32_t uvec4_t[4];
|
typedef uint32_t uint_t;
|
||||||
typedef uint32_t uvec3_t[3];
|
typedef uint_t uvec4_t[4];
|
||||||
typedef uint32_t uvec2_t[2];
|
typedef uint_t uvec3_t[3];
|
||||||
typedef uint32_t uint_t;
|
typedef uint_t uvec2_t[2];
|
@ -14,6 +14,6 @@ void overworldRender() {
|
|||||||
mapShaderUse();
|
mapShaderUse();
|
||||||
quadRender(OVERWORLD.mapWidth * OVERWORLD.mapHeight);
|
quadRender(OVERWORLD.mapWidth * OVERWORLD.mapHeight);
|
||||||
|
|
||||||
// entityShaderUse();
|
entityShaderUse();
|
||||||
// quadRender(OVERWORLD.entityCount);
|
quadRender(OVERWORLD.entityCount);
|
||||||
}
|
}
|
Reference in New Issue
Block a user