Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ if(BUILD_TESTING)
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/test_e6_s3_releases.py"
-v)
add_test(
NAME trackeditor-graphics-settings-contract
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/tests/test_graphics_settings.py"
-v)
endif()

if(TARGET TrackEditor)
Expand Down
3 changes: 3 additions & 0 deletions TrackEditor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ set(trackeditor_sources
GlobalTrackSettings.cpp
GlobalTrackSettings.h
GlobalTrackSettings.ui
GraphicsDialog.cpp
GraphicsDialog.h
GraphicsDialog.ui
LogDialog.cpp
LogDialog.h
LogDialog.ui
Expand Down
5 changes: 5 additions & 0 deletions TrackEditor/EditorRenderQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ struct tEdRenderRequest
// pointer payload, so the worker never reads UI-owned storage.
tEdOverlayState Overlay = {};
bool bHasOverlay = false;
// Graphics settings are process-wide renderer state, but each command
// carries the revision it was queued against. The worker applies a changed
// revision before touching the scene and never reads UI-owned storage.
tEdGraphicsSettings GraphicsSettings = {};
uint64_t ullGraphicsSettingsRevision = 0;
// Only set when the reference mesh actually changed: uploading it on every
// camera nudge would copy the whole model through the queue each frame.
tEdReferenceMeshPayload ReferenceMesh;
Expand Down
46 changes: 46 additions & 0 deletions TrackEditor/EditorRenderService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class CEditorRenderThread : public QThread
, m_bInitAttempted(false)
, m_eInitResult(ROLLER_ED_RESULT_NOT_INITIALIZED)
, m_ullActiveDocumentId(0)
, m_ullAppliedGraphicsSettingsRevision(0)
{
}

Expand Down Expand Up @@ -348,6 +349,21 @@ class CEditorRenderThread : public QThread
return Result;
}

if (Request.ullGraphicsSettingsRevision != 0
&& Request.ullGraphicsSettingsRevision
!= m_ullAppliedGraphicsSettingsRevision) {
AssertWorkerThread("RollerEd_SetGraphicsSettings");
const eRollerEdResult eGraphicsResult =
RollerEd_SetGraphicsSettings(&Request.GraphicsSettings);
if (eGraphicsResult != ROLLER_ED_RESULT_OK) {
Result.bLoadFailed = bLoadCommand;
SetFacadeFailure(Result, eGraphicsResult);
return Result;
}
m_ullAppliedGraphicsSettingsRevision =
Request.ullGraphicsSettingsRevision;
}

tEdGeometrySizes Sizes = {};
if (Request.eKind == eEdRenderCommandKind::UNLOAD) {
AssertWorkerThread("RollerEd_UnloadTrack for empty document");
Expand Down Expand Up @@ -554,13 +570,25 @@ class CEditorRenderThread : public QThread
eRollerEdResult m_eInitResult;
std::string m_sInitError;
uint64_t m_ullActiveDocumentId;
uint64_t m_ullAppliedGraphicsSettingsRevision;
};

CEditorRenderService::CEditorRenderService(const QString &sAssetRoot, QObject *pParent)
: QObject(pParent)
, m_pThread(new CEditorRenderThread(this, EncodePath(sAssetRoot)))
, m_ullGraphicsSettingsRevision(1)
{
Q_ASSERT(!sAssetRoot.isEmpty());
m_GraphicsSettings = {};
m_GraphicsSettings.uiStructSize = sizeof(m_GraphicsSettings);
m_GraphicsSettings.uiVersion = ROLLER_ED_GRAPHICS_SETTINGS_VERSION;
m_GraphicsSettings.eRenderer = ROLLER_ED_RENDERER_GPU;
m_GraphicsSettings.eSoftwareDisplay = ROLLER_ED_SOFTWARE_DISPLAY_SVGA;
m_GraphicsSettings.eAntiAliasing = ROLLER_ED_ANTI_ALIASING_OFF;
m_GraphicsSettings.eAnisotropy = ROLLER_ED_ANISOTROPY_16X;
m_GraphicsSettings.eTextureFilter = ROLLER_ED_TEXTURE_FILTER_NEAREST;
m_GraphicsSettings.fDrawDistanceFraction = 1.0f;
m_GraphicsSettings.uiEmulateTransparentBorders = 1u;
}

CEditorRenderService::~CEditorRenderService()
Expand All @@ -584,6 +612,16 @@ void CEditorRenderService::Stop()
m_pThread->StopAndWait();
}

void CEditorRenderService::SetGraphicsSettings(
const tEdGraphicsSettings &Settings)
{
Q_ASSERT(QThread::currentThread() == thread());
m_GraphicsSettings = Settings;
if (m_ullGraphicsSettingsRevision == std::numeric_limits<uint64_t>::max())
std::terminate();
++m_ullGraphicsSettingsRevision;
}

void CEditorRenderService::RegisterDocument(uint64_t ullDocumentId)
{
Q_ASSERT(QThread::currentThread() == thread());
Expand Down Expand Up @@ -625,6 +663,8 @@ uint64_t CEditorRenderService::EnqueueLoadAndRender(
Request.bHasCamera = true;
Request.Overlay = Overlay;
Request.bHasOverlay = true;
Request.GraphicsSettings = m_GraphicsSettings;
Request.ullGraphicsSettingsRevision = m_ullGraphicsSettingsRevision;
Request.uiWidth = static_cast<uint32_t>(NormalizedSize.width());
Request.uiHeight = static_cast<uint32_t>(NormalizedSize.height());
Request.dDevicePixelRatio = dDevicePixelRatio;
Expand Down Expand Up @@ -656,6 +696,8 @@ uint64_t CEditorRenderService::EnqueueSerializedLoadAndRender(
Request.bHasCamera = true;
Request.Overlay = Overlay;
Request.bHasOverlay = true;
Request.GraphicsSettings = m_GraphicsSettings;
Request.ullGraphicsSettingsRevision = m_ullGraphicsSettingsRevision;
Request.uiWidth = static_cast<uint32_t>(NormalizedSize.width());
Request.uiHeight = static_cast<uint32_t>(NormalizedSize.height());
Request.dDevicePixelRatio = dDevicePixelRatio;
Expand Down Expand Up @@ -683,6 +725,8 @@ uint64_t CEditorRenderService::EnqueueRender(
Request.Tag.uiExpectedGeometryEpoch = uiExpectedGeometryEpoch;
Request.Tag.uiFlags = ROLLER_ED_REQUEST_HAS_EXPECTED_EPOCH;
Request.eKind = eEdRenderCommandKind::RENDER_ONLY;
Request.GraphicsSettings = m_GraphicsSettings;
Request.ullGraphicsSettingsRevision = m_ullGraphicsSettingsRevision;
Request.Camera = Camera;
Request.bHasCamera = true;
Request.Overlay = Overlay;
Expand Down Expand Up @@ -713,6 +757,8 @@ uint64_t CEditorRenderService::EnqueueUnload(
Request.Tag.ullDocumentId = ullDocumentId;
Request.Tag.ullDocumentRevision = ullDocumentRevision;
Request.eKind = eEdRenderCommandKind::UNLOAD;
Request.GraphicsSettings = m_GraphicsSettings;
Request.ullGraphicsSettingsRevision = m_ullGraphicsSettingsRevision;
const uint64_t ullRequestId = Request.Tag.ullRequestId;
m_pThread->Enqueue(std::move(Request));
return ullRequestId;
Expand Down
3 changes: 3 additions & 0 deletions TrackEditor/EditorRenderService.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CEditorRenderService : public QObject

void Start();
void Stop();
void SetGraphicsSettings(const tEdGraphicsSettings &Settings);
void RegisterDocument(uint64_t ullDocumentId);
void InvalidateDocument(uint64_t ullDocumentId);

Expand Down Expand Up @@ -93,6 +94,8 @@ class CEditorRenderService : public QObject

CEditorRenderThread *m_pThread;
std::unordered_set<uint64_t> m_RegisteredDocuments;
tEdGraphicsSettings m_GraphicsSettings;
uint64_t m_ullGraphicsSettingsRevision;
};

#endif
79 changes: 79 additions & 0 deletions TrackEditor/GraphicsDialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "TrackEditor.h"
#include "GraphicsDialog.h"
#include "MainWindow.h"

CGraphicsDialog::CGraphicsDialog(QWidget *pParent)
: QDialog(pParent)
{
setupUi(this);

slDrawDistance->setValue(g_pMainWindow->m_graphics.iDrawDistancePercent);
lblDrawDistanceValue->setText(
QString("%1%").arg(g_pMainWindow->m_graphics.iDrawDistancePercent));
ckHardwareRendering->setChecked(
g_pMainWindow->m_graphics.bHardwareRendering);
cbSoftwareDisplay->setCurrentIndex(
g_pMainWindow->m_graphics.iSoftwareDisplay);
cbAntiAliasing->setCurrentIndex(g_pMainWindow->m_graphics.iAntiAliasing);
cbAnisotropy->setCurrentIndex(g_pMainWindow->m_graphics.iAnisotropy);
cbTextureFilter->setCurrentIndex(g_pMainWindow->m_graphics.iTextureFilter);
ckTrilinear->setChecked(g_pMainWindow->m_graphics.bTrilinear);
dsbLodBias->setValue(g_pMainWindow->m_graphics.dLodBias);
ckEmulateTransparentBorders->setChecked(
g_pMainWindow->m_graphics.bEmulateTransparentBorders);

connect(pbClose, &QPushButton::clicked, this, &CGraphicsDialog::reject);
connect(slDrawDistance, &QSlider::valueChanged,
this, &CGraphicsDialog::DialogEdited);
connect(ckHardwareRendering, &QCheckBox::toggled,
this, &CGraphicsDialog::HardwareRenderingToggled);
connect(cbSoftwareDisplay, &QComboBox::currentIndexChanged,
this, &CGraphicsDialog::DialogEdited);
connect(cbAntiAliasing, &QComboBox::currentIndexChanged,
this, &CGraphicsDialog::DialogEdited);
connect(cbAnisotropy, &QComboBox::currentIndexChanged,
this, &CGraphicsDialog::DialogEdited);
connect(cbTextureFilter, &QComboBox::currentIndexChanged,
this, &CGraphicsDialog::DialogEdited);
connect(ckTrilinear, &QCheckBox::toggled,
this, &CGraphicsDialog::DialogEdited);
connect(dsbLodBias, &QDoubleSpinBox::valueChanged,
this, &CGraphicsDialog::DialogEdited);
connect(ckEmulateTransparentBorders, &QCheckBox::toggled,
this, &CGraphicsDialog::DialogEdited);

UpdateHardwareControls();
}

CGraphicsDialog::~CGraphicsDialog() = default;

void CGraphicsDialog::HardwareRenderingToggled(bool bChecked)
{
(void)bChecked;
UpdateHardwareControls();
DialogEdited();
}

void CGraphicsDialog::DialogEdited()
{
g_pMainWindow->m_graphics.iDrawDistancePercent = slDrawDistance->value();
lblDrawDistanceValue->setText(QString("%1%").arg(slDrawDistance->value()));
g_pMainWindow->m_graphics.bHardwareRendering =
ckHardwareRendering->isChecked();
g_pMainWindow->m_graphics.iSoftwareDisplay =
cbSoftwareDisplay->currentIndex();
g_pMainWindow->m_graphics.iAntiAliasing = cbAntiAliasing->currentIndex();
g_pMainWindow->m_graphics.iAnisotropy = cbAnisotropy->currentIndex();
g_pMainWindow->m_graphics.iTextureFilter = cbTextureFilter->currentIndex();
g_pMainWindow->m_graphics.bTrilinear = ckTrilinear->isChecked();
g_pMainWindow->m_graphics.dLodBias = dsbLodBias->value();
g_pMainWindow->m_graphics.bEmulateTransparentBorders =
ckEmulateTransparentBorders->isChecked();
g_pMainWindow->ApplyGraphicsSettings();
}

void CGraphicsDialog::UpdateHardwareControls()
{
gbHardwareOptions->setEnabled(ckHardwareRendering->isChecked());
gbSoftwareOptions->setEnabled(!ckHardwareRendering->isChecked());
}
22 changes: 22 additions & 0 deletions TrackEditor/GraphicsDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef _TRACKEDITOR_GRAPHICSDIALOG_H
#define _TRACKEDITOR_GRAPHICSDIALOG_H

#include "ui_GraphicsDialog.h"

class CGraphicsDialog : public QDialog, private Ui::GraphicsDialog
{
Q_OBJECT

public:
explicit CGraphicsDialog(QWidget *pParent);
~CGraphicsDialog() override;

private slots:
void HardwareRenderingToggled(bool bChecked);
void DialogEdited();

private:
void UpdateHardwareControls();
};

#endif
Loading
Loading