Jump to content
  • Advertisement
Sign in to follow this  
cozzie

DX11 Where to set meshes, materials etc?

This topic is 632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

I've arrived at the moment that I need to choose 'where' to implement functions for setting a mesh, material etc. (in my 3d engine).

For sure I'll be using a MeshRenderer system/class, that will be a member of the Renderer class. The renderer class will have a DrawMesh function, that'll be forwarded to the MeshRenderer.

 

The engine works with inheritance:

- IDevice base class -> DX11Device class inherits

- IBuffer base class -> DX11Buffer class (with GetAPIPtr virtual function)

etc.

 

I've thought of 2 approaches:

 

 

1. IDevice gets members for SetMesh (i.e. buffers), SetMaterial etc., all taking abstracted class objects (API independent).
The low-level API calls are all done within the IDevice (virtual), implemented in DX11Device (SetMesh etc.).
For example: IDevice::SetMesh -> DX11Device::SetMesh, will do something like mD3ddev->SetIndexbuffer(pBuffer->GetAPIPtr())
The MeshRenderer is API independent, and will do the calls to IDevice.
 
2. I create a IMeshRenderer with all virtual functions (SetMesh, SetMaterial etc), and a child class: DX11MeshRenderer.
The inherited class will do the lowlevel API calls using IDevice ptr->GetAPIPtr(). Here also MeshRenderer is member of Renderer
 
From a design point of view I'm leaning towards option 1.
But the con here is that IDevice will get quite a list of member functions, within this it's already like below.
 
Any input is appreciated.
 
class IDevice 
{
public:
	IDevice(CRendererSettings *pSettings, const CR_BUFFER_FORMAT pBackBufferFormat, const CR_BUFFER_FORMAT pDepthBufferFormat);
	virtual ~IDevice();

	template<typename T> IBuffer* CreateBuffer(const CR_BUFFER_TYPE pType, const T* pData, const size_t pNrElements, const bool pDynamic, const bool pGPUWrite)
	{
		return OnCreateBuffer(pType, pData, sizeof(T)*pNrElements, pDynamic, pGPUWrite);
	}

	virtual void* GetAPIDevicePtr()		const = 0;
	virtual void* GetAPIContextPtr()	const = 0;

	virtual bool Startup() = 0;
	virtual bool UpdateFullscreenState() = 0;
	virtual bool Resize() = 0;
	virtual bool CheckAASupport(const CR_BUFFER_FORMAT pFormat, const uint pNrSamples) = 0;

	virtual bool SetRenderTargets(const IRenderTarget **pRT, const uint pNumRt) = 0;
	virtual void ResetRenderTargets() = 0;
	virtual bool Present(const IRenderTarget &pRT) = 0;

	virtual bool ClearRTView(const IRenderTarget &pRT, const float pColor[4]) = 0;
	virtual bool ClearDepthView() = 0;

	virtual bool SetViewports(const CViewport **pViewports, const uint pNumVp) = 0;

	virtual IBuffer* OnCreateBuffer(const CR_BUFFER_TYPE pType, const void* pData, const size_t pBufferSize, const bool pDynamic, const bool pGPUWrite) = 0;

	// Rendering and drawing
	// OR IMeshRenderer???

protected:
	virtual bool Create() = 0;

	virtual bool CreateSwapchain() = 0;
	virtual bool ResizeSwapchain() = 0;
	virtual bool CreateDepthBuffer() = 0;

	CRendererSettings	*mSettings;

	CR_BUFFER_FORMAT	mBackBufferFormat;
	CR_BUFFER_FORMAT	mDepthBufferFormat;
};

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!