Skip to content

Commit

Permalink
Cleanup custom CEGUI D3D9 renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lpsd committed Oct 8, 2024
1 parent 91d0b6f commit 9682928
Show file tree
Hide file tree
Showing 16 changed files with 1,375 additions and 1,565 deletions.
6 changes: 5 additions & 1 deletion Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CLocalGUI* CSingleton<CLocalGUI>::m_pSingleton = NULL;
#endif
#define GET_WHEEL_DELTA_WPARAM(wParam) ((short)HIWORD(wParam))

const char* const DEFAULT_SKIN_NAME = "Default 2023"; // TODO: Change to whatever the default skin is if it changes
const char* const DEFAULT_SKIN_NAME = "GWEN"; // TODO: Change to whatever the default skin is if it changes

CLocalGUI::CLocalGUI()
{
Expand Down Expand Up @@ -56,6 +56,10 @@ CLocalGUI::~CLocalGUI()

void CLocalGUI::SetSkin(const char* szName)
{
// Temp override
CVARS_SET("current_skin", "GWEN");
szName = "GWEN";

bool guiWasLoaded = m_pMainMenu != NULL;
if (guiWasLoaded)
DestroyWindows();
Expand Down
6 changes: 3 additions & 3 deletions Client/gui/CGUI_Impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice)
m_pWindowManager = CEGUI::WindowManager::getSingletonPtr();
m_pWindowFactoryManager = CEGUI::WindowFactoryManager::getSingletonPtr();

auto renderMaterial = &m_pRenderer->createRenderMaterial(CEGUI::DefaultShaderType::Solid);
m_pGeometryBuffer = &m_pRenderer->createGeometryBufferColoured(*renderMaterial);
auto& renderMaterial = m_pRenderer->createRenderMaterial(CEGUI::DefaultShaderType::Textured);
m_pGeometryBuffer = &m_pRenderer->createGeometryBufferTextured(renderMaterial);

m_pResourceProvider = m_pSystem->getResourceProvider();
m_pDefaultResourceProvider = static_cast<CEGUI::DefaultResourceProvider*>(m_pSystem->getResourceProvider());
Expand Down Expand Up @@ -86,7 +86,7 @@ CGUI_Impl::CGUI_Impl(IDirect3DDevice9* pDevice)
// Set XML parser defaults
m_pXMLParser = m_pSystem->getXMLParser();

auto resolution = GetResolution();
auto& resolution = GetResolution();
CEGUI::TextureTarget* renderTextureTarget = m_pSystem->getRenderer()->createTextureTarget(false);
renderTextureTarget->declareRenderSize(CEGUI::Sizef(resolution.fX, resolution.fY));
m_pDefaultGUIContext = &m_pSystem->createGUIContext(static_cast<CEGUI::RenderTarget&>(*renderTextureTarget));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,57 @@
#ifndef _CEGUIDirect3D9GeometryBuffer_h_
#define _CEGUIDirect3D9GeometryBuffer_h_

#include "CEGUI/GeometryBuffer.h"
#include "CEGUI/Rectf.h"
#include "CEGUI/Vertex.h"
#include "CEGUI/Sizef.h"

#include "../../GeometryBuffer.h"
#include "CEGUI/RendererModules/Direct3D9/Renderer.h"
#include "../../Rectf.h"
#include "../../Quaternion.h"
#include <d3dx9.h>
#include <utility>
#include <vector>
#include <cstdint>

#include <glm/glm.hpp>

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4251)
#endif

// Start of CEGUI namespace section
namespace CEGUI
{
class Direct3D9Renderer;
class Direct3D9Texture;

//! Implementation of CEGUI::GeometryBuffer for the Direct3D 11 API.
class Direct3D9GeometryBuffer : public GeometryBuffer
/*!
\brief
Direct3D9 based implementation of the GeometryBuffer interface.
*/
class DIRECT3D9_GUIRENDERER_API Direct3D9GeometryBuffer : public GeometryBuffer
{
public:
//! Constructor
Direct3D9GeometryBuffer(Direct3D9Renderer& owner, LPDIRECT3DDEVICE9 device, RefCounted<RenderMaterial> renderMaterial);
Direct3D9GeometryBuffer(Direct3D9Renderer& owner, LPDIRECT3DDEVICE9 device, CEGUI::RefCounted<RenderMaterial> renderMaterial);

//! return pointer to D3DXMATRIX used as world transform.
const D3DXMATRIX* getMatrix() const;

// Implement GeometryBuffer interface.
virtual void draw(std::uint32_t drawModeMask = DrawModeMaskAll) const;
virtual void setTranslation(const glm::vec3& v);
virtual void setRotation(const glm::quat& r);
virtual void setPivot(const glm::vec3& p);
virtual void appendVertex(const TexturedColouredVertex& vertex);
virtual void appendGeometry(const TexturedColouredVertex* const vbuff, unsigned int vertex_count);
virtual void setActiveTexture(Texture* texture);
virtual void reset();
virtual Texture* getActiveTexture() const;
virtual unsigned int getVertexCount() const;
virtual unsigned int getBatchCount() const;
virtual void setRenderEffect(RenderEffect* effect);
virtual RenderEffect* getRenderEffect();
virtual void setClippingActive(const bool active);
virtual bool isClippingActive() const;
virtual void setClippingRegion(const Rectf& region);
// implementation of abstract members from GeometryBuffer
void draw(uint32_t drawModeMask = DrawModeMaskAll) const override;
void setTranslation(const glm::vec3& t);
void setRotation(const glm::quat& r);
void setPivot(const glm::vec3& p);
void setClippingRegion(const Rectf& region);
void setActiveTexture(Texture* texture);
Texture* getActiveTexture() const;
unsigned int getVertexCount() const;
unsigned int getBatchCount() const;
void setRenderEffect(RenderEffect* effect);
RenderEffect* getRenderEffect();
void setClippingActive(const bool active);
bool isClippingActive() const;

protected:
//! perform batch management operations prior to adding new geometry.
void performBatchManagement();

//! update cached matrix
void updateMatrix() const;

Expand All @@ -95,7 +95,7 @@ namespace CEGUI
//! type to track info for per-texture sub batches of geometry
struct BatchInfo
{
IDirect3DTexture9* texture;
LPDIRECT3DTEXTURE9 texture;
unsigned int vertexCount;
bool clip;
};
Expand Down Expand Up @@ -124,12 +124,12 @@ namespace CEGUI
glm::vec3 d_pivot;
//! RenderEffect that will be used by the GeometryBuffer
RenderEffect* d_effect;
//! The D3D Device
LPDIRECT3DDEVICE9 d_device;
//! model matrix cache
mutable D3DXMATRIX d_matrix;
//! true when d_matrix is valid and up to date
mutable bool d_matrixValid;
//! The D3D Device
LPDIRECT3DDEVICE9 d_device;
};

} // namespace CEGUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,64 +28,64 @@
#define _CEGUIDirect3D9RenderTarget_h_

#include "CEGUI/RendererModules/Direct3D9/Renderer.h"
#include "CEGUI/RenderTarget.h"
#include "CEGUI/Rectf.h"

#include "../../RenderTarget.h"
#include "../../Rectf.h"
#include <d3dx9.h>

#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4251)
# pragma warning(push)
# pragma warning(disable : 4251)
#endif

// Start of CEGUI namespace section
namespace CEGUI
{
/*!
\brief
Intermediate Direct3D9 implementation of a RenderTarget.
*/

class DIRECT3D9_GUIRENDERER_API Direct3D9RenderTarget : virtual public RenderTarget
{
public:
//! Constructor
Direct3D9RenderTarget(Direct3D9Renderer& owner);
/*!
\brief
Intermediate Direct3D9 implementation of a RenderTarget.
*/
template <typename T = RenderTarget>
class DIRECT3D9_GUIRENDERER_API Direct3D9RenderTarget : public T
{
public:
//! Constructor
Direct3D9RenderTarget(Direct3D9Renderer& owner, bool addStencilBuffer);

// implement parts of RenderTarget interface
void draw(const GeometryBuffer& buffer);
void draw(const RenderQueue& queue);
void setArea(const Rectf& area);
const Rectf& getArea() const;
void activate();
void deactivate();

// implement parts of RenderTarget interface
virtual void draw(const GeometryBuffer& buffer);
virtual void draw(const RenderQueue& queue);
virtual void setArea(const Rectf& area);
virtual const Rectf& getArea() const;
virtual void activate();
virtual void deactivate();
virtual void unprojectPoint(const GeometryBuffer& buff, const glm::vec2& p_in, glm::vec2& p_out) const;
virtual Direct3D9Renderer& getOwner() override { return d_owner; }
// implementing the virtual function with a covariant return type
Direct3D9Renderer& getOwner() override;

protected:
//! helper that initialises the cached matrix
void updateMatrix() const;
//! helper to initialise the D3DVIEWPORT9 \a vp for this target.
void setupViewport(D3DVIEWPORT9& vp) const;
protected:
//! helper that initialises the cached matrix
void updateMatrix() const;
//! helper to initialise the D3DVIEWPORT9 \a vp for this target.
void setupViewport(D3DVIEWPORT9& vp) const;

//! Direct3D9Renderer that created this object
Direct3D9Renderer& d_owner;
//! Direct3DDevice9 interface obtained from our owner.
LPDIRECT3DDEVICE9 d_device;
//! holds defined area for the RenderTarget
Rectf d_area;
//! projection / view matrix cache
mutable D3DXMATRIX d_matrix;
//! true when d_matrix is valid and up to date
mutable bool d_matrixValid;
//! tracks viewing distance (this is set up at the same time as d_matrix)
mutable float d_viewDistance;
};
//! Direct3D9Renderer that created this object
Direct3D9Renderer& d_owner;
//! Direct3DDevice9 interface obtained from our owner.
LPDIRECT3DDEVICE9 d_device;
//! holds defined area for the RenderTarget
Rectf d_area;
//! projection / view matrix cache
mutable D3DXMATRIX d_matrix;
//! true when d_matrix is valid and up to date
mutable bool d_matrixValid;
//! tracks viewing distance (this is set up at the same time as d_matrix)
mutable float d_viewDistance;
};

} // namespace CEGUI
} // End of CEGUI namespace section

#if defined(_MSC_VER)
#pragma warning(pop)
# pragma warning(pop)
#endif

#endif // end of guard _CEGUIDirect3D9RenderTarget_h_
#endif // end of guard _CEGUIDirect3D9RenderTarget_h_
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#ifndef _CEGUIDirect3D9Renderer_h_
#define _CEGUIDirect3D9Renderer_h_

#include "CEGUI/Base.h"
#include "CEGUI/Renderer.h"
#include "CEGUI/Sizef.h"
#include "CEGUI/UVector.h"
#include "../../Renderer.h"
#include "../../Sizef.h"

#include <glm/glm.hpp>

#include <d3d9.h>
#include <vector>
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace CEGUI
\return
Reference to the CEGUI::Direct3D9Renderer object that was created.
*/
static Direct3D9Renderer& bootstrapSystem(LPDIRECT3DDEVICE9 device, const int abi = CEGUI_VERSION_ABI, std::string moduleDir = "");
static Direct3D9Renderer& bootstrapSystem(LPDIRECT3DDEVICE9 device, const int abi = CEGUI_VERSION_ABI, String moduleDir = "");

/*!
\brief
Expand Down Expand Up @@ -160,31 +160,31 @@ namespace CEGUI
//! set the render states for the specified BlendMode.
void setupRenderingBlendMode(const BlendMode mode, const bool force = false);

// Implementation of Renderer interface.
virtual RenderTarget& getDefaultRenderTarget();
// implement Renderer interface
RenderTarget& getDefaultRenderTarget();
virtual RefCounted<RenderMaterial> createRenderMaterial(const DefaultShaderType shaderType) const;
virtual GeometryBuffer& createGeometryBufferColoured(RefCounted<RenderMaterial> renderMaterial);
virtual GeometryBuffer& createGeometryBufferTextured(RefCounted<RenderMaterial> renderMaterial);
virtual void destroyGeometryBuffer(const GeometryBuffer& buffer);
virtual void destroyAllGeometryBuffers();
virtual TextureTarget* createTextureTarget(bool addStencilBuffer);
virtual void destroyTextureTarget(TextureTarget* target);
virtual void destroyAllTextureTargets();
virtual Texture& createTexture(const CEGUI::String& name);
virtual Texture& createTexture(const CEGUI::String& name, const String& filename, const String& resourceGroup);
virtual Texture& createTexture(const CEGUI::String& name, const Sizef& size);
virtual void destroyTexture(Texture& texture);
virtual void destroyTexture(const CEGUI::String& name);
virtual void destroyAllTextures();
virtual Texture& getTexture(const String&) const;
virtual bool isTextureDefined(const String& name) const;
virtual void beginRendering();
virtual void endRendering();
virtual void setDisplaySize(const Sizef& sz);
virtual const Sizef& getDisplaySize() const;
virtual unsigned int getMaxTextureSize() const;
virtual const String& getIdentifierString() const;
virtual GeometryBuffer& createGeometryBufferColoured(CEGUI::RefCounted<RenderMaterial> renderMaterial);
virtual GeometryBuffer& createGeometryBufferTextured(CEGUI::RefCounted<RenderMaterial> renderMaterial);
void destroyGeometryBuffer(const GeometryBuffer& buffer);
void destroyAllGeometryBuffers();
TextureTarget* createTextureTarget(bool addStencilBuffer) override;
void destroyTextureTarget(TextureTarget* target);
void destroyAllTextureTargets();
Texture& createTexture(const String& name);
Texture& createTexture(const String& name, const String& filename, const String& resourceGroup);
Texture& createTexture(const String& name, const Sizef& size);
void destroyTexture(Texture& texture);
void destroyTexture(const String& name);
void destroyAllTextures();
Texture& getTexture(const String& name) const;
bool isTextureDefined(const String& name) const;
void beginRendering();
void endRendering();
void setDisplaySize(const Sizef& sz);
const Sizef& getDisplaySize() const;
const glm::vec2& getDisplayDPI() const;
unsigned int getMaxTextureSize() const;
const String& getIdentifierString() const;

private:
//! Constructor for Direct3D9 Renderer objects.
Expand All @@ -205,17 +205,6 @@ namespace CEGUI
//! returns next power of 2 size if \a size is not power of 2
float getSizeNextPOT(float sz) const;

//! Initialises the ShaderManager and the required D3D9 shaders
void initialiseShaders();
//! Initialises the D3D9 ShaderWrapper for textured objects
void initialiseStandardTexturedShaderWrapper();
//! Initialises the D3D9 ShaderWrapper for coloured objects
void initialiseStandardColouredShaderWrapper();
//! Wrapper of the OpenGL shader we will use for textured geometry
Direct3D9ShaderWrapper* d_shaderWrapperTextured;
//! Wrapper of the OpenGL shader we will use for solid geometry
Direct3D9ShaderWrapper* d_shaderWrapperSolid;

//! String holding the renderer identification text.
static String d_rendererID;
//! Direct3DDevice9 interface we were given when constructed.
Expand Down Expand Up @@ -246,6 +235,11 @@ namespace CEGUI
bool d_supportNonSquareTex;
//! What we think is the active blendine mode
BlendMode d_activeBlendMode;

//! Shaderwrapper for textured & coloured vertices
Direct3D9ShaderWrapper* d_shaderWrapperTextured;
//! Shaderwrapper for coloured vertices
Direct3D9ShaderWrapper* d_shaderWrapperSolid;
};

} // namespace CEGUI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
#ifndef _CEGUIDirect3D9Texture_h_
#define _CEGUIDirect3D9Texture_h_

#include "CEGUI/Base.h"
#include "CEGUI/Renderer.h"
#include "CEGUI/Texture.h"
#include "../../Base.h"
#include "../../Renderer.h"
#include "../../Texture.h"
#include "CEGUI/RendererModules/Direct3D9/Renderer.h"

#include <glm/glm.hpp>

#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4251)
Expand Down
Loading

0 comments on commit 9682928

Please sign in to comment.