Skip to content

Commit

Permalink
Moved out some renderer types.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Nov 16, 2024
1 parent 283e7ad commit 5024e2f
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 98 deletions.
4 changes: 2 additions & 2 deletions OpenTESArena/src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ bool Game::init()
constexpr RendererSystemType3D rendererSystemType3D = RendererSystemType3D::SoftwareClassic;
const DitheringMode ditheringMode = static_cast<DitheringMode>(this->options.getGraphics_DitheringMode());
if (!this->renderer.init(this->options.getGraphics_ScreenWidth(), this->options.getGraphics_ScreenHeight(),
static_cast<Renderer::WindowMode>(this->options.getGraphics_WindowMode()), this->options.getGraphics_LetterboxMode(),
static_cast<RenderWindowMode>(this->options.getGraphics_WindowMode()), this->options.getGraphics_LetterboxMode(),
this->options.getGraphics_ModernInterface(), resolutionScaleFunc, rendererSystemType2D, rendererSystemType3D,
this->options.getGraphics_RenderThreadsMode(), ditheringMode))
{
Expand Down Expand Up @@ -671,7 +671,7 @@ void Game::renderDebugInfo()
const std::string windowHeight = std::to_string(windowDims.y);
debugText.append("\nScreen: " + windowWidth + "x" + windowHeight);

const Renderer::ProfilerData &profilerData = this->renderer.getProfilerData();
const RendererProfilerData &profilerData = this->renderer.getProfilerData();
const Int2 renderDims(profilerData.width, profilerData.height);
const bool profilerDataIsValid = (renderDims.x > 0) && (renderDims.y > 0);
if (profilerDataIsValid)
Expand Down
10 changes: 5 additions & 5 deletions OpenTESArena/src/Interface/OptionsUiModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ std::unique_ptr<OptionsUiModel::IntOption> OptionsUiModel::makeWindowModeOption(
auto &renderer = game.renderer;
options.setGraphics_WindowMode(value);

const Renderer::WindowMode mode = [value]()
const RenderWindowMode mode = [value]()
{
switch (value)
{
case 0:
return Renderer::WindowMode::Window;
return RenderWindowMode::Window;
case 1:
return Renderer::WindowMode::BorderlessFullscreen;
return RenderWindowMode::BorderlessFullscreen;
case 2:
return Renderer::WindowMode::ExclusiveFullscreen;
return RenderWindowMode::ExclusiveFullscreen;
default:
DebugUnhandledReturnMsg(Renderer::WindowMode, std::to_string(value));
DebugUnhandledReturnMsg(RenderWindowMode, std::to_string(value));
}
}();

Expand Down
42 changes: 21 additions & 21 deletions OpenTESArena/src/Rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ namespace
constexpr double PHYSICS_DEBUG_MAX_DISTANCE = 3.0;
constexpr double PHYSICS_DEBUG_MAX_DISTANCE_SQR = PHYSICS_DEBUG_MAX_DISTANCE * PHYSICS_DEBUG_MAX_DISTANCE;

int GetSdlWindowPosition(Renderer::WindowMode windowMode)
int GetSdlWindowPosition(RenderWindowMode windowMode)
{
switch (windowMode)
{
case Renderer::WindowMode::Window:
case RenderWindowMode::Window:
return SDL_WINDOWPOS_CENTERED;
case Renderer::WindowMode::BorderlessFullscreen:
case Renderer::WindowMode::ExclusiveFullscreen:
case RenderWindowMode::BorderlessFullscreen:
case RenderWindowMode::ExclusiveFullscreen:
return SDL_WINDOWPOS_UNDEFINED;
default:
DebugUnhandledReturnMsg(int, std::to_string(static_cast<int>(windowMode)));
}
}

uint32_t GetSdlWindowFlags(Renderer::WindowMode windowMode)
uint32_t GetSdlWindowFlags(RenderWindowMode windowMode)
{
uint32_t flags = SDL_WINDOW_ALLOW_HIGHDPI;
if (windowMode == Renderer::WindowMode::Window)
if (windowMode == RenderWindowMode::Window)
{
flags |= SDL_WINDOW_RESIZABLE;
}
else if (windowMode == Renderer::WindowMode::BorderlessFullscreen)
else if (windowMode == RenderWindowMode::BorderlessFullscreen)
{
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if (windowMode == Renderer::WindowMode::ExclusiveFullscreen)
else if (windowMode == RenderWindowMode::ExclusiveFullscreen)
{
flags |= SDL_WINDOW_FULLSCREEN;
}
Expand All @@ -73,9 +73,9 @@ namespace
return "nearest";
}

Int2 GetWindowDimsForMode(Renderer::WindowMode windowMode, int fallbackWidth, int fallbackHeight)
Int2 GetWindowDimsForMode(RenderWindowMode windowMode, int fallbackWidth, int fallbackHeight)
{
if (windowMode == Renderer::WindowMode::ExclusiveFullscreen)
if (windowMode == RenderWindowMode::ExclusiveFullscreen)
{
// Use desktop resolution of the primary display device. In the future, the display index could be
// an option in the options menu.
Expand Down Expand Up @@ -172,14 +172,14 @@ namespace
}
}

Renderer::DisplayMode::DisplayMode(int width, int height, int refreshRate)
RenderDisplayMode::RenderDisplayMode(int width, int height, int refreshRate)
{
this->width = width;
this->height = height;
this->refreshRate = refreshRate;
}

Renderer::ProfilerData::ProfilerData()
RendererProfilerData::RendererProfilerData()
{
this->width = -1;
this->height = -1;
Expand All @@ -196,7 +196,7 @@ Renderer::ProfilerData::ProfilerData()
this->presentTime = 0.0;
}

void Renderer::ProfilerData::init(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
void RendererProfilerData::init(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
int objectTextureCount, int64_t objectTextureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites,
double renderTime, double presentTime)
{
Expand Down Expand Up @@ -284,7 +284,7 @@ double Renderer::getWindowAspect() const
return static_cast<double>(dims.x) / static_cast<double>(dims.y);
}

BufferView<const Renderer::DisplayMode> Renderer::getDisplayModes() const
BufferView<const RenderDisplayMode> Renderer::getDisplayModes() const
{
return this->displayModes;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ Surface Renderer::getScreenshot() const
return screenshot;
}

const Renderer::ProfilerData &Renderer::getProfilerData() const
const RendererProfilerData &Renderer::getProfilerData() const
{
return this->profilerData;
}
Expand Down Expand Up @@ -489,8 +489,8 @@ Texture Renderer::createTexture(uint32_t format, int access, int w, int h)
return texture;
}

bool Renderer::init(int width, int height, WindowMode windowMode, int letterboxMode, bool fullGameWindow,
const ResolutionScaleFunc &resolutionScaleFunc, RendererSystemType2D systemType2D, RendererSystemType3D systemType3D,
bool Renderer::init(int width, int height, RenderWindowMode windowMode, int letterboxMode, bool fullGameWindow,
const RenderResolutionScaleFunc &resolutionScaleFunc, RendererSystemType2D systemType2D, RendererSystemType3D systemType3D,
int renderThreadsMode, DitheringMode ditheringMode)
{
DebugLog("Initializing.");
Expand Down Expand Up @@ -546,7 +546,7 @@ bool Renderer::init(int width, int height, WindowMode windowMode, int letterboxM
// know how to do that for all possible displays out there.
if (mode.format == SDL_PIXELFORMAT_RGB888)
{
this->displayModes.emplace_back(DisplayMode(mode.w, mode.h, mode.refresh_rate));
this->displayModes.emplace_back(RenderDisplayMode(mode.w, mode.h, mode.refresh_rate));
}
}
}
Expand Down Expand Up @@ -697,10 +697,10 @@ void Renderer::setLetterboxMode(int letterboxMode)
this->letterboxMode = letterboxMode;
}

void Renderer::setWindowMode(WindowMode mode)
void Renderer::setWindowMode(RenderWindowMode mode)
{
int result = 0;
if (mode == WindowMode::ExclusiveFullscreen)
if (mode == RenderWindowMode::ExclusiveFullscreen)
{
SDL_DisplayMode displayMode; // @todo: may consider changing this to some GetDisplayModeForWindowMode()
result = SDL_GetDesktopDisplayMode(0, &displayMode);
Expand Down Expand Up @@ -1151,7 +1151,7 @@ void Renderer::submitFrame(const RenderCamera &camera, const RenderCommandBuffer
const double presentTotalTime = static_cast<double>((presentEndTime - presentStartTime).count()) / static_cast<double>(std::nano::den);

// Update profiler stats.
const RendererSystem3D::ProfilerData swProfilerData = this->renderer3D->getProfilerData();
const Renderer3DProfilerData swProfilerData = this->renderer3D->getProfilerData();
this->profilerData.init(swProfilerData.width, swProfilerData.height, swProfilerData.threadCount,
swProfilerData.drawCallCount, swProfilerData.presentedTriangleCount, swProfilerData.textureCount,
swProfilerData.textureByteCount, swProfilerData.totalLightCount, swProfilerData.totalDepthTests,
Expand Down
94 changes: 47 additions & 47 deletions OpenTESArena/src/Rendering/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,67 +34,67 @@ struct SDL_Surface;
struct SDL_Texture;
struct SDL_Window;

// Manages the active window and 2D and 3D rendering operations.
class Renderer : public JPH::DebugRendererSimple
struct RenderDisplayMode
{
public:
struct DisplayMode
{
int width, height, refreshRate;
int width, height, refreshRate;

DisplayMode(int width, int height, int refreshRate);
};
RenderDisplayMode(int width, int height, int refreshRate);
};

enum class WindowMode
{
Window,
BorderlessFullscreen,
ExclusiveFullscreen
};
enum class RenderWindowMode
{
Window,
BorderlessFullscreen,
ExclusiveFullscreen
};

// Profiler information from the most recently rendered frame.
struct ProfilerData
{
// Internal renderer resolution.
int width, height;
int pixelCount;
// Profiler information from the most recently rendered frame.
struct RendererProfilerData
{
// Internal renderer resolution.
int width, height;
int pixelCount;

int threadCount;
int drawCallCount;
int threadCount;
int drawCallCount;

// Geometry.
int presentedTriangleCount; // After clipping, only screen-space triangles with onscreen area.
// Geometry.
int presentedTriangleCount; // After clipping, only screen-space triangles with onscreen area.

// Textures.
int objectTextureCount;
int64_t objectTextureByteCount;
// Textures.
int objectTextureCount;
int64_t objectTextureByteCount;

// Lights.
int totalLightCount;
// Lights.
int totalLightCount;

// Pixel writes/overdraw.
int totalDepthTests;
int totalColorWrites;
// Pixel writes/overdraw.
int totalDepthTests;
int totalColorWrites;

double renderTime;
double presentTime;
double renderTime;
double presentTime;

ProfilerData();
RendererProfilerData();

void init(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount, int objectTextureCount,
int64_t objectTextureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites, double renderTime, double presentTime);
};

void init(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount, int objectTextureCount,
int64_t objectTextureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites, double renderTime, double presentTime);
};
using RenderResolutionScaleFunc = std::function<double()>;

using ResolutionScaleFunc = std::function<double()>;
// Manages the active window and 2D and 3D rendering operations.
class Renderer : public JPH::DebugRendererSimple
{
private:
std::unique_ptr<RendererSystem2D> renderer2D;
std::unique_ptr<RendererSystem3D> renderer3D;
std::vector<DisplayMode> displayModes;
std::vector<RenderDisplayMode> displayModes;
SDL_Window *window;
SDL_Renderer *renderer;
Texture nativeTexture, gameWorldTexture; // Frame buffers.
ProfilerData profilerData;
ResolutionScaleFunc resolutionScaleFunc; // Gets an up-to-date resolution scale value from the game options.
RendererProfilerData profilerData;
RenderResolutionScaleFunc resolutionScaleFunc; // Gets an up-to-date resolution scale value from the game options.
int letterboxMode; // Determines aspect ratio of the original UI (16:10, 4:3, etc.).
bool fullGameWindow; // Determines height of 3D frame buffer.
public:
Expand All @@ -118,7 +118,7 @@ class Renderer : public JPH::DebugRendererSimple
double getWindowAspect() const;

// Gets a list of supported fullscreen display modes.
BufferView<const DisplayMode> getDisplayModes() const;
BufferView<const RenderDisplayMode> getDisplayModes() const;

// Gets the active window's pixels-per-inch scale divided by platform DPI.
double getDpiScale() const;
Expand All @@ -137,7 +137,7 @@ class Renderer : public JPH::DebugRendererSimple
Surface getScreenshot() const;

// Gets profiler data (timings, renderer properties, etc.).
const ProfilerData &getProfilerData() const;
const RendererProfilerData &getProfilerData() const;

// Transforms a native window (i.e., 1920x1080) point or rectangle to an original
// (320x200) point or rectangle. Points outside the letterbox will either be negative
Expand All @@ -155,8 +155,8 @@ class Renderer : public JPH::DebugRendererSimple
// Wrapper methods for SDL_CreateTexture.
Texture createTexture(uint32_t format, int access, int w, int h);

bool init(int width, int height, WindowMode windowMode, int letterboxMode, bool fullGameWindow,
const ResolutionScaleFunc &resolutionScaleFunc, RendererSystemType2D systemType2D,
bool init(int width, int height, RenderWindowMode windowMode, int letterboxMode, bool fullGameWindow,
const RenderResolutionScaleFunc &resolutionScaleFunc, RendererSystemType2D systemType2D,
RendererSystemType3D systemType3D, int renderThreadsMode, DitheringMode ditheringMode);

// Resizes the renderer dimensions.
Expand All @@ -169,7 +169,7 @@ class Renderer : public JPH::DebugRendererSimple
void setLetterboxMode(int letterboxMode);

// Sets whether the program is windowed, fullscreen, etc..
void setWindowMode(WindowMode mode);
void setWindowMode(RenderWindowMode mode);

// Sets the window icon to be the given surface.
void setWindowIcon(const Surface &icon);
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Rendering/RendererSystem3D.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "RendererSystem3D.h"

RendererSystem3D::ProfilerData::ProfilerData(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
Renderer3DProfilerData::Renderer3DProfilerData(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
int textureCount, int64_t textureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites)
{
this->width = width;
Expand Down
36 changes: 18 additions & 18 deletions OpenTESArena/src/Rendering/RendererSystem3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@ struct RenderDrawCall;
struct RenderFrameSettings;
struct RenderInitSettings;

// Profiling info gathered from internal renderer state.
struct Renderer3DProfilerData
{
int width, height;
int threadCount;
int drawCallCount;
int presentedTriangleCount;
int textureCount;
int64_t textureByteCount;
int totalLightCount;
int totalDepthTests;
int totalColorWrites;

Renderer3DProfilerData(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
int textureCount, int64_t textureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites);
};

// Abstract base class for 3D renderer.
class RendererSystem3D
{
public:
// Profiling info gathered from internal renderer state.
struct ProfilerData
{
int width, height;
int threadCount;
int drawCallCount;
int presentedTriangleCount;
int textureCount;
int64_t textureByteCount;
int totalLightCount;
int totalDepthTests;
int totalColorWrites;

ProfilerData(int width, int height, int threadCount, int drawCallCount, int presentedTriangleCount,
int textureCount, int64_t textureByteCount, int totalLightCount, int totalDepthTests, int totalColorWrites);
};

virtual ~RendererSystem3D();

virtual void init(const RenderInitSettings &settings) = 0;
Expand Down Expand Up @@ -84,7 +84,7 @@ class RendererSystem3D
virtual std::optional<Int2> tryGetObjectTextureDims(ObjectTextureID id) const = 0;

// Gets various profiler information about internal renderer state.
virtual ProfilerData getProfilerData() const = 0;
virtual Renderer3DProfilerData getProfilerData() const = 0;

// Begins rendering a frame. Currently this is a blocking call and it should be safe to present the frame
// upon returning from this.
Expand Down
Loading

0 comments on commit 5024e2f

Please sign in to comment.