Skip to content

Commit

Permalink
Merge pull request #387 from avaraline/render-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rherriman authored Jan 27, 2024
2 parents eca42d5 + ffa14f9 commit 505d0db
Show file tree
Hide file tree
Showing 101 changed files with 1,804 additions and 1,500 deletions.
54 changes: 46 additions & 8 deletions Avara.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rsrc/shaders/avara_frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ uniform vec3 light3 = vec3(0, 0, 0);
uniform vec3 light3Color = vec3(1, 1, 1);
uniform float ambient = 0.0;
uniform vec3 ambientColor = vec3(1, 1, 1);
uniform float lights_active = 1.0;
uniform float lightsActive = 1.0;

out vec4 color;

Expand All @@ -33,7 +33,7 @@ vec4 light_color() {
return mix(
ambient * vec4(ambientColor, 1.0) * fragmentColor,
vec4((ambient * ambientColor) + diffuse(), 1.0) * fragmentColor,
lights_active
lightsActive
);
}

Expand Down
4 changes: 2 additions & 2 deletions rsrc/shaders/avara_vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ layout(location = 2) in vec3 vertexNormal;
uniform mat4 view;
uniform mat4 proj;
uniform mat4 modelview;
uniform mat3 normal_transform;
uniform mat3 normalTransform;

out vec4 fragmentColor;
out vec3 fragmentNormal;
Expand All @@ -16,5 +16,5 @@ void main() {
vec4 pos = vec4(vertexPosition_modelspace, 1.0);
gl_Position = proj * (modelview * pos);
fragmentColor = vertexColor;
fragmentNormal = vertexNormal * normal_transform;
fragmentNormal = vertexNormal * normalTransform;
}
7 changes: 5 additions & 2 deletions rsrc/shaders/hud_frag.glsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#version 330 core

// in vec4 gl_FragCoord;
in vec4 fragmentColor;
in vec3 fragmentNormal;

uniform float ambient = 0.0;
uniform float lights_active = 1.0;
uniform float hudAlpha = 1.0;
uniform float lightsActive = 1.0;

out vec4 color;

Expand All @@ -26,11 +28,12 @@ vec4 light_color() {
return mix(
ambient * vec4(lightColor, 1.0) * fragmentColor,
vec4((ambient * lightColor) + diffuse(), 1.0) * fragmentColor,
lights_active
lightsActive
);
}

void main() {
color = light_color();
color[3] *= hudAlpha;
}

1 change: 0 additions & 1 deletion src/Avara.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Modified: Monday, September 2, 1996, 17:39
*/

#include "AvaraGL.h"
#include "AvaraTCP.h"
#include "CAvaraApp.h"
#include "CAvaraGame.h"
Expand Down
7 changes: 2 additions & 5 deletions src/BSPViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ class BSPViewer : public CApplication {
AvaraGLSetFOV(50);

current_id = id;
itsWorld = new CBSPWorldImpl;
itsWorld->IBSPWorld(1);
itsWorld = new CBSPWorldImpl(1);
newPart(current_id);

itsView = new CViewParameters;
itsView->IViewParameters();

itsView->yonBound = FIX(100);
itsView->dirtyLook = true;
Expand Down Expand Up @@ -124,8 +122,7 @@ class BSPViewer : public CApplication {
if (itsWorld->GetPartCount() > 0) {
itsWorld->RemovePart(itsPart);
}
itsPart = new CBSPPart;
itsPart->IBSPPart(id);
itsPart = CBSPPart::Create(id);
if (itsPart->polyCount > 0) {
itsPart->ReplaceColor(
*ColorManager::getMarkerColor(0),
Expand Down
9 changes: 8 additions & 1 deletion src/assets/BaseAssetStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <SDL2/SDL.h>
#include <sstream>

BaseAssetStorage::BaseAssetStorage()
{
char *sdlPathTmp = SDL_GetBasePath();
basePath = std::string(sdlPathTmp);
SDL_free(sdlPathTmp);
}

std::shared_ptr<BaseAssetStorage> BaseAssetStorage::GetInstance() {
static auto instance = std::make_shared<BaseAssetStorage>(BaseAssetStorage());
return instance;
Expand All @@ -12,6 +19,6 @@ std::shared_ptr<BaseAssetStorage> BaseAssetStorage::GetInstance() {
std::string BaseAssetStorage::GetRootPath()
{
std::stringstream path;
path << SDL_GetBasePath() << "rsrc";
path << basePath << "rsrc";
return path.str();
}
4 changes: 3 additions & 1 deletion src/assets/BaseAssetStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ class BaseAssetStorage final: public AssetStorage {
*/
std::string GetRootPath();
private:
BaseAssetStorage() {};
std::string basePath;

BaseAssetStorage();
};
12 changes: 10 additions & 2 deletions src/assets/LocalAssetRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
#include <fstream>
#include <sstream>

std::shared_ptr<LocalAssetRepository> LocalAssetRepository::GetInstance() {
LocalAssetRepository::LocalAssetRepository()
{
char *sdlPathTmp = SDL_GetBasePath();
basePath = std::string(sdlPathTmp);
SDL_free(sdlPathTmp);
}

std::shared_ptr<LocalAssetRepository> LocalAssetRepository::GetInstance()
{
static auto instance = std::make_shared<LocalAssetRepository>(LocalAssetRepository());
return instance;
};
Expand All @@ -25,7 +33,7 @@ std::shared_ptr<std::vector<std::string>> LocalAssetRepository::GetPackageList()
std::string LocalAssetRepository::GetRootPath()
{
std::stringstream path;
path << SDL_GetBasePath() << "levels";
path << basePath << "levels";
return path.str();
}

Expand Down
5 changes: 4 additions & 1 deletion src/assets/LocalAssetRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "AssetRepository.h"
#include "AssetStorage.h"

#include <string>

class LocalAssetRepository final: public AssetRepository, public AssetStorage {
public:
static std::shared_ptr<LocalAssetRepository> GetInstance();
Expand All @@ -27,8 +29,9 @@ class LocalAssetRepository final: public AssetRepository, public AssetStorage {
void Refresh();
private:
bool populatedList = false;
std::string basePath;
std::shared_ptr<std::vector<std::string>> packageList = std::make_shared<std::vector<std::string>>();

LocalAssetRepository() {};
LocalAssetRepository();
void BuildPackageList();
};
78 changes: 27 additions & 51 deletions src/bsp/CBSPPart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
Modified: Monday, September 9, 1996, 00:15
*/

#include "AssetManager.h"
#include "CBSPPart.h"

#include "AssetManager.h"
#include "AvaraDefines.h"
#include "CViewParameters.h"
#include "Memory.h"
#include "AvaraDefines.h"
#include "RenderManager.h"

#include <fstream>
#include <iostream>
Expand All @@ -29,6 +30,13 @@ Vector **bspPointTemp = 0;

ARGBColor ***bspColorLookupTable = 0;

CBSPPart *CBSPPart::Create(short resId) {
CBSPPart *part = new CBSPPart;
part->IBSPPart(resId);
return part;
}


void CBSPPart::IBSPPart(short resId) {
//SDL_Log("Loading BSP: %s\n", bspName);
lightSeed = 0;
Expand Down Expand Up @@ -161,16 +169,15 @@ void CBSPPart::IBSPPart(short resId) {

BuildBoundingVolumes();
Reset();
AvaraGLUpdateData(this);

vData = gRenderer->NewVertexDataInstance();
if (vData) vData->Replace(*this);
}

void CBSPPart::PostRender() {}

void CBSPPart::TransformLights() {
CViewParameters *vp;
//Matrix *invFull;

vp = currentView;
auto vp = gRenderer->viewParams;
if (!ignoreDirectionalLights) {
if (lightSeed != vp->lightSeed) {
lightSeed = vp->lightSeed;
Expand All @@ -184,22 +191,13 @@ void CBSPPart::TransformLights() {
localViewOrigin[2] = invFullTransform[3][2];
}

void CBSPPart::DrawPolygons(Shader shader) {
AvaraGLDrawPolygons(this, shader);
}

Boolean CBSPPart::InViewPyramid() {
CViewParameters *vp;
//short i;
//Vector *norms;
Fixed radius;
Fixed distance;
Fixed x, y;
Fixed z;

//return true;

vp = currentView;
auto vp = gRenderer->viewParams;

if (hither >= yon)
return false;
Expand Down Expand Up @@ -263,11 +261,11 @@ void CBSPPart::PrintMatrix(Matrix *m) {
** See if the part is in the viewing pyramid and do calculations
** in preparation to shading.
*/
Boolean CBSPPart::PrepareForRender(CViewParameters *vp) {
Boolean CBSPPart::PrepareForRender() {
auto vp = gRenderer->viewParams;
Boolean inPyramid = vp->showTransparent || !isTransparent;

if (inPyramid) {
currentView = vp;

if (!usesPrivateHither)
hither = vp->hitherBound;
Expand Down Expand Up @@ -303,23 +301,6 @@ Boolean CBSPPart::PrepareForRender(CViewParameters *vp) {
return inPyramid;
}

/*
** Normally you would create a CBSPWorld and attach the
** part to that world. However, if you only have a single
** CBSPPart, you can call Render and you don't need a
** CBSPWorld. Even then it is recommended that you use a
** CBSPWorld, since it really doesn't add any significant
** overhead.
*/
void CBSPPart::Render(CViewParameters *vp, Shader shader) {
vp->DoLighting();

if (PrepareForRender(vp)) {
DrawPolygons(shader);
PostRender();
}
}

/*
** Reset the part to the origin and to its natural
** orientation.
Expand Down Expand Up @@ -418,21 +399,27 @@ Matrix *CBSPPart::GetInverseTransform() {
}

void CBSPPart::ReplaceColor(ARGBColor origColor, ARGBColor newColor) {
bool colorReplaced = false;
for (int i = 0; i < colorCount; i++) {
if (origColorTable[i] == origColor) {
currColorTable[i] = newColor;
colorReplaced = true;
}
}
CheckForAlpha();
AvaraGLUpdateData(this);
if (colorReplaced && vData) vData->Replace(*this);
}

void CBSPPart::ReplaceAllColors(ARGBColor newColor) {
bool colorReplaced = false;
for (int i = 0; i < colorCount; i++) {
if (currColorTable[i] != newColor) {
colorReplaced = true;
}
currColorTable[i] = newColor;
}
hasAlpha = (newColor.GetA() != 0xff);
AvaraGLUpdateData(this);
if (colorReplaced && vData) vData->Replace(*this);
}

void CBSPPart::BuildBoundingVolumes() {
Expand All @@ -453,18 +440,7 @@ void CBSPPart::BuildBoundingVolumes() {
tolerance = MINIMUM_TOLERANCE;
}

void CBSPPart::Dispose() {
if(polyCount < 1) {
CDirectObject::Dispose();
return;
}
if (AvaraGLIsRendering()) {
glDataSize = 0;
glDeleteVertexArrays(1, &vertexArray);
glDeleteBuffers(1, &vertexBuffer);
}
CDirectObject::Dispose();
}
CBSPPart::~CBSPPart() {}

void CBSPPart::CheckForAlpha() {
hasAlpha = false;
Expand All @@ -476,7 +452,7 @@ void CBSPPart::CheckForAlpha() {
}
}

bool CBSPPart::HasAlpha() {
bool CBSPPart::HasAlpha() const {
return hasAlpha;
}

Expand Down
Loading

0 comments on commit 505d0db

Please sign in to comment.