mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 12:47:58 +03:00
tr1/output: rewrite room drawing
This commit is contained in:
parent
6e27f24264
commit
28dbf86d32
21 changed files with 679 additions and 262 deletions
80
data/tr1/ship/shaders/meshes.glsl
Normal file
80
data/tr1/ship/shaders/meshes.glsl
Normal file
|
@ -0,0 +1,80 @@
|
|||
#define NEUTRAL_SHADE 0x1000
|
||||
#define NO_VERT_MOVE 0x2000
|
||||
|
||||
#ifdef VERTEX
|
||||
|
||||
uniform samplerBuffer uUVW; // texture u, v, layer
|
||||
uniform vec2 uViewportSize;
|
||||
uniform mat4 uMatProjection;
|
||||
uniform mat4 uMatModelView;
|
||||
uniform float uWibbleOffset;
|
||||
uniform bool uTrapezoidFilterEnabled;
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in int inUVWIdx;
|
||||
layout(location = 2) in vec2 inTrapezoidRatios;
|
||||
layout(location = 3) in int inFlags;
|
||||
layout(location = 4) in float inShade;
|
||||
|
||||
out vec2 gTexUV;
|
||||
flat out int gTexLayer;
|
||||
out vec2 gTrapezoidRatios;
|
||||
out float gShade;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = uMatProjection * uMatModelView * vec4(inPosition, 1.0);
|
||||
|
||||
if (uWibbleOffset >= 0.0 && (inFlags & NO_VERT_MOVE) == 0) {
|
||||
gl_Position.xyz =
|
||||
waterWibble(gl_Position, uViewportSize, uWibbleOffset);
|
||||
}
|
||||
|
||||
vec3 uvw = texelFetch(uUVW, int(inUVWIdx)).xyz;
|
||||
gTexUV = uvw.xy;
|
||||
gTexLayer = int(uvw.z);
|
||||
gTrapezoidRatios = inTrapezoidRatios;
|
||||
if (uTrapezoidFilterEnabled) {
|
||||
gTexUV *= inTrapezoidRatios;
|
||||
}
|
||||
gShade = inShade;
|
||||
}
|
||||
|
||||
#elif defined(FRAGMENT)
|
||||
|
||||
uniform sampler2DArray uTexture;
|
||||
uniform bool uSmoothingEnabled;
|
||||
uniform bool uTrapezoidFilterEnabled;
|
||||
uniform float uAlphaThreshold;
|
||||
uniform float uBrightnessMultiplier;
|
||||
uniform vec3 uGlobalTint;
|
||||
|
||||
in vec2 gTexUV;
|
||||
flat in int gTexLayer;
|
||||
in float gShade;
|
||||
in vec2 gTrapezoidRatios;
|
||||
out vec4 outColor;
|
||||
|
||||
void main(void) {
|
||||
vec4 texColor = vec4(1);
|
||||
vec3 texCoords = vec3(gTexUV.x, gTexUV.y, gTexLayer);
|
||||
if (texCoords.z >= 0) {
|
||||
if (uTrapezoidFilterEnabled) {
|
||||
texCoords.xy /= gTrapezoidRatios.xy;
|
||||
}
|
||||
|
||||
if (uSmoothingEnabled && discardTranslucent(uTexture, texCoords)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
texColor = texture(uTexture, texCoords);
|
||||
if (uAlphaThreshold >= 0.0 && texColor.a <= uAlphaThreshold) {
|
||||
discard;
|
||||
}
|
||||
}
|
||||
|
||||
texColor.rgb *= 2.0 - (gShade / NEUTRAL_SHADE);
|
||||
texColor.rgb *= uBrightnessMultiplier;
|
||||
texColor.rgb *= uGlobalTint;
|
||||
outColor = vec4(texColor.rgb, 1.0);
|
||||
}
|
||||
#endif
|
|
@ -7,11 +7,10 @@ uniform vec2 uViewportSize;
|
|||
uniform mat4 uMatProjection;
|
||||
uniform mat4 uMatModelView;
|
||||
uniform float uWibbleOffset;
|
||||
uniform vec2 uFog; // x = start, y = end
|
||||
|
||||
layout(location = 0) in vec3 inPosition;
|
||||
layout(location = 1) in vec2 inDisplacement;
|
||||
layout(location = 2) in int inTextureIdx;
|
||||
layout(location = 2) in int inUVWIdx;
|
||||
layout(location = 3) in float inShade;
|
||||
|
||||
out vec2 gTexUV;
|
||||
|
@ -28,7 +27,7 @@ void main(void) {
|
|||
waterWibble(gl_Position, uViewportSize, uWibbleOffset);
|
||||
}
|
||||
|
||||
vec3 uvw = texelFetch(uUVW, int(inTextureIdx)).xyz;
|
||||
vec3 uvw = texelFetch(uUVW, int(inUVWIdx)).xyz;
|
||||
gTexUV = uvw.xy;
|
||||
gTexLayer = int(uvw.z);
|
||||
gShade = inShade;
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.9...develop) - ××××-××-××
|
||||
- fixed anisotropy filter causing black lines (#902)
|
||||
- improved rendering performance
|
||||
|
||||
## [4.9](https://github.com/LostArtefacts/TRX/compare/tr1-4.8.3...tr1-4.9) - 2025-03-31
|
||||
- added quadrilateral interpolation (#354)
|
||||
|
|
|
@ -32,7 +32,7 @@ void GFX_GL_Program_Close(GFX_GL_PROGRAM *program)
|
|||
}
|
||||
}
|
||||
|
||||
void GFX_GL_Program_Bind(GFX_GL_PROGRAM *program)
|
||||
void GFX_GL_Program_Bind(const GFX_GL_PROGRAM *const program)
|
||||
{
|
||||
ASSERT(program != nullptr);
|
||||
glUseProgram(program->id);
|
||||
|
|
|
@ -12,7 +12,7 @@ typedef struct {
|
|||
bool GFX_GL_Program_Init(GFX_GL_PROGRAM *program);
|
||||
void GFX_GL_Program_Close(GFX_GL_PROGRAM *program);
|
||||
|
||||
void GFX_GL_Program_Bind(GFX_GL_PROGRAM *program);
|
||||
void GFX_GL_Program_Bind(const GFX_GL_PROGRAM *program);
|
||||
char *GFX_GL_Program_PreprocessShader(
|
||||
const char *content, GLenum type, GFX_GL_BACKEND backend);
|
||||
void GFX_GL_Program_AttachShader(
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
#include "game/output.h"
|
||||
|
||||
#include "game/clock.h"
|
||||
#include "game/output/meshes.h"
|
||||
#include "game/output/rooms.h"
|
||||
#include "game/output/sprites.h"
|
||||
#include "game/output/textures.h"
|
||||
#include "game/overlay.h"
|
||||
#include "game/random.h"
|
||||
#include "game/room.h"
|
||||
#include "game/shell.h"
|
||||
#include "game/viewport.h"
|
||||
#include "global/const.h"
|
||||
#include "global/types.h"
|
||||
#include "global/vars.h"
|
||||
#include "specific/s_output.h"
|
||||
|
||||
|
@ -18,14 +15,7 @@
|
|||
#include <libtrx/engine/image.h>
|
||||
#include <libtrx/filesystem.h>
|
||||
#include <libtrx/game/game_buf.h>
|
||||
#include <libtrx/game/math.h>
|
||||
#include <libtrx/game/matrix.h>
|
||||
#include <libtrx/gfx/context.h>
|
||||
#include <libtrx/memory.h>
|
||||
#include <libtrx/utils.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_LIGHTNINGS 64
|
||||
#define PHD_IONE (PHD_ONE / 4)
|
||||
|
@ -49,19 +39,9 @@ static bool m_IsSkyboxEnabled = false;
|
|||
static bool m_IsWibbleEffect = false;
|
||||
static bool m_IsWaterEffect = false;
|
||||
static bool m_IsShadeEffect = false;
|
||||
static int m_OverlayCurAlpha = 0;
|
||||
static int m_OverlayDstAlpha = 0;
|
||||
static int m_BackdropCurAlpha = 0;
|
||||
static int m_BackdropDstAlpha = 0;
|
||||
|
||||
static int32_t m_WibbleOffset = 0;
|
||||
static int32_t m_AnimatedTexturesOffset = 0;
|
||||
static CLOCK_TIMER m_WibbleTimer = { .type = CLOCK_TIMER_SIM };
|
||||
static CLOCK_TIMER m_AnimatedTexturesTimer = { .type = CLOCK_TIMER_SIM };
|
||||
static CLOCK_TIMER m_FadeTimer = { .type = CLOCK_TIMER_SIM };
|
||||
static int32_t m_WibbleTable[WIBBLE_SIZE] = {};
|
||||
static int32_t m_ShadeTable[WIBBLE_SIZE] = {};
|
||||
static int32_t m_RandTable[WIBBLE_SIZE] = {};
|
||||
|
||||
static PHD_VBUF *m_VBuf = nullptr;
|
||||
static TEXTURE_UV *m_EnvMapUV = nullptr;
|
||||
|
@ -93,14 +73,10 @@ static void M_DrawTexturedFace4s(const FACE4 *faces, int32_t count);
|
|||
static void M_DrawObjectFace3EnvMap(const FACE3 *faces, int32_t count);
|
||||
static void M_DrawObjectFace4EnvMap(const FACE4 *faces, int32_t count);
|
||||
static uint16_t M_CalcVertex(PHD_VBUF *vbuf, const XYZ_16 pos);
|
||||
static void M_CalcVertexWibble(PHD_VBUF *vbuf);
|
||||
static bool M_CalcObjectVertices(const XYZ_16 *vertices, int16_t count);
|
||||
static void M_CalcVerticeLight(const OBJECT_MESH *mesh);
|
||||
static bool M_CalcVerticeEnvMap(const OBJECT_MESH *mesh);
|
||||
static void M_CalcSkyboxLight(const OBJECT_MESH *mesh);
|
||||
static void M_CalcRoomVertices(const ROOM_MESH *mesh);
|
||||
static void M_CalcRoomVerticesWibble(const ROOM_MESH *mesh);
|
||||
static void M_CalcWibbleTable(void);
|
||||
|
||||
static void M_DrawSphere(const XYZ_32 pos, const int32_t radius)
|
||||
{
|
||||
|
@ -354,31 +330,6 @@ static uint16_t M_CalcVertex(PHD_VBUF *const vbuf, const XYZ_16 pos)
|
|||
return clip_flags;
|
||||
}
|
||||
|
||||
static void M_CalcVertexWibble(PHD_VBUF *const vbuf)
|
||||
{
|
||||
double xs = vbuf->xs;
|
||||
double ys = vbuf->ys;
|
||||
xs += m_WibbleTable[(m_WibbleOffset + (int)ys) & (WIBBLE_SIZE - 1)];
|
||||
ys += m_WibbleTable[(m_WibbleOffset + (int)xs) & (WIBBLE_SIZE - 1)];
|
||||
|
||||
int16_t clip_flags = vbuf->clip & ~15;
|
||||
if (xs < g_PhdLeft) {
|
||||
clip_flags |= 1;
|
||||
} else if (xs > g_PhdRight) {
|
||||
clip_flags |= 2;
|
||||
}
|
||||
|
||||
if (ys < g_PhdTop) {
|
||||
clip_flags |= 4;
|
||||
} else if (ys > g_PhdBottom) {
|
||||
clip_flags |= 8;
|
||||
}
|
||||
|
||||
vbuf->xs = xs;
|
||||
vbuf->ys = ys;
|
||||
vbuf->clip = clip_flags;
|
||||
}
|
||||
|
||||
static bool M_CalcObjectVertices(
|
||||
const XYZ_16 *const vertices, const int16_t count)
|
||||
{
|
||||
|
@ -493,70 +444,19 @@ static void M_CalcSkyboxLight(const OBJECT_MESH *const mesh)
|
|||
}
|
||||
}
|
||||
|
||||
static void M_CalcRoomVertices(const ROOM_MESH *const mesh)
|
||||
{
|
||||
for (int32_t i = 0; i < mesh->num_vertices; i++) {
|
||||
PHD_VBUF *const vbuf = &m_VBuf[i];
|
||||
const ROOM_VERTEX *const vertex = &mesh->vertices[i];
|
||||
|
||||
M_CalcVertex(vbuf, vertex->pos);
|
||||
|
||||
vbuf->g = vertex->light_adder;
|
||||
if (vbuf->zv >= Output_GetNearZ()) {
|
||||
const int32_t depth = ((int32_t)vbuf->zv) >> W2V_SHIFT;
|
||||
if (depth > Output_GetDrawDistMax()) {
|
||||
vbuf->g = MAX_LIGHTING;
|
||||
if (!m_IsSkyboxEnabled) {
|
||||
vbuf->clip |= 16;
|
||||
}
|
||||
} else {
|
||||
vbuf->g += Output_CalcFogShade(depth);
|
||||
if (!m_IsWaterEffect) {
|
||||
CLAMPG(vbuf->g, MAX_LIGHTING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_IsWaterEffect) {
|
||||
vbuf->g += m_ShadeTable[(
|
||||
((uint8_t)m_WibbleOffset
|
||||
+ (uint8_t)m_RandTable[(mesh->num_vertices - i) % WIBBLE_SIZE])
|
||||
% WIBBLE_SIZE)];
|
||||
CLAMP(vbuf->g, 0, 0x1FFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void M_CalcRoomVerticesWibble(const ROOM_MESH *const mesh)
|
||||
{
|
||||
for (int32_t i = 0; i < mesh->num_vertices; i++) {
|
||||
if (mesh->vertices[i].flags & NO_VERT_MOVE) {
|
||||
continue;
|
||||
}
|
||||
M_CalcVertexWibble(&m_VBuf[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void M_CalcWibbleTable(void)
|
||||
{
|
||||
for (int i = 0; i < WIBBLE_SIZE; i++) {
|
||||
PHD_ANGLE angle = (i * DEG_360) / WIBBLE_SIZE;
|
||||
m_WibbleTable[i] = Math_Sin(angle) * MAX_WIBBLE >> W2V_SHIFT;
|
||||
m_ShadeTable[i] = Math_Sin(angle) * MAX_SHADE >> W2V_SHIFT;
|
||||
m_RandTable[i] = (Random_GetDraw() >> 5) - 0x01FF;
|
||||
}
|
||||
}
|
||||
|
||||
bool Output_Init(void)
|
||||
{
|
||||
M_CalcWibbleTable();
|
||||
Output_Sprites_Init();
|
||||
Output_Textures_Init();
|
||||
Output_Sprites_Init();
|
||||
Output_Meshes_Init();
|
||||
Output_Rooms_Init();
|
||||
return S_Output_Init();
|
||||
}
|
||||
|
||||
void Output_Shutdown(void)
|
||||
{
|
||||
Output_Rooms_Shutdown();
|
||||
Output_Meshes_Shutdown();
|
||||
Output_Sprites_Shutdown();
|
||||
Output_Textures_Shutdown();
|
||||
S_Output_Shutdown();
|
||||
|
@ -576,6 +476,7 @@ void Output_SetWindowSize(int width, int height)
|
|||
|
||||
void Output_ApplyRenderSettings(void)
|
||||
{
|
||||
Output_Textures_ApplyRenderSettings();
|
||||
S_Output_ApplyRenderSettings();
|
||||
if (m_BackdropImagePath) {
|
||||
Output_LoadBackgroundFromFile(m_BackdropImagePath);
|
||||
|
@ -588,6 +489,7 @@ void Output_DownloadTextures(void)
|
|||
|
||||
Output_Textures_ObserveLevelLoad();
|
||||
Output_Sprites_ObserveLevelLoad();
|
||||
Output_Rooms_ObserveLevelLoad();
|
||||
}
|
||||
|
||||
void Output_DrawBlack(void)
|
||||
|
@ -614,6 +516,7 @@ void Output_BeginScene(void)
|
|||
Text_DrawReset();
|
||||
|
||||
Output_Sprites_RenderBegin();
|
||||
Output_Meshes_RenderBegin();
|
||||
S_Output_RenderBegin();
|
||||
m_LightningCount = 0;
|
||||
}
|
||||
|
@ -709,19 +612,7 @@ void Output_DrawSkybox(const OBJECT_MESH *const mesh)
|
|||
|
||||
void Output_DrawRoomMesh(const ROOM *const room)
|
||||
{
|
||||
const ROOM_MESH *const mesh = &room->mesh;
|
||||
M_CalcRoomVertices(mesh);
|
||||
|
||||
if (m_IsWibbleEffect) {
|
||||
S_Output_DisableDepthWrites();
|
||||
M_DrawTexturedFace4s(mesh->face4s, mesh->num_face4s);
|
||||
M_DrawTexturedFace3s(mesh->face3s, mesh->num_face3s);
|
||||
S_Output_EnableDepthWrites();
|
||||
M_CalcRoomVerticesWibble(mesh);
|
||||
}
|
||||
|
||||
M_DrawTexturedFace4s(mesh->face4s, mesh->num_face4s);
|
||||
M_DrawTexturedFace3s(mesh->face3s, mesh->num_face3s);
|
||||
Output_Rooms_RenderRoom(g_MatrixPtr, Output_GetTint(), room);
|
||||
}
|
||||
|
||||
void Output_DrawRoomPortals(const ROOM *const room)
|
||||
|
@ -1429,8 +1320,9 @@ void Output_EnableScissor(
|
|||
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(
|
||||
x * scale_x, (GFX_Context_GetDisplayHeight() - y) * scale_y,
|
||||
w * scale_x, h * scale_y);
|
||||
x * scale_x - border,
|
||||
(GFX_Context_GetDisplayHeight() - y) * scale_y - border,
|
||||
w * scale_x + border * 2, h * scale_y + border * 2);
|
||||
}
|
||||
|
||||
void Output_DisableScissor(void)
|
||||
|
|
|
@ -96,3 +96,5 @@ void Output_DisableScissor(void);
|
|||
// TODO: these functions are poor in their design and should be not needed
|
||||
void Output_RememberState(void);
|
||||
void Output_RestoreState(void);
|
||||
|
||||
float Output_AdjustUV(uint16_t uv);
|
||||
|
|
25
src/tr1/game/output/meshes.c
Normal file
25
src/tr1/game/output/meshes.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "game/output/meshes.h"
|
||||
|
||||
static OUTPUT_SHADER *m_Shader = nullptr;
|
||||
|
||||
void Output_Meshes_Init(void)
|
||||
{
|
||||
m_Shader = Output_Shader_Create("shaders/meshes.glsl");
|
||||
}
|
||||
|
||||
void Output_Meshes_Shutdown(void)
|
||||
{
|
||||
Output_Shader_Free(m_Shader);
|
||||
m_Shader = nullptr;
|
||||
}
|
||||
|
||||
void Output_Meshes_RenderBegin(void)
|
||||
{
|
||||
Output_Shader_UploadCommonUniforms(m_Shader);
|
||||
Output_Shader_UploadProjectionMatrix(m_Shader);
|
||||
}
|
||||
|
||||
OUTPUT_SHADER *Output_Meshes_GetShader(void)
|
||||
{
|
||||
return m_Shader;
|
||||
}
|
8
src/tr1/game/output/meshes.h
Normal file
8
src/tr1/game/output/meshes.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "game/output/shader.h"
|
||||
|
||||
void Output_Meshes_Init(void);
|
||||
void Output_Meshes_Shutdown(void);
|
||||
void Output_Meshes_RenderBegin(void);
|
||||
OUTPUT_SHADER *Output_Meshes_GetShader(void);
|
290
src/tr1/game/output/rooms.c
Normal file
290
src/tr1/game/output/rooms.c
Normal file
|
@ -0,0 +1,290 @@
|
|||
#include "game/output/rooms.h"
|
||||
|
||||
#include "game/output.h"
|
||||
#include "game/output/meshes.h"
|
||||
#include "game/output/textures.h"
|
||||
#include "game/output/utils.h"
|
||||
#include "game/room.h"
|
||||
|
||||
#include <libtrx/gfx/gl/utils.h>
|
||||
#include <libtrx/memory.h>
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
// attribute 0
|
||||
XYZ_F pos;
|
||||
|
||||
// attribute 1
|
||||
int32_t uvw_idx;
|
||||
|
||||
// attribute 2
|
||||
float trapezoid_ratio[2];
|
||||
|
||||
// attribute 3
|
||||
uint16_t flags;
|
||||
} M_MESH_VERTEX;
|
||||
|
||||
typedef uint16_t M_MESH_SHADE;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
int32_t vertex_start;
|
||||
int32_t vertex_count;
|
||||
} M_ROOM_BATCH;
|
||||
|
||||
static struct {
|
||||
GLuint vao;
|
||||
GLuint geom_vbo;
|
||||
size_t vertex_count;
|
||||
GLuint shade_vbo;
|
||||
M_MESH_VERTEX *geom_vbo_data;
|
||||
M_MESH_SHADE *shade_vbo_data;
|
||||
size_t batch_count;
|
||||
M_ROOM_BATCH *batches;
|
||||
size_t last_vertex;
|
||||
} m_Priv;
|
||||
|
||||
static OUTPUT_SHADER *m_Shader = nullptr;
|
||||
|
||||
static M_ROOM_BATCH *M_GetBatch(const ROOM *const room)
|
||||
{
|
||||
// Room data gets swapped when flipping, but the VBOs do not. So a room 2
|
||||
// that gets flipped to room 17 ends up getting the data from room 2,
|
||||
// whereas the VBO needs to take data from room 17.
|
||||
const int16_t room_num =
|
||||
Room_GetFlipStatus() && room->flipped_room != NO_ROOM_NEG
|
||||
? room->flipped_room
|
||||
: Room_GetNumber(room);
|
||||
return &m_Priv.batches[room_num];
|
||||
}
|
||||
|
||||
static void M_FillVertex(
|
||||
M_MESH_VERTEX *const out_vertex, const int32_t uvw_idx, const XYZ_16 pos,
|
||||
const uint16_t flags)
|
||||
{
|
||||
out_vertex->pos = (XYZ_F) { .x = pos.x, .y = pos.y, .z = pos.z };
|
||||
out_vertex->uvw_idx = uvw_idx;
|
||||
out_vertex->flags = flags;
|
||||
}
|
||||
|
||||
static void M_AppendRoomFace4(const ROOM *const room, const FACE4 *const face)
|
||||
{
|
||||
for (int32_t i = 0; i < OUTPUT_QUAD_VERTICES; i++) {
|
||||
const int32_t j = OUTPUT_QUAD_TO_FAN(i);
|
||||
const int32_t uvw_idx = face->texture_idx * 4 + j;
|
||||
const ROOM_VERTEX *const room_vertex =
|
||||
&room->mesh.vertices[face->vertices[j]];
|
||||
M_MESH_VERTEX *const out_vertex =
|
||||
&m_Priv.geom_vbo_data[m_Priv.last_vertex];
|
||||
M_FillVertex(out_vertex, uvw_idx, room_vertex->pos, room_vertex->flags);
|
||||
out_vertex->trapezoid_ratio[0] = face->texture_zw[j].z;
|
||||
out_vertex->trapezoid_ratio[1] = face->texture_zw[j].w;
|
||||
m_Priv.last_vertex++;
|
||||
}
|
||||
}
|
||||
|
||||
static void M_AppendRoomFace3(const ROOM *const room, const FACE3 *const face)
|
||||
{
|
||||
for (int32_t i = 0; i < OUTPUT_TRI_VERTICES; i++) {
|
||||
const int32_t j = OUTPUT_TRI_TO_FAN(i);
|
||||
const int32_t uvw_idx = face->texture_idx * 4 + j;
|
||||
const ROOM_VERTEX *const room_vertex =
|
||||
&room->mesh.vertices[face->vertices[j]];
|
||||
M_MESH_VERTEX *const out_vertex =
|
||||
&m_Priv.geom_vbo_data[m_Priv.last_vertex];
|
||||
M_FillVertex(out_vertex, uvw_idx, room_vertex->pos, room_vertex->flags);
|
||||
out_vertex->trapezoid_ratio[0] = 1.0f;
|
||||
out_vertex->trapezoid_ratio[1] = 1.0f;
|
||||
m_Priv.last_vertex++;
|
||||
}
|
||||
}
|
||||
|
||||
static void M_UpdateRoomGeometry(const ROOM *const room)
|
||||
{
|
||||
M_ROOM_BATCH *const batch = &m_Priv.batches[Room_GetNumber(room)];
|
||||
batch->vertex_start = m_Priv.last_vertex;
|
||||
for (int32_t i = 0; i < room->mesh.num_face4s; i++) {
|
||||
M_AppendRoomFace4(room, &room->mesh.face4s[i]);
|
||||
}
|
||||
for (int32_t i = 0; i < room->mesh.num_face3s; i++) {
|
||||
M_AppendRoomFace3(room, &room->mesh.face3s[i]);
|
||||
}
|
||||
batch->vertex_count = m_Priv.last_vertex - batch->vertex_start;
|
||||
}
|
||||
|
||||
static void M_UpdateRoomShades(const ROOM *const room)
|
||||
{
|
||||
M_ROOM_BATCH *const batch = M_GetBatch(room);
|
||||
int32_t v = batch->vertex_start;
|
||||
for (int32_t i = 0; i < room->mesh.num_face4s; i++) {
|
||||
const FACE4 *const face = &room->mesh.face4s[i];
|
||||
for (int32_t j = 0; j < OUTPUT_QUAD_VERTICES; j++) {
|
||||
const int32_t k = OUTPUT_QUAD_TO_FAN(j);
|
||||
m_Priv.shade_vbo_data[v] =
|
||||
room->mesh.vertices[face->vertices[k]].light_adder;
|
||||
v++;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < room->mesh.num_face3s; i++) {
|
||||
const FACE3 *const face = &room->mesh.face3s[i];
|
||||
for (int32_t j = 0; j < OUTPUT_TRI_VERTICES; j++) {
|
||||
const int32_t k = OUTPUT_TRI_TO_FAN(j);
|
||||
m_Priv.shade_vbo_data[v] =
|
||||
room->mesh.vertices[face->vertices[k]].light_adder;
|
||||
v++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void M_UpdateRoomVertices(void)
|
||||
{
|
||||
m_Priv.last_vertex = 0;
|
||||
|
||||
for (int32_t i = 0; i < Room_GetCount(); i++) {
|
||||
const ROOM *const room = Room_Get(i);
|
||||
M_UpdateRoomGeometry(room);
|
||||
}
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.geom_vbo);
|
||||
GFX_TRACK_DATA(
|
||||
glBufferData, GL_ARRAY_BUFFER,
|
||||
m_Priv.vertex_count * sizeof(M_MESH_VERTEX), m_Priv.geom_vbo_data,
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.shade_vbo);
|
||||
GFX_TRACK_DATA(
|
||||
glBufferData, GL_ARRAY_BUFFER,
|
||||
m_Priv.vertex_count * sizeof(M_MESH_SHADE), m_Priv.shade_vbo_data,
|
||||
GL_DYNAMIC_DRAW); // shades are always dynamic
|
||||
}
|
||||
|
||||
static void M_PrepareBuffers(void)
|
||||
{
|
||||
m_Priv.batch_count = Room_GetCount();
|
||||
m_Priv.batches = Memory_Realloc(
|
||||
m_Priv.batches, sizeof(M_ROOM_BATCH) * m_Priv.batch_count);
|
||||
|
||||
int32_t num_vertices = 0;
|
||||
for (int32_t i = 0; i < Room_GetCount(); i++) {
|
||||
num_vertices += Room_Get(i)->mesh.num_face4s * 6;
|
||||
num_vertices += Room_Get(i)->mesh.num_face3s * 3;
|
||||
}
|
||||
|
||||
m_Priv.vertex_count = num_vertices;
|
||||
|
||||
m_Priv.geom_vbo_data =
|
||||
Memory_Alloc(m_Priv.vertex_count * sizeof(M_MESH_VERTEX));
|
||||
m_Priv.shade_vbo_data =
|
||||
Memory_Alloc(m_Priv.vertex_count * sizeof(M_MESH_SHADE));
|
||||
|
||||
glGenVertexArrays(1, &m_Priv.vao);
|
||||
glGenBuffers(1, &m_Priv.geom_vbo);
|
||||
glGenBuffers(1, &m_Priv.shade_vbo);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.geom_vbo);
|
||||
glBindVertexArray(m_Priv.vao);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.geom_vbo);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(
|
||||
0, 3, GL_FLOAT, GL_FALSE, sizeof(M_MESH_VERTEX),
|
||||
(void *)(intptr_t)offsetof(M_MESH_VERTEX, pos));
|
||||
|
||||
glEnableVertexAttribArray(1);
|
||||
glVertexAttribIPointer(
|
||||
1, 1, GL_UNSIGNED_INT, sizeof(M_MESH_VERTEX),
|
||||
(void *)(intptr_t)offsetof(M_MESH_VERTEX, uvw_idx));
|
||||
|
||||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribPointer(
|
||||
2, 2, GL_FLOAT, GL_FALSE, sizeof(M_MESH_VERTEX),
|
||||
(void *)(intptr_t)offsetof(M_MESH_VERTEX, trapezoid_ratio));
|
||||
|
||||
glEnableVertexAttribArray(3);
|
||||
glVertexAttribIPointer(
|
||||
3, 1, GL_UNSIGNED_SHORT, sizeof(M_MESH_VERTEX),
|
||||
(void *)(intptr_t)offsetof(M_MESH_VERTEX, flags));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.shade_vbo);
|
||||
glEnableVertexAttribArray(4);
|
||||
glVertexAttribPointer(
|
||||
4, 1, GL_UNSIGNED_SHORT, GL_FALSE, sizeof(M_MESH_SHADE), 0);
|
||||
|
||||
M_UpdateRoomVertices();
|
||||
}
|
||||
|
||||
static void M_FreeBuffers(void)
|
||||
{
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
if (m_Priv.vao != 0) {
|
||||
glDeleteVertexArrays(1, &m_Priv.vao);
|
||||
m_Priv.vao = 0;
|
||||
}
|
||||
if (m_Priv.geom_vbo != 0) {
|
||||
glDeleteBuffers(1, &m_Priv.geom_vbo);
|
||||
m_Priv.geom_vbo = 0;
|
||||
}
|
||||
if (m_Priv.shade_vbo != 0) {
|
||||
glDeleteBuffers(1, &m_Priv.shade_vbo);
|
||||
m_Priv.shade_vbo = 0;
|
||||
}
|
||||
Memory_FreePointer(&m_Priv.geom_vbo_data);
|
||||
Memory_FreePointer(&m_Priv.shade_vbo_data);
|
||||
Memory_FreePointer(&m_Priv.batches);
|
||||
}
|
||||
|
||||
void Output_Rooms_Init(void)
|
||||
{
|
||||
m_Shader = Output_Meshes_GetShader();
|
||||
}
|
||||
|
||||
void Output_Rooms_Shutdown(void)
|
||||
{
|
||||
M_FreeBuffers();
|
||||
}
|
||||
|
||||
void Output_Rooms_ObserveLevelLoad(void)
|
||||
{
|
||||
M_FreeBuffers();
|
||||
M_PrepareBuffers();
|
||||
}
|
||||
|
||||
void Output_Rooms_RenderRoom(
|
||||
const MATRIX *const matrix, const RGB_F tint, const ROOM *const room)
|
||||
{
|
||||
const M_ROOM_BATCH *const batch = M_GetBatch(room);
|
||||
|
||||
M_UpdateRoomShades(room);
|
||||
|
||||
Output_Shader_UploadMatrix(m_Shader, matrix);
|
||||
Output_Shader_UploadTint(m_Shader, tint);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_Priv.shade_vbo);
|
||||
GFX_TRACK_SUBDATA(
|
||||
glBufferSubData, GL_ARRAY_BUFFER,
|
||||
batch->vertex_start * sizeof(M_MESH_SHADE),
|
||||
batch->vertex_count * sizeof(M_MESH_SHADE),
|
||||
&m_Priv.shade_vbo_data[batch->vertex_start]);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glBindVertexArray(m_Priv.vao);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, Output_Textures_GetObjectUVWsTexture());
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D_ARRAY, Output_Textures_GetAtlasTexture());
|
||||
|
||||
if (Output_GetWibbleOffset() >= 0) {
|
||||
Output_Shader_UploadWibble(m_Shader, -1);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDrawArrays(GL_TRIANGLES, batch->vertex_start, batch->vertex_count);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
Output_Shader_UploadWibble(m_Shader, Output_GetWibbleOffset());
|
||||
glDrawArrays(GL_TRIANGLES, batch->vertex_start, batch->vertex_count);
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
GFX_GL_CheckError();
|
||||
}
|
12
src/tr1/game/output/rooms.h
Normal file
12
src/tr1/game/output/rooms.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <libtrx/game/matrix.h>
|
||||
#include <libtrx/game/output/types.h>
|
||||
#include <libtrx/game/rooms/types.h>
|
||||
|
||||
void Output_Rooms_Init(void);
|
||||
void Output_Rooms_Shutdown(void);
|
||||
void Output_Rooms_ObserveLevelLoad(void);
|
||||
|
||||
void Output_Rooms_RenderRoom(
|
||||
const MATRIX *matrix, RGB_F tint, const ROOM *room);
|
|
@ -1,4 +1,4 @@
|
|||
#include "game/output/sprite_program.h"
|
||||
#include "game/output/shader.h"
|
||||
|
||||
#include "game/output.h"
|
||||
#include "game/viewport.h"
|
||||
|
@ -6,11 +6,13 @@
|
|||
|
||||
#include <libtrx/config.h>
|
||||
#include <libtrx/gfx/gl/utils.h>
|
||||
#include <libtrx/memory.h>
|
||||
|
||||
typedef enum {
|
||||
M_UNIFORM_TEX_ATLAS,
|
||||
M_UNIFORM_TEX_UVW,
|
||||
M_UNIFORM_SMOOTHING_ENABLED,
|
||||
M_UNIFORM_TRAPEZOID_FILTER_ENABLED,
|
||||
M_UNIFORM_BRIGHTNESS_MULTIPLIER,
|
||||
M_UNIFORM_GLOBAL_TINT,
|
||||
M_UNIFORM_VIEWPORT_SIZE,
|
||||
|
@ -20,25 +22,30 @@ typedef enum {
|
|||
M_UNIFORM_NUMBER_OF,
|
||||
} M_UNIFORM;
|
||||
|
||||
static GFX_GL_PROGRAM m_Program;
|
||||
static GLint m_Uniforms[M_UNIFORM_NUMBER_OF];
|
||||
struct OUTPUT_SHADER {
|
||||
GFX_GL_PROGRAM program;
|
||||
GLint uniforms[M_UNIFORM_NUMBER_OF];
|
||||
};
|
||||
|
||||
void Output_SpriteProgram_Init(void)
|
||||
OUTPUT_SHADER *Output_Shader_Create(const char *const path)
|
||||
{
|
||||
GFX_GL_Program_Init(&m_Program);
|
||||
OUTPUT_SHADER *const shader = Memory_Alloc(sizeof(OUTPUT_SHADER));
|
||||
|
||||
GFX_GL_Program_Init(&shader->program);
|
||||
GFX_GL_Program_AttachShader(
|
||||
&m_Program, GL_VERTEX_SHADER, "shaders/sprites.glsl",
|
||||
&shader->program, GL_VERTEX_SHADER, path,
|
||||
GFX_Context_GetConfig()->backend);
|
||||
GFX_GL_Program_AttachShader(
|
||||
&m_Program, GL_FRAGMENT_SHADER, "shaders/sprites.glsl",
|
||||
&shader->program, GL_FRAGMENT_SHADER, path,
|
||||
GFX_Context_GetConfig()->backend);
|
||||
GFX_GL_Program_FragmentData(&m_Program, "outColor");
|
||||
GFX_GL_Program_Link(&m_Program);
|
||||
GFX_GL_Program_FragmentData(&shader->program, "outColor");
|
||||
GFX_GL_Program_Link(&shader->program);
|
||||
|
||||
const char *const uniform_names[] = {
|
||||
[M_UNIFORM_TEX_ATLAS] = "uTexture",
|
||||
[M_UNIFORM_TEX_UVW] = "uUVW",
|
||||
[M_UNIFORM_SMOOTHING_ENABLED] = "uSmoothingEnabled",
|
||||
[M_UNIFORM_TRAPEZOID_FILTER_ENABLED] = "uTrapezoidFilterEnabled",
|
||||
[M_UNIFORM_BRIGHTNESS_MULTIPLIER] = "uBrightnessMultiplier",
|
||||
[M_UNIFORM_GLOBAL_TINT] = "uGlobalTint",
|
||||
[M_UNIFORM_VIEWPORT_SIZE] = "uViewportSize",
|
||||
|
@ -47,44 +54,42 @@ void Output_SpriteProgram_Init(void)
|
|||
[M_UNIFORM_WIBBLE_OFFSET] = "uWibbleOffset",
|
||||
};
|
||||
for (int32_t i = 0; i < M_UNIFORM_NUMBER_OF; i++) {
|
||||
m_Uniforms[i] =
|
||||
GFX_GL_Program_UniformLocation(&m_Program, uniform_names[i]);
|
||||
shader->uniforms[i] =
|
||||
GFX_GL_Program_UniformLocation(&shader->program, uniform_names[i]);
|
||||
GFX_GL_CheckError();
|
||||
}
|
||||
|
||||
GFX_GL_Program_Bind(&m_Program);
|
||||
glUniform1i(m_Uniforms[M_UNIFORM_TEX_ATLAS], 0);
|
||||
glUniform1i(m_Uniforms[M_UNIFORM_TEX_UVW], 1);
|
||||
GFX_GL_Program_Bind(&shader->program);
|
||||
glUniform1i(shader->uniforms[M_UNIFORM_TEX_ATLAS], 0);
|
||||
glUniform1i(shader->uniforms[M_UNIFORM_TEX_UVW], 1);
|
||||
return shader;
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_Shutdown(void)
|
||||
void Output_Shader_Free(OUTPUT_SHADER *const shader)
|
||||
{
|
||||
GFX_GL_Program_Close(&m_Program);
|
||||
GFX_GL_Program_Close(&shader->program);
|
||||
Memory_Free(shader);
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_Bind(void)
|
||||
void Output_Shader_UploadCommonUniforms(const OUTPUT_SHADER *const shader)
|
||||
{
|
||||
GFX_GL_Program_Bind(&m_Program);
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_UploadCommonUniforms(void)
|
||||
{
|
||||
Output_SpriteProgram_Bind();
|
||||
GFX_GL_Program_Bind(&shader->program);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_SMOOTHING_ENABLED],
|
||||
glUniform1f, shader->uniforms[M_UNIFORM_SMOOTHING_ENABLED],
|
||||
g_Config.rendering.texture_filter);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_BRIGHTNESS_MULTIPLIER],
|
||||
glUniform1f, shader->uniforms[M_UNIFORM_TRAPEZOID_FILTER_ENABLED],
|
||||
g_Config.rendering.enable_trapezoid_filter);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, shader->uniforms[M_UNIFORM_BRIGHTNESS_MULTIPLIER],
|
||||
g_Config.visuals.brightness);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform2f, m_Uniforms[M_UNIFORM_VIEWPORT_SIZE],
|
||||
glUniform2f, shader->uniforms[M_UNIFORM_VIEWPORT_SIZE],
|
||||
GFX_Context_GetDisplayWidth(), GFX_Context_GetDisplayHeight());
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform1f, m_Uniforms[M_UNIFORM_WIBBLE_OFFSET],
|
||||
Output_GetWibbleOffset());
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_UploadMatrix(const MATRIX *const source)
|
||||
void Output_Shader_UploadMatrix(
|
||||
const OUTPUT_SHADER *const shader, const MATRIX *const source)
|
||||
{
|
||||
GLfloat target[4][4];
|
||||
target[0][0] = source->_00 / (float)(1 << W2V_SHIFT);
|
||||
|
@ -107,26 +112,35 @@ void Output_SpriteProgram_UploadMatrix(const MATRIX *const source)
|
|||
target[3][2] = 0.0;
|
||||
target[3][3] = 1.0;
|
||||
|
||||
Output_SpriteProgram_Bind();
|
||||
GFX_GL_Program_Bind(&shader->program);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniformMatrix4fv, m_Uniforms[M_UNIFORM_MODEL_MATRIX], 1, GL_TRUE,
|
||||
&target[0][0]);
|
||||
glUniformMatrix4fv, shader->uniforms[M_UNIFORM_MODEL_MATRIX], 1,
|
||||
GL_TRUE, &target[0][0]);
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_UploadProjectionMatrix(void)
|
||||
void Output_Shader_UploadProjectionMatrix(const OUTPUT_SHADER *const shader)
|
||||
{
|
||||
Output_SpriteProgram_Bind();
|
||||
GFX_GL_Program_Bind(&shader->program);
|
||||
|
||||
GLfloat projection[4][4];
|
||||
Output_GetProjectionMatrix(projection);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniformMatrix4fv, m_Uniforms[M_UNIFORM_PROJECTION_MATRIX], 1, GL_TRUE,
|
||||
&projection[0][0]);
|
||||
glUniformMatrix4fv, shader->uniforms[M_UNIFORM_PROJECTION_MATRIX], 1,
|
||||
GL_TRUE, &projection[0][0]);
|
||||
}
|
||||
|
||||
void Output_SpriteProgram_UploadTint(const RGB_F tint)
|
||||
void Output_Shader_UploadWibble(
|
||||
const OUTPUT_SHADER *const shader, const int32_t offset)
|
||||
{
|
||||
GFX_GL_Program_Bind(&m_Program);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform3f, m_Uniforms[M_UNIFORM_GLOBAL_TINT], tint.r, tint.g, tint.b);
|
||||
glUniform1f, shader->uniforms[M_UNIFORM_WIBBLE_OFFSET], offset);
|
||||
}
|
||||
|
||||
void Output_Shader_UploadTint(
|
||||
const OUTPUT_SHADER *const shader, const RGB_F tint)
|
||||
{
|
||||
GFX_GL_Program_Bind(&shader->program);
|
||||
GFX_TRACK_UNIFORM(
|
||||
glUniform3f, shader->uniforms[M_UNIFORM_GLOBAL_TINT], tint.r, tint.g,
|
||||
tint.b);
|
||||
}
|
17
src/tr1/game/output/shader.h
Normal file
17
src/tr1/game/output/shader.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <libtrx/game/matrix.h>
|
||||
#include <libtrx/game/output/types.h>
|
||||
|
||||
typedef struct OUTPUT_SHADER OUTPUT_SHADER;
|
||||
|
||||
OUTPUT_SHADER *Output_Shader_Create(const char *path);
|
||||
void Output_Shader_Free(OUTPUT_SHADER *shader);
|
||||
void Output_Shader_UploadCommonUniforms(const OUTPUT_SHADER *shader);
|
||||
void Output_Shader_UploadProjectionMatrix(const OUTPUT_SHADER *shader);
|
||||
|
||||
// TODO: these functions are poor design.
|
||||
void Output_Shader_UploadMatrix(
|
||||
const OUTPUT_SHADER *shader, const MATRIX *source);
|
||||
void Output_Shader_UploadWibble(const OUTPUT_SHADER *shader, int32_t offset);
|
||||
void Output_Shader_UploadTint(const OUTPUT_SHADER *shader, RGB_F tint);
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <libtrx/game/matrix.h>
|
||||
#include <libtrx/game/output/types.h>
|
||||
|
||||
void Output_SpriteProgram_Init(void);
|
||||
void Output_SpriteProgram_Shutdown(void);
|
||||
void Output_SpriteProgram_Bind(void);
|
||||
void Output_SpriteProgram_UploadCommonUniforms(void);
|
||||
void Output_SpriteProgram_UploadProjectionMatrix(void);
|
||||
|
||||
// TODO: these functions are poor design.
|
||||
void Output_SpriteProgram_UploadMatrix(const MATRIX *source);
|
||||
void Output_SpriteProgram_UploadTint(RGB_F tint);
|
|
@ -1,8 +1,9 @@
|
|||
#include "game/output/sprites.h"
|
||||
|
||||
#include "game/output.h"
|
||||
#include "game/output/sprite_program.h"
|
||||
#include "game/output/shader.h"
|
||||
#include "game/output/textures.h"
|
||||
#include "game/output/utils.h"
|
||||
#include "game/room.h"
|
||||
#include "specific/s_output.h"
|
||||
|
||||
|
@ -11,8 +12,6 @@
|
|||
#include <libtrx/memory.h>
|
||||
#include <libtrx/vector.h>
|
||||
|
||||
#define M_QUAD_VERTICES 6
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
// attribute 0
|
||||
|
@ -24,7 +23,7 @@ typedef struct {
|
|||
} displacement;
|
||||
|
||||
// attribute 2
|
||||
int32_t texture_idx;
|
||||
int32_t uvw_idx;
|
||||
} M_SPRITE_VERTEX;
|
||||
|
||||
typedef uint16_t M_SPRITE_SHADE;
|
||||
|
@ -53,7 +52,7 @@ typedef struct {
|
|||
int32_t quad_count;
|
||||
} M_ROOM_BATCH;
|
||||
|
||||
static const int32_t m_QuadToFan[] = { 0, 1, 2, 0, 2, 3 };
|
||||
static OUTPUT_SHADER *m_Shader = nullptr;
|
||||
|
||||
static struct {
|
||||
M_SPRITE_BUFFER sprite_buf;
|
||||
|
@ -76,7 +75,7 @@ static void M_MakeQuad(
|
|||
}
|
||||
|
||||
for (int32_t k = 0; k < 4; k++) {
|
||||
out_quad[k].texture_idx = sprite_idx * 4 + k;
|
||||
out_quad[k].uvw_idx = sprite_idx * 4 + k;
|
||||
}
|
||||
|
||||
out_quad[0].displacement.x = sprite->x0;
|
||||
|
@ -118,24 +117,6 @@ static void M_BufferReallocGPU(M_SPRITE_BUFFER *const buffer)
|
|||
buffer->shade_vbo_data, GL_DYNAMIC_DRAW); // shades are always dynamic
|
||||
}
|
||||
|
||||
static void M_BufferUploadGPU(
|
||||
M_SPRITE_BUFFER *const buffer, const int32_t start, const int32_t count)
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer->geom_vbo);
|
||||
GFX_GL_CheckError();
|
||||
GFX_TRACK_DATA(
|
||||
glBufferSubData, GL_ARRAY_BUFFER, start * sizeof(M_SPRITE_VERTEX),
|
||||
count * sizeof(M_SPRITE_VERTEX), &buffer->geom_vbo_data[start]);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer->shade_vbo);
|
||||
GFX_GL_CheckError();
|
||||
GFX_TRACK_DATA(
|
||||
glBufferSubData, GL_ARRAY_BUFFER, start * sizeof(M_SPRITE_SHADE),
|
||||
count * sizeof(M_SPRITE_SHADE), &buffer->shade_vbo_data[start]);
|
||||
GFX_GL_CheckError();
|
||||
}
|
||||
|
||||
static void M_PrepareBuffer(
|
||||
M_SPRITE_BUFFER *const buffer, const size_t capacity, const GLenum usage)
|
||||
{
|
||||
|
@ -168,7 +149,7 @@ static void M_PrepareBuffer(
|
|||
glEnableVertexAttribArray(2);
|
||||
glVertexAttribIPointer(
|
||||
2, 1, GL_UNSIGNED_INT, sizeof(M_SPRITE_VERTEX),
|
||||
(void *)(intptr_t)offsetof(M_SPRITE_VERTEX, texture_idx));
|
||||
(void *)(intptr_t)offsetof(M_SPRITE_VERTEX, uvw_idx));
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffer->shade_vbo);
|
||||
glEnableVertexAttribArray(3);
|
||||
|
@ -240,8 +221,6 @@ static void M_PrepareLevelBatches(void)
|
|||
|
||||
static void M_UpdateRoomGeometry(const ROOM *const room)
|
||||
{
|
||||
M_BufferReallocGPU(&m_LevelData.sprite_buf);
|
||||
|
||||
int32_t current_vertex = 0;
|
||||
for (int32_t i = 0; i < Room_GetCount(); i++) {
|
||||
const ROOM *const room = Room_Get(i);
|
||||
|
@ -254,9 +233,9 @@ static void M_UpdateRoomGeometry(const ROOM *const room)
|
|||
|
||||
M_SPRITE_VERTEX quad[4];
|
||||
M_MakeQuad(quad, sprite_idx, pos);
|
||||
for (int32_t k = 0; k < M_QUAD_VERTICES; k++) {
|
||||
for (int32_t k = 0; k < OUTPUT_QUAD_VERTICES; k++) {
|
||||
m_LevelData.sprite_buf.geom_vbo_data[current_vertex] =
|
||||
quad[m_QuadToFan[k]];
|
||||
quad[OUTPUT_QUAD_TO_FAN(k)];
|
||||
current_vertex++;
|
||||
}
|
||||
}
|
||||
|
@ -266,10 +245,10 @@ static void M_UpdateRoomGeometry(const ROOM *const room)
|
|||
static void M_UpdateRoomShades(const ROOM *const room)
|
||||
{
|
||||
const M_ROOM_BATCH *const room_batch = M_GetRoomBatch(room);
|
||||
int32_t current_vertex = room_batch->quad_start * M_QUAD_VERTICES;
|
||||
int32_t current_vertex = room_batch->quad_start * OUTPUT_QUAD_VERTICES;
|
||||
for (int32_t j = 0; j < room->mesh.num_sprites; j++) {
|
||||
const ROOM_SPRITE *const room_sprite = &room->mesh.sprites[j];
|
||||
for (int32_t k = 0; k < M_QUAD_VERTICES; k++) {
|
||||
for (int32_t k = 0; k < OUTPUT_QUAD_VERTICES; k++) {
|
||||
m_LevelData.sprite_buf.shade_vbo_data[current_vertex] =
|
||||
room->mesh.vertices[room_sprite->vertex].light_adder;
|
||||
current_vertex++;
|
||||
|
@ -296,25 +275,28 @@ static void M_PrepareLevelBuffers(void)
|
|||
}
|
||||
M_PrepareBuffer(&m_Dynamic.sprite_buf, 500, GL_DYNAMIC_DRAW);
|
||||
M_PrepareBuffer(
|
||||
&m_LevelData.sprite_buf, num_quads * M_QUAD_VERTICES, GL_STATIC_DRAW);
|
||||
&m_LevelData.sprite_buf, num_quads * OUTPUT_QUAD_VERTICES,
|
||||
GL_STATIC_DRAW);
|
||||
|
||||
m_LevelData.sprite_buf.vertex_count = num_quads * M_QUAD_VERTICES;
|
||||
m_LevelData.sprite_buf.vertex_count = num_quads * OUTPUT_QUAD_VERTICES;
|
||||
for (int32_t i = 0; i < Room_GetCount(); i++) {
|
||||
const ROOM *const room = Room_Get(i);
|
||||
M_UpdateRoomGeometry(room);
|
||||
}
|
||||
M_BufferReallocGPU(&m_LevelData.sprite_buf);
|
||||
}
|
||||
|
||||
void Output_Sprites_Init(void)
|
||||
{
|
||||
Output_SpriteProgram_Init();
|
||||
m_Shader = Output_Shader_Create("shaders/sprites.glsl");
|
||||
m_Dynamic.source = Vector_CreateAtCapacity(sizeof(M_DYNAMIC_SPRITE), 50);
|
||||
}
|
||||
|
||||
void Output_Sprites_Shutdown(void)
|
||||
{
|
||||
M_FreeBuffers();
|
||||
Output_SpriteProgram_Shutdown();
|
||||
Output_Shader_Free(m_Shader);
|
||||
m_Shader = nullptr;
|
||||
}
|
||||
|
||||
void Output_Sprites_ObserveLevelLoad(void)
|
||||
|
@ -325,7 +307,7 @@ void Output_Sprites_ObserveLevelLoad(void)
|
|||
}
|
||||
|
||||
void Output_Sprites_RenderRoomSprites(
|
||||
const MATRIX *matrix, const RGB_F tint, const ROOM *const room)
|
||||
const MATRIX *const matrix, const RGB_F tint, const ROOM *const room)
|
||||
{
|
||||
M_UpdateRoomShades(room);
|
||||
|
||||
|
@ -334,20 +316,21 @@ void Output_Sprites_RenderRoomSprites(
|
|||
GFX_GL_CheckError();
|
||||
GFX_TRACK_SUBDATA(
|
||||
glBufferSubData, GL_ARRAY_BUFFER,
|
||||
room_batch->quad_start * M_QUAD_VERTICES * sizeof(M_SPRITE_SHADE),
|
||||
room_batch->quad_count * M_QUAD_VERTICES * sizeof(M_SPRITE_SHADE),
|
||||
room_batch->quad_start * OUTPUT_QUAD_VERTICES * sizeof(M_SPRITE_SHADE),
|
||||
room_batch->quad_count * OUTPUT_QUAD_VERTICES * sizeof(M_SPRITE_SHADE),
|
||||
&m_LevelData.sprite_buf
|
||||
.shade_vbo_data[room_batch->quad_start * M_QUAD_VERTICES]);
|
||||
.shade_vbo_data[room_batch->quad_start * OUTPUT_QUAD_VERTICES]);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
Output_SpriteProgram_UploadMatrix(matrix);
|
||||
Output_SpriteProgram_UploadTint(tint);
|
||||
Output_Shader_UploadWibble(m_Shader, Output_GetWibbleOffset());
|
||||
Output_Shader_UploadMatrix(m_Shader, matrix);
|
||||
Output_Shader_UploadTint(m_Shader, tint);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
const M_ROOM_BATCH *const batch = M_GetRoomBatch(room);
|
||||
M_DrawBuffer(
|
||||
&m_LevelData.sprite_buf, batch->quad_start * M_QUAD_VERTICES,
|
||||
batch->quad_count * M_QUAD_VERTICES);
|
||||
&m_LevelData.sprite_buf, batch->quad_start * OUTPUT_QUAD_VERTICES,
|
||||
batch->quad_count * OUTPUT_QUAD_VERTICES);
|
||||
}
|
||||
|
||||
void Output_Sprites_RenderSingleSprite(
|
||||
|
@ -365,8 +348,8 @@ void Output_Sprites_RenderSingleSprite(
|
|||
|
||||
void Output_Sprites_RenderBegin(void)
|
||||
{
|
||||
Output_SpriteProgram_UploadCommonUniforms();
|
||||
Output_SpriteProgram_UploadProjectionMatrix();
|
||||
Output_Shader_UploadCommonUniforms(m_Shader);
|
||||
Output_Shader_UploadProjectionMatrix(m_Shader);
|
||||
}
|
||||
|
||||
bool Output_Sprites_Flush(void)
|
||||
|
@ -376,10 +359,10 @@ bool Output_Sprites_Flush(void)
|
|||
}
|
||||
|
||||
M_SPRITE_BUFFER *const buffer = &m_Dynamic.sprite_buf;
|
||||
if ((size_t)m_Dynamic.source->count * M_QUAD_VERTICES
|
||||
if ((size_t)m_Dynamic.source->count * OUTPUT_QUAD_VERTICES
|
||||
> buffer->vertex_capacity) {
|
||||
buffer->vertex_capacity =
|
||||
(m_Dynamic.source->count + 50) * M_QUAD_VERTICES;
|
||||
(m_Dynamic.source->count + 50) * OUTPUT_QUAD_VERTICES;
|
||||
buffer->geom_vbo_data = Memory_Realloc(
|
||||
buffer->geom_vbo_data,
|
||||
buffer->vertex_capacity * sizeof(M_SPRITE_VERTEX));
|
||||
|
@ -394,20 +377,23 @@ bool Output_Sprites_Flush(void)
|
|||
M_MakeQuad(
|
||||
quad, sprite->sprite_idx,
|
||||
(XYZ_16) { sprite->pos.x, sprite->pos.y, sprite->pos.z });
|
||||
for (int32_t i = 0; i < M_QUAD_VERTICES; i++) {
|
||||
buffer->geom_vbo_data[buffer->vertex_count] = quad[m_QuadToFan[i]];
|
||||
for (int32_t i = 0; i < OUTPUT_QUAD_VERTICES; i++) {
|
||||
buffer->geom_vbo_data[buffer->vertex_count] =
|
||||
quad[OUTPUT_QUAD_TO_FAN(i)];
|
||||
buffer->shade_vbo_data[buffer->vertex_count] = sprite->shade;
|
||||
buffer->vertex_count++;
|
||||
}
|
||||
}
|
||||
M_BufferReallocGPU(buffer);
|
||||
|
||||
Output_SpriteProgram_UploadTint((RGB_F) { 1.0f, 1.0f, 1.0f });
|
||||
Output_Shader_UploadWibble(m_Shader, Output_GetWibbleOffset());
|
||||
Output_Shader_UploadTint(m_Shader, (RGB_F) { 1.0f, 1.0f, 1.0f });
|
||||
for (int32_t i = 0; i < m_Dynamic.source->count; i++) {
|
||||
const M_DYNAMIC_SPRITE *const sprite = Vector_Get(m_Dynamic.source, i);
|
||||
Output_SpriteProgram_UploadMatrix(&sprite->matrix);
|
||||
Output_Shader_UploadMatrix(m_Shader, &sprite->matrix);
|
||||
M_DrawBuffer(
|
||||
&m_Dynamic.sprite_buf, i * M_QUAD_VERTICES, M_QUAD_VERTICES);
|
||||
&m_Dynamic.sprite_buf, i * OUTPUT_QUAD_VERTICES,
|
||||
OUTPUT_QUAD_VERTICES);
|
||||
}
|
||||
|
||||
Vector_Clear(m_Dynamic.source);
|
||||
|
|
|
@ -42,6 +42,7 @@ static struct {
|
|||
|
||||
static struct {
|
||||
GLuint tex; // 3D texture to hold atlas pages
|
||||
M_TEXTURE_DATA objects;
|
||||
M_TEXTURE_DATA sprites;
|
||||
} m_LevelData = {};
|
||||
|
||||
|
@ -156,6 +157,18 @@ static void M_PrepareAnimationRanges(void)
|
|||
M_PrepareSpriteAnimationRanges();
|
||||
}
|
||||
|
||||
static void M_FreeTextureData(M_TEXTURE_DATA *const data)
|
||||
{
|
||||
if (data->tbo != 0) {
|
||||
glDeleteBuffers(1, &data->tbo);
|
||||
data->tbo = 0;
|
||||
}
|
||||
if (data->tex != 0) {
|
||||
glDeleteTextures(1, &data->tex);
|
||||
data->tex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Output_Textures_Init(void)
|
||||
{
|
||||
}
|
||||
|
@ -164,14 +177,8 @@ void Output_Textures_Shutdown(void)
|
|||
{
|
||||
glBindTexture(GL_TEXTURE_BUFFER, 0);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, 0);
|
||||
if (m_LevelData.sprites.tbo != 0) {
|
||||
glDeleteBuffers(1, &m_LevelData.sprites.tbo);
|
||||
m_LevelData.sprites.tbo = 0;
|
||||
}
|
||||
if (m_LevelData.sprites.tex != 0) {
|
||||
glDeleteTextures(1, &m_LevelData.sprites.tex);
|
||||
m_LevelData.sprites.tex = 0;
|
||||
}
|
||||
M_FreeTextureData(&m_LevelData.objects);
|
||||
M_FreeTextureData(&m_LevelData.sprites);
|
||||
if (m_LevelData.tex != 0) {
|
||||
glDeleteTextures(1, &m_LevelData.tex);
|
||||
m_LevelData.tex = 0;
|
||||
|
@ -181,6 +188,17 @@ void Output_Textures_Shutdown(void)
|
|||
Memory_FreePointer(&m_AnimationRanges.sprites.ranges);
|
||||
}
|
||||
|
||||
static void M_FillObjectUVW(const int32_t i)
|
||||
{
|
||||
const OBJECT_TEXTURE *const texture = Output_GetObjectTexture(i);
|
||||
M_UVW *const corners = m_LevelData.objects.uvw[i].corners;
|
||||
for (int32_t j = 0; j < 4; j++) {
|
||||
corners[j].u = Output_AdjustUV(texture->uv[j].u);
|
||||
corners[j].v = Output_AdjustUV(texture->uv[j].v);
|
||||
corners[j].w = texture->tex_page;
|
||||
}
|
||||
}
|
||||
|
||||
static void M_FillSpriteUVW(const int32_t i)
|
||||
{
|
||||
const SPRITE_TEXTURE *const sprite = Output_GetSpriteTexture(i);
|
||||
|
@ -189,7 +207,7 @@ static void M_FillSpriteUVW(const int32_t i)
|
|||
const float v0 = (sprite->offset >> 8) / 256.0f + adj;
|
||||
const float u1 = u0 + (sprite->width >> 8) / 256.0f - 2 * adj;
|
||||
const float v1 = v0 + (sprite->height >> 8) / 256.0f - 2 * adj;
|
||||
M_UVW *corners = m_LevelData.sprites.uvw[i].corners;
|
||||
M_UVW *const corners = m_LevelData.sprites.uvw[i].corners;
|
||||
// clang-format off
|
||||
corners[0].u = u0; corners[0].v = v0; corners[0].w = sprite->tex_page;
|
||||
corners[1].u = u1; corners[1].v = v0; corners[1].w = sprite->tex_page;
|
||||
|
@ -198,6 +216,13 @@ static void M_FillSpriteUVW(const int32_t i)
|
|||
// clang-format on
|
||||
}
|
||||
|
||||
static void M_FillObjectUVWs(void)
|
||||
{
|
||||
for (int32_t i = 0; i < Output_GetObjectTextureCount(); i++) {
|
||||
M_FillObjectUVW(i);
|
||||
}
|
||||
}
|
||||
|
||||
static void M_FillSpriteUVWs(void)
|
||||
{
|
||||
for (int32_t i = 0; i < Output_GetSpriteTextureCount(); i++) {
|
||||
|
@ -205,13 +230,39 @@ static void M_FillSpriteUVWs(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void M_UploadTextureData(const M_TEXTURE_DATA *const data)
|
||||
{
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, data->tbo);
|
||||
GFX_TRACK_DATA(
|
||||
glBufferData, GL_TEXTURE_BUFFER, data->count * sizeof(M_UVW_PACK),
|
||||
data->uvw, GL_DYNAMIC_DRAW);
|
||||
GFX_GL_CheckError();
|
||||
}
|
||||
|
||||
static void M_UploadObjectUVWs(void)
|
||||
{
|
||||
M_UploadTextureData(&m_LevelData.objects);
|
||||
}
|
||||
|
||||
static void M_UploadSpriteUVWs(void)
|
||||
{
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, m_LevelData.sprites.tbo);
|
||||
GFX_TRACK_DATA(
|
||||
glBufferData, GL_TEXTURE_BUFFER,
|
||||
m_LevelData.sprites.count * sizeof(M_UVW_PACK), m_LevelData.sprites.uvw,
|
||||
GL_DYNAMIC_DRAW);
|
||||
M_UploadTextureData(&m_LevelData.sprites);
|
||||
}
|
||||
|
||||
static void M_UploadObjectAnimatedUVWs(const M_ANIMATION_RANGES *const source)
|
||||
{
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, m_LevelData.objects.tbo);
|
||||
for (int32_t i = 0; i < source->range_count; i++) {
|
||||
const M_ANIMATION_RANGE *const range = &source->ranges[i];
|
||||
for (int32_t j = 0; j < range->count; j++) {
|
||||
M_FillObjectUVW(range->index + j);
|
||||
}
|
||||
GFX_TRACK_DATA(
|
||||
glBufferSubData, GL_TEXTURE_BUFFER,
|
||||
range->index * sizeof(M_UVW_PACK),
|
||||
range->count * sizeof(M_UVW_PACK),
|
||||
m_LevelData.objects.uvw + range->index);
|
||||
}
|
||||
}
|
||||
|
||||
static void M_UploadSpriteAnimatedUVWs(const M_ANIMATION_RANGES *const source)
|
||||
|
@ -230,23 +281,34 @@ static void M_UploadSpriteAnimatedUVWs(const M_ANIMATION_RANGES *const source)
|
|||
}
|
||||
}
|
||||
|
||||
static void M_PrepareSpriteUVWs(void)
|
||||
static void M_PrepareTextureData(M_TEXTURE_DATA *const data, const size_t count)
|
||||
{
|
||||
m_LevelData.sprites.count = Output_GetSpriteTextureCount();
|
||||
m_LevelData.sprites.uvw =
|
||||
Memory_Alloc(m_LevelData.sprites.count * sizeof(M_UVW_PACK));
|
||||
M_FillSpriteUVWs();
|
||||
data->count = count;
|
||||
data->uvw = Memory_Alloc(data->count * sizeof(M_UVW_PACK));
|
||||
|
||||
glGenBuffers(1, &m_LevelData.sprites.tbo);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, m_LevelData.sprites.tbo);
|
||||
glGenBuffers(1, &data->tbo);
|
||||
glBindBuffer(GL_TEXTURE_BUFFER, data->tbo);
|
||||
|
||||
GLint limit;
|
||||
glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &limit);
|
||||
ASSERT(m_LevelData.sprites.count * sizeof(M_UVW_PACK) <= (size_t)limit);
|
||||
ASSERT(data->count * sizeof(M_UVW_PACK) <= (size_t)limit);
|
||||
|
||||
glGenTextures(1, &m_LevelData.sprites.tex);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, m_LevelData.sprites.tex);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, m_LevelData.sprites.tbo);
|
||||
glGenTextures(1, &data->tex);
|
||||
glBindTexture(GL_TEXTURE_BUFFER, data->tex);
|
||||
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, data->tbo);
|
||||
GFX_GL_CheckError();
|
||||
}
|
||||
|
||||
static void M_PrepareObjectUVWs(void)
|
||||
{
|
||||
M_PrepareTextureData(&m_LevelData.objects, Output_GetObjectTextureCount());
|
||||
M_FillObjectUVWs();
|
||||
}
|
||||
|
||||
static void M_PrepareSpriteUVWs(void)
|
||||
{
|
||||
M_PrepareTextureData(&m_LevelData.sprites, Output_GetSpriteTextureCount());
|
||||
M_FillSpriteUVWs();
|
||||
}
|
||||
|
||||
static void M_UploadAtlas(void)
|
||||
|
@ -258,12 +320,14 @@ static void M_UploadAtlas(void)
|
|||
1, // number of mipmaps
|
||||
GL_RGBA8, TEXTURE_PAGE_WIDTH, TEXTURE_PAGE_HEIGHT,
|
||||
Output_GetTexturePageCount());
|
||||
GFX_GL_CheckError();
|
||||
|
||||
// TODO: handle bilinear toggle
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
GFX_GL_CheckError();
|
||||
|
||||
for (int32_t i = 0; i < Output_GetTexturePageCount(); i++) {
|
||||
const RGBA_8888 *const input_ptr = Output_GetTexturePage32(i);
|
||||
|
@ -278,23 +342,33 @@ static void M_UploadAtlas(void)
|
|||
1, // depth
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, input_ptr);
|
||||
}
|
||||
GFX_GL_CheckError();
|
||||
}
|
||||
|
||||
void Output_Textures_ObserveLevelLoad(void)
|
||||
{
|
||||
Output_Textures_Shutdown();
|
||||
M_PrepareAnimationRanges();
|
||||
M_PrepareObjectUVWs();
|
||||
M_PrepareSpriteUVWs();
|
||||
M_UploadObjectUVWs();
|
||||
M_UploadSpriteUVWs();
|
||||
M_UploadAtlas();
|
||||
}
|
||||
|
||||
void Output_Textures_Update(void)
|
||||
{
|
||||
if (m_LevelData.sprites.tex == 0) {
|
||||
return;
|
||||
if (m_LevelData.sprites.tex != 0) {
|
||||
M_UploadSpriteAnimatedUVWs(&m_AnimationRanges.sprites);
|
||||
}
|
||||
M_UploadSpriteAnimatedUVWs(&m_AnimationRanges.sprites);
|
||||
if (m_LevelData.objects.tex != 0) {
|
||||
M_UploadObjectAnimatedUVWs(&m_AnimationRanges.objects);
|
||||
}
|
||||
}
|
||||
|
||||
GLuint Output_Textures_GetObjectUVWsTexture(void)
|
||||
{
|
||||
return m_LevelData.objects.tex;
|
||||
}
|
||||
|
||||
GLuint Output_Textures_GetSpriteUVWsTexture(void)
|
||||
|
@ -306,3 +380,12 @@ GLuint Output_Textures_GetAtlasTexture(void)
|
|||
{
|
||||
return m_LevelData.tex;
|
||||
}
|
||||
|
||||
void Output_Textures_ApplyRenderSettings(void)
|
||||
{
|
||||
// re-adjust UVs when the bilinear filter is toggled.
|
||||
if (m_LevelData.objects.tex != 0) {
|
||||
M_FillObjectUVWs();
|
||||
M_UploadObjectUVWs();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,7 @@ void Output_Textures_Init(void);
|
|||
void Output_Textures_Shutdown(void);
|
||||
void Output_Textures_ObserveLevelLoad(void);
|
||||
void Output_Textures_Update(void);
|
||||
void Output_Textures_ApplyRenderSettings(void);
|
||||
GLuint Output_Textures_GetObjectUVWsTexture(void);
|
||||
GLuint Output_Textures_GetSpriteUVWsTexture(void);
|
||||
GLuint Output_Textures_GetAtlasTexture(void);
|
||||
|
|
5
src/tr1/game/output/utils.h
Normal file
5
src/tr1/game/output/utils.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#define OUTPUT_QUAD_VERTICES 6
|
||||
#define OUTPUT_TRI_VERTICES 3
|
||||
|
||||
#define OUTPUT_QUAD_TO_FAN(i) ((int32_t[]) { 0, 2, 1, 0, 3, 2 }[i])
|
||||
#define OUTPUT_TRI_TO_FAN(i) ((int32_t[]) { 0, 2, 1 }[i])
|
|
@ -281,7 +281,14 @@ void Room_DrawSingleRoom(int16_t room_num)
|
|||
g_PhdBottom = room->bound_bottom;
|
||||
|
||||
Output_LightRoom(room);
|
||||
Output_EnableScissor(
|
||||
room->bound_left, room->bound_bottom,
|
||||
room->bound_right - room->bound_left,
|
||||
room->bound_bottom - room->bound_top);
|
||||
Output_RememberState();
|
||||
Output_DrawRoomMesh(room);
|
||||
Output_RestoreState();
|
||||
Output_DisableScissor();
|
||||
|
||||
int16_t item_num = room->item_num;
|
||||
while (item_num != NO_ITEM) {
|
||||
|
|
|
@ -244,8 +244,10 @@ sources = [
|
|||
'game/option/option_passport.c',
|
||||
'game/option/option_sound.c',
|
||||
'game/output.c',
|
||||
'game/output/meshes.c',
|
||||
'game/output/rooms.c',
|
||||
'game/output/shader.c',
|
||||
'game/output/sprites.c',
|
||||
'game/output/sprite_program.c',
|
||||
'game/output/textures.c',
|
||||
'game/overlay.c',
|
||||
'game/requester.c',
|
||||
|
|
|
@ -1192,3 +1192,8 @@ void S_Output_2ToneColourTextBox(
|
|||
S_Output_DisableTextureMode();
|
||||
M_DrawTriangleStrip(vertices, 18);
|
||||
}
|
||||
|
||||
float Output_AdjustUV(const uint16_t uv)
|
||||
{
|
||||
return M_GetUV(uv);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue