Skip to content

Commit

Permalink
Merge pull request #5613 from Web-eWorks/model-viewer-widget
Browse files Browse the repository at this point in the history
Add Model Viewer Widget
  • Loading branch information
Webster Sheets authored Sep 8, 2023
2 parents cee3259 + 6ca2caa commit 0938f42
Show file tree
Hide file tree
Showing 52 changed files with 1,699 additions and 1,127 deletions.
2 changes: 1 addition & 1 deletion data/modules/MissionUtils.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Game = require "Game"
Expand Down
2 changes: 1 addition & 1 deletion data/modules/Scout/ScanDisplay.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Game = require 'Game'
Expand Down
2 changes: 1 addition & 1 deletion data/modules/Scout/ScanGauge.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Game = require 'Game'
Expand Down
2 changes: 1 addition & 1 deletion data/modules/Scout/ScanManager.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Event = require 'Event'
Expand Down
2 changes: 1 addition & 1 deletion data/modules/Scout/Scout.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local Lang = require "Lang"
Expand Down
16 changes: 8 additions & 8 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "galaxy/StarSystem.h"
#include "graphics/TextureBuilder.h"
#include "graphics/Types.h"
#include "graphics/RenderState.h"

using namespace Graphics;

Expand Down Expand Up @@ -318,17 +319,16 @@ void Camera::Draw(const Body *excludeBody)
continue;
}

if (attrs->calcAtmosphereLighting) {
double ambient, direct;
double ambient = 0.05, direct = 1.0;
if (attrs->calcAtmosphereLighting)
CalcLighting(attrs->body, ambient, direct);

for (size_t i = 0; i < m_lightSources.size(); i++)
lightIntensities[i] = direct * ShadowedIntensity(i, attrs->body);
for (size_t i = 0; i < m_lightSources.size(); i++)
lightIntensities[i] = direct * ShadowedIntensity(i, attrs->body);

// Setup dynamic lighting parameters
m_renderer->SetAmbientColor(Color(ambient * 255, ambient * 255, ambient * 255));
m_renderer->SetLightIntensity(m_lightSources.size(), lightIntensities.data());
}
// Setup dynamic lighting parameters
m_renderer->SetAmbientColor(Color(ambient * 255, ambient * 255, ambient * 255));
m_renderer->SetLightIntensity(m_lightSources.size(), lightIntensities.data());

attrs->body->Render(m_renderer, this, attrs->viewCoords, attrs->viewTransform);
}
Expand Down
2 changes: 1 addition & 1 deletion src/DateTime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "DateTime.h"
Expand Down
2 changes: 1 addition & 1 deletion src/GameLog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "GameLog.h"
Expand Down
2 changes: 1 addition & 1 deletion src/GameLog.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#ifndef _GAMELOG_H
Expand Down
12 changes: 3 additions & 9 deletions src/GasGiant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,14 +832,8 @@ void GasGiant::SetRenderTargetCubemap(const Uint32 face, Graphics::Texture *pTex
s_renderTarget->SetCubeFaceTexture(face, pTexture);
}

//static
void GasGiant::BeginRenderTarget()
{
Pi::renderer->SetRenderTarget(s_renderTarget);
}

//static
void GasGiant::EndRenderTarget()
// static
Graphics::RenderTarget *GasGiant::GetRenderTarget()
{
Pi::renderer->SetRenderTarget(nullptr);
return s_renderTarget;
}
1 change: 1 addition & 0 deletions src/GasGiant.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class GasGiant : public BaseSphere {

static void CreateRenderTarget(const Uint16 width, const Uint16 height);
static void SetRenderTargetCubemap(const Uint32, Graphics::Texture *, const bool unBind = true);
static Graphics::RenderTarget *GetRenderTarget();
static void BeginRenderTarget();
static void EndRenderTarget();

Expand Down
5 changes: 3 additions & 2 deletions src/GasGiantJobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ namespace GasGiantJobs {
Pi::renderer->SetOrthographicProjection(0, mData->UVDims(), mData->UVDims(), 0, -1, 1);
Pi::renderer->SetTransform(matrix4x4f::Identity());

GasGiant::BeginRenderTarget();
// render to offscreen rt
Pi::renderer->SetRenderTarget(GasGiant::GetRenderTarget());

for (Uint32 iFace = 0; iFace < NUM_PATCHES; iFace++) {
// render the scene
GasGiant::SetRenderTargetCubemap(iFace, mData->Texture());
Expand All @@ -277,7 +279,6 @@ namespace GasGiantJobs {
// FIXME: use different render targets for each cubemap face
Pi::renderer->FlushCommandBuffers();
}
GasGiant::EndRenderTarget();

// add this patches data
SGPUGenResult *sr = new SGPUGenResult();
Expand Down
1 change: 1 addition & 0 deletions src/GasGiantJobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "JobQueue.h"
#include "graphics/Material.h"
#include "graphics/VertexBuffer.h"
#include "graphics/RenderState.h"
#include "profiler/Profiler.h"
#include "terrain/Terrain.h"
#include "vector3.h"
Expand Down
3 changes: 3 additions & 0 deletions src/Intro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ void Intro::Draw(float deltaTime)
m_renderer->SetTransform(matrix4x4f::Identity());

m_renderer->SetAmbientColor(m_ambientColor);

float intensity[4] = { 1.f, 1.f, 1.f, 1.f };
m_renderer->SetLights(m_lights.size(), &m_lights[0]);
m_renderer->SetLightIntensity(4, intensity);

// XXX all this stuff will be gone when intro uses a Camera
// rotate background by time, and a bit extra Z so it's not so flat
Expand Down
1 change: 0 additions & 1 deletion src/Pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ void MainMenu::Update(float deltaTime)

Pi::intro->Draw(deltaTime);

Pi::renderer->SetRenderTarget(0);
Pi::pigui->NewFrame();
PiGui::RunHandler(deltaTime, "mainMenu");

Expand Down
15 changes: 8 additions & 7 deletions src/SectorMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,18 @@ void SectorMap::DrawEmbed()
ImGui::Image(m_renderTarget->GetColorTexture(), m_size, ImVec2(0, 1), ImVec2(1, 0));

auto *r = m_context.renderer;
Graphics::Renderer::StateTicket ticket(r);
r->SetRenderTarget(m_renderTarget.get());
const auto &desc = m_renderTarget.get()->GetDesc();
r->SetViewport({ 0, 0, desc.width, desc.height });

r->SetClearColor(Color(0, 0, 0, 255));
{
// state ticket resets all draw state at the end of the scope
Graphics::Renderer::StateTicket ticket(r);

Draw3D();
DrawLabels(ImGui::IsItemHovered(), imagePos);
r->SetRenderTarget(m_renderTarget.get());
r->SetViewport({ 0, 0, desc.width, desc.height });

r->SetRenderTarget(nullptr);
Draw3D();
DrawLabels(ImGui::IsItemHovered(), imagePos);
}

if (ImGui::IsItemHovered()) {
ImGui::CaptureMouseFromApp(false);
Expand Down
1 change: 1 addition & 0 deletions src/Star.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "galaxy/SystemBody.h"
#include "graphics/Material.h"
#include "graphics/Renderer.h"
#include "graphics/RenderState.h"
#include "graphics/Types.h"
#include "graphics/VertexArray.h"
#include "graphics/VertexBuffer.h"
Expand Down
1 change: 1 addition & 0 deletions src/SystemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "graphics/Graphics.h"
#include "graphics/Material.h"
#include "graphics/Renderer.h"
#include "graphics/RenderState.h"
#include "graphics/TextureBuilder.h"
#include "graphics/Types.h"

Expand Down
3 changes: 1 addition & 2 deletions src/Tombstone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ Tombstone::Tombstone(Graphics::Renderer *r, int width, int height) :

void Tombstone::Draw(float _time)
{
m_renderer->SetClearColor(Color::BLACK);
m_renderer->ClearScreen();
m_renderer->ClearScreen(Color::BLACK);

m_renderer->SetPerspectiveProjection(75, m_aspectRatio, 1.f, 10000.f);
m_renderer->SetTransform(matrix4x4f::Identity());
Expand Down
1 change: 1 addition & 0 deletions src/WorldView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "graphics/Graphics.h"
#include "graphics/Material.h"
#include "graphics/Renderer.h"
#include "graphics/RenderState.h"
#include "matrix4x4.h"
#include "ship/PlayerShipController.h"
#include "ship/ShipViewController.h"
Expand Down
81 changes: 13 additions & 68 deletions src/core/GuiApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,20 @@ GuiApplication::GuiApplication(std::string title) :
GuiApplication::~GuiApplication()
{ }

// FIXME: add support for offscreen rendertarget drawing and multisample RTs
#define RTT 0

void GuiApplication::BeginFrame()
{
PROFILE_SCOPED()
#if RTT
m_renderer->SetRenderTarget(m_renderTarget);
#endif
// TODO: render target size
m_renderer->SetViewport({ 0, 0, Graphics::GetScreenWidth(), Graphics::GetScreenHeight() });
m_renderer->BeginFrame();
}

void GuiApplication::DrawRenderTarget()
{
#if RTT
m_renderer->SetRenderTarget(nullptr);
m_renderer->SetRenderTarget(m_renderTarget.get());
m_renderer->SetViewport({ 0, 0, Graphics::GetScreenWidth(), Graphics::GetScreenHeight() });
m_renderer->ClearScreen();
m_renderer->SetViewport(0, 0, Graphics::GetScreenWidth(), Graphics::GetScreenHeight());
m_renderer->SetTransform(matrix4x4f::Identity());

{
m_renderer->SetMatrixMode(Graphics::MatrixMode::PROJECTION);
m_renderer->PushMatrix();
m_renderer->SetOrthographicProjection(0, Graphics::GetScreenWidth(), Graphics::GetScreenHeight(), 0, -1, 1);
m_renderer->SetMatrixMode(Graphics::MatrixMode::MODELVIEW);
m_renderer->PushMatrix();
m_renderer->LoadIdentity();
}

m_renderQuad->Draw(m_renderer);

{
m_renderer->SetMatrixMode(Graphics::MatrixMode::PROJECTION);
m_renderer->PopMatrix();
m_renderer->SetMatrixMode(Graphics::MatrixMode::MODELVIEW);
m_renderer->PopMatrix();
}

m_renderer->EndFrame();
#endif
m_renderer->BeginFrame();
}

void GuiApplication::EndFrame()
{
PROFILE_SCOPED()
#if RTT
DrawRenderTarget();
#endif

m_renderer->FlushCommandBuffers();
m_renderer->EndFrame();
Expand All @@ -83,35 +47,14 @@ void GuiApplication::EndFrame()

Graphics::RenderTarget *GuiApplication::CreateRenderTarget(const Graphics::Settings &settings)
{
/* @fluffyfreak here's a rendertarget implementation you can use for oculusing and other things. It's pretty simple:
- fill out a RenderTargetDesc struct and call Renderer::CreateRenderTarget
- pass target to Renderer::SetRenderTarget to start rendering to texture
- set up viewport, clear etc, then draw as usual
- SetRenderTarget(0) to resume render to screen
- you can access the attached texture with GetColorTexture to use it with a material
You can reuse the same target with multiple textures.
In that case, leave the color format to NONE so the initial texture is not created, then use SetColorTexture to attach your own.
*/
#if RTT
Graphics::RenderStateDesc rsd;
rsd.depthTest = false;
rsd.depthWrite = false;
rsd.blendMode = Graphics::BLEND_SOLID;
m_renderState.reset(m_renderer->CreateRenderState(rsd));

// Complete the RT description so we can request a buffer.
Graphics::RenderTargetDesc rtDesc(
width,
height,
Graphics::TEXTURE_RGB_888, // don't create a texture
Graphics::TEXTURE_DEPTH,
false, settings.requestedSamples);
m_renderTarget.reset(m_renderer->CreateRenderTarget(rtDesc));

m_renderTarget->SetColorTexture(*m_renderTexture);
#endif

return nullptr;
Graphics::RenderTargetDesc rtDesc = {
uint16_t(settings.width), uint16_t(settings.height),
Graphics::TEXTURE_RGBA_8888,
Graphics::TEXTURE_DEPTH, true,
uint16_t(settings.requestedSamples)
};

return m_renderer->CreateRenderTarget(rtDesc);
}

void GuiApplication::PollEvents()
Expand Down Expand Up @@ -219,6 +162,8 @@ Graphics::Renderer *GuiApplication::StartupRenderer(IniConfig *config, bool hidd
m_renderer.reset(Graphics::Init(videoSettings));
m_renderTarget.reset(CreateRenderTarget(videoSettings));

m_settings = videoSettings;

return m_renderer.get();
}

Expand Down
17 changes: 11 additions & 6 deletions src/core/GuiApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include "RefCounted.h"
#include "SDL_events.h"

#include "graphics/RenderState.h"
#include "graphics/RenderTarget.h"
#include "graphics/Renderer.h"
#include "graphics/Graphics.h"

class IniConfig;

Expand All @@ -21,6 +19,11 @@ namespace PiGui {
class Instance;
}

namespace Graphics {
class Renderer;
class RenderTarget;
}

class GuiApplication : public Application {
public:
GuiApplication(std::string title);
Expand All @@ -30,10 +33,11 @@ class GuiApplication : public Application {
Input::Manager *GetInput() { return m_input.get(); }
PiGui::Instance *GetPiGui() { return m_pigui.Get(); }

Graphics::RenderTarget *GetRenderTarget() { return m_renderTarget.get(); }

const Graphics::Settings &GetGraphicsSettings() { return m_settings; }

protected:
// Called at the end of the frame automatically, blits the RT onto the application
// framebuffer
void DrawRenderTarget();

// Call this from your OnStartup() method
void SetupProfiler(IniConfig *config);
Expand Down Expand Up @@ -84,4 +88,5 @@ class GuiApplication : public Application {

std::unique_ptr<Graphics::Renderer> m_renderer;
std::unique_ptr<Graphics::RenderTarget> m_renderTarget;
Graphics::Settings m_settings;
};
2 changes: 1 addition & 1 deletion src/core/macros.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#pragma once
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorApp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#include "EditorApp.h"
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorApp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2008-2022 Pioneer Developers. See AUTHORS.txt for details
// Copyright © 2008-2023 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

#pragma once
Expand Down
Loading

0 comments on commit 0938f42

Please sign in to comment.