Skip to content

Commit

Permalink
[#17] : Fixed offscreen render target support
Browse files Browse the repository at this point in the history
  • Loading branch information
ange-yaghi committed Jun 4, 2020
1 parent 1e7a95a commit 5edaf3b
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 93 deletions.
4 changes: 2 additions & 2 deletions include/yds_d3d10_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ysD3D10Device : public ysDevice {
virtual ysError SetContextMode(ysRenderingContext *context, ysRenderingContext::ContextMode mode);

virtual ysError CreateOnScreenRenderTarget(ysRenderTarget **newTarget, ysRenderingContext *context, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);
virtual ysError CreateSubRenderTarget(ysRenderTarget **newTarget, ysRenderTarget *parent, int x, int y, int width, int height);
virtual ysError ResizeRenderTarget(ysRenderTarget *target, int width, int height);
virtual ysError DestroyRenderTarget(ysRenderTarget *&target);
Expand Down Expand Up @@ -96,7 +96,7 @@ class ysD3D10Device : public ysDevice {
ysError DestroyD3D10DepthBuffer(ID3D10DepthStencilView *&depthStencil);

ysError CreateD3D10OnScreenRenderTarget(ysRenderTarget *target, ysRenderingContext *context, bool depthBuffer);
ysError CreateD3D10OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
ysError CreateD3D10OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);

ysError DestroyD3D10RenderTarget(ysRenderTarget *target);
};
Expand Down
7 changes: 4 additions & 3 deletions include/yds_d3d11_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct IDXGIFactory;
struct ID3D11Device;
struct ID3D11RasterizerState;
struct ID3D11DepthStencilView;
struct ID3D11ShaderResourceView;
enum DXGI_FORMAT;

class ysD3D11Device : public ysDevice {
Expand All @@ -32,7 +33,7 @@ class ysD3D11Device : public ysDevice {
virtual ysError SetContextMode(ysRenderingContext *context, ysRenderingContext::ContextMode mode);

virtual ysError CreateOnScreenRenderTarget(ysRenderTarget **newTarget, ysRenderingContext *context, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);
virtual ysError CreateSubRenderTarget(ysRenderTarget **newTarget, ysRenderTarget *parent, int x, int y, int width, int height);
virtual ysError ResizeRenderTarget(ysRenderTarget *target, int width, int height);
virtual ysError DestroyRenderTarget(ysRenderTarget *&target);
Expand Down Expand Up @@ -108,11 +109,11 @@ class ysD3D11Device : public ysDevice {

protected:
// Platform specific functionality
ysError CreateD3D11DepthStencilView(ID3D11DepthStencilView **newDepthStencil, int width, int height, int count, int quality);
ysError CreateD3D11DepthStencilView(ID3D11DepthStencilView **newDepthStencil, ID3D11ShaderResourceView **shaderResourceView, int width, int height, int count, int quality, bool shaderResource);
ysError DestroyD3D11DepthStencilView(ID3D11DepthStencilView *&depthStencil);

ysError CreateD3D11OnScreenRenderTarget(ysRenderTarget *target, ysRenderingContext *context, bool depthBuffer);
ysError CreateD3D11OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
ysError CreateD3D11OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);

ysError DestroyD3D11RenderTarget(ysRenderTarget *target);
};
Expand Down
2 changes: 1 addition & 1 deletion include/yds_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ysDevice : public ysContextObject {
virtual ysError CreateOnScreenRenderTarget(ysRenderTarget **newTarget, ysRenderingContext *context, bool depthBuffer) = 0;

// Create an off-screen render target
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer) = 0;
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, bool colorData = true, bool depthBuffer = true) = 0;

// Create a off-screen copy
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, const ysRenderTarget *reference);
Expand Down
4 changes: 2 additions & 2 deletions include/yds_opengl_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ysOpenGLDevice : public ysDevice {
virtual ysError SetContextMode(ysRenderingContext *context, ysRenderingContext::ContextMode mode);

virtual ysError CreateOnScreenRenderTarget(ysRenderTarget **newTarget, ysRenderingContext *context, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
virtual ysError CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);
virtual ysError CreateSubRenderTarget(ysRenderTarget **newTarget, ysRenderTarget *parent, int x, int y, int width, int height);
virtual ysError ResizeRenderTarget(ysRenderTarget *target, int width, int height);
virtual ysError DestroyRenderTarget(ysRenderTarget *&target);
Expand Down Expand Up @@ -97,7 +97,7 @@ class ysOpenGLDevice : public ysDevice {

protected:
// Hidden functionality
ysError CreateOpenGLOffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer);
ysError CreateOpenGLOffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer);
ysError DestroyOpenGLRenderTarget(ysRenderTarget *target);

};
Expand Down
8 changes: 6 additions & 2 deletions include/yds_render_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ class ysRenderTarget : public ysContextObject {
};

enum class Format {
RTF_R8G8B8A8_UNORM,
RTF_R32G32B32_FLOAT
R8G8B8A8_UNORM,
R32G32B32_FLOAT,
R32_FLOAT
};

public:
Expand All @@ -40,6 +41,8 @@ class ysRenderTarget : public ysContextObject {
int GetSampleCount() const { return m_sampleCount; }
bool HasDepthBuffer() const { return m_hasDepthBuffer; }

bool HasColorData() const { return m_hasColorData; }

ysRenderingContext *GetAssociatedContext() { return m_associatedContext; }
ysRenderTarget *GetParent() { return m_parent; }

Expand All @@ -57,6 +60,7 @@ class ysRenderTarget : public ysContextObject {
Format m_format;

int m_sampleCount;
bool m_hasColorData;
bool m_hasDepthBuffer;
bool m_depthTestEnabled;

Expand Down
18 changes: 9 additions & 9 deletions src/yds_d3d10_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ ysError ysD3D10Device::CreateOnScreenRenderTarget(ysRenderTarget **newTarget, ys
return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}

ysError ysD3D10Device::CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer) {
ysError ysD3D10Device::CreateOffScreenRenderTarget(ysRenderTarget **newTarget, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer) {
YDS_ERROR_DECLARE("CreateOffScreenRenderTarget");

if (newTarget == nullptr) return YDS_ERROR_RETURN(ysError::YDS_INVALID_PARAMETER);
*newTarget = nullptr;

ysD3D10RenderTarget *d3d10Target = m_renderTargets.NewGeneric<ysD3D10RenderTarget>();

ysError result = CreateD3D10OffScreenRenderTarget(d3d10Target, width, height, format, sampleCount, depthBuffer);
ysError result = CreateD3D10OffScreenRenderTarget(d3d10Target, width, height, format, colorData, depthBuffer);

if (result != ysError::YDS_NO_ERROR) {
m_renderTargets.Delete(d3d10Target->GetIndex());
Expand All @@ -328,7 +328,7 @@ ysError ysD3D10Device::CreateSubRenderTarget(ysRenderTarget **newTarget, ysRende
newRenderTarget->m_posY = y;
newRenderTarget->m_width = width;
newRenderTarget->m_height = height;
newRenderTarget->m_format = ysRenderTarget::Format::RTF_R8G8B8A8_UNORM;
newRenderTarget->m_format = ysRenderTarget::Format::R8G8B8A8_UNORM;
newRenderTarget->m_hasDepthBuffer = parent->HasDepthBuffer();
newRenderTarget->m_associatedContext = parent->GetAssociatedContext();
newRenderTarget->m_parent = parent;
Expand All @@ -353,7 +353,7 @@ ysError ysD3D10Device::ResizeRenderTarget(ysRenderTarget *target, int width, int
return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}
else if (target->GetType() == ysRenderTarget::Type::OffScreen) {
YDS_NESTED_ERROR_CALL( CreateD3D10OffScreenRenderTarget(target, width, height, target->GetFormat(), target->GetSampleCount(), target->HasDepthBuffer()) );
YDS_NESTED_ERROR_CALL( CreateD3D10OffScreenRenderTarget(target, width, height, target->GetFormat(), target->HasColorData(), target->HasDepthBuffer()) );
return YDS_ERROR_RETURN(ysError::YDS_NOT_IMPLEMENTED);
}
else if (target->GetType() == ysRenderTarget::Type::Subdivision) {
Expand Down Expand Up @@ -1227,7 +1227,7 @@ ysError ysD3D10Device::CreateD3D10OnScreenRenderTarget(ysRenderTarget *newTarget
newRenderTarget->m_posY = 0;
newRenderTarget->m_width = context->GetWindow()->GetScreenWidth();
newRenderTarget->m_height = context->GetWindow()->GetScreenHeight();
newRenderTarget->m_format = ysRenderTarget::Format::RTF_R8G8B8A8_UNORM;
newRenderTarget->m_format = ysRenderTarget::Format::R8G8B8A8_UNORM;
newRenderTarget->m_hasDepthBuffer = depthBuffer;
newRenderTarget->m_associatedContext = context;

Expand All @@ -1238,7 +1238,7 @@ ysError ysD3D10Device::CreateD3D10OnScreenRenderTarget(ysRenderTarget *newTarget
return YDS_ERROR_RETURN(ysError::YDS_NO_ERROR);
}

ysError ysD3D10Device::CreateD3D10OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, int sampleCount, bool depthBuffer) {
ysError ysD3D10Device::CreateD3D10OffScreenRenderTarget(ysRenderTarget *target, int width, int height, ysRenderTarget::Format format, bool colorData, bool depthBuffer) {
YDS_ERROR_DECLARE("CreateD3D10OffScreenRenderTarget");

HRESULT result;
Expand All @@ -1256,9 +1256,9 @@ ysError ysD3D10Device::CreateD3D10OffScreenRenderTarget(ysRenderTarget *target,
descBuffer.MipLevels = 1;
descBuffer.ArraySize = 1;

if (format == ysRenderTarget::Format::RTF_R32G32B32_FLOAT)
if (format == ysRenderTarget::Format::R32G32B32_FLOAT)
descBuffer.Format = DXGI_FORMAT::DXGI_FORMAT_R32G32B32_FLOAT;
else if (format == ysRenderTarget::Format::RTF_R8G8B8A8_UNORM)
else if (format == ysRenderTarget::Format::R8G8B8A8_UNORM)
descBuffer.Format = DXGI_FORMAT::DXGI_FORMAT_R8G8B8A8_UNORM;

descBuffer.SampleDesc.Count = 1;
Expand Down Expand Up @@ -1324,7 +1324,7 @@ ysError ysD3D10Device::CreateD3D10OffScreenRenderTarget(ysRenderTarget *target,
newRenderTarget->m_posY = 0;
newRenderTarget->m_width = width;
newRenderTarget->m_height = height;
newRenderTarget->m_format = ysRenderTarget::Format::RTF_R8G8B8A8_UNORM;
newRenderTarget->m_format = ysRenderTarget::Format::R8G8B8A8_UNORM;
newRenderTarget->m_hasDepthBuffer = depthBuffer;
newRenderTarget->m_associatedContext = nullptr;

Expand Down
Loading

0 comments on commit 5edaf3b

Please sign in to comment.