summaryrefslogtreecommitdiffstats
path: root/o3d/command_buffer
diff options
context:
space:
mode:
authorrlp@google.com <rlp@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:45:01 +0000
committerrlp@google.com <rlp@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 22:45:01 +0000
commit02525bc37fe1722c8b38af1d6087bf286e075bf9 (patch)
treeecb6e9b67b7745cf14a7574b331525346b5e638c /o3d/command_buffer
parent139dd55c937dbad1224571ddca0d13d9e723af0f (diff)
downloadchromium_src-02525bc37fe1722c8b38af1d6087bf286e075bf9.zip
chromium_src-02525bc37fe1722c8b38af1d6087bf286e075bf9.tar.gz
chromium_src-02525bc37fe1722c8b38af1d6087bf286e075bf9.tar.bz2
Adding in render surfaces for command buffers. Fixing SetRect as well.
Review URL: http://codereview.chromium.org/160401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/command_buffer')
-rw-r--r--o3d/command_buffer/common/cross/cmd_buffer_format.h34
-rw-r--r--o3d/command_buffer/common/cross/gapi_interface.h73
-rw-r--r--o3d/command_buffer/service/build.scons2
-rw-r--r--o3d/command_buffer/service/cross/gapi_decoder.cc67
-rw-r--r--o3d/command_buffer/service/cross/resource.h22
-rw-r--r--o3d/command_buffer/service/win/d3d9/gapi_d3d9.cc14
-rw-r--r--o3d/command_buffer/service/win/d3d9/gapi_d3d9.h825
-rw-r--r--o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc208
-rw-r--r--o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h102
-rw-r--r--o3d/command_buffer/service/win/d3d9/texture_d3d9.cc161
-rw-r--r--o3d/command_buffer/service/win/d3d9/texture_d3d9.h63
11 files changed, 1112 insertions, 459 deletions
diff --git a/o3d/command_buffer/common/cross/cmd_buffer_format.h b/o3d/command_buffer/common/cross/cmd_buffer_format.h
index 1872a34..1338329 100644
--- a/o3d/command_buffer/common/cross/cmd_buffer_format.h
+++ b/o3d/command_buffer/common/cross/cmd_buffer_format.h
@@ -108,6 +108,16 @@ typedef BitField<8, 8> Format;
typedef BitField<16, 16> Flags;
} // namespace create_texture_cube_cmd
+// Bitfields for the CREATE_RENDER_SURFACE command.
+namespace create_render_surface_cmd {
+// argument 1
+typedef BitField<0, 16> Width;
+typedef BitField<16, 16> Height;
+// argument 2 may refer to side or depth
+typedef BitField<0, 16> Levels;
+typedef BitField<16, 16> Side;
+} // namespace create_render_surface_cmd
+
// Bitfields for the SET_TEXTURE_DATA command.
namespace set_texture_data_cmd {
// argument 1
@@ -261,7 +271,7 @@ typedef BitField<31, 1> Enable;
// GAPI commands.
enum CommandId {
NOOP, // No operation. Arbitrary argument size.
- SET_TOKEN, // Sets token. 1 argument.
+ SET_TOKEN, // Sets token. 1 argument. val 0
BEGIN_FRAME, // BeginFrame. 0 argument.
END_FRAME, // EndFrame. 0 argument.
CLEAR, // Clear. 7 arguments.
@@ -269,8 +279,8 @@ enum CommandId {
DESTROY_VERTEX_BUFFER, // DestroyVertexBuffer. 1 argument.
SET_VERTEX_BUFFER_DATA, // SetVertexBufferData, 5 args
SET_VERTEX_BUFFER_DATA_IMMEDIATE, // SetVertexBufferData, 2 args + data
- GET_VERTEX_BUFFER_DATA, // GetVertexBufferData, 5 args
- CREATE_INDEX_BUFFER, // CreateIndexBuffer, 3 arguments.
+ GET_VERTEX_BUFFER_DATA, // GetVertexBufferData, 5 args,
+ CREATE_INDEX_BUFFER, // CreateIndexBuffer, 3 arguments. val 10
DESTROY_INDEX_BUFFER, // DestroyIndexBuffer. 1 argument.
SET_INDEX_BUFFER_DATA, // SetIndexBufferData, 5 args
SET_INDEX_BUFFER_DATA_IMMEDIATE, // SetIndexBufferData, 2 args + data
@@ -279,8 +289,8 @@ enum CommandId {
DESTROY_VERTEX_STRUCT, // DestroyVertexStruct. 1 argument.
SET_VERTEX_INPUT, // SetVertexInput, 5 args.
SET_VERTEX_STRUCT, // SetVertexStruct, 1 arg.
- DRAW, // Draw, 3 args.
- DRAW_INDEXED, // DrawIndexed, 6 args.
+ DRAW, // Draw, 3 args. value
+ DRAW_INDEXED, // DrawIndexed, 6 args. val 20
CREATE_EFFECT, // CreateEffect, 4 args.
CREATE_EFFECT_IMMEDIATE, // CreateEffect, 2 args + data
DESTROY_EFFECT, // DestroyEffect, 1 arg.
@@ -290,17 +300,17 @@ enum CommandId {
CREATE_PARAM_BY_NAME, // CreateParamByName, 5 args.
CREATE_PARAM_BY_NAME_IMMEDIATE, // CreateParamByName, 3 args + data
DESTROY_PARAM, // DestroyParam, 1 arg
- SET_PARAM_DATA, // SetParamData, 4 args
+ SET_PARAM_DATA, // SetParamData, 4 args val 30
SET_PARAM_DATA_IMMEDIATE, // SetParamData, 2 args + data
GET_PARAM_DESC, // GetParamDesc, 4 args
GET_STREAM_COUNT, // GetStreamCount, 4 args.
GET_STREAM_DESC, // GetStreamDesc, 5 args
DESTROY_TEXTURE, // DestroyTexture, 1 arg
- CREATE_TEXTURE_2D, // CreateTexture2D, 3 args
+ CREATE_TEXTURE_2D, // CreateTexture2D, 4 args
CREATE_TEXTURE_3D, // CreateTexture3D, 4 args
CREATE_TEXTURE_CUBE, // CreateTextureCube, 3 args
SET_TEXTURE_DATA, // SetTextureData, 10 args
- SET_TEXTURE_DATA_IMMEDIATE, // SetTextureData, 8 args + data
+ SET_TEXTURE_DATA_IMMEDIATE, // SetTextureData, 8 args + data val 40
GET_TEXTURE_DATA, // GetTextureData, 10 args
CREATE_SAMPLER, // CreateSampler, 1 arg
DESTROY_SAMPLER, // DestroySampler, 1 arg
@@ -310,7 +320,7 @@ enum CommandId {
SET_VIEWPORT, // SetViewport. 6 arguments.
SET_SCISSOR, // SetScissor, 2 args
SET_POINT_LINE_RASTER, // SetPointLineRaster, 2 args
- SET_POLYGON_RASTER, // SetPolygonRaster, 1 args
+ SET_POLYGON_RASTER, // SetPolygonRaster, 1 args val 50
SET_POLYGON_OFFSET, // SetPolygonOffest, 2 args
SET_ALPHA_TEST, // SetAlphaTest, 2 args
SET_DEPTH_TEST, // SetDepthTest, 1 args
@@ -318,6 +328,12 @@ enum CommandId {
SET_BLENDING, // SetBlending, 1 args
SET_BLENDING_COLOR, // SetBlendingColor, 4 args
SET_COLOR_WRITE, // SetColorWrite, 1 args
+ CREATE_RENDER_SURFACE, // CreateRenderSurface, 4 args.
+ DESTROY_RENDER_SURFACE, // DestoryRenderSurface, 1 arg.
+ CREATE_DEPTH_SURFACE, // CreateRenderSurface, 2 args. val 60
+ DESTROY_DEPTH_SURFACE, // DestoryRenderSurface, 1 arg.
+ SET_RENDER_SURFACE, // SetRenderSurface, 2 args.
+ SET_BACK_SURFACES // SetBackSurfaces
};
} // namespace command_buffer
diff --git a/o3d/command_buffer/common/cross/gapi_interface.h b/o3d/command_buffer/common/cross/gapi_interface.h
index 67700b7..46189e2 100644
--- a/o3d/command_buffer/common/cross/gapi_interface.h
+++ b/o3d/command_buffer/common/cross/gapi_interface.h
@@ -518,6 +518,7 @@ class GAPIInterface {
// maximum.
// format: the format of the texels in the texture.
// flags: the texture flags, as a combination of texture::Flags.
+ // enable_render_surfaces: bool for whether to enable render surfaces
// Returns:
// BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
// passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
@@ -526,7 +527,8 @@ class GAPIInterface {
unsigned int height,
unsigned int levels,
texture::Format format,
- unsigned int flags) = 0;
+ unsigned int flags,
+ bool enable_render_surfaces) = 0;
// Creates a 3D texture resource.
// Parameters:
@@ -538,6 +540,7 @@ class GAPIInterface {
// maximum.
// format: the format of the pixels in the texture.
// flags: the texture flags, as a combination of texture::Flags.
+ // enable_render_surfaces: bool for whether to enable render surfaces
// Returns:
// BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
// passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
@@ -547,7 +550,8 @@ class GAPIInterface {
unsigned int depth,
unsigned int levels,
texture::Format format,
- unsigned int flags) = 0;
+ unsigned int flags,
+ bool enable_render_surfaces) = 0;
// Creates a cube map texture resource.
// Parameters:
@@ -557,6 +561,7 @@ class GAPIInterface {
// maximum.
// format: the format of the pixels in the texture.
// flags: the texture flags, as a combination of texture::Flags.
+ // enable_render_surfaces: bool for whether to enable render surfaces
// Returns:
// BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
// passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
@@ -564,7 +569,8 @@ class GAPIInterface {
unsigned int side,
unsigned int levels,
texture::Format format,
- unsigned int flags) = 0;
+ unsigned int flags,
+ bool enable_render_surfaces) = 0;
// Sets texel data into a texture resource. This is a common function for
// each of the texture types, but some restrictions exist based on the
@@ -846,6 +852,67 @@ class GAPIInterface {
// Sets the blending color.
virtual void SetBlendingColor(const RGBA &color) = 0;
+
+ // Creates a render surface resource.
+ // Parameters:
+ // id: the resource ID of the render surface.
+ // width: the texture width. Must be positive.
+ // height: the texture height. Must be positive.
+ // texture_id: the resource id of the texture.
+ // Returns:
+ // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
+ // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
+ virtual ParseError CreateRenderSurface(ResourceID id,
+ unsigned int width,
+ unsigned int height,
+ unsigned int mip_level,
+ unsigned int side,
+ ResourceID texture_id) = 0;
+
+ // Destroys a render surface resource.
+ // Parameters:
+ // id: the resource ID of the render surface.
+ // Returns:
+ // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid render
+ // surface
+ // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
+ virtual ParseError DestroyRenderSurface(ResourceID id) = 0;
+
+ // Creates a depth stencil surface resource.
+ // Parameters:
+ // id: the resource ID of the depth stencil surface.
+ // width: the texture width. Must be positive.
+ // height: the texture height. Must be positive.
+ // Returns:
+ // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
+ // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
+ virtual ParseError CreateDepthSurface(ResourceID id,
+ unsigned int width,
+ unsigned int height) = 0;
+
+ // Destroys a depth stencil surface resource.
+ // Parameters:
+ // id: the resource ID of the depth stencil surface.
+ // Returns:
+ // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if an invalid render
+ // surface
+ // resource ID was passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
+ virtual ParseError DestroyDepthSurface(ResourceID id) = 0;
+
+ // Switches the render surface and depth stencil surface to those
+ // corresponding to the passed in IDs.
+ // Parameters:
+ // render_surface_id: the resource ID of the render surface.
+ // depth_stencil_id: the resource ID of the render depth stencil surface.
+ // Returns:
+ // BufferSyncInterface::PARSE_INVALID_ARGUMENTS if invalid arguments are
+ // passed, BufferSyncInterface::PARSE_NO_ERROR otherwise.
+ virtual ParseError SetRenderSurface(ResourceID render_surface_id,
+ ResourceID depth_stencil_id) = 0;
+
+ // Switch the render surface and depth stencil surface back to the main
+ // surfaces stored in the render
+ virtual void SetBackSurfaces() = 0;
};
} // namespace command_buffer
diff --git a/o3d/command_buffer/service/build.scons b/o3d/command_buffer/service/build.scons
index 8bd7e4f..9c29f77 100644
--- a/o3d/command_buffer/service/build.scons
+++ b/o3d/command_buffer/service/build.scons
@@ -87,6 +87,7 @@ if env['TARGET_PLATFORM'] == 'WINDOWS':
INPUTS += ['win/d3d9/effect_d3d9.cc',
'win/d3d9/gapi_d3d9.cc',
'win/d3d9/geometry_d3d9.cc',
+ 'win/d3d9/render_surface_d3d9.cc',
'win/d3d9/sampler_d3d9.cc',
'win/d3d9/states_d3d9.cc',
'win/d3d9/texture_d3d9.cc']
@@ -102,7 +103,6 @@ if env['TARGET_PLATFORM'] == 'WINDOWS':
'cross/gl/sampler_gl.cc',
'cross/gl/states_gl.cc',
'cross/gl/texture_gl.cc']
-
BIG_TEST_SERVER += ['win/big_test_main.cc']
elif env['TARGET_PLATFORM'] == 'LINUX':
env.Append(LIBS = ['GL', 'GLEW', 'Cg', 'CgGL'],
diff --git a/o3d/command_buffer/service/cross/gapi_decoder.cc b/o3d/command_buffer/service/cross/gapi_decoder.cc
index dfd0cff..d37f7e0 100644
--- a/o3d/command_buffer/service/cross/gapi_decoder.cc
+++ b/o3d/command_buffer/service/cross/gapi_decoder.cc
@@ -566,6 +566,62 @@ BufferSyncInterface::ParseError GAPIDecoder::DoCommand(
} else {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
+ case CREATE_RENDER_SURFACE:
+ if (arg_count == 4) {
+ namespace cmd = create_render_surface_cmd;
+ ResourceID id = args[0].value_uint32;
+ unsigned int width_height = args[1].value_uint32;
+ unsigned int width = cmd::Width::Get(width_height);
+ unsigned int height = cmd::Height::Get(width_height);
+ unsigned int levels_side = args[2].value_uint32;
+ unsigned int mip_level = cmd::Levels::Get(levels_side);
+ unsigned int side = cmd::Side::Get(levels_side);
+ ResourceID texture_id = args[3].value_uint32;
+ return gapi_->CreateRenderSurface(id, width, height, mip_level,
+ side, texture_id);
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ case DESTROY_RENDER_SURFACE:
+ if (arg_count == 1) {
+ ResourceID id = args[0].value_uint32;
+ return gapi_->DestroyRenderSurface(id);
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ case CREATE_DEPTH_SURFACE:
+ if (arg_count == 2) {
+ namespace cmd = create_render_surface_cmd;
+ ResourceID id = args[0].value_uint32;
+ unsigned int width_height = args[1].value_uint32;
+ unsigned int width = cmd::Width::Get(width_height);
+ unsigned int height = cmd::Height::Get(width_height);
+ return gapi_->CreateDepthSurface(id, width, height);
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ case DESTROY_DEPTH_SURFACE:
+ if (arg_count == 1) {
+ ResourceID id = args[0].value_uint32;
+ return gapi_->DestroyDepthSurface(id);
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ case SET_RENDER_SURFACE:
+ if (arg_count == 2) {
+ ResourceID render_surface_id = args[0].value_uint32;
+ ResourceID depth_stencil_id = args[1].value_uint32;
+ return gapi_->SetRenderSurface(render_surface_id, depth_stencil_id);
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ case SET_BACK_SURFACES:
+ if (arg_count == 0) {
+ gapi_->SetBackSurfaces();
+ return BufferSyncInterface::PARSE_NO_ERROR;
+ } else {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
default:
return BufferSyncInterface::PARSE_UNKNOWN_COMMAND;
}
@@ -617,8 +673,10 @@ BufferSyncInterface::ParseError GAPIDecoder::DecodeCreateTexture2D(
(unused != 0) || (format >= texture::NUM_FORMATS))
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
if (levels == 0) levels = max_levels;
+ bool enable_render_surfaces = flags;
return gapi_->CreateTexture2D(id, width, height, levels,
- static_cast<texture::Format>(format), flags);
+ static_cast<texture::Format>(format), flags,
+ enable_render_surfaces);
} else {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
@@ -649,8 +707,10 @@ BufferSyncInterface::ParseError GAPIDecoder::DecodeCreateTexture3D(
(format >= texture::NUM_FORMATS))
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
if (levels == 0) levels = max_levels;
+ bool enable_render_surfaces = flags;
return gapi_->CreateTexture3D(id, width, height, depth, levels,
- static_cast<texture::Format>(format), flags);
+ static_cast<texture::Format>(format), flags,
+ enable_render_surfaces);
} else {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
@@ -676,9 +736,10 @@ BufferSyncInterface::ParseError GAPIDecoder::DecodeCreateTextureCube(
(unused2 != 0) || (format >= texture::NUM_FORMATS))
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
if (levels == 0) levels = max_levels;
+ bool enable_render_surfaces = flags;
return gapi_->CreateTextureCube(id, side, levels,
static_cast<texture::Format>(format),
- flags);
+ flags, enable_render_surfaces);
} else {
return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
}
diff --git a/o3d/command_buffer/service/cross/resource.h b/o3d/command_buffer/service/cross/resource.h
index 5c6e6ed..c97fc70 100644
--- a/o3d/command_buffer/service/cross/resource.h
+++ b/o3d/command_buffer/service/cross/resource.h
@@ -159,10 +159,12 @@ class Texture: public Resource {
Texture(texture::Type type,
unsigned int levels,
texture::Format format,
+ bool enable_render_surfaces,
unsigned int flags)
: type_(type),
levels_(levels),
format_(format),
+ render_surfaces_enabled_(enable_render_surfaces),
flags_(flags) {}
virtual ~Texture() {}
@@ -172,16 +174,36 @@ class Texture: public Resource {
unsigned int flags() const { return flags_; }
// Returns the texture format.
texture::Format format() const { return format_; }
+ // Returns whether the texture supports render surfaces
+ bool render_surfaces_enabled() const { return render_surfaces_enabled_; }
// Returns the number of mipmap levels in the texture.
unsigned int levels() const { return levels_; }
private:
texture::Type type_;
unsigned int levels_;
texture::Format format_;
+ bool render_surfaces_enabled_;
unsigned int flags_;
DISALLOW_COPY_AND_ASSIGN(Texture);
};
+// RenderSurface class, representing a render surface/target
+class RenderSurface: public Resource {
+ public:
+ RenderSurface() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderSurface);
+};
+
+// RenderSurface class, representing a render surface/target
+class RenderDepthStencilSurface: public Resource {
+ public:
+ RenderDepthStencilSurface() {}
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurface);
+};
+
+
// Texture class, representing a sampler resource.
class Sampler: public Resource {
public:
diff --git a/o3d/command_buffer/service/win/d3d9/gapi_d3d9.cc b/o3d/command_buffer/service/win/d3d9/gapi_d3d9.cc
index f5fe0d4..824f504 100644
--- a/o3d/command_buffer/service/win/d3d9/gapi_d3d9.cc
+++ b/o3d/command_buffer/service/win/d3d9/gapi_d3d9.cc
@@ -49,7 +49,11 @@ GAPID3D9::GAPID3D9()
current_effect_(NULL),
vertex_buffers_(),
index_buffers_(),
- vertex_structs_() {}
+ vertex_structs_(),
+ back_buffer_surface_(NULL),
+ back_buffer_depth_surface_(NULL),
+ current_surface_id_(kInvalidResource),
+ current_depth_surface_id_(kInvalidResource) {}
GAPID3D9::~GAPID3D9() {}
@@ -143,6 +147,8 @@ void GAPID3D9::Destroy() {
effect_params_.DestroyAllResources();
textures_.DestroyAllResources();
samplers_.DestroyAllResources();
+ render_surfaces_.DestroyAllResources();
+ depth_surfaces_.DestroyAllResources();
if (d3d_device_) {
d3d_device_->Release();
d3d_device_ = NULL;
@@ -155,6 +161,8 @@ void GAPID3D9::Destroy() {
// Begins the frame.
void GAPID3D9::BeginFrame() {
+ HR(d3d_device_->GetRenderTarget(0, &back_buffer_surface_));
+ HR(d3d_device_->GetDepthStencilSurface(&back_buffer_depth_surface_));
HR(d3d_device_->BeginScene());
}
@@ -163,6 +171,10 @@ void GAPID3D9::EndFrame() {
DirtyEffect();
HR(d3d_device_->EndScene());
HR(d3d_device_->Present(NULL, NULL, NULL, NULL));
+
+ // Release the back-buffer references.
+ back_buffer_surface_ = NULL;
+ back_buffer_depth_surface_ = NULL;
}
// Clears the selected buffers.
diff --git a/o3d/command_buffer/service/win/d3d9/gapi_d3d9.h b/o3d/command_buffer/service/win/d3d9/gapi_d3d9.h
index c757cc6..ca1c73f 100644
--- a/o3d/command_buffer/service/win/d3d9/gapi_d3d9.h
+++ b/o3d/command_buffer/service/win/d3d9/gapi_d3d9.h
@@ -1,395 +1,432 @@
-/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file contains the GAPID3D9 class, implementing the GAPI interface for
-// D3D9.
-
-#ifndef O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
-#define O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
-
-#include "command_buffer/common/cross/gapi_interface.h"
-#include "command_buffer/service/win/d3d9/d3d9_utils.h"
-#include "command_buffer/service/win/d3d9/geometry_d3d9.h"
-#include "command_buffer/service/win/d3d9/effect_d3d9.h"
-#include "command_buffer/service/win/d3d9/texture_d3d9.h"
-#include "command_buffer/service/win/d3d9/sampler_d3d9.h"
-
-namespace o3d {
-namespace command_buffer {
-
-// This class implements the GAPI interface for D3D9.
-class GAPID3D9 : public GAPIInterface {
- public:
- GAPID3D9();
- virtual ~GAPID3D9();
-
- void set_hwnd(HWND hwnd) { hwnd_ = hwnd; }
-
- // Initializes the graphics context, bound to a window.
- // Returns:
- // true if successful.
- virtual bool Initialize();
-
- // Destroys the graphics context.
- virtual void Destroy();
-
- // Implements the BeginFrame function for D3D9.
- virtual void BeginFrame();
-
- // Implements the EndFrame function for D3D9.
- virtual void EndFrame();
-
- // Implements the Clear function for D3D9.
- virtual void Clear(unsigned int buffers,
- const RGBA &color,
- float depth,
- unsigned int stencil);
-
- // Implements the SetViewport function for D3D9.
- virtual void SetViewport(unsigned int x,
- unsigned int y,
- unsigned int width,
- unsigned int height,
- float z_min,
- float z_max);
-
- // Implements the CreateVertexBuffer function for D3D9.
- virtual ParseError CreateVertexBuffer(ResourceID id,
- unsigned int size,
- unsigned int flags);
-
- // Implements the DestroyVertexBuffer function for D3D9.
- virtual ParseError DestroyVertexBuffer(ResourceID id);
-
- // Implements the SetVertexBufferData function for D3D9.
- virtual ParseError SetVertexBufferData(ResourceID id,
- unsigned int offset,
- unsigned int size,
- const void *data);
-
- // Implements the GetVertexBufferData function for D3D9.
- virtual ParseError GetVertexBufferData(ResourceID id,
- unsigned int offset,
- unsigned int size,
- void *data);
-
- // Implements the CreateIndexBuffer function for D3D9.
- virtual ParseError CreateIndexBuffer(ResourceID id,
- unsigned int size,
- unsigned int flags);
-
- // Implements the DestroyIndexBuffer function for D3D9.
- virtual ParseError DestroyIndexBuffer(ResourceID id);
-
- // Implements the SetIndexBufferData function for D3D9.
- virtual ParseError SetIndexBufferData(ResourceID id,
- unsigned int offset,
- unsigned int size,
- const void *data);
-
- // Implements the GetIndexBufferData function for D3D9.
- virtual ParseError GetIndexBufferData(ResourceID id,
- unsigned int offset,
- unsigned int size,
- void *data);
-
- // Implements the CreateVertexStruct function for D3D9.
- virtual ParseError CreateVertexStruct(ResourceID id,
- unsigned int input_count);
-
- // Implements the DestroyVertexStruct function for D3D9.
- virtual ParseError DestroyVertexStruct(ResourceID id);
-
- // Implements the SetVertexInput function for D3D9.
- virtual ParseError SetVertexInput(ResourceID vertex_struct_id,
- unsigned int input_index,
- ResourceID vertex_buffer_id,
- unsigned int offset,
- unsigned int stride,
- vertex_struct::Type type,
- vertex_struct::Semantic semantic,
- unsigned int semantic_index);
-
- // Implements the SetVertexStruct function for D3D9.
- virtual ParseError SetVertexStruct(ResourceID id);
-
- // Implements the Draw function for D3D9.
- virtual ParseError Draw(PrimitiveType primitive_type,
- unsigned int first,
- unsigned int count);
-
- // Implements the DrawIndexed function for D3D9.
- virtual ParseError DrawIndexed(PrimitiveType primitive_type,
- ResourceID index_buffer_id,
- unsigned int first,
- unsigned int count,
- unsigned int min_index,
- unsigned int max_index);
-
- // Implements the CreateEffect function for D3D9.
- virtual ParseError CreateEffect(ResourceID id,
- unsigned int size,
- const void *data);
-
- // Implements the DestroyEffect function for D3D9.
- virtual ParseError DestroyEffect(ResourceID id);
-
- // Implements the SetEffect function for D3D9.
- virtual ParseError SetEffect(ResourceID id);
-
- // Implements the GetParamCount function for D3D9.
- virtual ParseError GetParamCount(ResourceID id,
- unsigned int size,
- void *data);
-
- // Implements the CreateParam function for D3D9.
- virtual ParseError CreateParam(ResourceID param_id,
- ResourceID effect_id,
- unsigned int index);
-
- // Implements the CreateParamByName function for D3D9.
- virtual ParseError CreateParamByName(ResourceID param_id,
- ResourceID effect_id,
- unsigned int size,
- const void *name);
-
- // Implements the DestroyParam function for D3D9.
- virtual ParseError DestroyParam(ResourceID id);
-
- // Implements the SetParamData function for D3D9.
- virtual ParseError SetParamData(ResourceID id,
- unsigned int size,
- const void *data);
-
- // Implements the GetParamDesc function for D3D9.
- virtual ParseError GetParamDesc(ResourceID id,
- unsigned int size,
- void *data);
-
- // Implements the GetStreamCount function for D3D9.
- virtual ParseError GetStreamCount(ResourceID id,
- unsigned int size,
- void *data);
-
- // Implements the GetStreamDesc function for D3D9.
- virtual ParseError GetStreamDesc(ResourceID id,
- unsigned int index,
- unsigned int size,
- void *data);
-
- // Implements the CreateTexture2D function for D3D9.
- virtual ParseError CreateTexture2D(ResourceID id,
- unsigned int width,
- unsigned int height,
- unsigned int levels,
- texture::Format format,
- unsigned int flags);
-
- // Implements the CreateTexture3D function for D3D9.
- virtual ParseError CreateTexture3D(ResourceID id,
- unsigned int width,
- unsigned int height,
- unsigned int depth,
- unsigned int levels,
- texture::Format format,
- unsigned int flags);
-
- // Implements the CreateTextureCube function for D3D9.
- virtual ParseError CreateTextureCube(ResourceID id,
- unsigned int side,
- unsigned int levels,
- texture::Format format,
- unsigned int flags);
-
- // Implements the SetTextureData function for D3D9.
- virtual ParseError SetTextureData(ResourceID id,
- unsigned int x,
- unsigned int y,
- unsigned int z,
- unsigned int width,
- unsigned int height,
- unsigned int depth,
- unsigned int level,
- texture::Face face,
- unsigned int pitch,
- unsigned int slice_pitch,
- unsigned int size,
- const void *data);
-
- // Implements the GetTextureData function for D3D9.
- virtual ParseError GetTextureData(ResourceID id,
- unsigned int x,
- unsigned int y,
- unsigned int z,
- unsigned int width,
- unsigned int height,
- unsigned int depth,
- unsigned int level,
- texture::Face face,
- unsigned int pitch,
- unsigned int slice_pitch,
- unsigned int size,
- void *data);
-
- // Implements the DestroyTexture function for D3D9.
- virtual ParseError DestroyTexture(ResourceID id);
-
- // Implements the CreateSampler function for D3D9.
- virtual ParseError CreateSampler(ResourceID id);
-
- // Implements the DestroySampler function for D3D9.
- virtual ParseError DestroySampler(ResourceID id);
-
- // Implements the SetSamplerStates function for D3D9.
- virtual ParseError SetSamplerStates(ResourceID id,
- sampler::AddressingMode addressing_u,
- sampler::AddressingMode addressing_v,
- sampler::AddressingMode addressing_w,
- sampler::FilteringMode mag_filter,
- sampler::FilteringMode min_filter,
- sampler::FilteringMode mip_filter,
- unsigned int max_anisotropy);
-
- // Implements the SetSamplerBorderColor function for D3D9.
- virtual ParseError SetSamplerBorderColor(ResourceID id, const RGBA &color);
-
- // Implements the SetSamplerTexture function for D3D9.
- virtual ParseError SetSamplerTexture(ResourceID id, ResourceID texture_id);
-
- // Implements the SetScissor function for D3D9.
- virtual void SetScissor(bool enable,
- unsigned int x,
- unsigned int y,
- unsigned int width,
- unsigned int height);
-
- // Implements the SetPointLineRaster function for D3D9.
- virtual void SetPointLineRaster(bool line_smooth,
- bool point_sprite,
- float point_size);
-
- // Implements the SetPolygonOffset function for D3D9.
- virtual void SetPolygonOffset(float slope_factor, float units);
-
- // Implements the SetPolygonRaster function for D3D9.
- virtual void SetPolygonRaster(PolygonMode fill_mode,
- FaceCullMode cull_mode);
-
- // Implements the SetAlphaTest function for D3D9.
- virtual void SetAlphaTest(bool enable,
- float reference,
- Comparison comp);
-
- // Implements the SetDepthTest function for D3D9.
- virtual void SetDepthTest(bool enable,
- bool write_enable,
- Comparison comp);
-
- // Implements the SetStencilTest function for D3D9.
- virtual void SetStencilTest(bool enable,
- bool separate_ccw,
- unsigned int write_mask,
- unsigned int compare_mask,
- unsigned int ref,
- Uint32 func_ops);
-
- // Implements the SetColorWritefunction for D3D9.
- virtual void SetColorWrite(bool red,
- bool green,
- bool blue,
- bool alpha,
- bool dither);
-
- // Implements the SetBlending function for D3D9.
- virtual void SetBlending(bool enable,
- bool separate_alpha,
- BlendEq color_eq,
- BlendFunc color_src_func,
- BlendFunc color_dst_func,
- BlendEq alpha_eq,
- BlendFunc alpha_src_func,
- BlendFunc alpha_dst_func);
-
- // Implements the SetBlendingColor function for D3D9.
- virtual void SetBlendingColor(const RGBA &color);
-
- // Gets the D3D9 device.
- IDirect3DDevice9 *d3d_device() const { return d3d_device_; }
-
- // Gets a vertex buffer by resource ID.
- VertexBufferD3D9 *GetVertexBuffer(ResourceID id) {
- return vertex_buffers_.Get(id);
- }
-
- // Gets a texture by resource ID.
- TextureD3D9 *GetTexture(ResourceID id) {
- return textures_.Get(id);
- }
-
- // Gets a sampler by resource ID.
- SamplerD3D9 *GetSampler(ResourceID id) {
- return samplers_.Get(id);
- }
-
- EffectD3D9 *current_effect() { return current_effect_; }
- private:
- // Validates the current vertex struct to D3D, setting the streams.
- bool ValidateStreams();
- // Validates the current effect to D3D. This sends the effect states to D3D.
- bool ValidateEffect();
- // "Dirty" the current effect. This resets the effect states to D3D, and
- // requires ValidateEffect() to be called before further draws occur.
- void DirtyEffect();
-
- LPDIRECT3D9 d3d_;
- LPDIRECT3DDEVICE9 d3d_device_;
- HWND hwnd_;
- ResourceID current_vertex_struct_;
- bool validate_streams_;
- unsigned int max_vertices_;
- ResourceID current_effect_id_;
- bool validate_effect_;
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// This file contains the GAPID3D9 class, implementing the GAPI interface for
+// D3D9.
+
+#ifndef O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
+#define O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
+
+#include "command_buffer/common/cross/gapi_interface.h"
+#include "command_buffer/service/win/d3d9/d3d9_utils.h"
+#include "command_buffer/service/win/d3d9/geometry_d3d9.h"
+#include "command_buffer/service/win/d3d9/effect_d3d9.h"
+#include "command_buffer/service/win/d3d9/texture_d3d9.h"
+#include "command_buffer/service/win/d3d9/sampler_d3d9.h"
+#include "command_buffer/service/win/d3d9/render_surface_d3d9.h"
+
+namespace o3d {
+namespace command_buffer {
+
+// This class implements the GAPI interface for D3D9.
+class GAPID3D9 : public GAPIInterface {
+ public:
+ GAPID3D9();
+ virtual ~GAPID3D9();
+
+ void set_hwnd(HWND hwnd) { hwnd_ = hwnd; }
+
+ // Initializes the graphics context, bound to a window.
+ // Returns:
+ // true if successful.
+ virtual bool Initialize();
+
+ // Destroys the graphics context.
+ virtual void Destroy();
+
+ // Implements the BeginFrame function for D3D9.
+ virtual void BeginFrame();
+
+ // Implements the EndFrame function for D3D9.
+ virtual void EndFrame();
+
+ // Implements the Clear function for D3D9.
+ virtual void Clear(unsigned int buffers,
+ const RGBA &color,
+ float depth,
+ unsigned int stencil);
+
+ // Implements the SetViewport function for D3D9.
+ virtual void SetViewport(unsigned int x,
+ unsigned int y,
+ unsigned int width,
+ unsigned int height,
+ float z_min,
+ float z_max);
+
+ // Implements the CreateVertexBuffer function for D3D9.
+ virtual ParseError CreateVertexBuffer(ResourceID id,
+ unsigned int size,
+ unsigned int flags);
+
+ // Implements the DestroyVertexBuffer function for D3D9.
+ virtual ParseError DestroyVertexBuffer(ResourceID id);
+
+ // Implements the SetVertexBufferData function for D3D9.
+ virtual ParseError SetVertexBufferData(ResourceID id,
+ unsigned int offset,
+ unsigned int size,
+ const void *data);
+
+ // Implements the GetVertexBufferData function for D3D9.
+ virtual ParseError GetVertexBufferData(ResourceID id,
+ unsigned int offset,
+ unsigned int size,
+ void *data);
+
+ // Implements the CreateIndexBuffer function for D3D9.
+ virtual ParseError CreateIndexBuffer(ResourceID id,
+ unsigned int size,
+ unsigned int flags);
+
+ // Implements the DestroyIndexBuffer function for D3D9.
+ virtual ParseError DestroyIndexBuffer(ResourceID id);
+
+ // Implements the SetIndexBufferData function for D3D9.
+ virtual ParseError SetIndexBufferData(ResourceID id,
+ unsigned int offset,
+ unsigned int size,
+ const void *data);
+
+ // Implements the GetIndexBufferData function for D3D9.
+ virtual ParseError GetIndexBufferData(ResourceID id,
+ unsigned int offset,
+ unsigned int size,
+ void *data);
+
+ // Implements the CreateVertexStruct function for D3D9.
+ virtual ParseError CreateVertexStruct(ResourceID id,
+ unsigned int input_count);
+
+ // Implements the DestroyVertexStruct function for D3D9.
+ virtual ParseError DestroyVertexStruct(ResourceID id);
+
+ // Implements the SetVertexInput function for D3D9.
+ virtual ParseError SetVertexInput(ResourceID vertex_struct_id,
+ unsigned int input_index,
+ ResourceID vertex_buffer_id,
+ unsigned int offset,
+ unsigned int stride,
+ vertex_struct::Type type,
+ vertex_struct::Semantic semantic,
+ unsigned int semantic_index);
+
+ // Implements the SetVertexStruct function for D3D9.
+ virtual ParseError SetVertexStruct(ResourceID id);
+
+ // Implements the Draw function for D3D9.
+ virtual ParseError Draw(PrimitiveType primitive_type,
+ unsigned int first,
+ unsigned int count);
+
+ // Implements the DrawIndexed function for D3D9.
+ virtual ParseError DrawIndexed(PrimitiveType primitive_type,
+ ResourceID index_buffer_id,
+ unsigned int first,
+ unsigned int count,
+ unsigned int min_index,
+ unsigned int max_index);
+
+ // Implements the CreateEffect function for D3D9.
+ virtual ParseError CreateEffect(ResourceID id,
+ unsigned int size,
+ const void *data);
+
+ // Implements the DestroyEffect function for D3D9.
+ virtual ParseError DestroyEffect(ResourceID id);
+
+ // Implements the SetEffect function for D3D9.
+ virtual ParseError SetEffect(ResourceID id);
+
+ // Implements the GetParamCount function for D3D9.
+ virtual ParseError GetParamCount(ResourceID id,
+ unsigned int size,
+ void *data);
+
+ // Implements the CreateParam function for D3D9.
+ virtual ParseError CreateParam(ResourceID param_id,
+ ResourceID effect_id,
+ unsigned int index);
+
+ // Implements the CreateParamByName function for D3D9.
+ virtual ParseError CreateParamByName(ResourceID param_id,
+ ResourceID effect_id,
+ unsigned int size,
+ const void *name);
+
+ // Implements the DestroyParam function for D3D9.
+ virtual ParseError DestroyParam(ResourceID id);
+
+ // Implements the SetParamData function for D3D9.
+ virtual ParseError SetParamData(ResourceID id,
+ unsigned int size,
+ const void *data);
+
+ // Implements the GetParamDesc function for D3D9.
+ virtual ParseError GetParamDesc(ResourceID id,
+ unsigned int size,
+ void *data);
+
+ // Implements the GetStreamCount function for D3D9.
+ virtual ParseError GetStreamCount(ResourceID id,
+ unsigned int size,
+ void *data);
+
+ // Implements the GetStreamDesc function for D3D9.
+ virtual ParseError GetStreamDesc(ResourceID id,
+ unsigned int index,
+ unsigned int size,
+ void *data);
+
+ // Implements the CreateTexture2D function for D3D9.
+ virtual ParseError CreateTexture2D(ResourceID id,
+ unsigned int width,
+ unsigned int height,
+ unsigned int levels,
+ texture::Format format,
+ unsigned int flags,
+ bool enable_render_surfaces);
+
+ // Implements the CreateTexture3D function for D3D9.
+ virtual ParseError CreateTexture3D(ResourceID id,
+ unsigned int width,
+ unsigned int height,
+ unsigned int depth,
+ unsigned int levels,
+ texture::Format format,
+ unsigned int flags,
+ bool enable_render_surfaces);
+
+ // Implements the CreateTextureCube function for D3D9.
+ virtual ParseError CreateTextureCube(ResourceID id,
+ unsigned int side,
+ unsigned int levels,
+ texture::Format format,
+ unsigned int flags,
+ bool enable_render_surfaces);
+
+ // Implements the SetTextureData function for D3D9.
+ virtual ParseError SetTextureData(ResourceID id,
+ unsigned int x,
+ unsigned int y,
+ unsigned int z,
+ unsigned int width,
+ unsigned int height,
+ unsigned int depth,
+ unsigned int level,
+ texture::Face face,
+ unsigned int pitch,
+ unsigned int slice_pitch,
+ unsigned int size,
+ const void *data);
+
+ // Implements the GetTextureData function for D3D9.
+ virtual ParseError GetTextureData(ResourceID id,
+ unsigned int x,
+ unsigned int y,
+ unsigned int z,
+ unsigned int width,
+ unsigned int height,
+ unsigned int depth,
+ unsigned int level,
+ texture::Face face,
+ unsigned int pitch,
+ unsigned int slice_pitch,
+ unsigned int size,
+ void *data);
+
+ // Implements the DestroyTexture function for D3D9.
+ virtual ParseError DestroyTexture(ResourceID id);
+
+ // Implements the CreateSampler function for D3D9.
+ virtual ParseError CreateSampler(ResourceID id);
+
+ // Implements the DestroySampler function for D3D9.
+ virtual ParseError DestroySampler(ResourceID id);
+
+ // Implements the SetSamplerStates function for D3D9.
+ virtual ParseError SetSamplerStates(ResourceID id,
+ sampler::AddressingMode addressing_u,
+ sampler::AddressingMode addressing_v,
+ sampler::AddressingMode addressing_w,
+ sampler::FilteringMode mag_filter,
+ sampler::FilteringMode min_filter,
+ sampler::FilteringMode mip_filter,
+ unsigned int max_anisotropy);
+
+ // Implements the SetSamplerBorderColor function for D3D9.
+ virtual ParseError SetSamplerBorderColor(ResourceID id, const RGBA &color);
+
+ // Implements the SetSamplerTexture function for D3D9.
+ virtual ParseError SetSamplerTexture(ResourceID id, ResourceID texture_id);
+
+ // Implements the SetScissor function for D3D9.
+ virtual void SetScissor(bool enable,
+ unsigned int x,
+ unsigned int y,
+ unsigned int width,
+ unsigned int height);
+
+ // Implements the SetPointLineRaster function for D3D9.
+ virtual void SetPointLineRaster(bool line_smooth,
+ bool point_sprite,
+ float point_size);
+
+ // Implements the SetPolygonOffset function for D3D9.
+ virtual void SetPolygonOffset(float slope_factor, float units);
+
+ // Implements the SetPolygonRaster function for D3D9.
+ virtual void SetPolygonRaster(PolygonMode fill_mode,
+ FaceCullMode cull_mode);
+
+ // Implements the SetAlphaTest function for D3D9.
+ virtual void SetAlphaTest(bool enable,
+ float reference,
+ Comparison comp);
+
+ // Implements the SetDepthTest function for D3D9.
+ virtual void SetDepthTest(bool enable,
+ bool write_enable,
+ Comparison comp);
+
+ // Implements the SetStencilTest function for D3D9.
+ virtual void SetStencilTest(bool enable,
+ bool separate_ccw,
+ unsigned int write_mask,
+ unsigned int compare_mask,
+ unsigned int ref,
+ Uint32 func_ops);
+
+ // Implements the SetColorWritefunction for D3D9.
+ virtual void SetColorWrite(bool red,
+ bool green,
+ bool blue,
+ bool alpha,
+ bool dither);
+
+ // Implements the SetBlending function for D3D9.
+ virtual void SetBlending(bool enable,
+ bool separate_alpha,
+ BlendEq color_eq,
+ BlendFunc color_src_func,
+ BlendFunc color_dst_func,
+ BlendEq alpha_eq,
+ BlendFunc alpha_src_func,
+ BlendFunc alpha_dst_func);
+
+ // Implements the SetBlendingColor function for D3D9.
+ virtual void SetBlendingColor(const RGBA &color);
+
+ // Implements the CreateRenderSurface function for D3D9.
+ virtual ParseError CreateRenderSurface(ResourceID id,
+ unsigned int width,
+ unsigned int height,
+ unsigned int mip_level,
+ unsigned int side,
+ ResourceID texture_id);
+
+ // Implements the DestroyRenderSurface function for D3D9.
+ virtual ParseError DestroyRenderSurface(ResourceID id);
+
+ // Implements the CreateDepthSurface function for D3D9.
+ virtual ParseError CreateDepthSurface(ResourceID id,
+ unsigned int width,
+ unsigned int height);
+
+ // Implements teh DestroyDepthSurface function for D3D9.
+ virtual ParseError DestroyDepthSurface(ResourceID id);
+
+ // Implements the SetRenderSurface function for D3D9.
+ virtual ParseError SetRenderSurface(ResourceID render_surface_id,
+ ResourceID depth_stencil_id);
+
+ // Implements the SetBackSurfaces function for D3D9.
+ virtual void SetBackSurfaces();
+
+ // Gets the D3D9 device.
+ IDirect3DDevice9 *d3d_device() const { return d3d_device_; }
+
+ // Gets a vertex buffer by resource ID.
+ VertexBufferD3D9 *GetVertexBuffer(ResourceID id) {
+ return vertex_buffers_.Get(id);
+ }
+
+ // Gets a texture by resource ID.
+ TextureD3D9 *GetTexture(ResourceID id) {
+ return textures_.Get(id);
+ }
+
+ // Gets a sampler by resource ID.
+ SamplerD3D9 *GetSampler(ResourceID id) {
+ return samplers_.Get(id);
+ }
+
+ EffectD3D9 *current_effect() { return current_effect_; }
+ private:
+ // Validates the current vertex struct to D3D, setting the streams.
+ bool ValidateStreams();
+ // Validates the current effect to D3D. This sends the effect states to D3D.
+ bool ValidateEffect();
+ // "Dirty" the current effect. This resets the effect states to D3D, and
+ // requires ValidateEffect() to be called before further draws occur.
+ void DirtyEffect();
+
+ LPDIRECT3D9 d3d_;
+ LPDIRECT3DDEVICE9 d3d_device_;
+ HWND hwnd_;
+ ResourceID current_vertex_struct_;
+ bool validate_streams_;
+ unsigned int max_vertices_;
+ ResourceID current_effect_id_;
+ bool validate_effect_;
EffectD3D9 *current_effect_;
-
- ResourceMap<VertexBufferD3D9> vertex_buffers_;
- ResourceMap<IndexBufferD3D9> index_buffers_;
- ResourceMap<VertexStructD3D9> vertex_structs_;
- ResourceMap<EffectD3D9> effects_;
- ResourceMap<EffectParamD3D9> effect_params_;
- ResourceMap<TextureD3D9> textures_;
- ResourceMap<SamplerD3D9> samplers_;
-};
-
-} // namespace command_buffer
-} // namespace o3d
-
-#endif // O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
+ IDirect3DSurface9* back_buffer_surface_;
+ IDirect3DSurface9* back_buffer_depth_surface_;
+ ResourceID current_surface_id_;
+ ResourceID current_depth_surface_id_;
+
+ ResourceMap<VertexBufferD3D9> vertex_buffers_;
+ ResourceMap<IndexBufferD3D9> index_buffers_;
+ ResourceMap<VertexStructD3D9> vertex_structs_;
+ ResourceMap<EffectD3D9> effects_;
+ ResourceMap<EffectParamD3D9> effect_params_;
+ ResourceMap<TextureD3D9> textures_;
+ ResourceMap<SamplerD3D9> samplers_;
+ ResourceMap<RenderSurfaceD3D9> render_surfaces_;
+ ResourceMap<RenderDepthStencilSurfaceD3D9> depth_surfaces_;
+};
+
+} // namespace command_buffer
+} // namespace o3d
+
+#endif // O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_GAPI_D3D9_H__
+
diff --git a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc
new file mode 100644
index 0000000..7be89d4
--- /dev/null
+++ b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc
@@ -0,0 +1,208 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// 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/gapi_d3d9.h"
+#include "command_buffer/service/win/d3d9/texture_d3d9.h"
+
+
+namespace o3d {
+namespace command_buffer {
+
+RenderSurfaceD3D9::RenderSurfaceD3D9(int width,
+ int height,
+ int mip_level,
+ int side,
+ TextureD3D9 *texture,
+ IDirect3DSurface9* direct3d_surface)
+ : width_(width), height_(height), mip_level_(mip_level), texture_(texture),
+ direct3d_surface_(direct3d_surface) {
+}
+
+RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi,
+ int width,
+ int height,
+ int mip_level,
+ int side,
+ TextureD3D9 *texture) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0);
+ CComPtr<IDirect3DSurface9> direct3d_surface_handle;
+ bool success =
+ 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);
+ return render_surface;
+}
+
+RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9(
+ int width,
+ int height,
+ IDirect3DSurface9* direct3d_surface)
+ : width_(width), height_(height), direct3d_surface_(direct3d_surface) {
+}
+
+RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create(
+ GAPID3D9 *gapi,
+ int width,
+ int height) {
+ DCHECK_GT(width, 0);
+ DCHECK_GT(height, 0);
+
+ CComPtr<IDirect3DSurface9> direct3d_surface;
+ gapi->d3d_device()->CreateDepthStencilSurface(
+ width,
+ height,
+ D3DFMT_D24S8,
+ D3DMULTISAMPLE_NONE,
+ 0,
+ FALSE,
+ &direct3d_surface,
+ NULL);
+ if (direct3d_surface == NULL) {
+ return NULL;
+ }
+ RenderDepthStencilSurfaceD3D9* depth_stencil =
+ new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface);
+ return depth_stencil;
+}
+
+// Copies the data from a texture resource.
+BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface(
+ ResourceID id,
+ unsigned int width,
+ unsigned int height,
+ unsigned int mip_level,
+ unsigned int side,
+ ResourceID texture_id) {
+ if (id == current_surface_id_) {
+ // This will delete the current surface which would be bad.
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ TextureD3D9 *texture = textures_.Get(texture_id);
+ if (!texture->render_surfaces_enabled()) {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ } else {
+ RenderSurfaceD3D9* render_surface = RenderSurfaceD3D9::Create(this,
+ width,
+ height,
+ mip_level,
+ side,
+ texture);
+ if (render_surface == NULL) {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ render_surfaces_.Assign(id, render_surface);
+ }
+ return BufferSyncInterface::PARSE_NO_ERROR;
+}
+
+BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) {
+ if (id == current_surface_id_) {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ return render_surfaces_.Destroy(id) ?
+ BufferSyncInterface::PARSE_NO_ERROR :
+ BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+}
+
+BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface(
+ ResourceID id,
+ unsigned int width,
+ unsigned int height) {
+ if (id == current_depth_surface_id_) {
+ // This will delete the current surface which would be bad.
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ RenderDepthStencilSurfaceD3D9* depth_surface =
+ RenderDepthStencilSurfaceD3D9::Create(this, width, height);
+ if (depth_surface == NULL) {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ depth_surfaces_.Assign(id, depth_surface);
+ return BufferSyncInterface::PARSE_NO_ERROR;
+}
+
+BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) {
+ if (id == current_depth_surface_id_) {
+ return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
+ }
+ return depth_surfaces_.Destroy(id) ?
+ 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);
+ RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface =
+ 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;
+ IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ?
+ d3d_render_depth_surface->GetSurfaceHandle() : NULL;
+
+ // Get the device and set the render target and the depth stencil surface.
+ IDirect3DDevice9 *device = this->d3d_device();
+
+ HR(device->SetRenderTarget(0, d3d_surface));
+ HR(device->SetDepthStencilSurface(d3d_depth_surface));
+ current_surface_id_ = render_surface_id;
+ current_depth_surface_id_ = depth_stencil_id;
+ return BufferSyncInterface::PARSE_NO_ERROR;
+}
+
+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()->SetDepthStencilSurface(back_buffer_depth_surface_));
+}
+
+} // namespace command_buffer
+} // namespace o3d
+
diff --git a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h
new file mode 100644
index 0000000..f4b9cd9
--- /dev/null
+++ b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_RENDER_SURFACE_D3D9_H__
+#define O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_RENDER_SURFACE_D3D9_H__
+
+// This file contains the definition of the D3D9 versions of
+// render surface-related resource classes.
+
+#include <d3d9.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"
+
+namespace o3d {
+namespace command_buffer {
+
+class GAPID3D9;
+
+class RenderSurfaceD3D9 : public RenderSurface {
+ public:
+ RenderSurfaceD3D9(int width,
+ int height,
+ int mip_level,
+ int side,
+ TextureD3D9 *texture,
+ IDirect3DSurface9* direct3d_surface);
+ virtual ~RenderSurfaceD3D9() {}
+
+ static RenderSurfaceD3D9* Create(GAPID3D9 *gapi,
+ int width,
+ int height,
+ int mip_level,
+ int side,
+ TextureD3D9 *texture);
+ IDirect3DSurface9* GetSurfaceHandle() const {
+ return direct3d_surface_;
+ }
+ private:
+ CComPtr<IDirect3DSurface9> direct3d_surface_;
+ unsigned int width_;
+ unsigned int height_;
+ unsigned int mip_level_;
+ TextureD3D9* texture_;
+ DISALLOW_COPY_AND_ASSIGN(RenderSurfaceD3D9);
+};
+
+class RenderDepthStencilSurfaceD3D9 : public RenderDepthStencilSurface {
+ public:
+ RenderDepthStencilSurfaceD3D9(int width,
+ int height,
+ IDirect3DSurface9* direct3d_surface);
+ virtual ~RenderDepthStencilSurfaceD3D9() {}
+
+ static RenderDepthStencilSurfaceD3D9* Create(
+ GAPID3D9 *gapi,
+ int width,
+ int height);
+ IDirect3DSurface9* GetSurfaceHandle() const {
+ return direct3d_surface_;
+ }
+ private:
+ CComPtr<IDirect3DSurface9> direct3d_surface_;
+ unsigned int width_;
+ unsigned int height_;
+ DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceD3D9);
+};
+
+} // namespace command_buffer
+} // namespace o3d
+
+#endif // O3D_COMMAND_BUFFER_SERVICE_WIN_D3D9_RENDER_SURFACE_D3D9_H__
+
diff --git a/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc b/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc
index cbd8cf5..121bf6f 100644
--- a/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc
+++ b/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc
@@ -40,7 +40,7 @@ namespace o3d {
namespace command_buffer {
// Converts a texture format to a D3D texture format.
-static D3DFORMAT D3DFormat(texture::Format format) {
+D3DFORMAT TextureD3D9::D3DFormat(texture::Format format) {
switch (format) {
case texture::XRGB8: return D3DFMT_X8R8G8B8;
case texture::ARGB8: return D3DFMT_A8R8G8B8;
@@ -51,7 +51,7 @@ static D3DFORMAT D3DFormat(texture::Format format) {
}
// Converts a cube map face to a D3D face.
-static D3DCUBEMAP_FACES D3DFace(texture::Face face) {
+D3DCUBEMAP_FACES TextureD3D9::D3DFace(texture::Face face) {
switch (face) {
case texture::FACE_POSITIVE_X:
return D3DCUBEMAP_FACE_POSITIVE_X;
@@ -75,7 +75,6 @@ static D3DCUBEMAP_FACES D3DFace(texture::Face face) {
// Destroys the 2D texture, releasing the D3D texture, and its shadow if any.
Texture2DD3D9::~Texture2DD3D9() {
DCHECK(d3d_texture_);
- d3d_texture_->Release();
d3d_texture_ = NULL;
if (d3d_shadow_) {
d3d_shadow_->Release();
@@ -91,14 +90,28 @@ Texture2DD3D9 *Texture2DD3D9::Create(GAPID3D9 *gapi,
unsigned int height,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
DCHECK_GT(width, 0);
DCHECK_GT(height, 0);
DCHECK_GT(levels, 0);
D3DFORMAT d3d_format = D3DFormat(format);
IDirect3DDevice9 *device = gapi->d3d_device();
- if (flags & texture::DYNAMIC) {
- IDirect3DTexture9 *d3d_texture = NULL;
+ if (enable_render_surfaces) {
+ CComPtr<IDirect3DTexture9> d3d_texture = NULL;
+ HRESULT result = device->CreateTexture(width, height, levels,
+ D3DUSAGE_RENDERTARGET, d3d_format,
+ D3DPOOL_DEFAULT, &d3d_texture,
+ NULL);
+ if (result != D3D_OK) {
+ LOG(ERROR) << "DirectX error when calling CreateTexture: "
+ << DXGetErrorStringA(result);
+ return NULL;
+ }
+ return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture,
+ NULL, enable_render_surfaces);
+ } else if (flags & texture::DYNAMIC) {
+ CComPtr<IDirect3DTexture9> d3d_texture = NULL;
HRESULT result = device->CreateTexture(width, height, levels,
D3DUSAGE_DYNAMIC, d3d_format,
D3DPOOL_DEFAULT, &d3d_texture,
@@ -108,20 +121,19 @@ Texture2DD3D9 *Texture2DD3D9::Create(GAPID3D9 *gapi,
<< DXGetErrorStringA(result);
return NULL;
}
- IDirect3DTexture9 *d3d_shadow = NULL;
+ CComPtr<IDirect3DTexture9> d3d_shadow = NULL;
result = device->CreateTexture(width, height, levels, D3DUSAGE_DYNAMIC,
d3d_format, D3DPOOL_SYSTEMMEM, &d3d_shadow,
NULL);
if (result != D3D_OK) {
LOG(ERROR) << "DirectX error when calling CreateTexture: "
<< DXGetErrorStringA(result);
- d3d_texture->Release();
return NULL;
}
return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture,
- d3d_shadow);
+ d3d_shadow, enable_render_surfaces);
} else {
- IDirect3DTexture9 *d3d_texture = NULL;
+ CComPtr<IDirect3DTexture9> d3d_texture = NULL;
HRESULT result = device->CreateTexture(width, height, levels, 0, d3d_format,
D3DPOOL_MANAGED, &d3d_texture, NULL);
if (result != D3D_OK) {
@@ -130,7 +142,7 @@ Texture2DD3D9 *Texture2DD3D9::Create(GAPID3D9 *gapi,
return NULL;
}
return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture,
- NULL);
+ NULL, enable_render_surfaces);
}
}
@@ -218,12 +230,27 @@ bool Texture2DD3D9::GetData(GAPID3D9 *gapi,
return true;
}
+bool Texture2DD3D9::CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface) {
+ IDirect3DTexture9* d3d_texture =
+ static_cast<IDirect3DTexture9*>(d3d_base_texture());
+ D3DSURFACE_DESC surface_desc;
+ d3d_texture->GetLevelDesc(mip_level, &surface_desc);
+ if (width != surface_desc.Width || height != surface_desc.Height) {
+ return false;
+ }
+ HR(d3d_texture->GetSurfaceLevel(mip_level, direct3d_surface));
+ return true;
+}
+
// Texture 3D functions
// Destroys the 3D texture.
Texture3DD3D9::~Texture3DD3D9() {
DCHECK(d3d_texture_);
- d3d_texture_->Release();
d3d_texture_ = NULL;
if (d3d_shadow_) {
d3d_shadow_->Release();
@@ -240,15 +267,29 @@ Texture3DD3D9 *Texture3DD3D9::Create(GAPID3D9 *gapi,
unsigned int depth,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
DCHECK_GT(width, 0);
DCHECK_GT(height, 0);
DCHECK_GT(depth, 0);
DCHECK_GT(levels, 0);
D3DFORMAT d3d_format = D3DFormat(format);
IDirect3DDevice9 *device = gapi->d3d_device();
- if (flags & texture::DYNAMIC) {
- IDirect3DVolumeTexture9 *d3d_texture = NULL;
+ if (enable_render_surfaces) {
+ CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL;
+ HRESULT result = device->CreateVolumeTexture(width, height, depth, levels,
+ D3DUSAGE_RENDERTARGET,
+ d3d_format, D3DPOOL_DEFAULT,
+ &d3d_texture, NULL);
+ if (result != D3D_OK) {
+ LOG(ERROR) << "DirectX error when calling CreateTexture: "
+ << DXGetErrorStringA(result);
+ return NULL;
+ }
+ return new Texture3DD3D9(levels, format, flags, width, height, depth,
+ d3d_texture, NULL, enable_render_surfaces);
+ } else if (flags & texture::DYNAMIC) {
+ CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL;
HRESULT result = device->CreateVolumeTexture(width, height, depth, levels,
D3DUSAGE_DYNAMIC, d3d_format,
D3DPOOL_DEFAULT, &d3d_texture,
@@ -258,20 +299,19 @@ Texture3DD3D9 *Texture3DD3D9::Create(GAPID3D9 *gapi,
<< DXGetErrorStringA(result);
return NULL;
}
- IDirect3DVolumeTexture9 *d3d_shadow = NULL;
+ CComPtr<IDirect3DVolumeTexture9> d3d_shadow = NULL;
result = device->CreateVolumeTexture(width, height, depth, levels,
D3DUSAGE_DYNAMIC, d3d_format,
D3DPOOL_SYSTEMMEM, &d3d_shadow, NULL);
if (result != D3D_OK) {
LOG(ERROR) << "DirectX error when calling CreateTexture: "
<< DXGetErrorStringA(result);
- d3d_texture->Release();
return NULL;
}
return new Texture3DD3D9(levels, format, flags, width, height, depth,
- d3d_texture, d3d_shadow);
+ d3d_texture, d3d_shadow, enable_render_surfaces);
} else {
- IDirect3DVolumeTexture9 *d3d_texture = NULL;
+ CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL;
HRESULT result = device->CreateVolumeTexture(width, height, depth, levels,
D3DUSAGE_DYNAMIC, d3d_format,
D3DPOOL_MANAGED, &d3d_texture,
@@ -282,7 +322,7 @@ Texture3DD3D9 *Texture3DD3D9::Create(GAPID3D9 *gapi,
return NULL;
}
return new Texture3DD3D9(levels, format, flags, width, height, depth,
- d3d_texture, NULL);
+ d3d_texture, NULL, enable_render_surfaces);
}
}
@@ -372,13 +412,22 @@ bool Texture3DD3D9::GetData(GAPID3D9 *gapi,
return true;
}
+bool Texture3DD3D9::CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface) {
+ // TODO(rlp): Currently unsupported.
+ DCHECK(false);
+ return false;
+}
+
// Texture Cube functions.
// Destroys the cube map texture, releasing the D3D texture, and its shadow if
// any.
TextureCubeD3D9::~TextureCubeD3D9() {
DCHECK(d3d_texture_);
- d3d_texture_->Release();
d3d_texture_ = NULL;
if (d3d_shadow_) {
d3d_shadow_->Release();
@@ -393,13 +442,27 @@ TextureCubeD3D9 *TextureCubeD3D9::Create(GAPID3D9 *gapi,
unsigned int side,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
DCHECK_GT(side, 0);
DCHECK_GT(levels, 0);
D3DFORMAT d3d_format = D3DFormat(format);
IDirect3DDevice9 *device = gapi->d3d_device();
- if (flags & texture::DYNAMIC) {
- IDirect3DCubeTexture9 *d3d_texture = NULL;
+ if (enable_render_surfaces) {
+ CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL;
+ HRESULT result = device->CreateCubeTexture(side, levels,
+ D3DUSAGE_RENDERTARGET,
+ d3d_format, D3DPOOL_DEFAULT,
+ &d3d_texture, NULL);
+ if (result != D3D_OK) {
+ LOG(ERROR) << "DirectX error when calling CreateTexture: "
+ << DXGetErrorStringA(result);
+ return NULL;
+ }
+ return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, NULL,
+ enable_render_surfaces);
+ } else if (flags & texture::DYNAMIC) {
+ CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL;
HRESULT result = device->CreateCubeTexture(side, levels, D3DUSAGE_DYNAMIC,
d3d_format, D3DPOOL_DEFAULT,
&d3d_texture, NULL);
@@ -408,20 +471,19 @@ TextureCubeD3D9 *TextureCubeD3D9::Create(GAPID3D9 *gapi,
<< DXGetErrorStringA(result);
return NULL;
}
- IDirect3DCubeTexture9 *d3d_shadow = NULL;
+ CComPtr<IDirect3DCubeTexture9> d3d_shadow = NULL;
result = device->CreateCubeTexture(side, levels, D3DUSAGE_DYNAMIC,
d3d_format, D3DPOOL_SYSTEMMEM,
&d3d_shadow, NULL);
if (result != D3D_OK) {
LOG(ERROR) << "DirectX error when calling CreateTexture: "
<< DXGetErrorStringA(result);
- d3d_texture->Release();
return NULL;
}
return new TextureCubeD3D9(levels, format, flags, side, d3d_texture,
- d3d_shadow);
+ d3d_shadow, enable_render_surfaces);
} else {
- IDirect3DCubeTexture9 *d3d_texture = NULL;
+ CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL;
HRESULT result = device->CreateCubeTexture(side, levels, 0, d3d_format,
D3DPOOL_MANAGED, &d3d_texture,
NULL);
@@ -430,7 +492,8 @@ TextureCubeD3D9 *TextureCubeD3D9::Create(GAPID3D9 *gapi,
<< DXGetErrorStringA(result);
return NULL;
}
- return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, NULL);
+ return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, NULL,
+ enable_render_surfaces);
}
}
@@ -520,6 +583,28 @@ bool TextureCubeD3D9::GetData(GAPID3D9 *gapi,
HR(lock_texture->UnlockRect(d3d_face, level));
return true;
}
+
+bool TextureCubeD3D9::CreateRenderSurface(
+ int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface) {
+ IDirect3DCubeTexture9* d3d_cube_texture =
+ static_cast<IDirect3DCubeTexture9*>(d3d_base_texture());
+ D3DSURFACE_DESC surface_desc;
+ d3d_cube_texture->GetLevelDesc(mip_level, &surface_desc);
+ if (width != surface_desc.Width || height != surface_desc.Height ||
+ side < 0 || side > 5) {
+ return false;
+ }
+ HR(d3d_cube_texture->GetCubeMapSurface(
+ D3DFace(static_cast<texture::Face>(side)),
+ mip_level,
+ direct3d_surface));
+ return true;
+}
+
// GAPID3D9 functions.
// Destroys a texture resource.
@@ -538,9 +623,11 @@ BufferSyncInterface::ParseError GAPID3D9::CreateTexture2D(
unsigned int height,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
Texture2DD3D9 *texture = Texture2DD3D9::Create(this, width, height, levels,
- format, flags);
+ format, flags,
+ enable_render_surfaces);
if (!texture) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
// Dirty effect, because this texture id may be used
DirtyEffect();
@@ -556,9 +643,11 @@ BufferSyncInterface::ParseError GAPID3D9::CreateTexture3D(
unsigned int depth,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
Texture3DD3D9 *texture = Texture3DD3D9::Create(this, width, height, depth,
- levels, format, flags);
+ levels, format, flags,
+ enable_render_surfaces);
if (!texture) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
// Dirty effect, because this texture id may be used
DirtyEffect();
@@ -572,9 +661,11 @@ BufferSyncInterface::ParseError GAPID3D9::CreateTextureCube(
unsigned int side,
unsigned int levels,
texture::Format format,
- unsigned int flags) {
+ unsigned int flags,
+ bool enable_render_surfaces) {
TextureCubeD3D9 *texture = TextureCubeD3D9::Create(this, side, levels,
- format, flags);
+ format, flags,
+ enable_render_surfaces);
if (!texture) return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
// Dirty effect, because this texture id may be used
DirtyEffect();
diff --git a/o3d/command_buffer/service/win/d3d9/texture_d3d9.h b/o3d/command_buffer/service/win/d3d9/texture_d3d9.h
index c55ba4f..9d2f153 100644
--- a/o3d/command_buffer/service/win/d3d9/texture_d3d9.h
+++ b/o3d/command_buffer/service/win/d3d9/texture_d3d9.h
@@ -35,6 +35,7 @@
// This file contains the definition of the D3D9 versions of texture-related
// resource classes.
+#include <atlbase.h>
#include "command_buffer/common/cross/gapi_interface.h"
#include "command_buffer/service/win/d3d9/d3d9_utils.h"
@@ -53,8 +54,9 @@ class TextureD3D9 : public Texture {
TextureD3D9(texture::Type type,
unsigned int levels,
texture::Format format,
+ bool enable_render_surfaces,
unsigned int flags)
- : Texture(type, levels, format, flags) {}
+ : Texture(type, levels, format, enable_render_surfaces, flags) {}
// Gets the D3D base texture.
virtual IDirect3DBaseTexture9 *d3d_base_texture() const = 0;
// Sets data into a texture resource.
@@ -75,6 +77,14 @@ class TextureD3D9 : public Texture {
unsigned int slice_pitch,
unsigned int size,
void *data) = 0;
+ // Creates the render surface, returning false if unable to.
+ virtual bool CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface) = 0;
+ static D3DFORMAT D3DFormat(texture::Format format);
+ static D3DCUBEMAP_FACES D3DFace(texture::Face face);
private:
DISALLOW_COPY_AND_ASSIGN(TextureD3D9);
};
@@ -88,8 +98,10 @@ class Texture2DD3D9 : public TextureD3D9 {
unsigned int width,
unsigned int height,
IDirect3DTexture9 *texture,
- IDirect3DTexture9 *shadow)
- : TextureD3D9(texture::TEXTURE_2D, levels, format, flags),
+ IDirect3DTexture9 *shadow,
+ bool enable_render_surfaces)
+ : TextureD3D9(texture::TEXTURE_2D, levels, format,
+ enable_render_surfaces, flags),
width_(width),
height_(height),
d3d_texture_(texture),
@@ -102,7 +114,8 @@ class Texture2DD3D9 : public TextureD3D9 {
unsigned int height,
unsigned int levels,
texture::Format format,
- unsigned int flags);
+ unsigned int flags,
+ bool enable_render_surfaces);
// Sets data into a 2D texture resource.
virtual bool SetData(GAPID3D9 *gapi,
const Volume& volume,
@@ -121,6 +134,12 @@ class Texture2DD3D9 : public TextureD3D9 {
unsigned int slice_pitch,
unsigned int size,
void *data);
+ // Create a render surface which matches this texture type.
+ virtual bool CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface);
// Gets the D3D base texture.
virtual IDirect3DBaseTexture9 *d3d_base_texture() const {
return d3d_texture_;
@@ -128,7 +147,7 @@ class Texture2DD3D9 : public TextureD3D9 {
private:
unsigned int width_;
unsigned int height_;
- IDirect3DTexture9 *d3d_texture_;
+ CComPtr<IDirect3DTexture9> d3d_texture_;
IDirect3DTexture9 *d3d_shadow_;
DISALLOW_COPY_AND_ASSIGN(Texture2DD3D9);
};
@@ -143,8 +162,10 @@ class Texture3DD3D9 : public TextureD3D9 {
unsigned int height,
unsigned int depth,
IDirect3DVolumeTexture9 *texture,
- IDirect3DVolumeTexture9 *shadow)
- : TextureD3D9(texture::TEXTURE_2D, levels, format, flags),
+ IDirect3DVolumeTexture9 *shadow,
+ bool enable_render_surfaces)
+ : TextureD3D9(texture::TEXTURE_2D, levels, format,
+ enable_render_surfaces, flags),
width_(width),
height_(height),
depth_(depth),
@@ -158,7 +179,8 @@ class Texture3DD3D9 : public TextureD3D9 {
unsigned int depth,
unsigned int levels,
texture::Format format,
- unsigned int flags);
+ unsigned int flags,
+ bool enable_render_surfaces);
// Sets data into a 3D texture resource.
virtual bool SetData(GAPID3D9 *gapi,
const Volume& volume,
@@ -177,6 +199,12 @@ class Texture3DD3D9 : public TextureD3D9 {
unsigned int slice_pitch,
unsigned int size,
void *data);
+ // Create a render surface which matches this texture type.
+ virtual bool CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface);
// Gets the D3D base texture.
virtual IDirect3DBaseTexture9 *d3d_base_texture() const {
return d3d_texture_;
@@ -185,7 +213,7 @@ class Texture3DD3D9 : public TextureD3D9 {
unsigned int width_;
unsigned int height_;
unsigned int depth_;
- IDirect3DVolumeTexture9 *d3d_texture_;
+ CComPtr<IDirect3DVolumeTexture9> d3d_texture_;
IDirect3DVolumeTexture9 *d3d_shadow_;
DISALLOW_COPY_AND_ASSIGN(Texture3DD3D9);
};
@@ -198,8 +226,10 @@ class TextureCubeD3D9 : public TextureD3D9 {
unsigned int flags,
unsigned int side,
IDirect3DCubeTexture9 *texture,
- IDirect3DCubeTexture9 *shadow)
- : TextureD3D9(texture::TEXTURE_CUBE, levels, format, flags),
+ IDirect3DCubeTexture9 *shadow,
+ bool enable_render_surfaces)
+ : TextureD3D9(texture::TEXTURE_CUBE, levels, format,
+ enable_render_surfaces, flags),
side_(side),
d3d_texture_(texture),
d3d_shadow_(shadow) {}
@@ -209,7 +239,8 @@ class TextureCubeD3D9 : public TextureD3D9 {
unsigned int side,
unsigned int levels,
texture::Format format,
- unsigned int flags);
+ unsigned int flags,
+ bool enable_render_surfaces);
// Sets data into a cube map texture resource.
virtual bool SetData(GAPID3D9 *gapi,
const Volume& volume,
@@ -228,13 +259,19 @@ class TextureCubeD3D9 : public TextureD3D9 {
unsigned int slice_pitch,
unsigned int size,
void *data);
+ // Create a render surface which matches this texture type.
+ virtual bool CreateRenderSurface(int width,
+ int height,
+ int mip_level,
+ int side,
+ IDirect3DSurface9** direct3d_surface);
// Gets the D3D base texture.
virtual IDirect3DBaseTexture9 *d3d_base_texture() const {
return d3d_texture_;
}
private:
unsigned int side_;
- IDirect3DCubeTexture9 *d3d_texture_;
+ CComPtr<IDirect3DCubeTexture9> d3d_texture_;
IDirect3DCubeTexture9 *d3d_shadow_;
DISALLOW_COPY_AND_ASSIGN(TextureCubeD3D9);
};