diff options
author | rlp@google.com <rlp@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:02:28 +0000 |
---|---|---|
committer | rlp@google.com <rlp@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 22:02:28 +0000 |
commit | 910a39ca11c5cfa20cb03e408586b63d3ac321d8 (patch) | |
tree | bcfbfe7891ca14063d6a5c1bd2de466bea1b5681 /o3d | |
parent | 1bdffff7418eec3f0cac4385078484628a9ed35e (diff) | |
download | chromium_src-910a39ca11c5cfa20cb03e408586b63d3ac321d8.zip chromium_src-910a39ca11c5cfa20cb03e408586b63d3ac321d8.tar.gz chromium_src-910a39ca11c5cfa20cb03e408586b63d3ac321d8.tar.bz2 |
Review URL: http://codereview.chromium.org/176026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc | 86 | ||||
-rw-r--r-- | o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h | 91 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/render_surface_cb.cc | 23 | ||||
-rw-r--r-- | o3d/core/cross/command_buffer/render_surface_cb.h | 59 | ||||
-rw-r--r-- | o3d/core/cross/render_surface_test.cc | 156 |
5 files changed, 323 insertions, 92 deletions
diff --git a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc index 7be89d4..987eceb 100644 --- a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc +++ b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc @@ -33,6 +33,7 @@ // This file implements the D3D9 versions of the render surface resources,
// as well as the related GAPID3D9 function implementations.
+#include "command_buffer/service/win/d3d9/render_surface_d3d9.h"
#include "command_buffer/service/win/d3d9/gapi_d3d9.h"
#include "command_buffer/service/win/d3d9/texture_d3d9.h"
@@ -45,44 +46,63 @@ RenderSurfaceD3D9::RenderSurfaceD3D9(int width, int mip_level,
int side,
TextureD3D9 *texture,
- IDirect3DSurface9* direct3d_surface)
- : width_(width), height_(height), mip_level_(mip_level), texture_(texture),
- direct3d_surface_(direct3d_surface) {
+ IDirect3DSurface9 *direct3d_surface)
+ : width_(width),
+ height_(height),
+ mip_level_(mip_level),
+ texture_(texture),
+ direct3d_surface_(direct3d_surface) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0);
+ DCHECK_GT(mip_level, -1);
+ DCHECK(texture);
}
RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi,
- int width,
- int height,
- int mip_level,
- int side,
- TextureD3D9 *texture) {
+ int width,
+ int height,
+ int mip_level,
+ int side,
+ TextureD3D9 *texture) {
+ DCHECK(gapi);
DCHECK_GT(width, 0);
DCHECK_GT(height, 0);
+ DCHECK_GT(mip_level, -1);
+ DCHECK(texture);
CComPtr<IDirect3DSurface9> direct3d_surface_handle;
bool success =
- texture->CreateRenderSurface(width, height, mip_level, side,
- &direct3d_surface_handle);
+ texture->CreateRenderSurface(width, height, mip_level, side,
+ &direct3d_surface_handle);
if (!success || direct3d_surface_handle == NULL) {
// If the surface was not created properly, delete and return nothing.
return NULL;
}
- RenderSurfaceD3D9* render_surface =
- new RenderSurfaceD3D9(width, height, mip_level, side, texture,
- direct3d_surface_handle);
+ RenderSurfaceD3D9 *render_surface =
+ new RenderSurfaceD3D9(width,
+ height,
+ mip_level,
+ side,
+ texture,
+ direct3d_surface_handle);
return render_surface;
}
RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9(
int width,
int height,
- IDirect3DSurface9* direct3d_surface)
- : width_(width), height_(height), direct3d_surface_(direct3d_surface) {
+ IDirect3DSurface9 *direct3d_surface)
+ : width_(width),
+ height_(height),
+ direct3d_surface_(direct3d_surface) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0);
}
RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create(
GAPID3D9 *gapi,
int width,
int height) {
+ DCHECK(gapi);
DCHECK_GT(width, 0);
DCHECK_GT(height, 0);
@@ -90,20 +110,22 @@ RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create( gapi->d3d_device()->CreateDepthStencilSurface(
width,
height,
- D3DFMT_D24S8,
- D3DMULTISAMPLE_NONE,
- 0,
- FALSE,
+ D3DFMT_D24S8, // d3d format
+ D3DMULTISAMPLE_NONE, // multisampling type
+ 0, // multisample quality level
+ FALSE, // z-buffer discarding disabled
&direct3d_surface,
- NULL);
+ NULL); // This parameter is required to be NULL.
if (direct3d_surface == NULL) {
return NULL;
}
- RenderDepthStencilSurfaceD3D9* depth_stencil =
+ RenderDepthStencilSurfaceD3D9 *depth_stencil =
new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface);
return depth_stencil;
}
+// GAPI Interface functions ---------------------------------------------------
+
// Copies the data from a texture resource.
BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface(
ResourceID id,
@@ -120,7 +142,7 @@ BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface( if (!texture->render_surfaces_enabled()) {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
} else {
- RenderSurfaceD3D9* render_surface = RenderSurfaceD3D9::Create(this,
+ RenderSurfaceD3D9 *render_surface = RenderSurfaceD3D9::Create(this,
width,
height,
mip_level,
@@ -139,8 +161,8 @@ BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) { return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
return render_surfaces_.Destroy(id) ?
- BufferSyncInterface::PARSE_NO_ERROR :
- BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ BufferSyncInterface::PARSE_NO_ERROR :
+ BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface(
@@ -151,7 +173,7 @@ BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface( // This will delete the current surface which would be bad.
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
- RenderDepthStencilSurfaceD3D9* depth_surface =
+ RenderDepthStencilSurfaceD3D9 *depth_surface =
RenderDepthStencilSurfaceD3D9::Create(this, width, height);
if (depth_surface == NULL) {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
@@ -165,26 +187,26 @@ BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) { return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
return depth_surfaces_.Destroy(id) ?
- BufferSyncInterface::PARSE_NO_ERROR :
- BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ BufferSyncInterface::PARSE_NO_ERROR :
+ BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface(
ResourceID render_surface_id,
ResourceID depth_stencil_id) {
RenderSurfaceD3D9 *d3d_render_surface =
- render_surfaces_.Get(render_surface_id);
+ render_surfaces_.Get(render_surface_id);
RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface =
- depth_surfaces_.Get(depth_stencil_id);
+ depth_surfaces_.Get(depth_stencil_id);
if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
IDirect3DSurface9 *d3d_surface =
- d3d_render_surface ? d3d_render_surface->GetSurfaceHandle() : NULL;
+ d3d_render_surface ? d3d_render_surface->direct3d_surface() : NULL;
IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ?
- d3d_render_depth_surface->GetSurfaceHandle() : NULL;
+ d3d_render_depth_surface->direct3d_surface() : NULL;
// Get the device and set the render target and the depth stencil surface.
IDirect3DDevice9 *device = this->d3d_device();
@@ -199,7 +221,7 @@ BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface( void GAPID3D9::SetBackSurfaces() {
// Get the device and set the render target and the depth stencil surface.
IDirect3DDevice9 *device = this->d3d_device();
- HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_)); + HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_));
HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_));
}
diff --git a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h index e9d8614..428c718 100644 --- a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h +++ b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h @@ -37,61 +37,120 @@ // render surface-related resource classes. #include <d3d9.h> +#include "base/scoped_ptr.h" #include "command_buffer/common/cross/gapi_interface.h" -#include "command_buffer/service/win/d3d9/d3d9_utils.h" #include "command_buffer/service/cross/resource.h" +#include "command_buffer/service/win/d3d9/d3d9_utils.h" +#include "command_buffer/service/win/d3d9/texture_d3d9.h" namespace o3d { namespace command_buffer { class GAPID3D9; +// The RenderSurfaceD3D class represents a render surface resource in the d3d +// backend of the command buffer server. class RenderSurfaceD3D9 : public RenderSurface { public: + + // Creates a render surface resource based on D3D. + // Parameters: + // width - width of the surface to be created. Must match width of texture + // at mip_level. + // height - height of the surface to be created. Must match width of + // texture at mip_level. + // mip_level - mip level of the texture to which the render surface maps. + // side - side of a cube if texture is a cube texture. Does not apply to + // texture 2d's. + // texture - the texture to which this render surface maps. Not owned by + // the RenderSurfaceD3D9. + // direct3d_surface - a surface to be used as this render surface's + // rendering surface. The new RenderSurfaceD3D9 will own the + // direct3d_surface. RenderSurfaceD3D9(int width, int height, int mip_level, int side, - TextureD3D9 *texture,
- IDirect3DSurface9* direct3d_surface); + TextureD3D9 *texture, + IDirect3DSurface9 *direct3d_surface); + + // Destructor for the render surface. virtual ~RenderSurfaceD3D9() {} + // Performs the setup necessary to create a render surface resource based on + // D3D and returns a new one if possibe. + // Parameters: + // gapi - the gapi interface to D3D. + // width - width of the surface to be created. Must match width of texture + // at mip_level. + // height - height of the surface to be created. Must match width of + // texture at mip_level. + // mip_level - mip level of the texture to which the render surface maps. + // side - side of a cube if texture is a cube texture. Does not apply to + // texture 2d's. + // texture - the texture to which this render surface maps. + // Returns: + // a new RenderSurfaceD3D9 or NULL on failure static RenderSurfaceD3D9* Create(GAPID3D9 *gapi, int width, int height, int mip_level, int side, TextureD3D9 *texture); - IDirect3DSurface9* GetSurfaceHandle() const { + + // Returns a reference to the actual direct3d surface that is rendered to. + IDirect3DSurface9* direct3d_surface() const { return direct3d_surface_; } private: CComPtr<IDirect3DSurface9> direct3d_surface_; - unsigned int width_; - unsigned int height_; - unsigned int mip_level_; - TextureD3D9* texture_; + int width_; + int height_; + int mip_level_; + TextureD3D9 *texture_; DISALLOW_COPY_AND_ASSIGN(RenderSurfaceD3D9); }; +// The RenderDepthStencilSurfaceD3D class represents a depth stencil surface +// resource in the d3d backend of the command buffer server. class RenderDepthStencilSurfaceD3D9 : public RenderDepthStencilSurface { public: + + // Creates a depth stencil surface resource based on D3D. + // Parameters: + // width - width of the surface to be created. + // height - height of the surface to be created. + // direct3d_surface - a surface to be used as this depth stencil surface's + // rendering rendering surface. The new RenderDepthStencilSurfaceD3D9 + // will own the direct3d_surface. RenderDepthStencilSurfaceD3D9(int width, int height, - IDirect3DSurface9* direct3d_surface); + IDirect3DSurface9 *direct3d_surface); + + // Destructor for the depth stencil surface. virtual ~RenderDepthStencilSurfaceD3D9() {} - static RenderDepthStencilSurfaceD3D9* Create( - GAPID3D9 *gapi, - int width, - int height); - IDirect3DSurface9* GetSurfaceHandle() const { + + // Performs the setup necessary to create a depth stencil surface resource + // based on D3D and returns a new one if possibe. + // Parameters: + // gapi - the gapi interface to D3D. + // width - width of the surface to be created. + // height - height of the surface to be created. + // Returns: + // a new RenderDepthStencilSurfaceD3D9 or NULL on failure. + static RenderDepthStencilSurfaceD3D9* Create(GAPID3D9 *gapi, + int width, + int height); + + // Returns a reference to the actual direct3d surface that is rendered to. + IDirect3DSurface9* direct3d_surface() const { return direct3d_surface_; } private: CComPtr<IDirect3DSurface9> direct3d_surface_; - unsigned int width_; - unsigned int height_; + int width_; + int height_; DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceD3D9); }; diff --git a/o3d/core/cross/command_buffer/render_surface_cb.cc b/o3d/core/cross/command_buffer/render_surface_cb.cc index 0f57536e..f65ce3d 100644 --- a/o3d/core/cross/command_buffer/render_surface_cb.cc +++ b/o3d/core/cross/command_buffer/render_surface_cb.cc @@ -49,8 +49,12 @@ RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator, RendererCB *renderer) : RenderSurface(service_locator, width, height, texture), resource_id_(command_buffer::kInvalidResource), - renderer_(renderer) { + renderer_(renderer) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0);
+ DCHECK_GT(mip_level, -1); DCHECK(texture); + DCHECK(renderer); ResourceID id = renderer_->render_surface_ids().AllocateID(); resource_id_ = id; @@ -58,13 +62,13 @@ RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator, CommandBufferEntry args[4]; args[0].value_uint32 = id; args[1].value_uint32 = - create_render_surface_cmd::Width::MakeValue(width) | - create_render_surface_cmd::Height::MakeValue(height); + create_render_surface_cmd::Width::MakeValue(width) | + create_render_surface_cmd::Height::MakeValue(height); args[2].value_uint32 = create_render_surface_cmd::Levels::MakeValue(mip_level) | create_render_surface_cmd::Side::MakeValue(side); args[3].value_uint32 = - reinterpret_cast<ResourceID>(texture->GetTextureHandle()); + reinterpret_cast<ResourceID>(texture->GetTextureHandle()); helper->AddCommand(command_buffer::CREATE_RENDER_SURFACE, 4, args); } @@ -73,7 +77,7 @@ RenderSurfaceCB::~RenderSurfaceCB() { } void RenderSurfaceCB::Destroy() { - // This should never get called during rendering. + // This should never be called during rendering. if (resource_id_ != command_buffer::kInvalidResource) { CommandBufferHelper *helper = renderer_->helper(); CommandBufferEntry args[1]; @@ -91,15 +95,18 @@ RenderDepthStencilSurfaceCB::RenderDepthStencilSurfaceCB( RendererCB *renderer) : RenderDepthStencilSurface(service_locator, width, height), resource_id_(command_buffer::kInvalidResource), - renderer_(renderer) { + renderer_(renderer) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0); + DCHECK(renderer); ResourceID id = renderer_->depth_surface_ids().AllocateID(); resource_id_ = id; CommandBufferHelper *helper = renderer_->helper(); CommandBufferEntry args[2]; args[0].value_uint32 = id; args[1].value_uint32 = - create_render_surface_cmd::Width::MakeValue(width) | - create_render_surface_cmd::Height::MakeValue(height); + create_render_surface_cmd::Width::MakeValue(width) | + create_render_surface_cmd::Height::MakeValue(height); helper->AddCommand(command_buffer::CREATE_DEPTH_SURFACE, 2, args); } diff --git a/o3d/core/cross/command_buffer/render_surface_cb.h b/o3d/core/cross/command_buffer/render_surface_cb.h index 76581ac..357d0f7 100644 --- a/o3d/core/cross/command_buffer/render_surface_cb.h +++ b/o3d/core/cross/command_buffer/render_surface_cb.h @@ -33,16 +33,39 @@ #ifndef O3D_CORE_CROSS_COMMAND_BUFFER_RENDER_SURFACE_CB_H_
#define O3D_CORE_CROSS_COMMAND_BUFFER_RENDER_SURFACE_CB_H_
+// This file contains the definition of the CB versions of
+// render surface sub-classes.
+
#include "core/cross/render_surface.h"
#include "core/cross/command_buffer/renderer_cb.h"
#include "command_buffer/common/cross/resource.h"
namespace o3d {
+// The RenderSurfaceCB class represents a render surface in the core library
+// of the client for command buffers. This class is responsible for sending
+// calls across the command buffer to create an actual render surface resource
+// on the server.
class RenderSurfaceCB : public RenderSurface {
public:
typedef SmartPointer<RenderSurfaceCB> Ref;
+ // The render surface maintains a reference to its texture and renderer but
+ // does not own them. The owner of the render surface is responsible for
+ // properly deleting any textures.
+ // Parameters:
+ // service_locator - for central lookup. Not owned by RenderSurfaceCB.
+ // width - width of the bitmap for this render surface. It must match the
+ // the width of the texture at 'mip_level'
+ // height - height of the bitmap for this render surface. It must match the
+ // the height of the texture at 'mip_level'
+ // mip_level - mip level of 'texture' for this render surface.
+ // side - which side of a cube texture the render surface represents. The
+ // 'side' parameter will not be used for a texture2d render surface.
+ // texture - the texture this render surface maps to. Not owned by
+ // RenderSurfaceCB.
+ // renderer - the renderer to render to render surface. Not owned by
+ // RenderSurfaceCB.
RenderSurfaceCB(ServiceLocator *service_locator,
int width,
int height,
@@ -50,41 +73,65 @@ class RenderSurfaceCB : public RenderSurface { int side,
Texture *texture,
RendererCB *renderer);
- virtual ~RenderSurfaceCB(); - + virtual ~RenderSurfaceCB();
+
+ // The CB specific implementation of GetBitmap.
+ // Returns:
+ // a reference to the underlying bitmap of the render surface.
virtual Bitmap::Ref PlatformSpecificGetBitmap() const {
// TODO(rlp): Add this functionality.
DCHECK(false);
return Bitmap::Ref();
}
+ // Destroys any data structures associated with the render surface and
+ // resets any allocated IDs. This function should never be called during
+ // rendering.
virtual void Destroy();
- // Gets the render surface resource ID.
+ // Returns the render surface resource ID.
command_buffer::ResourceID resource_id() const { return resource_id_; }
+
private:
command_buffer::ResourceID resource_id_;
- RendererCB* renderer_;
+ RendererCB *renderer_;
DISALLOW_COPY_AND_ASSIGN(RenderSurfaceCB);
};
+// The RenderDepthStencilSurfaceCB class represents a depth stencil surface in
+// the core library of the client for command buffers. This class is
+// responsible for sending calls across the command buffer to create an actual
+// depth stencil surface resource on the server.
class RenderDepthStencilSurfaceCB : public RenderDepthStencilSurface {
public:
typedef SmartPointer<RenderDepthStencilSurfaceCB> Ref;
+ // The depth stencil surface maintains a reference to its renderer which is
+ // also what typically creates it (though not always). The depth stencil
+ // does not maintain ownership of the renderer.
+ // Parameters:
+ // service_locator - for central lookup.
+ // width - width of the bitmap for this render surface.
+ // height - height of the bitmap for this render surface.
+ // renderer - the renderer to render to render surface. Not owned by
+ // RenderDepthStencilSurfaceCB.
RenderDepthStencilSurfaceCB(ServiceLocator *service_locator,
int width,
int height,
RendererCB *renderer);
virtual ~RenderDepthStencilSurfaceCB() {}
+ // Destroys any data structures associated with the render surface and
+ // resets any allocated IDs. This function should never be called during
+ // rendering.
virtual void Destroy();
- // Gets the render depth stencil surface resource ID.
+ // Returns the render depth stencil surface resource ID.
command_buffer::ResourceID resource_id() const { return resource_id_; }
+
private:
command_buffer::ResourceID resource_id_;
- RendererCB* renderer_;
+ RendererCB *renderer_;
DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceCB);
};
diff --git a/o3d/core/cross/render_surface_test.cc b/o3d/core/cross/render_surface_test.cc index 34e1e6d..5aafbfe 100644 --- a/o3d/core/cross/render_surface_test.cc +++ b/o3d/core/cross/render_surface_test.cc @@ -36,6 +36,7 @@ #include "core/cross/pack.h"
#include "core/cross/renderer.h"
#include "core/cross/bitmap.h"
+#include "core/cross/features.h"
#include "core/cross/texture.h"
#include "core/cross/render_surface.h"
#include "core/cross/render_surface_set.h"
@@ -43,48 +44,102 @@ #include "core/cross/error_status.h"
// Defined in testing_common.cc, for each platform.
-extern o3d::DisplayWindow* g_display_window;
+extern o3d::DisplayWindow *g_display_window;
namespace o3d {
-class RenderSurfaceTest : public testing::Test {
+// A mock render which pushes commands to the renderer so that
+// actual rendering calls that maintain state can be handled by a
+// variable rather than actually rendering.
+class MockRenderer {
public:
- RenderSurfaceTest()
- : object_manager_(g_service_locator),
- error_status_(g_service_locator) {
+ // Creates a forwarding render class that pushes functionality to be tested
+ // to the desired renderer and handles other functionality on its own.
+ explicit MockRenderer(Renderer *renderer) : renderer_(renderer) {}
+
+ virtual ~MockRenderer() {}
+
+ // Rather than actually rendering, this just sets the state in the renderer.
+ void StartRendering() {
+ renderer_->set_rendering(true);
+ }
+
+ // This resets the state in the renderer.
+ void FinishRendering() {
+ renderer_->set_rendering(false);
+ }
+
+ // Pushes SetRenderSurfaces to the renderer.
+ void SetRenderSurfaces(const RenderSurface *surface,
+ const RenderDepthStencilSurface *depth_surface,
+ bool is_back_buffer) {
+ renderer_->SetRenderSurfaces(surface, depth_surface, is_back_buffer);
}
- Renderer* renderer() {
- return g_renderer;
+ // Pushes GetRenderSurfaces to the renderer.
+ void GetRenderSurfaces(const RenderSurface **surface,
+ const RenderDepthStencilSurface **depth_surface,
+ bool *is_back_buffer) {
+ renderer_->GetRenderSurfaces(surface, depth_surface, is_back_buffer);
}
+ private:
+ Renderer *renderer_;
+};
+
+// Class for testing render surfaces and associated functionality.
+class RenderSurfaceTest : public testing::Test {
+ public:
+ RenderSurfaceTest()
+ : object_manager_(g_service_locator),
+ error_status_(g_service_locator) {}
protected:
virtual void SetUp() {
+ service_locator_ = new ServiceLocator;
+ features_ = new Features(service_locator_);
pack_ = object_manager_->CreatePack();
- g_renderer->StartRendering();
+ renderer_ = new MockRenderer(g_renderer);
+ renderer_->StartRendering();
}
virtual void TearDown() {
- g_renderer->FinishRendering();
+ renderer_->FinishRendering();
pack_->Destroy();
error_status_.ClearLastError();
+ delete features_;
+ delete service_locator_;
+ delete renderer_;
+ }
+
+ ServiceLocator* service_locator() const {
+ return service_locator_;
+ }
+
+ MockRenderer* renderer() const {
+ return renderer_;
}
- Pack* pack() { return pack_; }
+ Pack* pack() const {
+ return pack_;
+ }
ServiceDependency<ObjectManager> object_manager_;
ErrorStatus error_status_;
- Pack* pack_;
+ ServiceLocator *service_locator_;
+ Features *features_;
+ Pack *pack_;
+ MockRenderer *renderer_;
};
-// Test that non PoT textures can't make render surfaces
+// Tests that non PoT textures can't make render surfaces.
TEST_F(RenderSurfaceTest, NonPowerOfTwoRenderSurfaceEnabled) {
- Texture2D* texture = pack()->CreateTexture2D(20, 32, Texture::ARGB8, 2, true);
+ Texture2D *texture = pack()->CreateTexture2D(20, 32, Texture::ARGB8, 2, true);
ASSERT_TRUE(NULL == texture);
}
-// Test that a render surface can be created
+
+// Tests that a render surface can be created from a texture 2d.
TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTexture2D) {
- Texture2D* texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
+ Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
ASSERT_TRUE(NULL != texture);
RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
@@ -94,33 +149,36 @@ TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTexture2D) { ASSERT_EQ(render_surface->height(), 32);
}
+// Tests that a render surface can be created from a cube texture.
TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTextureCUBE) {
- TextureCUBE* texture = pack()->CreateTextureCUBE(16, Texture::ARGB8, 2, true);
+ TextureCUBE *texture = pack()->CreateTextureCUBE(16, Texture::ARGB8, 2, true);
ASSERT_TRUE(NULL != texture);
RenderSurface::Ref render_surface = texture->GetRenderSurface(
- TextureCUBE::FACE_POSITIVE_X, 0);
+ TextureCUBE::FACE_POSITIVE_X, 0);
ASSERT_TRUE(NULL != render_surface);
ASSERT_TRUE(NULL != render_surface->texture());
ASSERT_EQ(render_surface->width(), 16);
ASSERT_EQ(render_surface->height(), 16);
}
+// Tests the renderer's functionality to swap render surfaces and that
+// the correct render surfaces are set.
TEST_F(RenderSurfaceTest, SwapRenderSurfaces) {
- Texture2D* texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
+ Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
ASSERT_TRUE(NULL != texture);
RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
ASSERT_TRUE(NULL != render_surface);
ASSERT_TRUE(texture == render_surface->texture());
- RenderDepthStencilSurface* depth_surface =
- pack()->CreateDepthStencilSurface(16, 32);
+ RenderDepthStencilSurface *depth_surface =
+ pack()->CreateDepthStencilSurface(16, 32);
// Now swap surfaces.
renderer()->SetRenderSurfaces(render_surface, depth_surface, false);
- const RenderSurface* test_render_surface = NULL;
- const RenderDepthStencilSurface* test_depth_surface = NULL;
+ const RenderSurface *test_render_surface = NULL;
+ const RenderDepthStencilSurface *test_depth_surface = NULL;
bool test_is_back_buffer;
renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface,
&test_is_back_buffer);
@@ -129,19 +187,57 @@ TEST_F(RenderSurfaceTest, SwapRenderSurfaces) { ASSERT_FALSE(test_is_back_buffer);
}
+// Tests the renderer's functionality to swap render surfaces and return
+// the old one to the main rendering surface.
+TEST_F(RenderSurfaceTest, SetBackSurfaces) {
+ Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
+ ASSERT_TRUE(NULL != texture);
+
+ RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
+ ASSERT_TRUE(NULL != render_surface);
+ ASSERT_TRUE(texture == render_surface->texture());
+
+ RenderDepthStencilSurface *depth_surface =
+ pack()->CreateDepthStencilSurface(16, 32);
+
+ // Save the original surfaces for comparison.
+ const RenderSurface *original_render_surface = NULL;
+ const RenderDepthStencilSurface *original_depth_surface = NULL;
+ bool original_is_back_buffer;
+ renderer()->GetRenderSurfaces(&original_render_surface,
+ &original_depth_surface,
+ &original_is_back_buffer);
+ // Now swap surfaces.
+ renderer()->SetRenderSurfaces(render_surface, depth_surface, false);
+ // Return the back buffers
+ renderer()->SetRenderSurfaces(NULL, NULL, true);
+ // Get the original surfaces again for comparison.
+ const RenderSurface *restored_render_surface = NULL;
+ const RenderDepthStencilSurface *restored_depth_surface = NULL;
+ bool restored_is_back_buffer;
+ renderer()->GetRenderSurfaces(&original_render_surface,
+ &original_depth_surface,
+ &restored_is_back_buffer);
+ ASSERT_TRUE(original_render_surface == restored_render_surface);
+ ASSERT_TRUE(original_depth_surface == restored_depth_surface);
+ ASSERT_TRUE(restored_is_back_buffer);
+}
+
+// Tests the render surfaces interaction as part of a render surface set
+// which is how they are commonly used in practice.
TEST_F(RenderSurfaceTest, RenderSurfaceSetTest) {
- Texture2D* texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
+ Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
ASSERT_TRUE(NULL != texture);
RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
ASSERT_TRUE(NULL != render_surface);
ASSERT_TRUE(texture == render_surface->texture());
- RenderDepthStencilSurface* depth_surface =
- pack()->CreateDepthStencilSurface(16, 32);
+ RenderDepthStencilSurface *depth_surface =
+ pack()->CreateDepthStencilSurface(16, 32);
ASSERT_TRUE(depth_surface != NULL);
- RenderSurfaceSet* render_surface_set = pack()->Create<RenderSurfaceSet>();
+ RenderSurfaceSet *render_surface_set = pack()->Create<RenderSurfaceSet>();
ASSERT_TRUE(render_surface_set != NULL);
render_surface_set->set_render_surface(render_surface);
render_surface_set->set_render_depth_stencil_surface(depth_surface);
@@ -149,15 +245,15 @@ TEST_F(RenderSurfaceTest, RenderSurfaceSetTest) { RenderContext render_context(g_renderer);
- const RenderSurface* old_render_surface = NULL;
- const RenderDepthStencilSurface* old_depth_surface = NULL;
+ const RenderSurface *old_render_surface = NULL;
+ const RenderDepthStencilSurface *old_depth_surface = NULL;
bool old_is_back_buffer = false;
renderer()->GetRenderSurfaces(&old_render_surface, &old_depth_surface,
&old_is_back_buffer);
render_surface_set->Render(&render_context);
- const RenderSurface* test_render_surface = NULL;
- const RenderDepthStencilSurface* test_depth_surface = NULL;
+ const RenderSurface *test_render_surface = NULL;
+ const RenderDepthStencilSurface *test_depth_surface = NULL;
bool test_is_back_buffer = false;
renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface,
&test_is_back_buffer);
|