Skip to content

Commit

Permalink
0.3a-19612e1
Browse files Browse the repository at this point in the history
  • Loading branch information
DirtBagXon committed Jun 13, 2024
1 parent 3f7ab6f commit 36805cc
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 115 deletions.
2 changes: 2 additions & 0 deletions Docs/FORKINFO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Compiled versions will follow the official repo commit SHORT SHA tag.
Additional arguments:
=====================

-game=<name> Specific game to start in multi-romset

-sinden=<n> Sinden border configuration for gun games:
0=none [Default], 1=standard, 2=wide

Expand Down
1 change: 1 addition & 0 deletions Makefiles/Rules.inc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ SRC_FILES = \
Src/Graphics/New3D/R3DShader.cpp \
Src/Graphics/New3D/R3DFloat.cpp \
Src/Graphics/New3D/R3DScrollFog.cpp \
Src/Graphics/New3D/TextureBank.cpp \
Src/Graphics/FBO.cpp \
Src/Graphics/Render2D.cpp \
Src/Graphics/SuperAA.cpp \
Expand Down
10 changes: 8 additions & 2 deletions Src/Graphics/New3D/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ struct Mesh
enum TexWrapMode : int { repeat = 0, repeatClamp, mirror, mirrorClamp };

// texture
int format, x, y, width, height = 0;
int format = 0;
int x = 0;
int y = 0;
int width = 0;
int height = 0;
int page = 0;
bool inverted = false;

TexWrapMode wrapModeU;
TexWrapMode wrapModeV;
bool inverted = false;

// microtexture
bool microTexture = false;
Expand Down
57 changes: 36 additions & 21 deletions Src/Graphics/New3D/New3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ CNew3D::CNew3D(const Util::Config::Node &config, const std::string& gameName) :
m_r3dShader(config),
m_r3dScrollFog(config),
m_gameName(gameName),
m_textureBuffer(0),
m_vao(0),
m_aaTarget(0)
{
Expand All @@ -43,16 +42,6 @@ CNew3D::CNew3D(const Util::Config::Node &config, const std::string& gameName) :
m_r3dShader.LoadShader();
glUseProgram(0);

// setup our texture memory

glGenTextures(1, &m_textureBuffer);
glBindTexture(GL_TEXTURE_2D, m_textureBuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, 2048, 2048, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, nullptr); // allocate storage

// setup up our vertex buffer memory

glGenVertexArrays(1, &m_vao);
Expand Down Expand Up @@ -87,11 +76,6 @@ CNew3D::~CNew3D()
m_vao = 0;
}

if (m_textureBuffer) {
glDeleteTextures(1, &m_textureBuffer);
m_textureBuffer = 0;
}

m_r3dShader.UnloadShader();
}

Expand All @@ -102,6 +86,9 @@ void CNew3D::AttachMemory(const UINT32 *cullingRAMLoPtr, const UINT32 *cullingRA
m_polyRAM = polyRAMPtr;
m_vrom = vromPtr;
m_textureRAM = textureRAMPtr;

m_textureBank[0].AttachMemory(textureRAMPtr);
m_textureBank[1].AttachMemory(textureRAMPtr + (2048*1024));
}

void CNew3D::SetStepping(int stepping)
Expand Down Expand Up @@ -143,12 +130,28 @@ bool CNew3D::Init(unsigned xOffset, unsigned yOffset, unsigned xRes, unsigned yR

void CNew3D::UploadTextures(unsigned level, unsigned x, unsigned y, unsigned width, unsigned height)
{
glBindTexture(GL_TEXTURE_2D, m_textureBuffer);
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
// handle case of entire sheet invalidation
if (width == 2048 && height == 2048) {

height = 1024;

const int mipXBase[] = { 0, 1024, 1536, 1792, 1920, 1984, 2016, 2032, 2040, 2044, 2046, 2047 };
const int mipYBase[] = { 0, 512, 768, 896, 960, 992, 1008, 1016, 1020, 1022, 1023 };

for (int i = 0; i < m_textureBank[0].GetNumberOfLevels(); i++) {
m_textureBank[0].UploadTextures(i, mipXBase[i], mipYBase[i], width, height);
m_textureBank[1].UploadTextures(i, mipXBase[i], mipYBase[i], width, height);
width = (width > 1) ? width / 2 : 1;
height = (height > 1) ? height / 2 : 1;
}

for (unsigned i = 0; i < height; i++) {
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y + i, width, 1, GL_RED_INTEGER, GL_UNSIGNED_SHORT, m_textureRAM + ((y + i) * 2048) + x);
return;
}

int page;
TranslateTexture(x, y, width, height, page);

m_textureBank[page].UploadTextures(level, x, y, width, height);
}

void CNew3D::DrawScrollFog()
Expand Down Expand Up @@ -280,7 +283,10 @@ void CNew3D::DrawAmbientFog()
bool CNew3D::RenderScene(int priority, bool renderOverlay, Layer layer)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_textureBuffer);
m_textureBank[0].Bind();
glActiveTexture(GL_TEXTURE1);
m_textureBank[1].Bind();
glActiveTexture(GL_TEXTURE0);

bool hasOverlay = false; // (high priority polys)

Expand Down Expand Up @@ -1249,6 +1255,7 @@ void CNew3D::SetMeshValues(SortingMesh *currentMesh, PolyHeader &ph)
currentMesh->height = ph.TexHeight();
currentMesh->microTexture = ph.MicroTexture();
currentMesh->inverted = ph.TranslatorMapOffset() == 2;
currentMesh->page = ph.Page();

{
bool smoothU = ph.TexSmoothU();
Expand Down Expand Up @@ -1592,6 +1599,14 @@ void CNew3D::CalcViewport(Viewport* vp)
}
}

void CNew3D::TranslateTexture(unsigned& x, unsigned& y, int width, int height, int& page)
{
page = y / 1024;

// remove page from y coordinate
y -= (page * 1024);
}

void CNew3D::SetSunClamp(bool enable)
{
m_sunClamp = enable;
Expand Down
4 changes: 3 additions & 1 deletion Src/Graphics/New3D/New3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "PolyHeader.h"
#include "R3DFrameBuffers.h"
#include <mutex>
#include "TextureBank.h"

namespace New3D {

Expand Down Expand Up @@ -224,6 +225,7 @@ class CNew3D : public IRender3D
void TranslateLosPosition(int inX, int inY, int& outX, int& outY);
bool ProcessLos(int priority);
void CalcViewport(Viewport* vp);
void TranslateTexture(unsigned& x, unsigned& y, int width, int height, int& page);

/*
* Data
Expand Down Expand Up @@ -261,7 +263,6 @@ class CNew3D : public IRender3D
UINT32 m_colorTableAddr = 0x400; // address of color table in polygon RAM
LODBlendTable* m_LODBlendTable;

GLuint m_textureBuffer;
NodeAttributes m_nodeAttribs;
Mat4 m_modelMat; // current modelview matrix

Expand All @@ -281,6 +282,7 @@ class CNew3D : public IRender3D
std::vector<FVertex> m_polyBufferRam; // dynamic polys
std::vector<FVertex> m_polyBufferRom; // rom polys
std::unordered_map<UINT32, std::shared_ptr<std::vector<Mesh>>> m_romMap; // a hash table for all the ROM models. The meshes don't have model matrices or tex offsets yet
TextureBank m_textureBank[2];

GLuint m_vao;
VBO m_vbo; // large VBO to hold our poly data, start of VBO is ROM data, ram polys follow
Expand Down
14 changes: 3 additions & 11 deletions Src/Graphics/New3D/PolyHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,11 @@ int PolyHeader::X()

int PolyHeader::Y()
{
//=======
//====
int y;
int page;
//=======

if (Page()) {
page = 1024;
}
else {
page = 0;
}
//====

y = (32 * (header[5] & 0x1F) + page); // if we hit 2nd page add 1024 to y coordinate
y = 32 * (header[5] & 0x1F); // if we hit 2nd page add 1024 to y coordinate
y &= 2047;

return y;
Expand Down
35 changes: 12 additions & 23 deletions Src/Graphics/New3D/R3DShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void R3DShader::Start()
m_specularValue = 0;
m_microTexScale = 0;
m_microTexID = -1;
m_texturePage = -1;

m_baseTexInfo[0] = -1;
m_baseTexInfo[1] = -1;
Expand Down Expand Up @@ -100,7 +101,9 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader)

PrintProgramResult(m_shaderProgram);

m_locTexture1 = glGetUniformLocation(m_shaderProgram, "tex1");
m_locTextureBank[0] = glGetUniformLocation(m_shaderProgram, "textureBank[0]");
m_locTextureBank[1] = glGetUniformLocation(m_shaderProgram, "textureBank[1]");
m_locTexturePage = glGetUniformLocation(m_shaderProgram, "texturePage");
m_locTexture1Enabled = glGetUniformLocation(m_shaderProgram, "textureEnabled");
m_locTexture2Enabled = glGetUniformLocation(m_shaderProgram, "microTexture");
m_locTextureAlpha = glGetUniformLocation(m_shaderProgram, "textureAlpha");
Expand Down Expand Up @@ -202,7 +205,8 @@ void R3DShader::SetMeshUniforms(const Mesh* m)
}

if (m_dirtyMesh) {
glUniform1i(m_locTexture1, 0);
glUniform1i(m_locTextureBank[0], 0);
glUniform1i(m_locTextureBank[1], 1);
}

if (m_dirtyMesh || m->textured != m_textured1) {
Expand All @@ -215,6 +219,11 @@ void R3DShader::SetMeshUniforms(const Mesh* m)
m_textured2 = m->microTexture;
}

if (m_dirtyMesh || (m->page ^ m_transPage) != m_texturePage) {
glUniform1i(m_locTexturePage, m->page ^ m_transPage);
m_texturePage = (m->page ^ m_transPage);
}

if (m_dirtyMesh || m->microTextureScale != m_microTexScale) {
glUniform1f(m_locMicroTexScale, m->microTextureScale);
m_microTexScale = m->microTextureScale;
Expand All @@ -232,10 +241,7 @@ void R3DShader::SetMeshUniforms(const Mesh* m)
m_baseTexInfo[2] = m->width;
m_baseTexInfo[3] = m->height;

int translatedX, translatedY;
CalcTexOffset(m_transX, m_transY, m_transPage, m->x, m->y, translatedX, translatedY); // need to apply model translation

glUniform4i(m_locBaseTexInfo, translatedX, translatedY, m->width, m->height);
glUniform4i(m_locBaseTexInfo, (m->x + m_transX), (m->y + m_transY), m->width, m->height);
}

if (m_dirtyMesh || m_baseTexType != m->format) {
Expand Down Expand Up @@ -426,21 +432,4 @@ void R3DShader::PrintProgramResult(GLuint program)
}
}

void R3DShader::CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY)
{
newX = (x + offX) & 2047; // wrap around 2048, shouldn't be required

int oldPage = y / 1024;

y -= (oldPage * 1024); // remove page from tex y

// calc newY with wrap around, wraps around in the same sheet, not into another memory sheet

newY = (y + offY) & 1023;

// add page to Y

newY += ((oldPage + page) & 1) * 1024; // max page 0-1
}

} // New3D
10 changes: 5 additions & 5 deletions Src/Graphics/New3D/R3DShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class R3DShader
void PrintShaderResult(GLuint shader);
void PrintProgramResult(GLuint program);

void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);

// run-time config
const Util::Config::Node &m_config;

Expand All @@ -42,9 +40,10 @@ class R3DShader
GLuint m_fragmentShader;

// mesh uniform locations
GLint m_locTexture1;
GLint m_locTexture1Enabled;
GLint m_locTexture2Enabled;
GLint m_locTextureBank[2]; // 2 banks
GLint m_locTexture1Enabled; // base texture
GLint m_locTexture2Enabled; // micro texture
GLint m_locTexturePage;
GLint m_locTextureAlpha;
GLint m_locAlphaTest;
GLint m_locMicroTexScale;
Expand All @@ -70,6 +69,7 @@ class R3DShader
bool m_fixedShading;
bool m_translatorMap;
bool m_polyAlpha;
int m_texturePage;

bool m_layered;
bool m_noLosReturn;
Expand Down
Loading

0 comments on commit 36805cc

Please sign in to comment.