Remove (almost) all references to pRenderer (#651)

Remove all references to pRenderer, except from the DebugDraw and LyShine Gems that are still being updated.
This commit is contained in:
bosnichd
2021-05-10 10:05:15 -06:00
committed by GitHub
parent 4a2e6a77b5
commit 440c40e490
191 changed files with 118 additions and 23548 deletions
File diff suppressed because it is too large Load Diff
@@ -1,336 +0,0 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
// Original file Copyright Crytek GMBH or its affiliates, used under license.
#ifndef CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H
#define CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H
#pragma once
#include <platform.h>
#include <Cry_Geo.h>
#include <Cry_Color.h>
#include "EditorCommonAPI.h"
#include <QObject>
#include "QViewportConsumer.h"
namespace Serialization {
class IArchive;
}
class CAxisHelper;
// Manip is a set of reusable utilities for creating interactive 3d scene that
// can be manipulated with gizmos.
namespace Manip
{
using std::unique_ptr;
using std::set;
using std::vector;
enum EElementCaps
{
CAP_SELECT = 1 << 0,
CAP_HIDE = 1 << 1,
CAP_MOVE = 1 << 2,
CAP_ROTATE = 1 << 3,
CAP_SCALE = 1 << 4,
CAP_DELETE = 1 << 5,
};
enum EElementShape
{
SHAPE_AXES,
SHAPE_BOX
};
enum EElementAction
{
ACTION_NONE,
ACTION_DELETE,
ACTION_HIDE,
ACTION_UNHIDE
};
enum EElementColorGroup
{
ELEMENT_COLOR_PROXY,
ELEMENT_COLOR_CLOTH
};
struct SElementPlacement
{
QuatT transform;
QuatT startTransform;
Vec3 center;
Vec3 size;
SElementPlacement()
: transform(IDENTITY)
, startTransform(IDENTITY)
, size(1.0f, 1.0f, 1.0f)
, center(0.0f, 0.0f, 0.0f)
{}
void Serialize(Serialization::IArchive& ar);
};
typedef uint64 ElementId;
struct SSpaceAndIndex
{
int m_space;
int m_jointCRC32;
int m_attachmentCRC32;
SSpaceAndIndex()
{
m_space = -1;
m_jointCRC32 = -1;
m_attachmentCRC32 = -1;
};
};
struct SElement
{
int id;
union
{
int originalId;
const void* originalHandle;
};
int layer;
SElementPlacement placement;
int caps;
EElementAction action;
EElementShape shape;
EElementColorGroup colorGroup;
SSpaceAndIndex parentSpaceIndex;
SSpaceAndIndex parentOrientationSpaceIndex;
QuatT parentSpaceConcatenation;
int mousePickPriority;
bool hidden;
bool changed;
bool alwaysXRay;
SElement()
: id()
, layer(0)
, originalHandle(0)
, action(ACTION_NONE)
, shape(SHAPE_AXES)
, hidden(false)
, changed(false)
, colorGroup(ELEMENT_COLOR_PROXY)
, mousePickPriority(0)
, alwaysXRay(false)
, parentSpaceIndex()
, parentOrientationSpaceIndex()
, parentSpaceConcatenation(IDENTITY)
{
}
};
typedef std::vector<SElement> SElements;
struct SElementData {};
struct IMouseDragHandler
{
virtual ~IMouseDragHandler() = default;
virtual bool Begin(const SMouseEvent& ev, Vec3 hitPoint) = 0;
virtual void Update(const SMouseEvent& ev) = 0;
virtual void Render([[maybe_unused]] const SRenderContext& rc) {}
virtual void End(const SMouseEvent& ev) = 0;
};
struct SSelectionSet
{
SSelectionSet() {}
SSelectionSet(ElementId id) { items.push_back(id); }
void Clear();
void Add(ElementId elementId)
{
items.erase(std::remove(items.begin(), items.end(), elementId), items.end());
items.push_back(elementId);
std::sort(items.begin(), items.end());
}
void Remove(int elementId);
bool IsEmpty() const{ return items.empty(); }
bool Contains(int id) const{ return std::find(items.begin(), items.end(), id) != items.end(); }
size_t Size() const{ return items.size(); }
bool operator==(const SSelectionSet& rhs) const
{
return items == rhs.items;
}
bool operator!=(const SSelectionSet& rhs) const{ return !operator==(rhs); }
std::vector<ElementId> items;
};
struct ICommand {};
struct IElementTracer
{
virtual bool HitRay(Vec3* intersectionPoint, const Ray& ray, const SElement& element) const = 0;
};
struct IElementDrawer
{
virtual bool Draw(const SElement& element);
};
enum ETransformationSpace
{
SPACE_WORLD,
SPACE_LOCAL
};
enum ETransformationMode
{
MODE_TRANSLATE,
MODE_ROTATE,
MODE_SCALE
};
struct SLookSettings
{
ColorB proxyColor;
ColorB proxySelectionColor;
ColorB proxyHighlightColor;
ColorB clothProxyColor;
ColorB jointColor;
ColorB jointHighlightColor;
ColorB jointSelectionColor;
SLookSettings()
: proxyColor(126, 159, 243, 128)
, proxySelectionColor(255, 255, 255, 128)
, proxyHighlightColor(233, 255, 122, 128)
, clothProxyColor(243, 159, 126, 128)
, jointColor(0, 249, 48, 255)
, jointHighlightColor(255, 248, 0, 128)
, jointSelectionColor(255, 255, 255, 128)
{
}
};
struct ISpaceProvider
{
virtual ~ISpaceProvider() = default;
virtual SSpaceAndIndex FindSpaceIndexByName(int spaceType, const char* name, int parentsUp) const = 0;
virtual QuatT GetTransform(const SSpaceAndIndex& index) const = 0;
};
AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
class EDITOR_COMMON_API CScene
: public QObject
, public QViewportConsumer
{
AZ_POP_DISABLE_DLL_EXPORT_BASECLASS_WARNING
Q_OBJECT
public:
CScene();
~CScene();
void OnViewportKey(const SKeyEvent& ev) override;
bool ProcessesViewportKey(const QKeySequence& key) override;
void OnViewportMouse(const SMouseEvent& ev) override;
void OnViewportRender(const SRenderContext& rc) override;
void SetTransformationMode(ETransformationMode mode);
ETransformationMode TransformationMode() const;
void SetTransformationSpace(ETransformationSpace space);
ETransformationSpace TransformationSpace() const { return m_transformationSpace; }
void SetVisibleLayerMask(unsigned int layerMask);
unsigned int VisibleLayerMask() const { return m_visibleLayerMask; }
bool IsLayerVisible(int layer) const;
void Clear();
void ClearLayer(int layer);
void AddElement(const SElement& element);
void AddElement(const SElement& element, ElementId id);
void ApplyToAll(EElementAction);
void ApplyToSelection(EElementAction);
void SetSpaceProvider(ISpaceProvider* spaceProvider);
ISpaceProvider* SpaceProvider() const{ return m_spaceProvider; }
QuatT GetParentSpace(const SElement& e) const;
QuatT ElementToWorldSpace(const SElement& e) const;
void WorldSpaceToElement(SElement* e, const QuatT& worldSpaceTransform);
void SetCustomTracer(IElementTracer* tracer);
const SElements& Elements() const{ return m_elements; }
SElements& Elements() { return m_elements; }
void GetSelectedElements(SElements* elements) const;
const SSelectionSet& Selection() const{ return m_selection; }
void SetSelection(const SSelectionSet& selection);
void AddToSelection(const SSelectionSet& selection);
void AddToSelection(ElementId elementId);
bool SelectionCanBeMoved() const;
bool SelectionCanBeRotated() const;
QuatT GetSelectionTransform(ETransformationSpace space) const;
bool SetSelectionTransform(ETransformationSpace space, const QuatT& newTransform);
void Serialize(Serialization::IArchive& ar);
signals:
void SignalUndo();
void SignalRedo();
void SignalPushUndo(const char* description, ICommand* cause);
void SignalElementsChanged(unsigned int layerBits);
void SignalElementContinousChange(unsigned int layerBits);
void SignalPropertiesChanged();
void SignalRenderElements(const SElements& elements, const SRenderContext& rc);
void SignalSelectionChanged();
void SignalManipulationModeChanged();
private:
void UpdateElements(const SElements& elements);
bool SetSelectionTransform(const Matrix34& newMatrix);
Matrix34 GetSelectionTransform() const;
int GetSelectionCaps() const;
Vec3 GetSelectionSize() const;
bool SetSelectionSize(const Vec3& size);
void OnMouseMove(const SMouseEvent& ev);
struct SBlockSelectHandler;
struct SMoveHandler;
struct SRotationHandler;
struct SScalingHandler;
struct STransformBox;
IElementTracer* m_customTracer;
IElementDrawer* m_customDrawer;
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
SSelectionSet m_selection;
unique_ptr<IMouseDragHandler> m_mouseDragHandler;
ISpaceProvider* m_spaceProvider;
unique_ptr<CAxisHelper> m_axisHelper;
SElements m_elements;
std::vector<ElementId> m_lastIdByLayer;
ETransformationMode m_transformationMode;
ETransformationSpace m_transformationSpace;
int m_highlightItem;
unsigned int m_visibleLayerMask;
bool m_showGizmo;
SLookSettings m_lookSettings;
int m_highlightedItem;
QuatT m_temporaryLocalDelta;
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
};
}
#endif // CRYINCLUDE_EDITORCOMMON_MANIPSCENE_H
+5 -203
View File
@@ -145,7 +145,6 @@ QViewport::QViewport(QWidget* parent, StartupMode startupMode)
void QViewport::Startup()
{
m_frameTimer = new QElapsedTimer();
CreateRenderContext();
m_camera.reset(new CCamera());
ResetCamera();
@@ -162,8 +161,6 @@ void QViewport::Startup()
QViewport::~QViewport()
{
DestroyRenderContext();
m_viewportRequests.reset();
}
@@ -180,51 +177,14 @@ void QViewport::UpdateBackgroundColor()
bool QViewport::ScreenToWorldRay(Ray* ray, int x, int y)
{
if (!GetIEditor()->GetEnv()->pRenderer)
{
return false;
}
SetCurrentContext();
Vec3 pos0, pos1;
float wx, wy, wz;
if (!GetIEditor()->GetEnv()->pRenderer->UnProjectFromScreen(float(x), float(m_height - y), 0, &wx, &wy, &wz))
{
RestorePreviousContext();
return false;
}
pos0(wx, wy, wz);
if (!GetIEditor()->GetEnv()->pRenderer->UnProjectFromScreen(float(x), float(m_height - y), 1, &wx, &wy, &wz))
{
RestorePreviousContext();
return false;
}
pos1(wx, wy, wz);
RestorePreviousContext();
Vec3 v = (pos1 - pos0);
v = v.GetNormalized();
ray->origin = pos0;
ray->direction = v;
return true;
AZ_UNUSED(ray);
AZ_UNUSED(x);
AZ_UNUSED(y);
return false;
}
QPoint QViewport::ProjectToScreen(const Vec3& wp)
QPoint QViewport::ProjectToScreen(const Vec3&)
{
float x, y, z;
SetCurrentContext();
GetIEditor()->GetEnv()->pRenderer->ProjectToScreen(wp.x, wp.y, wp.z, &x, &y, &z);
if (_finite(x) || _finite(y))
{
RestorePreviousContext();
return QPoint(int((x / 100.0) * Width()), int((y / 100.0) * Height()));
}
RestorePreviousContext();
return QPoint(0, 0);
}
@@ -245,105 +205,6 @@ int QViewport::Height() const
return rect().height();
}
bool QViewport::CreateRenderContext()
{
if (m_creatingRenderContext || !isVisible())
{
return false;
}
HWND windowHandle = reinterpret_cast<HWND>(QWidget::winId());
if( m_renderContextCreated && windowHandle == m_lastHwnd)
{
// the hwnd has not changed, no need to destroy and recreate context (and swap chain etc)
return false;
}
m_creatingRenderContext = true;
DestroyRenderContext();
if (windowHandle && GetIEditor()->GetEnv()->pRenderer && !m_renderContextCreated)
{
m_renderContextCreated = true;
m_viewportRequests.get()->BusConnect(windowHandle);
AzFramework::WindowSystemNotificationBus::Broadcast(&AzFramework::WindowSystemNotificationBus::Handler::OnWindowCreated, windowHandle);
m_lastHwnd = windowHandle;
StorePreviousContext();
GetIEditor()->GetEnv()->pRenderer->CreateContext(windowHandle);
RestorePreviousContext();
m_creatingRenderContext = false;
return true;
}
m_creatingRenderContext = false;
return false;
}
void QViewport::DestroyRenderContext()
{
if (GetIEditor()->GetEnv()->pRenderer && m_renderContextCreated)
{
HWND windowHandle = reinterpret_cast<HWND>(QWidget::winId());
if (windowHandle != GetIEditor()->GetEnv()->pRenderer->GetHWND())
{
GetIEditor()->GetEnv()->pRenderer->DeleteContext(windowHandle);
}
m_renderContextCreated = false;
AzFramework::WindowNotificationBus::Event(windowHandle, &AzFramework::WindowNotificationBus::Handler::OnWindowClosed);
m_viewportRequests.get()->BusDisconnect();
m_lastHwnd = 0;
}
}
void QViewport::StorePreviousContext()
{
SPreviousContext previous;
previous.width = GetIEditor()->GetEnv()->pRenderer->GetWidth();
previous.height = GetIEditor()->GetEnv()->pRenderer->GetHeight();
previous.window = reinterpret_cast<HWND>(GetIEditor()->GetEnv()->pRenderer->GetCurrentContextHWND());
previous.renderCamera = GetIEditor()->GetEnv()->pRenderer->GetCamera();
previous.systemCamera = GetISystem()->GetViewCamera();
previous.isMainViewport = GetIEditor()->GetEnv()->pRenderer->IsCurrentContextMainVP();
m_previousContexts.push_back(previous);
}
void QViewport::SetCurrentContext()
{
StorePreviousContext();
if (m_camera.get() == 0)
{
return;
}
HWND windowHandle = reinterpret_cast<HWND>(QWidget::winId());
GetIEditor()->GetEnv()->pRenderer->SetCurrentContext(windowHandle);
GetIEditor()->GetEnv()->pRenderer->ChangeViewport(0, 0, m_width, m_height);
GetIEditor()->GetEnv()->pRenderer->SetCamera(*m_camera);
GetIEditor()->GetEnv()->pSystem->SetViewCamera(*m_camera);
}
void QViewport::RestorePreviousContext()
{
if (m_previousContexts.empty())
{
assert(0);
return;
}
SPreviousContext x = m_previousContexts.back();
m_previousContexts.pop_back();
GetIEditor()->GetEnv()->pRenderer->SetCurrentContext(x.window);
GetIEditor()->GetEnv()->pRenderer->ChangeViewport(0, 0, x.width, x.height, x.isMainViewport);
GetIEditor()->GetEnv()->pRenderer->SetCamera(x.renderCamera);
GetIEditor()->GetEnv()->pSystem->SetViewCamera(x.systemCamera);
}
void QViewport::Serialize(IArchive& ar)
{
if (!ar.IsEdit())
@@ -720,45 +581,6 @@ void QViewport::RenderInternal()
{
}
void QViewport::GetImageOffscreen(CImageEx& image, const QSize& customSize)
{
if ((m_width == 0) || (m_height == 0))
{
// This can occur, for example, if the material editor window is sized to zero OR
// if it is docked as a tab in another view pane window and is not the active tab when the editor starts.
image.Allocate(1, 1);
image.Clear();
return;
}
IRenderer* renderer = GetIEditor()->GetRenderer();
renderer->EnableSwapBuffers(false);
RenderInternal();
renderer->EnableSwapBuffers(true);
int w;
int h;
if (customSize.isValid())
{
w = customSize.width();
h = customSize.height();
}
else
{
w = width();
h = height();
}
image.Allocate(w, h);
// the renderer will read the frame buffer of the current render context, so we need to set ours as the current before we execute this command.
SetCurrentContext();
renderer->ReadFrameBufferFast(image.GetData(), w, h);
RestorePreviousContext();
}
void QViewport::SetWindowTitle(const AZStd::string& title)
{
// Do not support the WindowRequestBus changing the editor window title
@@ -1022,12 +844,6 @@ void QViewport::resizeEvent(QResizeEvent* ev)
m_width = cx;
m_height = cy;
// We queue the window resize event in case the windows is hidden.
// If the QWidget is hidden, the native windows does not resize and the
// swapchain may have the incorrect size. We need to wait
// until it's visible to trigger the resize event.
m_resizeWindowEvent = true;
GetIEditor()->GetEnv()->pSystem->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RESIZE, cx, cy);
SignalUpdate();
Update();
@@ -1035,18 +851,9 @@ void QViewport::resizeEvent(QResizeEvent* ev)
void QViewport::showEvent(QShowEvent* ev)
{
// force a context create once we're shown
// This must be queued, as the showEvent is sent before the widget is actually shown, not after
QMetaObject::invokeMethod(this, "ForceRebuildRenderContext", Qt::QueuedConnection);
QWidget::showEvent(ev);
}
void QViewport::ForceRebuildRenderContext()
{
CreateRenderContext();
}
void QViewport::moveEvent(QMoveEvent* ev)
{
QWidget::moveEvent(ev);
@@ -1058,11 +865,6 @@ bool QViewport::event(QEvent* ev)
{
bool result = QWidget::event(ev);
if (ev->type() == QEvent::WinIdChange)
{
CreateRenderContext();
}
if (ev->type() == QEvent::ShortcutOverride)
{
// When a shortcut is matched, Qt's event processing sends out a shortcut override event
@@ -104,7 +104,6 @@ public:
int Width() const;
int Height() const;
void SetSize(const QSize& size);
void GetImageOffscreen(CImageEx& image, const QSize& customSize);
// WindowRequestBus::Handler... (handler moved to cpp to resolve link issues in unity builds)
void SetWindowTitle(const AZStd::string& title);
@@ -119,7 +118,6 @@ public slots:
void Update();
protected slots:
void RenderInternal();
void ForceRebuildRenderContext();
signals:
void SignalPreRender(const SRenderContext&);
void SignalRender(const SRenderContext&);
@@ -146,12 +144,6 @@ protected:
private:
struct SPrivate;
bool CreateRenderContext();
void DestroyRenderContext();
void StorePreviousContext();
protected:
void SetCurrentContext();
void RestorePreviousContext();
private:
void UpdateBackgroundColor();
@@ -198,6 +190,4 @@ private:
std::vector<QViewportConsumer*> m_consumers;
AZStd::unique_ptr<QViewportRequests> m_viewportRequests;
AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
HWND m_lastHwnd = 0;
bool m_resizeWindowEvent = false;
};
@@ -15,8 +15,6 @@ set(FILES
EditorCommon.rc
EditorCommon.qrc
EditorCommonAPI.h
ManipScene.cpp
ManipScene.h
moc.cpp
QViewportConsumer.h
TimelineContent.h
@@ -13,11 +13,9 @@
#include "EditorCommon_precompiled.h"
#include <QViewport.h>
#include <ManipScene.h>
#include <Timeline.h>
#include <CurveEditor.h>
#include <moc_QViewport.cpp>
#include <moc_ManipScene.cpp>
#include <moc_Timeline.cpp>
#include <moc_CurveEditor.cpp>