summaryrefslogtreecommitdiffstats
path: root/o3d/core
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 21:12:57 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-25 21:12:57 +0000
commit6ad2e0a474b31402cc23451a19a04f5209a6c95f (patch)
treeb1d51d6bc70d30aeb27317ca262e7039ecf5f567 /o3d/core
parent37f46b46aea606bd1cfe6d7808c8cfcf42410fee (diff)
downloadchromium_src-6ad2e0a474b31402cc23451a19a04f5209a6c95f.zip
chromium_src-6ad2e0a474b31402cc23451a19a04f5209a6c95f.tar.gz
chromium_src-6ad2e0a474b31402cc23451a19a04f5209a6c95f.tar.bz2
Deleted gpu process and command buffer code from O3D tree. Now resides in Chrome tree at src/gpu.
Review URL: http://codereview.chromium.org/442013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core')
-rw-r--r--o3d/core/cross/command_buffer/buffer_cb.cc197
-rw-r--r--o3d/core/cross/command_buffer/buffer_cb.h168
-rw-r--r--o3d/core/cross/command_buffer/display_window_cb.h80
-rw-r--r--o3d/core/cross/command_buffer/effect_cb.cc259
-rw-r--r--o3d/core/cross/command_buffer/effect_cb.h88
-rw-r--r--o3d/core/cross/command_buffer/install_check.cc43
-rw-r--r--o3d/core/cross/command_buffer/param_cache_cb.cc286
-rw-r--r--o3d/core/cross/command_buffer/param_cache_cb.h80
-rw-r--r--o3d/core/cross/command_buffer/primitive_cb.cc143
-rw-r--r--o3d/core/cross/command_buffer/primitive_cb.h68
-rw-r--r--o3d/core/cross/command_buffer/render_surface_cb.cc108
-rw-r--r--o3d/core/cross/command_buffer/render_surface_cb.h141
-rw-r--r--o3d/core/cross/command_buffer/renderer_cb.cc419
-rw-r--r--o3d/core/cross/command_buffer/renderer_cb.h328
-rw-r--r--o3d/core/cross/command_buffer/sampler_cb.cc144
-rw-r--r--o3d/core/cross/command_buffer/sampler_cb.h67
-rw-r--r--o3d/core/cross/command_buffer/states_cb.cc646
-rw-r--r--o3d/core/cross/command_buffer/states_cb.h104
-rw-r--r--o3d/core/cross/command_buffer/stream_bank_cb.cc198
-rw-r--r--o3d/core/cross/command_buffer/stream_bank_cb.h78
-rw-r--r--o3d/core/cross/command_buffer/texture_cb.cc677
-rw-r--r--o3d/core/cross/command_buffer/texture_cb.h215
22 files changed, 0 insertions, 4537 deletions
diff --git a/o3d/core/cross/command_buffer/buffer_cb.cc b/o3d/core/cross/command_buffer/buffer_cb.cc
deleted file mode 100644
index 301dfa7..0000000
--- a/o3d/core/cross/command_buffer/buffer_cb.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * 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 implementation of VertexBufferCB and IndexBufferCB.
-
-#include "core/cross/precompile.h"
-#include "core/cross/command_buffer/buffer_cb.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-#include "gpu/command_buffer/client/fenced_allocator.h"
-
-namespace o3d {
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-using command_buffer::FencedAllocator;
-
-VertexBufferCB::VertexBufferCB(ServiceLocator* service_locator,
- RendererCB *renderer)
- : VertexBuffer(service_locator),
- lock_pointer_(NULL),
- has_data_(false),
- resource_id_(command_buffer::kInvalidResource),
- renderer_(renderer) {
-}
-
-
-VertexBufferCB::~VertexBufferCB() {
- ConcreteFree();
-}
-
-// Sends the DestroyVertexBuffer command, and frees the ID from the allocator.
-void VertexBufferCB::ConcreteFree() {
- if (resource_id_ != command_buffer::kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyVertexBuffer(resource_id_);
- renderer_->vertex_buffer_ids().FreeID(resource_id_);
- resource_id_ = command_buffer::kInvalidResource;
- }
-}
-
-// Allocates a resource ID, and sends the CreateVertexBuffer command.
-bool VertexBufferCB::ConcreteAllocate(size_t size_in_bytes) {
- ConcreteFree();
- if (size_in_bytes > 0) {
- resource_id_ = renderer_->vertex_buffer_ids().AllocateID();
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateVertexBuffer(resource_id_, size_in_bytes,
- command_buffer::vertex_buffer::kNone);
- has_data_ = false;
- }
- return true;
-}
-
-// Allocates the locked region into the transfer shared memory area. If the
-// buffer resource contains data, copies it back (by sending the
-// GetVertexBufferData command).
-bool VertexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) {
- *buffer_data = NULL;
- if (GetSizeInBytes() == 0 || lock_pointer_)
- return false;
- lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes());
- if (!lock_pointer_) return false;
- if (has_data_) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->GetVertexBufferData(
- resource_id_, 0, GetSizeInBytes(),
- renderer_->transfer_shm_id(),
- renderer_->allocator()->GetOffset(lock_pointer_));
- helper->Finish();
- }
- *buffer_data = lock_pointer_;
- return true;
-}
-
-// Copies the data into the resource by sending the SetVertexBufferData
-// command, then frees the shared memory, pending the transfer completion.
-bool VertexBufferCB::ConcreteUnlock() {
- if (GetSizeInBytes() == 0 || !lock_pointer_)
- return false;
- O3DCmdHelper* helper = renderer_->helper();
- helper->SetVertexBufferData(
- resource_id_, 0, GetSizeInBytes(),
- renderer_->transfer_shm_id(),
- renderer_->allocator()->GetOffset(lock_pointer_));
-
- renderer_->allocator()->FreePendingToken(lock_pointer_,
- helper->InsertToken());
- lock_pointer_ = NULL;
- has_data_ = true;
- return true;
-}
-
-IndexBufferCB::IndexBufferCB(ServiceLocator* service_locator,
- RendererCB *renderer)
- : IndexBuffer(service_locator),
- lock_pointer_(NULL),
- has_data_(false),
- resource_id_(command_buffer::kInvalidResource),
- renderer_(renderer) {
-}
-
-
-IndexBufferCB::~IndexBufferCB() {
- ConcreteFree();
-}
-
-// Sends the DestroyIndexBuffer command, and frees the ID from the allocator.
-void IndexBufferCB::ConcreteFree() {
- if (resource_id_ != command_buffer::kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyIndexBuffer(resource_id_);
- renderer_->index_buffer_ids().FreeID(resource_id_);
- resource_id_ = command_buffer::kInvalidResource;
- }
-}
-
-// Allocates a resource ID, and sends the CreateIndexBuffer command.
-bool IndexBufferCB::ConcreteAllocate(size_t size_in_bytes) {
- ConcreteFree();
- if (size_in_bytes > 0) {
- resource_id_ = renderer_->index_buffer_ids().AllocateID();
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateIndexBuffer(
- resource_id_, size_in_bytes,
- command_buffer::index_buffer::kIndex32Bit);
- has_data_ = false;
- }
- return true;
-}
-
-// Allocates the locked region into the transfer shared memory area. If the
-// buffer resource contains data, copies it back (by sending the
-// GetIndexBufferData command).
-bool IndexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) {
- *buffer_data = NULL;
- if (GetSizeInBytes() == 0 || lock_pointer_)
- return false;
- lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes());
- if (!lock_pointer_) return false;
- if (has_data_) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->GetIndexBufferData(
- resource_id_, 0, GetSizeInBytes(),
- renderer_->transfer_shm_id(),
- renderer_->allocator()->GetOffset(lock_pointer_));
- helper->Finish();
- }
- *buffer_data = lock_pointer_;
- return true;
-}
-
-// Copies the data into the resource by sending the SetIndexBufferData
-// command, then frees the shared memory, pending the transfer completion.
-bool IndexBufferCB::ConcreteUnlock() {
- if (GetSizeInBytes() == 0 || !lock_pointer_)
- return false;
- O3DCmdHelper* helper = renderer_->helper();
- helper->SetIndexBufferData(
- resource_id_, 0, GetSizeInBytes(),
- renderer_->transfer_shm_id(),
- renderer_->allocator()->GetOffset(lock_pointer_));
- renderer_->allocator()->FreePendingToken(lock_pointer_,
- helper->InsertToken());
- lock_pointer_ = NULL;
- has_data_ = true;
- return true;
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/buffer_cb.h b/o3d/core/cross/command_buffer/buffer_cb.h
deleted file mode 100644
index 7a6f567..0000000
--- a/o3d/core/cross/command_buffer/buffer_cb.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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 command-buffer versions of VertexBuffer and
-// IndexBuffer.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_BUFFER_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_BUFFER_CB_H_
-
-#include "core/cross/precompile.h"
-#include "core/cross/buffer.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-
-namespace o3d {
-
-// Command-buffer version of VertexBuffer. This class manages the resources for
-// vertex buffers and the transfer of data.
-// Vertex buffer resources are allocated on the service side (into GPU-friendly
-// memory), but the client side cannot map it. So instead, data updates go
-// through a buffer in the transfer shared memory when Lock and Unlock are
-// called.
-class VertexBufferCB : public VertexBuffer {
- public:
- VertexBufferCB(ServiceLocator* service_locator, RendererCB *renderer);
- ~VertexBufferCB();
-
- // Returns the resource ID for this vertex buffer.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- protected:
- // Allocates a vertex buffer resource.
- // Parameters:
- // size_in_bytes: the memory size of the vertex buffer.
- // Returns:
- // true if successful.
- virtual bool ConcreteAllocate(size_t size_in_bytes);
-
- // The concrete version of Free
- virtual void ConcreteFree();
-
- // Locks the vertex buffer for reading and writing. This allocates a buffer
- // into the transfer shared memory. If any data was set into the vertex
- // buffer, this function will copy it back for reading. Otherwise the data in
- // the returned buffer is undefined.
- // Parameters:
- // access_mode: How you want to access the data.
- // buffer_data: a pointer to a variable that will contain the pointer to
- // the locked buffer upon success.
- // Returns:
- // true if successful.
- virtual bool ConcreteLock(Buffer::AccessMode access_mode, void** buffer_data);
-
- // Unlocks the vertex buffer, copying the data into the vertex buffer
- // resource.
- // Returns:
- // true if successful.
- virtual bool ConcreteUnlock();
-
- private:
- // The pointer to the region in the transfer shared memory buffer when the
- // vertex buffer is locked, or NULL if it is not locked.
- void *lock_pointer_;
-
- // Whether or not data was entered into the vertex buffer, to avoid copying
- // back undefined pixels.
- bool has_data_;
-
- // The command buffer resource ID for the vertex buffer.
- command_buffer::ResourceId resource_id_;
-
- // The renderer that created this vertex buffer.
- RendererCB *renderer_;
-};
-
-// Command-buffer version of IndexBuffer. This class manages the resources for
-// index buffers and the transfer of data.
-// Index buffer resources are allocated on the service side (into GPU-friendly
-// memory), but the client side cannot map it. So instead, data updates go
-// through a buffer in the transfer shared memory when Lock and Unlock are
-// called.
-class IndexBufferCB : public IndexBuffer {
- public:
- IndexBufferCB(ServiceLocator* service_locator, RendererCB *renderer);
- ~IndexBufferCB();
-
- // Returns the resource ID for this vertex buffer.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- protected:
- // Allocates an index buffer resource.
- // Parameters:
- // size_in_bytes: the memory size of the index buffer.
- // Returns:
- // true if successful.
- virtual bool ConcreteAllocate(size_t size_in_bytes);
-
- // The concrete version of Free
- virtual void ConcreteFree();
-
- // Locks the index buffer for reading and writing. This allocates a buffer
- // into the transfer shared memory. If any data was set into the index
- // buffer, this function will copy it back for reading. Otherwise the data in
- // the returned buffer is undefined.
- // Parameters:
- // access_mode: How you want to access the data.
- // buffer_data: a pointer to a variable that will contain the pointer to
- // the locked buffer upon success.
- // Returns:
- // true if successful.
- virtual bool ConcreteLock(Buffer::AccessMode access_mode, void** buffer_data);
-
- // Unlocks the index buffer, copying the data into the index buffer
- // resource.
- // Returns:
- // true if successful.
- virtual bool ConcreteUnlock();
-
- private:
- // Destroys the resource, and frees the resource ID.
- void Destroy();
-
- // The pointer to the region in the transfer shared memory buffer when the
- // index buffer is locked, or NULL if it is not locked.
- void *lock_pointer_;
-
- // Whether or not data was entered into the index buffer, to avoid copying
- // back undefined pixels.
- bool has_data_;
-
- // The command buffer resource ID for the index buffer.
- command_buffer::ResourceId resource_id_;
-
- // The renderer that created this index buffer.
- RendererCB *renderer_;
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_BUFFER_CB_H_
diff --git a/o3d/core/cross/command_buffer/display_window_cb.h b/o3d/core/cross/command_buffer/display_window_cb.h
deleted file mode 100644
index a855457..0000000
--- a/o3d/core/cross/command_buffer/display_window_cb.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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_CORE_WIN_DISPLAY_WINDOW_CB_H_
-#define O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_
-
-#include "core/cross/display_window.h"
-#include "gpu/command_buffer/common/command_buffer.h"
-
-namespace o3d {
-
-// DisplayWindow subclass without information needed to connect to and use
-// an out-of-process command buffer renderer.
-class DisplayWindowCB : public DisplayWindow {
- public:
- DisplayWindowCB() : width_(0), height_(0) {}
- virtual ~DisplayWindowCB() {}
-
- command_buffer::CommandBuffer* command_buffer() const {
- return command_buffer_;
- }
-
- void set_command_buffer(command_buffer::CommandBuffer* command_buffer) {
- command_buffer_ = command_buffer;
- }
-
- int width() const {
- return width_;
- }
-
- void set_width(int width) {
- width_ = width;
- }
-
- int height() const {
- return height_;
- }
-
- void set_height(int height) {
- height_ = height;
- }
-
- private:
- command_buffer::CommandBuffer* command_buffer_;
- int width_;
- int height_;
- DISALLOW_COPY_AND_ASSIGN(DisplayWindowCB);
-};
-} // end namespace o3d
-
-#endif // O3D_CORE_WIN_DISPLAY_WINDOW_CB_H_
diff --git a/o3d/core/cross/command_buffer/effect_cb.cc b/o3d/core/cross/command_buffer/effect_cb.cc
deleted file mode 100644
index 9e860dd..0000000
--- a/o3d/core/cross/command_buffer/effect_cb.cc
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * 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 command-buffer version of the Effect class.
-
-#include "core/cross/precompile.h"
-#include "core/cross/error.h"
-#include "core/cross/semantic_manager.h"
-#include "core/cross/service_locator.h"
-#include "core/cross/command_buffer/effect_cb.h"
-#include "gpu/command_buffer/common/constants.h"
-#include "gpu/command_buffer/common/o3d_cmd_format.h"
-#include "gpu/command_buffer/client/fenced_allocator.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-namespace o3d {
-
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-using command_buffer::ResourceId;
-namespace effect_param = command_buffer::effect_param;
-namespace parse_error = command_buffer::parse_error;
-namespace vertex_struct = command_buffer::vertex_struct;
-
-EffectCB::EffectCB(ServiceLocator *service_locator, RendererCB *renderer)
- : Effect(service_locator),
- resource_id_(command_buffer::kInvalidResource),
- generation_(0),
- renderer_(renderer) {
-}
-
-EffectCB::~EffectCB() {
- Destroy();
-}
-
-bool EffectCB::LoadFromFXString(const String& source) {
- Destroy();
- // NOTE: Destroy() already increments the generation counter.
- String vp_main;
- String fp_main;
- MatrixLoadOrder load_order = ROW_MAJOR;
- // TODO: Check for failure once shader parser is in.
- if (!ValidateFX(source, &vp_main, &fp_main, &load_order)) {
- return false;
- }
- set_matrix_load_order(load_order);
- // buffer is vp_main \0 fp_main \0 effect_text
- // The source doesn't need to be 0-terminated, we are passing the size.
- size_t source_size = vp_main.size() + 1 + fp_main.size() + 1 + source.size();
- char *buffer_data = renderer_->allocator()->AllocTyped<char>(source_size);
- if (!buffer_data) {
- O3D_ERROR(service_locator()) << "Could not allocate " << source_size
- << " bytes to load the effect.";
- return false;
- }
- memcpy(buffer_data, vp_main.data(), vp_main.size());
- buffer_data[vp_main.size()] = 0;
- memcpy(buffer_data + vp_main.size() + 1, fp_main.data(), fp_main.size());
- buffer_data[vp_main.size() + 1 + fp_main.size()] = 0;
- memcpy(buffer_data + vp_main.size() + 1 + fp_main.size() + 1,
- source.data(), source.size());
-
- ResourceId resource_id = renderer_->effect_ids().AllocateID();
-
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateEffect(
- resource_id, source_size,
- renderer_->transfer_shm_id(),
- renderer_->allocator()->GetOffset(buffer_data));
- renderer_->allocator()->FreePendingToken(buffer_data, helper->InsertToken());
-
- // NOTE: we're calling Finish to check the command result, to see if
- // the effect has succesfully compiled.
- helper->Finish();
- if (renderer_->GetParseError() != parse_error::kParseNoError) {
- O3D_ERROR(service_locator()) << "Effect failed to compile.";
- renderer_->effect_ids().FreeID(resource_id);
- return false;
- }
- resource_id_ = resource_id;
- EffectHelper effect_helper(helper, renderer_->allocator(),
- renderer_->transfer_shm_id(),
- &renderer_->effect_param_ids());
- if (!effect_helper.CreateEffectParameters(resource_id, &param_descs_)) {
- O3D_ERROR(service_locator()) << "Failed to create effect parameters.";
- Destroy();
- return false;
- }
- for (unsigned int i = 0; i < param_descs_.size(); ++i) {
- if (!effect_helper.GetParamStrings(&(param_descs_[i]))) {
- O3D_ERROR(service_locator())
- << "Failed to create effect parameters strings.";
- Destroy();
- return false;
- }
- }
- if (!effect_helper.GetEffectStreams(resource_id, &stream_descs_)) {
- O3D_ERROR(service_locator()) << "Failed to get streams.";
- Destroy();
- return false;
- }
- set_source(source);
- return true;
-}
-
-void EffectCB::Destroy() {
- set_source("");
- ++generation_;
- if (resource_id_ != command_buffer::kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyEffect(resource_id_);
- renderer_->effect_ids().FreeID(resource_id_);
- resource_id_ = command_buffer::kInvalidResource;
- }
- if (param_descs_.size() > 0) {
- EffectHelper effect_helper(renderer_->helper(), renderer_->allocator(),
- renderer_->transfer_shm_id(),
- &renderer_->effect_param_ids());
- effect_helper.DestroyEffectParameters(param_descs_);
- param_descs_.clear();
- }
-}
-
-static const ObjectBase::Class* CBTypeToParamType(
- effect_param::DataType type) {
- switch (type) {
- case effect_param::kFloat1:
- return ParamFloat::GetApparentClass();
- case effect_param::kFloat2:
- return ParamFloat2::GetApparentClass();
- case effect_param::kFloat3:
- return ParamFloat3::GetApparentClass();
- case effect_param::kFloat4:
- return ParamFloat4::GetApparentClass();
- case effect_param::kInt:
- return ParamInteger::GetApparentClass();
- case effect_param::kMatrix4:
- return ParamMatrix4::GetApparentClass();
- case effect_param::kSampler:
- return ParamSampler::GetApparentClass();
- case effect_param::kTexture:
- return ParamTexture::GetApparentClass();
- default : {
- DLOG(ERROR) << "Cannot convert command buffer type "
- << type
- << " to a Param type.";
- return NULL;
- }
- }
-}
-
-void EffectCB::GetParameterInfo(EffectParameterInfoArray *array) {
- DCHECK(array);
- array->clear();
- SemanticManager *semantic_manager =
- service_locator()->GetService<SemanticManager>();
- for (unsigned int i = 0; i < param_descs_.size(); ++i) {
- EffectHelper::EffectParamDesc &desc = param_descs_[i];
- const ObjectBase::Class *param_class = CBTypeToParamType(desc.data_type);
- if (!param_class)
- continue;
- const ObjectBase::Class *sem_class = NULL;
-
- if (desc.semantic.size()) {
- sem_class = semantic_manager->LookupSemantic(desc.semantic);
- }
- array->push_back(EffectParameterInfo(desc.name,
- param_class,
- desc.num_elements,
- desc.semantic,
- sem_class));
- }
-}
-
-
-static bool CBSemanticToO3DSemantic(
- vertex_struct::Semantic semantic,
- unsigned int semantic_index,
- Stream::Semantic *out_semantic,
- unsigned int *out_semantic_index) {
- switch (semantic) {
- case vertex_struct::kPosition:
- if (semantic_index != 0) return false;
- *out_semantic = Stream::POSITION;
- *out_semantic_index = 0;
- return true;
- case vertex_struct::kNormal:
- if (semantic_index != 0) return false;
- *out_semantic = Stream::NORMAL;
- *out_semantic_index = 0;
- return true;
- case vertex_struct::kColor:
- if (semantic_index > 1) return false;
- *out_semantic = Stream::COLOR;
- *out_semantic_index = semantic_index;
- return true;
- case vertex_struct::kTexCoord:
- if (semantic_index == 6) {
- *out_semantic = Stream::TANGENT;
- *out_semantic_index = 0;
- return true;
- } else if (semantic_index == 7) {
- *out_semantic = Stream::BINORMAL;
- *out_semantic_index = 0;
- return true;
- } else {
- *out_semantic = Stream::TEXCOORD;
- *out_semantic_index = semantic_index;
- return true;
- }
- default:
- return false;
- }
-}
-void EffectCB::GetStreamInfo(EffectStreamInfoArray *array) {
- DCHECK(array);
- array->clear();
- for (unsigned int i = 0; i < stream_descs_.size(); ++i) {
- Stream::Semantic semantic;
- unsigned int semantic_index;
- if (CBSemanticToO3DSemantic(stream_descs_[i].semantic,
- stream_descs_[i].semantic_index,
- &semantic,
- &semantic_index)) {
- array->push_back(EffectStreamInfo(semantic, semantic_index));
- }
- }
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/effect_cb.h b/o3d/core/cross/command_buffer/effect_cb.h
deleted file mode 100644
index 21b4d7c..0000000
--- a/o3d/core/cross/command_buffer/effect_cb.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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 defines the command-buffer version of the Effect class.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_EFFECT_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_EFFECT_CB_H_
-
-#include <vector>
-#include "core/cross/effect.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "gpu/command_buffer/client/effect_helper.h"
-
-namespace o3d {
-
-class ParamCacheCB;
-
-// This class is the command-buffer implementation of the Effect class.
-class EffectCB : public Effect {
- public:
- friend class ParamCacheCB;
- typedef command_buffer::EffectHelper EffectHelper;
-
- EffectCB(ServiceLocator *service_locator, RendererCB *renderer);
- virtual ~EffectCB();
-
- // Loads the vertex and fragment shader programs from a string containing
- // a DirectX FX description.
- virtual bool LoadFromFXString(const String& effect);
-
- // Gets the ResourceId of the effect.
- command_buffer::ResourceId resource_id() { return resource_id_; }
-
- protected:
- // Gets info about the parameters this effect needs.
- // Overriden from Effect.
- virtual void GetParameterInfo(EffectParameterInfoArray* info_array);
-
- // Gets info about the varying parameters this effects vertex shader needs.
- // Parameters:
- // info_array: EffectStreamInfoArray to receive info.
- virtual void GetStreamInfo(EffectStreamInfoArray* info_array);
-
- private:
- void Destroy();
- // The command buffer resource ID for the effect.
- command_buffer::ResourceId resource_id_;
- std::vector<EffectHelper::EffectParamDesc> param_descs_;
- std::vector<EffectHelper::EffectStreamDesc> stream_descs_;
- // A generation counter to dirty ParamCacheCBs.
- unsigned int generation_;
- // The renderer that created this effect.
- RendererCB *renderer_;
- DISALLOW_IMPLICIT_CONSTRUCTORS(EffectCB);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_EFFECT_CB_H_
diff --git a/o3d/core/cross/command_buffer/install_check.cc b/o3d/core/cross/command_buffer/install_check.cc
deleted file mode 100644
index 3e7d6aeb..0000000
--- a/o3d/core/cross/command_buffer/install_check.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.
- */
-
-
-// The precompiled header must appear before anything else.
-#include "core/cross/precompile.h"
-
-#include "core/cross/install_check.h"
-
-namespace o3d {
-
-bool RendererInstallCheck(std::string *error) {
- return true;
-}
-} // o3d
diff --git a/o3d/core/cross/command_buffer/param_cache_cb.cc b/o3d/core/cross/command_buffer/param_cache_cb.cc
deleted file mode 100644
index 5c5f64e..0000000
--- a/o3d/core/cross/command_buffer/param_cache_cb.cc
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * 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 implementation of the ParamCacheCB class.
-
-#include "core/cross/precompile.h"
-#include "core/cross/draw_element.h"
-#include "core/cross/element.h"
-#include "core/cross/semantic_manager.h"
-#include "core/cross/command_buffer/effect_cb.h"
-#include "core/cross/command_buffer/param_cache_cb.h"
-#include "core/cross/command_buffer/sampler_cb.h"
-#include "gpu/command_buffer/common/o3d_cmd_format.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-namespace o3d {
-
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-using command_buffer::EffectHelper;
-using command_buffer::ResourceId;
-namespace effect_param = command_buffer::effect_param;
-
-// Base class for ParamHandlers.
-class ParamHandlerCB {
- public:
- virtual ~ParamHandlerCB() {}
- virtual void SetValue(O3DCmdHelper* helper) = 0;
-};
-
-// Template implementation of ParamHandlerCB.
-template <typename T>
-class TypedParamHandlerCB : public ParamHandlerCB {
- public:
- TypedParamHandlerCB(T* param, ResourceId id)
- : param_(param),
- id_(id) {
- }
-
- // Sends the param value to the service.
- // This template definition only works for value types (floatn, matrix, int,
- // ..., but not textures or samplers).
- virtual void SetValue(O3DCmdHelper* helper) {
- typename T::DataType value = param_->value();
- helper->SetParamDataImmediate(id_, sizeof(value), &value);
- }
- private:
- T* param_;
- ResourceId id_;
-};
-
-// Matrices are expected in row major order in the command buffer, so
-// TypedParamHandlerCB<ParamMatrix4> works for row major, and we make a new
-// class for column major.
-typedef TypedParamHandlerCB<ParamMatrix4> MatrixParamHandlerRowsCB;
-
-class MatrixParamHandlerColumnsCB : public ParamHandlerCB {
- public:
- MatrixParamHandlerColumnsCB(ParamMatrix4* param, ResourceId id)
- : param_(param),
- id_(id) {
- }
-
- // Sends the param value to the service.
- virtual void SetValue(O3DCmdHelper* helper) {
- Matrix4 value = transpose(param_->value());
- helper->SetParamDataImmediate(id_, sizeof(value), &value);
- }
- private:
- ParamMatrix4* param_;
- ResourceId id_;
-};
-
-class SamplerParamHandlerCB : public ParamHandlerCB {
- public:
- SamplerParamHandlerCB(ParamSampler* param, ResourceId id)
- : param_(param),
- id_(id) {
- }
-
- // Sends the param value to the service.
- virtual void SetValue(O3DCmdHelper* helper) {
- SamplerCB *sampler = down_cast<SamplerCB *>(param_->value());
- uint32 value;
- if (!sampler) {
- // TODO: use error sampler
- value = command_buffer::kInvalidResource;
- } else {
- sampler->SetTextureAndStates();
- value = sampler->resource_id();
- }
- helper->SetParamDataImmediate(id_, sizeof(value), &value);
- }
- private:
- ParamSampler* param_;
- ResourceId id_;
-};
-
-static ParamHandlerCB *GetHandlerFromParamAndDesc(
- Param *param,
- const EffectHelper::EffectParamDesc &desc,
- Effect::MatrixLoadOrder matrix_load_order) {
- switch (desc.data_type) {
- case effect_param::kMatrix4:
- if (param->IsA(ParamMatrix4::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamMatrix4::DataType), desc.data_size);
- ParamMatrix4 *matrix_param = down_cast<ParamMatrix4*>(param);
- if (matrix_load_order == Effect::ROW_MAJOR) {
- return new MatrixParamHandlerRowsCB(matrix_param, desc.id);
- } else {
- return new MatrixParamHandlerColumnsCB(matrix_param, desc.id);
- }
- }
- break;
- case effect_param::kFloat1:
- if (param->IsA(ParamFloat::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamFloat::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamFloat>(
- down_cast<ParamFloat*>(param), desc.id);
- }
- break;
- case effect_param::kFloat2:
- if (param->IsA(ParamFloat2::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamFloat2::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamFloat2>(
- down_cast<ParamFloat2*>(param), desc.id);
- }
- break;
- case effect_param::kFloat3:
- if (param->IsA(ParamFloat3::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamFloat3::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamFloat3>(
- down_cast<ParamFloat3*>(param), desc.id);
- }
- break;
- case effect_param::kFloat4:
- if (param->IsA(ParamFloat4::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamFloat4::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamFloat4>(
- down_cast<ParamFloat4*>(param), desc.id);
- }
- break;
- case effect_param::kInt:
- if (param->IsA(ParamInteger::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamInteger::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamInteger>(
- down_cast<ParamInteger*>(param), desc.id);
- }
- break;
- case effect_param::kBool:
- if (param->IsA(ParamBoolean::GetApparentClass())) {
- DCHECK_EQ(sizeof(ParamBoolean::DataType), desc.data_size);
- return new TypedParamHandlerCB<ParamBoolean>(
- down_cast<ParamBoolean*>(param), desc.id);
- }
- break;
- case effect_param::kSampler:
- if (param->IsA(ParamSampler::GetApparentClass())) {
- DCHECK_EQ(sizeof(ResourceId), desc.data_size);
- return new SamplerParamHandlerCB(down_cast<ParamSampler*>(param),
- desc.id);
- }
- break;
- default:
- break;
- }
- // Do not report an error, it may be valid that the Param didn't match the
- // desc, we may still be looking for another match in other nodes.
- return NULL;
-}
-
-ParamCacheCB::ParamCacheCB()
- : last_effect_generation_(UINT_MAX),
- last_matrix_load_order_(Effect::ROW_MAJOR) {
-}
-
-ParamCacheCB::~ParamCacheCB() {
- ClearHandlers();
-}
-
-bool ParamCacheCB::ValidateEffect(Effect* effect) {
- DCHECK(effect);
-
- EffectCB* effect_cb = down_cast<EffectCB*>(effect);
- return (effect_cb->generation_ == last_effect_generation_) &&
- (effect_cb->matrix_load_order() == last_matrix_load_order_);
-}
-
-void ParamCacheCB::UpdateCache(Effect* effect,
- DrawElement* draw_element,
- Element* element,
- Material* material,
- ParamObject* override) {
- DLOG_ASSERT(effect);
- EffectCB* effect_cb = down_cast<EffectCB*>(effect);
- ClearHandlers();
- SemanticManager *semantic_manager =
- effect->service_locator()->GetService<SemanticManager>();
-
- Effect::MatrixLoadOrder load_order = effect_cb->matrix_load_order();
-
- ParamObject *param_objects[] = {
- override,
- draw_element,
- element,
- material,
- effect,
- semantic_manager->sas_param_object()
- };
- const unsigned int kParamObjectCount = arraysize(param_objects);
- for (unsigned int i = 0; i < effect_cb->param_descs_.size(); ++i) {
- EffectHelper::EffectParamDesc &desc = effect_cb->param_descs_[i];
- const ObjectBase::Class *sem_class = NULL;
- if (desc.semantic.size()) {
- sem_class = semantic_manager->LookupSemantic(desc.semantic);
- }
- ParamHandlerCB *handler = NULL;
-
- // find a valid param on one of the ParamObjects, and create a handler for
- // it.
- for (unsigned int j = 0; j < kParamObjectCount; ++j) {
- ParamObject *param_object = param_objects[j];
- Param *param = param_object->GetUntypedParam(desc.name);
- if (!param && sem_class) {
- param = param_object->GetUntypedParam(sem_class->name());
- }
- if (param) {
- handler = GetHandlerFromParamAndDesc(param, desc, load_order);
- if (handler)
- break;
- }
- }
- if (!handler) {
- DLOG(ERROR) << "Did not find a param matching " << desc.name;
- continue;
- }
- handlers_.push_back(handler);
- }
-
- last_matrix_load_order_ = load_order;
- last_effect_generation_ = effect_cb->generation_;
-}
-
-void ParamCacheCB::ClearHandlers() {
- for (unsigned int i = 0; i < handlers_.size(); ++i) {
- delete handlers_[i];
- }
- handlers_.clear();
-}
-
-void ParamCacheCB::RunHandlers(O3DCmdHelper* helper) {
- for (unsigned int i = 0; i < handlers_.size(); ++i) {
- handlers_[i]->SetValue(helper);
- }
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/param_cache_cb.h b/o3d/core/cross/command_buffer/param_cache_cb.h
deleted file mode 100644
index b96430c..0000000
--- a/o3d/core/cross/command_buffer/param_cache_cb.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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 declaration of the ParamCacheCB class.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_PARAM_CACHE_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_PARAM_CACHE_CB_H_
-
-#include <vector>
-#include "core/cross/param_cache.h"
-#include "core/cross/command_buffer/effect_cb.h"
-
-namespace o3d {
-
-class ParamHandlerCB;
-
-// This class is the command-buffer implementation of the ParamCache class. It
-// keeps a list of Param * -> param ResourceId associations handlers.
-class ParamCacheCB : public ParamCache {
- public:
- ParamCacheCB();
- virtual ~ParamCacheCB();
-
- // Updates the cache of params, re-creating the list of handlers.
- // Overridden from ParamCache.
- virtual void UpdateCache(Effect* effect,
- DrawElement* draw_element,
- Element* element,
- Material* material,
- ParamObject* override);
-
- // Runs all the cached handlers.
- void RunHandlers(command_buffer::O3DCmdHelper* helper);
-
- protected:
- // Validates platform specific information about the effect.
- // Overridden from ParamCache.
- virtual bool ValidateEffect(Effect* effect);
-
- private:
- // Destroys the handlers and clears the list.
- void ClearHandlers();
-
- unsigned int last_effect_generation_;
- Effect::MatrixLoadOrder last_matrix_load_order_;
- std::vector<ParamHandlerCB *> handlers_;
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_PARAM_CACHE_CB_H_
diff --git a/o3d/core/cross/command_buffer/primitive_cb.cc b/o3d/core/cross/command_buffer/primitive_cb.cc
deleted file mode 100644
index f97039a..0000000
--- a/o3d/core/cross/command_buffer/primitive_cb.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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 implementation of the PrimitiveCB class.
-
-#include "core/cross/precompile.h"
-#include "core/cross/command_buffer/param_cache_cb.h"
-#include "core/cross/command_buffer/primitive_cb.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "core/cross/command_buffer/buffer_cb.h"
-#include "core/cross/command_buffer/effect_cb.h"
-#include "core/cross/command_buffer/stream_bank_cb.h"
-#include "core/cross/error.h"
-#include "gpu/command_buffer/common/gapi_interface.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-// TODO: add unit tests.
-
-namespace o3d {
-
-using command_buffer::ResourceId;
-using command_buffer::O3DCmdHelper;
-using command_buffer::CommandBufferEntry;
-using command_buffer::o3d::GAPIInterface;
-using command_buffer::kInvalidResource;
-namespace vertex_struct = command_buffer::vertex_struct;
-
-PrimitiveCB::PrimitiveCB(ServiceLocator* service_locator, RendererCB *renderer)
- : Primitive(service_locator),
- renderer_(renderer) {
-}
-
-PrimitiveCB::~PrimitiveCB() {
-}
-
-// Converts an O3D primitive type to a command-buffer one.
-static command_buffer::o3d::PrimitiveType GetCBPrimitiveType(
- Primitive::PrimitiveType primitive_type) {
- switch (primitive_type) {
- case Primitive::LINELIST:
- return command_buffer::o3d::kLines;
- case Primitive::LINESTRIP:
- return command_buffer::o3d::kLineStrips;
- case Primitive::TRIANGLELIST:
- return command_buffer::o3d::kTriangles;
- case Primitive::TRIANGLESTRIP:
- return command_buffer::o3d::kTriangleStrips;
- case Primitive::TRIANGLEFAN:
- return command_buffer::o3d::kTriangleFans;
- default:
- // Note that POINTLIST falls into this case, for compatibility with D3D.
- return command_buffer::o3d::kMaxPrimitiveType;
- }
-}
-
-// Sends the draw commands to the command buffers.
-void PrimitiveCB::PlatformSpecificRender(Renderer* renderer,
- DrawElement* draw_element,
- Material* material,
- ParamObject* override,
- ParamCache* param_cache) {
- DLOG_ASSERT(draw_element);
- DLOG_ASSERT(param_cache);
- DLOG_ASSERT(material);
-
- EffectCB *effect_cb = down_cast<EffectCB*>(material->effect());
- DLOG_ASSERT(effect_cb);
- StreamBankCB* stream_bank_cb = down_cast<StreamBankCB*>(stream_bank());
- DLOG_ASSERT(stream_bank_cb);
-
- ParamCacheCB *param_cache_cb = down_cast<ParamCacheCB *>(param_cache);
-
- if (!param_cache_cb->ValidateAndCacheParams(effect_cb,
- draw_element,
- this,
- stream_bank_cb,
- material,
- override)) {
- // TODO: should we do this here, or on the service side ?
- // InsertMissingVertexStreams();
- }
-
- IndexBufferCB *index_buffer_cb =
- down_cast<IndexBufferCB *>(index_buffer());
- if (!index_buffer_cb) {
- // TODO(gman): draw non-indexed primitives.
- DLOG(INFO) << "Trying to draw with an empty index buffer.";
- return;
- }
- command_buffer::o3d::PrimitiveType cb_primitive_type =
- GetCBPrimitiveType(primitive_type_);
- if (cb_primitive_type == command_buffer::o3d::kMaxPrimitiveType) {
- DLOG(INFO) << "Invalid primitive type (" << primitive_type_ << ").";
- return;
- }
-
- // Make sure our streams are up to date (skinned, etc..)
- stream_bank_cb->UpdateStreams();
-
- stream_bank_cb->BindStreamsForRendering();
-
- O3DCmdHelper* helper = renderer_->helper();
-
- // Sets current effect.
- // TODO: cache current effect ?
- helper->SetEffect(effect_cb->resource_id());
- param_cache_cb->RunHandlers(helper);
-
- // Draws.
- helper->DrawIndexed(cb_primitive_type, index_buffer_cb->resource_id(),
- 0, number_primitives_, 0, number_vertices_ - 1);
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/primitive_cb.h b/o3d/core/cross/command_buffer/primitive_cb.h
deleted file mode 100644
index 955150c..0000000
--- a/o3d/core/cross/command_buffer/primitive_cb.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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 definition of the PrimitiveCB class.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_PRIMITIVE_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_PRIMITIVE_CB_H_
-
-#include "core/cross/precompile.h"
-#include "core/cross/primitive.h"
-#include "gpu/command_buffer/common/resource.h"
-
-namespace o3d {
-
-class RendererCB;
-
-// PrimitiveCB is the command-buffer implementation of the Primitive. It
-// provides the necessary interfaces for setting the geometry streams on the
-// Primitive.
-class PrimitiveCB : public Primitive {
- public:
- PrimitiveCB(ServiceLocator* service_locator, RendererCB *renderer);
- virtual ~PrimitiveCB();
-
- protected:
- // Overridden from Primitve.
- virtual void PlatformSpecificRender(Renderer* renderer,
- DrawElement* draw_element,
- Material* material,
- ParamObject* override,
- ParamCache* param_cache);
- private:
- // The renderer that created this shape data.
- RendererCB *renderer_;
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_PRIMITIVE_CB_H_
diff --git a/o3d/core/cross/command_buffer/render_surface_cb.cc b/o3d/core/cross/command_buffer/render_surface_cb.cc
deleted file mode 100644
index 83ebce4..0000000
--- a/o3d/core/cross/command_buffer/render_surface_cb.cc
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.
- */
-
-
-#include "core/cross/command_buffer/render_surface_cb.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-namespace o3d {
-
-using command_buffer::ResourceId;
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-
-RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator,
- int width,
- int height,
- int mip_level,
- int side,
- Texture *texture,
- RendererCB *renderer)
- : RenderSurface(service_locator, width, height, texture),
- resource_id_(command_buffer::kInvalidResource),
- 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;
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateRenderSurface(
- id,
- reinterpret_cast<uint32>(texture->GetTextureHandle()),
- width, height, mip_level, side);
-}
-
-RenderSurfaceCB::~RenderSurfaceCB() {
- Destroy();
-}
-
-void RenderSurfaceCB::Destroy() {
- // This should never be called during rendering.
- if (resource_id_ != command_buffer::kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyRenderSurface(resource_id_);
- renderer_->render_surface_ids().FreeID(resource_id_);
- resource_id_ = command_buffer::kInvalidResource;
- }
-}
-
-RenderDepthStencilSurfaceCB::RenderDepthStencilSurfaceCB(
- ServiceLocator *service_locator,
- int width,
- int height,
- RendererCB *renderer)
- : RenderDepthStencilSurface(service_locator, width, height),
- resource_id_(command_buffer::kInvalidResource),
- renderer_(renderer) {
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
- DCHECK(renderer);
- ResourceId id = renderer_->depth_surface_ids().AllocateID();
- resource_id_ = id;
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateDepthSurface(id, width, height);
-}
-
-void RenderDepthStencilSurfaceCB::Destroy() {
- if (resource_id_ != command_buffer::kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyDepthSurface(resource_id_);
- renderer_->depth_surface_ids().FreeID(resource_id_);
- resource_id_ = command_buffer::kInvalidResource;
- }
-}
-
-} // namespace o3d
-
diff --git a/o3d/core/cross/command_buffer/render_surface_cb.h b/o3d/core/cross/command_buffer/render_surface_cb.h
deleted file mode 100644
index 39e2cdf..0000000
--- a/o3d/core/cross/command_buffer/render_surface_cb.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * 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_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 "gpu/command_buffer/common/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,
- int mip_level,
- int side,
- Texture *texture,
- RendererCB *renderer);
- 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();
-
- // Returns the render surface resource ID.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- private:
- command_buffer::ResourceId resource_id_;
- 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();
-
- // 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_;
- DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceCB);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_RENDER_SURFACE_CB_H_
-
diff --git a/o3d/core/cross/command_buffer/renderer_cb.cc b/o3d/core/cross/command_buffer/renderer_cb.cc
deleted file mode 100644
index 3ea8db5..0000000
--- a/o3d/core/cross/command_buffer/renderer_cb.cc
+++ /dev/null
@@ -1,419 +0,0 @@
-/*
- * 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 implementation of the command buffer Renderer.
-
-#include "core/cross/precompile.h"
-
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-#include "gpu/command_buffer/client/fenced_allocator.h"
-#include "gpu/command_buffer/common/gapi_interface.h"
-#include "core/cross/command_buffer/buffer_cb.h"
-#include "core/cross/command_buffer/effect_cb.h"
-#include "core/cross/command_buffer/param_cache_cb.h"
-#include "core/cross/command_buffer/primitive_cb.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "core/cross/command_buffer/render_surface_cb.h"
-#include "core/cross/command_buffer/sampler_cb.h"
-#include "core/cross/command_buffer/states_cb.h"
-#include "core/cross/command_buffer/stream_bank_cb.h"
-#include "core/cross/command_buffer/texture_cb.h"
-#include "core/cross/command_buffer/display_window_cb.h"
-#include "core/cross/renderer_platform.h"
-#include "gpu/command_buffer/service/command_buffer_service.h"
-#include "gpu/command_buffer/service/gpu_processor.h"
-#include "gpu/np_utils/np_browser.h"
-#include "gpu/np_utils/np_utils.h"
-
-namespace o3d {
-using ::base::SharedMemory;
-using ::command_buffer::CommandBufferService;
-using command_buffer::o3d::GAPIInterface;
-using command_buffer::O3DCmdHelper;
-using np_utils::NPBrowser;
-using np_utils::NPCreateObject;
-using np_utils::NPGetProperty;
-using np_utils::NPInvoke;
-using np_utils::NPInvokeVoid;
-using np_utils::NPObjectPointer;
-
-#if !defined(CB_SERVICE_REMOTE)
-using command_buffer::CommandBuffer;
-using command_buffer::GPUProcessor;
-#endif
-
-RendererCB::RendererCB(ServiceLocator* service_locator,
- int32 transfer_memory_size)
- : Renderer(service_locator),
- transfer_memory_size_(transfer_memory_size),
- transfer_shm_id_(command_buffer::kInvalidSharedMemoryId),
- transfer_shm_address_(NULL),
- npp_(NULL),
- helper_(NULL),
- allocator_(NULL),
- frame_token_(0),
- state_manager_(new StateManager) {
- DCHECK_GT(transfer_memory_size, 0);
- state_manager_->AddStateHandlers(this);
-}
-
-RendererCB::~RendererCB() {
- Destroy();
-}
-
-void RendererCB::Destroy() {
- if (command_buffer_.get()) {
- command_buffer_->DestroyTransferBuffer(transfer_shm_id_);
- }
-
- transfer_shm_id_ = command_buffer::kInvalidSharedMemoryId;
- transfer_shm_ = NULL;
- transfer_shm_address_ = NULL;
-
- if (allocator_) {
- delete allocator_;
- allocator_ = NULL;
- }
-
- if (helper_) {
- helper_->Finish();
- delete helper_;
- helper_ = NULL;
- }
-
- npp_ = NULL;
-}
-
-void RendererCB::ApplyDirtyStates() {
- state_manager_->ValidateStates(helper_);
-}
-
-void RendererCB::Resize(int width, int height) {
- // TODO: the Resize event won't be coming to the client, but
- // potentially to the server, so that function doesn't directly make sense
- // in the command buffer implementation.
- SetClientSize(width, height);
-}
-
-bool RendererCB::PlatformSpecificBeginDraw() {
- return true;
-}
-
-// Adds the CLEAR command to the command buffer.
-void RendererCB::PlatformSpecificClear(const Float4 &color,
- bool color_flag,
- float depth,
- bool depth_flag,
- int stencil,
- bool stencil_flag) {
- uint32 buffers = (color_flag ? command_buffer::o3d::kColor : 0) |
- (depth_flag ? command_buffer::o3d::kDepth : 0) |
- (stencil_flag ? command_buffer::o3d::kStencil : 0);
- helper_->Clear(buffers, color[0], color[1], color[2], color[3],
- depth, stencil);
-}
-
-void RendererCB::PlatformSpecificEndDraw() {
-}
-
-// Adds the BeginFrame command to the command buffer.
-bool RendererCB::PlatformSpecificStartRendering() {
- // Any device issues are handled in the command buffer backend
- DCHECK(helper_);
- helper_->BeginFrame();
- return true;
-}
-
-// Adds the EndFrame command to the command buffer, and flushes the commands.
-void RendererCB::PlatformSpecificFinishRendering() {
- // Any device issues are handled in the command buffer backend
- helper_->EndFrame();
- helper_->WaitForToken(frame_token_);
- frame_token_ = helper_->InsertToken();
-}
-
-void RendererCB::PlatformSpecificPresent() {
- // TODO(gman): The EndFrame command needs to be split into EndFrame
- // and PRESENT.
-}
-
-// Assign the surface arguments to the renderer, and update the stack
-// of pushed surfaces.
-void RendererCB::SetRenderSurfacesPlatformSpecific(
- const RenderSurface* surface,
- const RenderDepthStencilSurface* surface_depth) {
- const RenderSurfaceCB* surface_cb =
- down_cast<const RenderSurfaceCB*>(surface);
- const RenderDepthStencilSurfaceCB* surface_depth_cb =
- down_cast<const RenderDepthStencilSurfaceCB*>(surface_depth);
- helper_->SetRenderSurface(
- surface_cb->resource_id(),
- surface_depth_cb->resource_id());
-}
-
-void RendererCB::SetBackBufferPlatformSpecific() {
- helper_->SetBackSurfaces();
-}
-
-// Creates a StreamBank, returning a platform specific implementation class.
-StreamBank::Ref RendererCB::CreateStreamBank() {
- return StreamBank::Ref(new StreamBankCB(service_locator(), this));
-}
-
-// Creates a Primitive, returning a platform specific implementation class.
-Primitive::Ref RendererCB::CreatePrimitive() {
- return Primitive::Ref(new PrimitiveCB(service_locator(), this));
-}
-
-// Creates a DrawElement, returning a platform specific implementation
-// class.
-DrawElement::Ref RendererCB::CreateDrawElement() {
- return DrawElement::Ref(new DrawElement(service_locator()));
-}
-
-Sampler::Ref RendererCB::CreateSampler() {
- return SamplerCB::Ref(new SamplerCB(service_locator(), this));
-}
-
-// Creates and returns a platform-specific float buffer
-VertexBuffer::Ref RendererCB::CreateVertexBuffer() {
- return VertexBuffer::Ref(new VertexBufferCB(service_locator(), this));
-}
-
-// Creates and returns a platform-specific integer buffer
-IndexBuffer::Ref RendererCB::CreateIndexBuffer() {
- return IndexBuffer::Ref(new IndexBufferCB(service_locator(), this));
-}
-
-// Creates and returns a platform-specific effect object
-Effect::Ref RendererCB::CreateEffect() {
- return Effect::Ref(new EffectCB(service_locator(), this));
-}
-
-// Creates and returns a platform-specific Texture2D object. It allocates
-// the necessary resources to store texture data for the given image size
-// and format.
-Texture2D::Ref RendererCB::CreatePlatformSpecificTexture2D(
- int width,
- int height,
- Texture::Format format,
- int levels,
- bool enable_render_surfaces) {
- return Texture2D::Ref(Texture2DCB::Create(service_locator(), format, levels,
- width, height,
- enable_render_surfaces));
-}
-
-// Creates and returns a platform-specific Texture2D object. It allocates
-// the necessary resources to store texture data for the given image size
-// and format.
-TextureCUBE::Ref RendererCB::CreatePlatformSpecificTextureCUBE(
- int edge,
- Texture::Format format,
- int levels,
- bool enable_render_surfaces) {
- return TextureCUBE::Ref(TextureCUBECB::Create(service_locator(), format,
- levels, edge,
- enable_render_surfaces));
-}
-
-// Creates a platform specific ParamCache.
-ParamCache* RendererCB::CreatePlatformSpecificParamCache() {
- return new ParamCacheCB();
-}
-
-void RendererCB::SetViewportInPixels(int left,
- int top,
- int width,
- int height,
- float min_z,
- float max_z) {
- helper_->SetViewport(left, top, width, height, min_z, max_z);
-}
-
-const int* RendererCB::GetRGBAUByteNSwizzleTable() {
- static int swizzle_table[] = { 0, 1, 2, 3, };
- return swizzle_table;
-}
-
-command_buffer::parse_error::ParseError RendererCB::GetParseError() {
- return helper_->GetParseError();
-}
-
-// Creates and returns a platform specific RenderDepthStencilSurface object.
-RenderDepthStencilSurface::Ref RendererCB::CreateDepthStencilSurface(
- int width,
- int height) {
- return RenderDepthStencilSurface::Ref(
- new RenderDepthStencilSurfaceCB(service_locator(),
- width,
- height,
- this));
-}
-
-Renderer::InitStatus RendererCB::InitPlatformSpecific(
- const DisplayWindow& display_window,
- bool off_screen) {
- if (off_screen) {
- // TODO: Off-screen support ?
- return UNINITIALIZED; // equivalent to 0/false
- }
-
- const DisplayWindowCB& display_platform =
- static_cast<const DisplayWindowCB&>(display_window);
-
- command_buffer_.reset(display_platform.command_buffer());
- DCHECK(command_buffer_.get());
-
- // Create and initialize a O3DCmdHelper.
- helper_ = new O3DCmdHelper(command_buffer_.get());
- if (!helper_->Initialize()) {
- Destroy();
- return INITIALIZATION_ERROR;
- }
-
- transfer_shm_id_ = command_buffer_->CreateTransferBuffer(
- transfer_memory_size_);
- if (transfer_shm_id_ < 0) {
- Destroy();
- return INITIALIZATION_ERROR;
- }
-
- transfer_shm_ = command_buffer_->GetTransferBuffer(transfer_shm_id_);
- if (!transfer_shm_) {
- Destroy();
- return INITIALIZATION_ERROR;
- }
-
- if (!transfer_shm_->Map(transfer_memory_size_)) {
- Destroy();
- return INITIALIZATION_ERROR;
- }
-
- transfer_shm_address_ = transfer_shm_->memory();
-
- // Insert a token.
- frame_token_ = helper_->InsertToken();
- if (frame_token_ < 0) {
- Destroy();
- return INITIALIZATION_ERROR;
- }
-
- // Create a fenced allocator.
- allocator_ = new FencedAllocatorWrapper(transfer_memory_size_,
- helper_,
- transfer_shm_address_);
-
- SetClientSize(display_platform.width(), display_platform.height());
-
- return SUCCESS;
-}
-
-// This should be enough to hold the biggest possible buffer
-// (2048x2048xABGR16F texture = 32MB)
-static const int32 kDefaultTransferMemorySize = 32 << 20;
-
-#if defined(CB_SERVICE_REMOTE)
-
-RendererCBRemote *RendererCBRemote::CreateDefault(
- ServiceLocator* service_locator) {
- return new RendererCBRemote(service_locator,
- kDefaultTransferMemorySize);
-}
-
-RendererCBRemote::RendererCBRemote(ServiceLocator* service_locator,
- int32 transfer_memory_size)
- : RendererCB(service_locator, transfer_memory_size) {
-}
-
-RendererCBRemote::~RendererCBRemote() {
-}
-
-Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
- return RendererCBRemote::CreateDefault(service_locator);
-}
-
-#else // CB_SERVICE_REMOTE
-
-static const unsigned int kDefaultCommandBufferSize = 256 << 10;
-
-RendererCBLocal *RendererCBLocal::CreateDefault(
- ServiceLocator* service_locator) {
- return new RendererCBLocal(service_locator,
- kDefaultTransferMemorySize);
-}
-
-RendererCBLocal::RendererCBLocal(ServiceLocator* service_locator,
- int32 transfer_memory_size)
- : RendererCB(service_locator, transfer_memory_size) {
-}
-
-RendererCBLocal::~RendererCBLocal() {
-}
-
-CommandBuffer* RendererCBLocal::CreateCommandBuffer(NPP npp,
- void* hwnd,
- int32 size) {
-#if defined(OS_WIN)
- scoped_ptr<SharedMemory> ring_buffer(new SharedMemory);
- if (!ring_buffer->Create(std::wstring(), false, false, size))
- return NULL;
-
- if (!ring_buffer->Map(size))
- return NULL;
-
- scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService);
- if (!command_buffer->Initialize(ring_buffer.release()))
- return NULL;
-
- scoped_refptr<GPUProcessor> gpu_processor(
- new GPUProcessor(npp, command_buffer.get()));
- if (!gpu_processor->Initialize(reinterpret_cast<HWND>(hwnd)))
- return NULL;
-
- command_buffer->SetPutOffsetChangeCallback(
- NewCallback(gpu_processor.get(), &GPUProcessor::ProcessCommands));
-
- return command_buffer.release();
-
-#else
- return NULL;
-#endif
-}
-
-Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
- return RendererCBLocal::CreateDefault(service_locator);
-}
-
-#endif // CB_SERVICE_REMOTE
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/renderer_cb.h b/o3d/core/cross/command_buffer/renderer_cb.h
deleted file mode 100644
index 56b1d17..0000000
--- a/o3d/core/cross/command_buffer/renderer_cb.h
+++ /dev/null
@@ -1,328 +0,0 @@
-/*
- * 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 implementation of the command buffer renderer.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_
-
-#include "base/shared_memory.h"
-#include "core/cross/precompile.h"
-#include <vector>
-#include "core/cross/renderer.h"
-#include "gpu/command_buffer/common/command_buffer.h"
-#include "gpu/command_buffer/common/constants.h"
-#include "gpu/command_buffer/common/resource.h"
-#include "gpu/command_buffer/client/fenced_allocator.h"
-#include "gpu/command_buffer/client/id_allocator.h"
-#include "gpu/np_utils/np_object_pointer.h"
-
-namespace command_buffer {
-class O3DCmdHelper;
-class BufferSyncInterface;
-class FencedAllocatorWrapper;
-} // namespace command_buffer
-
-namespace o3d {
-
-class Material;
-
-// TODO: change the Init API to not rely on direct HWND so we don't need
-// to create a command buffer locally.
-class Win32CBServer;
-
-// This is the implementation of the Renderer interface for command buffers.
-class RendererCB : public Renderer {
- public:
- typedef ::command_buffer::IdAllocator IdAllocator;
- typedef ::command_buffer::FencedAllocatorWrapper FencedAllocatorWrapper;
-
- virtual ~RendererCB();
-
- // Handles the plugin resize event.
- virtual void Resize(int width, int height);
-
- // Releases all hardware resources. This should be called before destroying
- // the window used for rendering. It will be called automatically from the
- // destructor.
- // Destroy() should be called before Init() is called again.
- virtual void Destroy();
-
- // Overridden from Renderer.
- virtual bool GoFullscreen(const DisplayWindow& display,
- int mode_id) {
- // TODO(gman): implement this.
- return false;
- }
-
- // Overridden from Renderer.
- virtual bool CancelFullscreen(const DisplayWindow& display,
- int width, int height) {
- // TODO(gman): implement this.
- return false;
- }
-
- // Tells whether we're currently displayed fullscreen or not.
- virtual bool fullscreen() const {
- // TODO(gman): implement this.
- return false;
- }
-
- // Get a vector of the available fullscreen display modes.
- // Clears *modes on error.
- virtual void GetDisplayModes(std::vector<DisplayMode> *modes) {
- // TODO(gman): implement this.
- }
-
- // Get a single fullscreen display mode by id.
- // Returns true on success, false on error.
- virtual bool GetDisplayMode(int id, DisplayMode *mode) {
- // TODO(gman): implement this.
- return false;
- }
-
- // Creates a StreamBank, returning a platform specific implementation class.
- virtual StreamBank::Ref CreateStreamBank();
-
- // Creates a Primitive, returning a platform specific implementation class.
- virtual Primitive::Ref CreatePrimitive();
-
- // Creates a DrawElement, returning a platform specific implementation
- // class.
- virtual DrawElement::Ref CreateDrawElement();
-
- // Creates and returns a platform specific float buffer
- virtual VertexBuffer::Ref CreateVertexBuffer();
-
- // Creates and returns a platform specific integer buffer
- virtual IndexBuffer::Ref CreateIndexBuffer();
-
- // Creates and returns a platform specific effect object
- virtual Effect::Ref CreateEffect();
-
- // Creates and returns a platform specific Sampler object.
- virtual Sampler::Ref CreateSampler();
-
- // Creates and returns a platform specific RenderDepthStencilSurface object.
- virtual RenderDepthStencilSurface::Ref CreateDepthStencilSurface(
- int width,
- int height);
-
- // Gets the allocator for vertex buffer IDs.
- IdAllocator &vertex_buffer_ids() { return vertex_buffer_ids_; }
-
- // Gets the allocator for index buffer IDs.
- IdAllocator &index_buffer_ids() { return index_buffer_ids_; }
-
- // Gets the allocator for vertex struct IDs.
- IdAllocator &vertex_structs_ids() { return vertex_structs_ids_; }
-
- // Gets the allocator for effect IDs.
- IdAllocator &effect_ids() { return effect_ids_; }
-
- // Gets the allocator for effect param IDs.
- IdAllocator &effect_param_ids() { return effect_param_ids_; }
-
- // Gets the allocator for texture IDs.
- IdAllocator &texture_ids() { return texture_ids_; }
-
- // Gets the allocator for sampler IDs.
- IdAllocator &sampler_ids() { return sampler_ids_; }
-
- // Gets the allocator for render surfaces IDs.
- IdAllocator &render_surface_ids() { return render_surface_ids_; }
-
- // Gets the allocator for depth stencil surfaces IDs.
- IdAllocator &depth_surface_ids() { return depth_surface_ids_; }
-
- // Gets the command buffer helper.
- command_buffer::O3DCmdHelper *helper() const { return helper_; }
-
- // Gets the registered ID of the transfer shared memory.
- int32 transfer_shm_id() const { return transfer_shm_id_; }
-
- // Gets the base address of the transfer shared memory.
- void *transfer_shm_address() const { return transfer_shm_address_; }
-
- // Gets the allocator of the transfer shared memory.
- FencedAllocatorWrapper *allocator() const {
- return allocator_;
- }
-
- // Overridden from Renderer.
- virtual const int* GetRGBAUByteNSwizzleTable();
-
- ::command_buffer::parse_error::ParseError GetParseError();
-
- protected:
- // Protected so that callers are forced to call the factory method.
- RendererCB(ServiceLocator* service_locator, int32 transfer_memory_size);
-
- // Overridden from Renderer.
- virtual bool PlatformSpecificBeginDraw();
-
- // Overridden from Renderer.
- virtual void PlatformSpecificEndDraw();
-
- // Overridden from Renderer.
- virtual bool PlatformSpecificStartRendering();
-
- // Overridden from Renderer.
- virtual void PlatformSpecificFinishRendering();
-
- // Overridden from Renderer.
- virtual void PlatformSpecificPresent();
-
- // Overridden from Renderer.
- virtual void PlatformSpecificClear(const Float4 &color,
- bool color_flag,
- float depth,
- bool depth_flag,
- int stencil,
- bool stencil_flag);
-
- // Creates a platform specific ParamCache.
- virtual ParamCache* CreatePlatformSpecificParamCache();
-
- // Sets the viewport. This is the platform specific version.
- virtual void SetViewportInPixels(int left,
- int top,
- int width,
- int height,
- float min_z,
- float max_z);
-
- // Overridden from Renderer.
- virtual void SetBackBufferPlatformSpecific();
-
- // Overridden from Renderer.
- virtual void SetRenderSurfacesPlatformSpecific(
- const RenderSurface* surface,
- const RenderDepthStencilSurface* depth_surface);
-
- // Overridden from Renderer.
- virtual Texture2D::Ref CreatePlatformSpecificTexture2D(
- int width,
- int height,
- Texture::Format format,
- int levels,
- bool enable_render_surfaces);
-
- // Overridden from Renderer.
- virtual TextureCUBE::Ref CreatePlatformSpecificTextureCUBE(
- int edge_length,
- Texture::Format format,
- int levels,
- bool enable_render_surfaces);
-
- // Overridden from Renderer.
- virtual void ApplyDirtyStates();
-
- protected:
- // Initializes the renderer for use, claiming hardware resources.
- // Takes ownership of CommandBuffer.
- virtual InitStatus InitPlatformSpecific(const DisplayWindow& display_window,
- bool off_screen);
-
- private:
- int32 transfer_memory_size_;
- ::base::SharedMemory* transfer_shm_;
- int32 transfer_shm_id_;
- void *transfer_shm_address_;
- NPP npp_;
- scoped_ptr<::command_buffer::CommandBuffer> command_buffer_;
- ::command_buffer::O3DCmdHelper *helper_;
- ::command_buffer::FencedAllocatorWrapper *allocator_;
-
- IdAllocator vertex_buffer_ids_;
- IdAllocator index_buffer_ids_;
- IdAllocator vertex_structs_ids_;
- IdAllocator effect_ids_;
- IdAllocator effect_param_ids_;
- IdAllocator texture_ids_;
- IdAllocator sampler_ids_;
- IdAllocator render_surface_ids_;
- IdAllocator depth_surface_ids_;
- int32 frame_token_;
-
- class StateManager;
- scoped_ptr<StateManager> state_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(RendererCB);
-};
-
-#if defined(CB_SERVICE_REMOTE)
-
-// This subclass initializes itself with a remotely created, potentially out-
-// of-process CommandBuffer. It requires that the browser supports the "system
-// service" to create shared memory, which is not available in the mange branch
-// of Chrome. Use RendererCBLocal for now.
-class RendererCBRemote : public RendererCB {
- public:
- // Creates a default RendererCBRemote.
- static RendererCBRemote *CreateDefault(ServiceLocator* service_locator);
-
- protected:
- RendererCBRemote(ServiceLocator* service_locator, int32 transfer_memory_size);
- virtual ~RendererCBRemote();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RendererCBRemote);
-};
-
-#else // CB_SERVICE_REMOTE
-
-// This subclass initializes itself with a locally created in-process
-// CommandBuffer and GPUProcessor. This class will eventually go away and the
-// code in RendererCBRemote will be merged into RendererCB.
-class RendererCBLocal : public RendererCB {
- public:
- static ::command_buffer::CommandBuffer* CreateCommandBuffer(
- NPP npp, void* hwnd, int32 size);
-
- // Creates a default RendererCBLocal.
- static RendererCBLocal *CreateDefault(ServiceLocator* service_locator);
-
- protected:
- RendererCBLocal(ServiceLocator* service_locator,
- int32 transfer_memory_size);
- virtual ~RendererCBLocal();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RendererCBLocal);
-};
-
-#endif // CB_SERVICE_REMOTE
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_RENDERER_CB_H_
diff --git a/o3d/core/cross/command_buffer/sampler_cb.cc b/o3d/core/cross/command_buffer/sampler_cb.cc
deleted file mode 100644
index 887b9ad..0000000
--- a/o3d/core/cross/command_buffer/sampler_cb.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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 implementation of the SamplerCB class.
-
-#include "core/cross/precompile.h"
-#include "core/cross/error.h"
-#include "core/cross/command_buffer/sampler_cb.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "gpu/command_buffer/common/o3d_cmd_format.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-namespace o3d {
-
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-using command_buffer::ResourceId;
-namespace sampler = command_buffer::sampler;
-
-namespace {
-
-sampler::AddressingMode AddressModeToCB(Sampler::AddressMode o3d_mode) {
- switch (o3d_mode) {
- case Sampler::WRAP:
- return sampler::kWrap;
- case Sampler::MIRROR:
- return sampler::kMirrorRepeat;
- case Sampler::CLAMP:
- return sampler::kClampToEdge;
- case Sampler::BORDER:
- return sampler::kClampToBorder;
- default:
- DLOG(ERROR) << "Unknown Address mode " << static_cast<int>(o3d_mode);
- return sampler::kWrap;
- }
-}
-
-sampler::FilteringMode FilterTypeToCB(Sampler::FilterType o3d_mode) {
- switch (o3d_mode) {
- case Sampler::NONE:
- return sampler::kNone;
- case Sampler::POINT:
- return sampler::kPoint;
- case Sampler::LINEAR:
- case Sampler::ANISOTROPIC:
- return sampler::kLinear;
- default:
- return sampler::kNone;
- }
-}
-
-} // anonymous namespace
-
-SamplerCB::SamplerCB(ServiceLocator* service_locator, RendererCB* renderer)
- : Sampler(service_locator),
- renderer_(renderer) {
- DCHECK(renderer_);
- resource_id_ = renderer_->sampler_ids().AllocateID();
- renderer_->helper()->CreateSampler(resource_id_);
-}
-
-SamplerCB::~SamplerCB() {
- renderer_->helper()->DestroySampler(resource_id_);
- renderer_->sampler_ids().FreeID(resource_id_);
-}
-
-void SamplerCB::SetTextureAndStates() {
- O3DCmdHelper* helper = renderer_->helper();
- sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u());
- sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v());
- sampler::AddressingMode address_mode_w_cb = AddressModeToCB(address_mode_w());
- sampler::FilteringMode mag_filter_cb = FilterTypeToCB(mag_filter());
- sampler::FilteringMode min_filter_cb = FilterTypeToCB(min_filter());
- sampler::FilteringMode mip_filter_cb = FilterTypeToCB(mip_filter());
- if (mag_filter_cb == sampler::kNone) mag_filter_cb = sampler::kPoint;
- if (min_filter_cb == sampler::kNone) min_filter_cb = sampler::kPoint;
- int max_max_anisotropy =
- command_buffer::o3d::SetSamplerStates::MaxAnisotropy::kMask;
- unsigned int max_anisotropy_cb =
- std::max(1, std::min(max_max_anisotropy, max_anisotropy()));
- if (min_filter() != Sampler::ANISOTROPIC) {
- max_anisotropy_cb = 1;
- }
- helper->SetSamplerStates(
- resource_id_,
- address_mode_u_cb,
- address_mode_v_cb,
- address_mode_w_cb,
- mag_filter_cb,
- min_filter_cb,
- mip_filter_cb,
- max_anisotropy_cb);
-
- Float4 color = border_color();
- helper->SetSamplerBorderColor(resource_id_,
- color[0], color[1], color[2], color[3]);
-
- Texture *texture_object = texture();
- if (!texture_object) {
- texture_object = renderer_->error_texture();
- if (!texture_object) {
- O3D_ERROR(service_locator())
- << "Missing texture for sampler " << name();
- texture_object = renderer_->fallback_error_texture();
- }
- }
-
- if (texture_object) {
- helper->SetSamplerTexture(
- resource_id_,
- reinterpret_cast<uint32>(texture_object->GetTextureHandle()));
- }
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/sampler_cb.h b/o3d/core/cross/command_buffer/sampler_cb.h
deleted file mode 100644
index 25892d55..0000000
--- a/o3d/core/cross/command_buffer/sampler_cb.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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 declaration of the command-buffer version of the
-// sampler.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_SAMPLER_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_SAMPLER_CB_H_
-
-#include "core/cross/precompile.h"
-#include "core/cross/sampler.h"
-#include "gpu/command_buffer/common/resource.h"
-
-namespace o3d {
-
-class RendererCB;
-
-// SamplerCB is an implementation of the Sampler object for command buffers.
-class SamplerCB : public Sampler {
- public:
- SamplerCB(ServiceLocator* service_locator, RendererCB* renderer);
- virtual ~SamplerCB();
-
- // Sets the d3d texture and sampler states for the given sampler unit.
- void SetTextureAndStates();
-
- // Gets the resource ID for this sampler.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- private:
- RendererCB* renderer_;
- command_buffer::ResourceId resource_id_;
- DISALLOW_COPY_AND_ASSIGN(SamplerCB);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_SAMPLER_CB_H_
diff --git a/o3d/core/cross/command_buffer/states_cb.cc b/o3d/core/cross/command_buffer/states_cb.cc
deleted file mode 100644
index 8572827d..0000000
--- a/o3d/core/cross/command_buffer/states_cb.cc
+++ /dev/null
@@ -1,646 +0,0 @@
-/*
- * 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 implementation of the RendererCB::StateManager class,
-// including all the state handlers for the command buffer renderer.
-
-#include "core/cross/precompile.h"
-#include "core/cross/state.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "core/cross/command_buffer/states_cb.h"
-#include "gpu/command_buffer/common/gapi_interface.h"
-
-namespace o3d {
-using command_buffer::CommandBufferEntry;
-using command_buffer::CommandBufferHelper;
-
-namespace {
-
-// Converts values meant to represent a Cull Mode to the corresponding
-// command-buffer value.
-// Default: CULL_NONE.
-command_buffer::o3d::FaceCullMode CullModeToCB(int cull) {
- switch (cull) {
- default:
- case State::CULL_NONE:
- return command_buffer::o3d::kCullNone;
- case State::CULL_CW:
- return command_buffer::o3d::kCullCW;
- case State::CULL_CCW:
- return command_buffer::o3d::kCullCCW;
- }
-}
-
-// Converts values meant to represent a Polygon Fill Mode to the corresponding
-// command-buffer value.
-// Default: kPolygonModeFill.
-command_buffer::o3d::PolygonMode FillModeToCB(int fill) {
- switch (fill) {
- case State::POINT:
- return command_buffer::o3d::kPolygonModePoints;
- case State::WIREFRAME:
- return command_buffer::o3d::kPolygonModeLines;
- default:
- case State::SOLID:
- return command_buffer::o3d::kPolygonModeFill;
- }
-}
-
-// Converts values meant to represent a Comparison Function to the corresponding
-// command-buffer value.
-// Default: kAlways.
-command_buffer::o3d::Comparison ComparisonToCB(int comparison) {
- switch (comparison) {
- case State::CMP_NEVER:
- return command_buffer::o3d::kNever;
- case State::CMP_LESS:
- return command_buffer::o3d::kLess;
- case State::CMP_EQUAL:
- return command_buffer::o3d::kEqual;
- case State::CMP_LEQUAL:
- return command_buffer::o3d::kLEqual;
- case State::CMP_GREATER:
- return command_buffer::o3d::kGreater;
- case State::CMP_NOTEQUAL:
- return command_buffer::o3d::kNotEqual;
- case State::CMP_GEQUAL:
- return command_buffer::o3d::kGEqual;
- case State::CMP_ALWAYS:
- default:
- return command_buffer::o3d::kAlways;
- }
-}
-
-// Converts values meant to represent a Stencil Operation to the corresponding
-// command-buffer value.
-// Default: kKeep.
-command_buffer::o3d::StencilOp StencilOpToCB(int op) {
- switch (op) {
- default:
- case State::STENCIL_KEEP:
- return command_buffer::o3d::kKeep;
- case State::STENCIL_ZERO:
- return command_buffer::o3d::kZero;
- case State::STENCIL_REPLACE:
- return command_buffer::o3d::kReplace;
- case State::STENCIL_INCREMENT_SATURATE:
- return command_buffer::o3d::kIncNoWrap;
- case State::STENCIL_DECREMENT_SATURATE:
- return command_buffer::o3d::kDecNoWrap;
- case State::STENCIL_INVERT:
- return command_buffer::o3d::kInvert;
- case State::STENCIL_INCREMENT:
- return command_buffer::o3d::kIncWrap;
- case State::STENCIL_DECREMENT:
- return command_buffer::o3d::kDecWrap;
- }
-}
-
-// Converts values meant to represent a Blending Function to the corresponding
-// command-buffer value.
-// Default: kBlendFuncOne.
-command_buffer::o3d::BlendFunc BlendFuncToCB(int func) {
- switch (func) {
- case State::BLENDFUNC_ZERO:
- return command_buffer::o3d::kBlendFuncZero;
- default:
- case State::BLENDFUNC_ONE:
- return command_buffer::o3d::kBlendFuncOne;
- case State::BLENDFUNC_SOURCE_COLOR:
- return command_buffer::o3d::kBlendFuncSrcColor;
- case State::BLENDFUNC_INVERSE_SOURCE_COLOR:
- return command_buffer::o3d::kBlendFuncInvSrcColor;
- case State::BLENDFUNC_SOURCE_ALPHA:
- return command_buffer::o3d::kBlendFuncSrcAlpha;
- case State::BLENDFUNC_INVERSE_SOURCE_ALPHA:
- return command_buffer::o3d::kBlendFuncInvSrcAlpha;
- case State::BLENDFUNC_DESTINATION_ALPHA:
- return command_buffer::o3d::kBlendFuncDstAlpha;
- case State::BLENDFUNC_INVERSE_DESTINATION_ALPHA:
- return command_buffer::o3d::kBlendFuncInvDstAlpha;
- case State::BLENDFUNC_DESTINATION_COLOR:
- return command_buffer::o3d::kBlendFuncDstColor;
- case State::BLENDFUNC_INVERSE_DESTINATION_COLOR:
- return command_buffer::o3d::kBlendFuncInvDstColor;
- case State::BLENDFUNC_SOURCE_ALPHA_SATUTRATE:
- return command_buffer::o3d::kBlendFuncSrcAlphaSaturate;
- }
-}
-
-// Converts values meant to represent a Blending Equation to the corresponding
-// command-buffer value.
-// Default: kBlendEqAdd.
-command_buffer::o3d::BlendEq BlendEqToCB(int eq) {
- switch (eq) {
- default:
- case State::BLEND_ADD:
- return command_buffer::o3d::kBlendEqAdd;
- case State::BLEND_SUBTRACT:
- return command_buffer::o3d::kBlendEqSub;
- case State::BLEND_REVERSE_SUBTRACT:
- return command_buffer::o3d::kBlendEqRevSub;
- case State::BLEND_MIN:
- return command_buffer::o3d::kBlendEqMin;
- case State::BLEND_MAX:
- return command_buffer::o3d::kBlendEqMax;
- }
-}
-
-} // anonymous namespace
-
-// This class wraps StateHandler to make it type-safe.
-template <typename T>
-class TypedStateHandler : public RendererCB::StateHandler {
- public:
- // Override this function to set a specific state.
- // Parameters:
- // renderer: The platform specific renderer.
- // param: A concrete param with state data.
- virtual void SetStateFromTypedParam(RendererCB* renderer, T* param) const = 0;
-
- // Gets Class of State's Parameter
- virtual const ObjectBase::Class* GetClass() const {
- return T::GetApparentClass();
- }
-
- private:
- // Calls SetStateFromTypedParam if the Param type is the correct type.
- // Parameters:
- // renderer: The renderer.
- // param: A param with state data.
- virtual void SetState(Renderer* renderer, Param* param) const {
- RendererCB *renderer_cb = down_cast<RendererCB *>(renderer);
- // This is safe because State guarntees Params match by type.
- DCHECK(param->IsA(T::GetApparentClass()));
- SetStateFromTypedParam(renderer_cb, down_cast<T*>(param));
- }
-};
-
-// A template that generates a handler for enable/disable states.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bit in the
-// command-buffer argument value.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class EnableStateHandler : public TypedStateHandler<ParamBoolean> {
- public:
- EnableStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamBoolean* param) const {
- bit_field::Set(value_, param->value() ? 1 : 0);
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for bit field states.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bit field.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class BitFieldStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- BitFieldStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- bit_field::Set(value_, param->value());
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A handler for the color write state.
-class ColorWriteStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- ColorWriteStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- using command_buffer::o3d::SetColorWrite;
- int mask = param->value();
- SetColorWrite::AllColorsMask::Set(value_, mask);
- renderer->SetWriteMask(mask);
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for full-size values (uint32, int32,
-// float).
-// Template Parameters:
-// ParamType: the type of the parameter.
-// Parameters:
-// value: a pointer to the argument value as the proper type.
-// dirty: a pointer to the dirty bit.
-template <typename ParamType>
-class ValueStateHandler : public TypedStateHandler<ParamType> {
- public:
- typedef typename ParamType::DataType DataType;
- ValueStateHandler(DataType *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamType* param) const {
- *value_ = param->value();
- *dirty_ = true;
- }
- private:
- DataType *value_;
- bool *dirty_;
-};
-
-// Handler for Cull Mode.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-class CullModeStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- CullModeStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- using command_buffer::o3d::SetPolygonRaster;
- SetPolygonRaster::CullMode::Set(value_, CullModeToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// Handler for Polygon Fill Mode.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-class FillModeStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- FillModeStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- using command_buffer::o3d::SetPolygonRaster;
- SetPolygonRaster::FillMode::Set(value_, FillModeToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for comparison functions.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bits.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class ComparisonStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- ComparisonStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- bit_field::Set(value_, ComparisonToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for stencil operations.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bits.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class StencilOpStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- StencilOpStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- bit_field::Set(value_, StencilOpToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for blend equations.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bits.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class BlendFuncStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- BlendFuncStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- bit_field::Set(value_, BlendFuncToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// A template that generates a handler for blend equations.
-// Template Parameters:
-// bit_field: the BitField type to access the proper bits.
-// Parameters:
-// value: a pointer to the argument value as an uint32.
-// dirty: a pointer to the dirty bit.
-template <typename bit_field>
-class BlendEqStateHandler : public TypedStateHandler<ParamInteger> {
- public:
- BlendEqStateHandler(uint32 *value, bool *dirty)
- : value_(value),
- dirty_(dirty) {
- }
-
- virtual void SetStateFromTypedParam(RendererCB* renderer,
- ParamInteger* param) const {
- bit_field::Set(value_, BlendEqToCB(param->value()));
- *dirty_ = true;
- }
- private:
- uint32 *value_;
- bool *dirty_;
-};
-
-// Adds all the state handlers for all the states. The list of handlers must
-// match in names and types the list in Renderer::AddDefaultStates()
-// (in renderer.cc).
-void RendererCB::StateManager::AddStateHandlers(RendererCB *renderer) {
- // Point/Line raster
- {
- bool *dirty = point_line_helper_.dirty_ptr();
- using command_buffer::o3d::SetPointLineRaster;
- SetPointLineRaster& cmd = point_line_helper_.command();
- renderer->AddStateHandler(
- State::kLineSmoothEnableParamName,
- new EnableStateHandler<
- SetPointLineRaster::LineSmoothEnable>(&cmd.enables, dirty));
- renderer->AddStateHandler(
- State::kPointSpriteEnableParamName,
- new EnableStateHandler<
- SetPointLineRaster::PointSpriteEnable>(&cmd.enables, dirty));
- renderer->AddStateHandler(State::kPointSizeParamName,
- new ValueStateHandler<ParamFloat>(
- &cmd.point_size, dirty));
- }
-
- // Polygon Raster
- {
- bool *dirty = poly_raster_helper_.dirty_ptr();
- using command_buffer::o3d::SetPolygonRaster;
- SetPolygonRaster& cmd = poly_raster_helper_.command();
- renderer->AddStateHandler(State::kCullModeParamName,
- new CullModeStateHandler(&cmd.fill_cull, dirty));
- renderer->AddStateHandler(State::kFillModeParamName,
- new FillModeStateHandler(&cmd.fill_cull, dirty));
- }
-
- // Polygon Offset
- {
- bool *dirty = poly_offset_helper_.dirty_ptr();
- command_buffer::o3d::SetPolygonOffset& cmd =
- poly_offset_helper_.command();
- renderer->AddStateHandler(
- State::kPolygonOffset1ParamName,
- new ValueStateHandler<ParamFloat>(&cmd.slope_factor, dirty));
- renderer->AddStateHandler(
- State::kPolygonOffset2ParamName,
- new ValueStateHandler<ParamFloat>(&cmd.units, dirty));
- }
-
- // Alpha test
- {
- using command_buffer::o3d::SetAlphaTest;
- SetAlphaTest& cmd = alpha_test_helper_.command();
- bool *dirty = alpha_test_helper_.dirty_ptr();
- renderer->AddStateHandler(
- State::kAlphaTestEnableParamName,
- new EnableStateHandler<SetAlphaTest::Enable>(&cmd.func_enable, dirty));
- renderer->AddStateHandler(
- State::kAlphaComparisonFunctionParamName,
- new ComparisonStateHandler<SetAlphaTest::Func>(&cmd.func_enable, dirty));
- renderer->AddStateHandler(
- State::kAlphaReferenceParamName,
- new ValueStateHandler<ParamFloat>(&cmd.value, dirty));
- }
-
- // Depth Test
- {
- bool *dirty = depth_test_helper_.dirty_ptr();
- using command_buffer::o3d::SetDepthTest;
- SetDepthTest& cmd = depth_test_helper_.command();
- renderer->AddStateHandler(
- State::kZWriteEnableParamName,
- new EnableStateHandler<SetDepthTest::WriteEnable>(&cmd.func_enable, dirty));
- renderer->AddStateHandler(
- State::kZEnableParamName,
- new EnableStateHandler<SetDepthTest::Enable>(&cmd.func_enable, dirty));
- renderer->AddStateHandler(
- State::kZComparisonFunctionParamName,
- new ComparisonStateHandler<SetDepthTest::Func>(&cmd.func_enable, dirty));
- }
-
- // Stencil Test
- {
- bool *dirty = stencil_test_helper_.dirty_ptr();
- using command_buffer::o3d::SetStencilTest;
- SetStencilTest& cmd = stencil_test_helper_.command();
- renderer->AddStateHandler(
- State::kStencilEnableParamName,
- new EnableStateHandler<SetStencilTest::Enable>(&cmd.stencil_args0, dirty));
- renderer->AddStateHandler(
- State::kTwoSidedStencilEnableParamName,
- new EnableStateHandler<
- SetStencilTest::SeparateCCW>(&cmd.stencil_args0, dirty));
- renderer->AddStateHandler(
- State::kStencilReferenceParamName,
- new BitFieldStateHandler<
- SetStencilTest::ReferenceValue>(&cmd.stencil_args0, dirty));
- renderer->AddStateHandler(
- State::kStencilMaskParamName,
- new BitFieldStateHandler<
- SetStencilTest::CompareMask>(&cmd.stencil_args0, dirty));
- renderer->AddStateHandler(
- State::kStencilWriteMaskParamName,
- new BitFieldStateHandler<
- SetStencilTest::WriteMask>(&cmd.stencil_args0, dirty));
-
- renderer->AddStateHandler(
- State::kStencilComparisonFunctionParamName,
- new ComparisonStateHandler<
- SetStencilTest::CWFunc>(&cmd.stencil_args1, dirty));
- renderer->AddStateHandler(
- State::kStencilPassOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CWPassOp>(&cmd.stencil_args1, dirty));
- renderer->AddStateHandler(
- State::kStencilFailOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CWFailOp>(&cmd.stencil_args1, dirty));
- renderer->AddStateHandler(
- State::kStencilZFailOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CWZFailOp>(&cmd.stencil_args1, dirty));
-
- renderer->AddStateHandler(
- State::kCCWStencilComparisonFunctionParamName,
- new ComparisonStateHandler<
- SetStencilTest::CCWFunc>(&cmd.stencil_args1, dirty));
-
- renderer->AddStateHandler(
- State::kCCWStencilPassOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CCWPassOp>(&cmd.stencil_args1, dirty));
- renderer->AddStateHandler(
- State::kCCWStencilFailOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CCWFailOp>(&cmd.stencil_args1, dirty));
- renderer->AddStateHandler(
- State::kCCWStencilZFailOperationParamName,
- new StencilOpStateHandler<
- SetStencilTest::CCWZFailOp>(&cmd.stencil_args1, dirty));
- }
-
- // Blending
- {
- bool *dirty = blending_helper_.dirty_ptr();
- using command_buffer::o3d::SetBlending;
- SetBlending& cmd = blending_helper_.command();
- renderer->AddStateHandler(
- State::kAlphaBlendEnableParamName,
- new EnableStateHandler<SetBlending::Enable>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kSeparateAlphaBlendEnableParamName,
- new EnableStateHandler<SetBlending::SeparateAlpha>(&cmd.blend_settings, dirty));
-
- renderer->AddStateHandler(
- State::kSourceBlendFunctionParamName,
- new BlendFuncStateHandler<
- SetBlending::ColorSrcFunc>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kDestinationBlendFunctionParamName,
- new BlendFuncStateHandler<
- SetBlending::ColorDstFunc>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kBlendEquationParamName,
- new BlendEqStateHandler<
- SetBlending::ColorEq>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kSourceBlendAlphaFunctionParamName,
- new BlendFuncStateHandler<
- SetBlending::AlphaSrcFunc>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kDestinationBlendAlphaFunctionParamName,
- new BlendFuncStateHandler<
- SetBlending::AlphaDstFunc>(&cmd.blend_settings, dirty));
- renderer->AddStateHandler(
- State::kBlendAlphaEquationParamName,
- new BlendEqStateHandler<
- SetBlending::AlphaEq>(&cmd.blend_settings, dirty));
- }
-
- // Color Write
- {
- bool *dirty = color_write_helper_.dirty_ptr();
- using command_buffer::o3d::SetColorWrite;
- SetColorWrite& cmd = color_write_helper_.command();
- renderer->AddStateHandler(
- State::kDitherEnableParamName,
- new EnableStateHandler<SetColorWrite::DitherEnable>(&cmd.flags, dirty));
- renderer->AddStateHandler(
- State::kColorWriteEnableParamName,
- new ColorWriteStateHandler(&cmd.flags, dirty));
- }
-}
-
-void RendererCB::StateManager::ValidateStates(CommandBufferHelper *helper) {
- point_line_helper_.Validate(helper);
- poly_offset_helper_.Validate(helper);
- poly_raster_helper_.Validate(helper);
- alpha_test_helper_.Validate(helper);
- depth_test_helper_.Validate(helper);
- stencil_test_helper_.Validate(helper);
- color_write_helper_.Validate(helper);
- blending_helper_.Validate(helper);
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/states_cb.h b/o3d/core/cross/command_buffer/states_cb.h
deleted file mode 100644
index 0732978..0000000
--- a/o3d/core/cross/command_buffer/states_cb.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * 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 RendererCB::StateManager class, managing states for
-// the command-buffer renderer.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_STATES_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_STATES_CB_H_
-
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "gpu/command_buffer/common/o3d_cmd_format.h"
-#include "gpu/command_buffer/client/cmd_buffer_helper.h"
-
-namespace o3d {
-
-// This class manages the states for the command-buffer renderer. It takes care
-// of the registration of the state handlers, as well as the sending of
-// commands to commit modified states.
-class RendererCB::StateManager {
- public:
- StateManager() { }
- ~StateManager() { }
-
- // Sends commands to commit all the changed states.
- void ValidateStates(command_buffer::CommandBufferHelper *helper);
-
- // Adds the state handlers for all the states.
- void AddStateHandlers(RendererCB *renderer);
- private:
- // A template helper. This wraps a command sent to set a set of states. It
- // keeps all the arguments of a single command, that get modified by the
- // various handles, as well as a dirty bit.
- template <typename CommandType>
- class StateHelper {
- public:
- StateHelper() : dirty_(false) {
- // NOTE: This code assumes the state commands only need their
- // header set and that the rest will be set by the state handlers.
- memset(&command_, 0, sizeof(command_));
- command_.SetHeader();
- }
-
- // Sends the command if it is marked as dirty.
- void Validate(command_buffer::CommandBufferHelper *helper) {
- if (!dirty_) return;
- helper->AddTypedCmdData(command_);
- dirty_ = false;
- }
-
- CommandType& command() {
- return command_;
- }
-
- bool *dirty_ptr() { return &dirty_; }
- private:
- bool dirty_;
- CommandType command_;
- DISALLOW_COPY_AND_ASSIGN(StateHelper);
- };
-
- StateHelper<command_buffer::o3d::SetPointLineRaster> point_line_helper_;
- StateHelper<command_buffer::o3d::SetPolygonOffset> poly_offset_helper_;
- StateHelper<command_buffer::o3d::SetPolygonRaster> poly_raster_helper_;
- StateHelper<command_buffer::o3d::SetAlphaTest> alpha_test_helper_;
- StateHelper<command_buffer::o3d::SetDepthTest> depth_test_helper_;
- StateHelper<command_buffer::o3d::SetStencilTest> stencil_test_helper_;
- StateHelper<command_buffer::o3d::SetColorWrite> color_write_helper_;
- StateHelper<command_buffer::o3d::SetBlending> blending_helper_;
- StateHelper<command_buffer::o3d::SetBlendingColor> blending_color_helper_;
- DISALLOW_COPY_AND_ASSIGN(StateManager);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_STATES_CB_H_
diff --git a/o3d/core/cross/command_buffer/stream_bank_cb.cc b/o3d/core/cross/command_buffer/stream_bank_cb.cc
deleted file mode 100644
index d7aebf4..0000000
--- a/o3d/core/cross/command_buffer/stream_bank_cb.cc
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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 implementation of the StreamBankCB class.
-
-#include "core/cross/precompile.h"
-#include "core/cross/command_buffer/param_cache_cb.h"
-#include "core/cross/command_buffer/primitive_cb.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "core/cross/command_buffer/buffer_cb.h"
-#include "core/cross/command_buffer/effect_cb.h"
-#include "core/cross/command_buffer/stream_bank_cb.h"
-#include "gpu/command_buffer/common/gapi_interface.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-
-// TODO: add unit tests.
-
-namespace o3d {
-
-using command_buffer::ResourceId;
-using command_buffer::O3DCmdHelper;
-using command_buffer::CommandBufferEntry;
-using command_buffer::o3d::GAPIInterface;
-using command_buffer::kInvalidResource;
-namespace vertex_struct = command_buffer::vertex_struct;
-
-StreamBankCB::StreamBankCB(ServiceLocator* service_locator,
- RendererCB *renderer)
- : StreamBank(service_locator),
- renderer_(renderer),
- vertex_struct_id_(kInvalidResource) {
-}
-
-StreamBankCB::~StreamBankCB() {
- DestroyVertexStruct();
-}
-
-// Converts a semantic/index pair from the O3D conventions to the command
-// buffer conventions.
-static bool GetCBSemantic(
- Stream::Semantic semantic,
- unsigned int semantic_index,
- vertex_struct::Semantic *out_semantic,
- unsigned int *out_semantic_index) {
- // TODO: what meaning do we really want to put to our semantics ? How
- // do they match the semantics that are set in the effect ? What combination
- // of (semantic, index) are supposed to work ?
- switch (semantic) {
- case Stream::POSITION:
- if (semantic_index != 0) return false;
- *out_semantic = vertex_struct::kPosition;
- *out_semantic_index = 0;
- return true;
- case Stream::NORMAL:
- if (semantic_index != 0) return false;
- *out_semantic = vertex_struct::kNormal;
- *out_semantic_index = 0;
- return true;
- case Stream::TANGENT:
- if (semantic_index != 0) return false;
- *out_semantic = vertex_struct::kTexCoord;
- *out_semantic_index = 6;
- return true;
- case Stream::BINORMAL:
- if (semantic_index != 0) return false;
- *out_semantic = vertex_struct::kTexCoord;
- *out_semantic_index = 7;
- return true;
- case Stream::COLOR:
- if (semantic_index > 1) return false;
- *out_semantic = vertex_struct::kColor;
- *out_semantic_index = semantic_index;
- return true;
- case Stream::TEXCOORD:
- *out_semantic = vertex_struct::kTexCoord;
- *out_semantic_index = semantic_index;
- return true;
- default:
- return false;
- }
-}
-
-// Converts a data type from O3D enum values to command-buffer enum values.
-static vertex_struct::Type GetCBType(const Field& field) {
- if (field.IsA(FloatField::GetApparentClass())) {
- switch (field.num_components()) {
- case 1:
- return vertex_struct::kFloat1;
- case 2:
- return vertex_struct::kFloat3;
- case 3:
- return vertex_struct::kFloat3;
- case 4:
- return vertex_struct::kFloat4;
- }
- } else if (field.IsA(UByteNField::GetApparentClass())) {
- switch (field.num_components()) {
- case 4:
- return vertex_struct::kUChar4N;
- }
- }
- DLOG(ERROR) << "Unknown Stream DataType";
- return vertex_struct::kNumTypes;
-}
-
-// This function is overridden so that we can invalidate the vertex struct any
-// time the streams change.
-void StreamBankCB::OnUpdateStreams() {
- DestroyVertexStruct();
-}
-
-// Creates the vertex struct resource on the service side. It will only set the
-// vertex inputs if they represent semantics and types we know about. The
-// command buffer API will not draw with an incomplete vertex struct.
-// This function will get called on Draw, after any change to the vertex inputs
-// has occurred.
-void StreamBankCB::CreateVertexStruct() {
- DCHECK_EQ(kInvalidResource, vertex_struct_id_);
- vertex_struct_id_ = renderer_->vertex_structs_ids().AllocateID();
- O3DCmdHelper* helper = renderer_->helper();
- helper->CreateVertexStruct(vertex_struct_id_, vertex_stream_params_.size());
- for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) {
- const Stream &stream = vertex_stream_params_[i]->stream();
- vertex_struct::Semantic cb_semantic;
- unsigned int cb_semantic_index;
- if (!GetCBSemantic(stream.semantic(), stream.semantic_index(), &cb_semantic,
- &cb_semantic_index)) {
- DLOG(INFO) << "Unknown semantic (" << stream.semantic() << ", "
- << stream.semantic_index() << ") - ignoring stream.";
- continue;
- }
- vertex_struct::Type cb_type = GetCBType(stream.field());
- if (cb_type == vertex_struct::kNumTypes) {
- DLOG(INFO) << "Invalid type (" << stream.field().num_components()
- << ") - ignoring stream.";
- continue;
- }
-
- VertexBufferCB *vertex_buffer =
- static_cast<VertexBufferCB *>(stream.field().buffer());
- helper->SetVertexInput(
- vertex_struct_id_, i,
- vertex_buffer->resource_id(),
- stream.field().offset(),
- cb_semantic,
- cb_semantic_index,
- cb_type,
- vertex_buffer->stride());
- }
-}
-
-// Destroys the vertex struct resource on the service side.
-void StreamBankCB::DestroyVertexStruct() {
- if (vertex_struct_id_ != kInvalidResource) {
- O3DCmdHelper* helper = renderer_->helper();
- helper->DestroyVertexStruct(vertex_struct_id_);
- renderer_->vertex_structs_ids().FreeID(vertex_struct_id_);
- vertex_struct_id_ = kInvalidResource;
- }
-}
-
-void StreamBankCB::BindStreamsForRendering() {
- if (vertex_struct_id_ == kInvalidResource)
- CreateVertexStruct();
- O3DCmdHelper* helper = renderer_->helper();
- helper->SetVertexStruct(vertex_struct_id_);
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/stream_bank_cb.h b/o3d/core/cross/command_buffer/stream_bank_cb.h
deleted file mode 100644
index 4f0656c..0000000
--- a/o3d/core/cross/command_buffer/stream_bank_cb.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 definition of the PrimitiveCB class.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_STREAM_BANK_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_STREAM_BANK_CB_H_
-
-#include "core/cross/precompile.h"
-#include "core/cross/stream_bank.h"
-#include "gpu/command_buffer/common/resource.h"
-
-namespace o3d {
-
-class RendererCB;
-
-// StreamBankCB is the command-buffer implementation of the StreamBank. It
-// provides the necessary interfaces for setting the geometry streams on the
-// StreamBank.
-class StreamBankCB : public StreamBank {
- public:
- StreamBankCB(ServiceLocator* service_locator, RendererCB *renderer);
- virtual ~StreamBankCB();
-
- // Creates the vertex struct from the vertex streams.
- void CreateVertexStruct();
-
- // Binds the streams for rendering.
- void BindStreamsForRendering();
-
- protected:
- // Overridden from StreamBank.
- virtual void OnUpdateStreams();
-
- private:
- // Destroys the vertex struct.
- void DestroyVertexStruct();
-
- // The renderer that created this shape data.
- RendererCB *renderer_;
-
- // The resource ID for the vertex struct representing the input vertex
- // streams, or kInvalidResource if it hasn't been created yet.
- command_buffer::ResourceId vertex_struct_id_;
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_STREAM_BANK_CB_H_
diff --git a/o3d/core/cross/command_buffer/texture_cb.cc b/o3d/core/cross/command_buffer/texture_cb.cc
deleted file mode 100644
index 8793339..0000000
--- a/o3d/core/cross/command_buffer/texture_cb.cc
+++ /dev/null
@@ -1,677 +0,0 @@
-/*
- * 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.
- */
-
-
-// Implementations of the abstract Texture2D and TextureCUBE classes using
-// the OpenCB graphics API.
-
-#include "core/cross/error.h"
-#include "core/cross/types.h"
-#include "core/cross/command_buffer/renderer_cb.h"
-#include "core/cross/command_buffer/texture_cb.h"
-
-#include "gpu/command_buffer/common/o3d_cmd_format.h"
-#include "gpu/command_buffer/common/resource.h"
-#include "gpu/command_buffer/client/o3d_cmd_helper.h"
-#include "gpu/command_buffer/client/fenced_allocator.h"
-
-namespace o3d {
-
-using command_buffer::CommandBufferEntry;
-using command_buffer::O3DCmdHelper;
-using command_buffer::FencedAllocatorWrapper;
-using command_buffer::ResourceId;
-namespace texture = command_buffer::texture;
-
-namespace {
-
-const Texture::RGBASwizzleIndices g_cb_abgr32f_swizzle_indices =
- {0, 1, 2, 3};
-
-// Converts an O3D texture format to a command buffer texture format.
-texture::Format CBFormatFromO3DFormat(Texture::Format format) {
- switch (format) {
- case Texture::XRGB8:
- return texture::kXRGB8;
- case Texture::ARGB8:
- return texture::kARGB8;
- case Texture::ABGR16F:
- return texture::kABGR16F;
- case Texture::R32F:
- return texture::kR32F;
- case Texture::ABGR32F:
- return texture::kABGR32F;
- case Texture::DXT1:
- return texture::kDXT1;
- // TODO: DXT3/5. It's not yet supported by the command buffer
- // renderer, though it would be a simple addition.
- default:
- break;
- }
- // failed to find a matching format
- LOG(ERROR) << "Unrecognized Texture format type.";
- return texture::kUnknown;
-}
-
-// Checks that enums match in value, so that they can be directly used in
-// SetTextureData::Face bitfields.
-COMPILE_ASSERT(TextureCUBE::FACE_POSITIVE_X == texture::kFacePositiveX,
- FACE_POSITIVE_X_enums_don_t_match);
-COMPILE_ASSERT(TextureCUBE::FACE_NEGATIVE_X == texture::kFaceNegativeX,
- FACE_NEGATIVE_X_enums_don_t_match);
-COMPILE_ASSERT(TextureCUBE::FACE_POSITIVE_Y == texture::kFacePositiveY,
- FACE_POSITIVE_Y_enums_don_t_match);
-COMPILE_ASSERT(TextureCUBE::FACE_NEGATIVE_Y == texture::kFaceNegativeY,
- FACE_NEGATIVE_Y_enums_don_t_match);
-COMPILE_ASSERT(TextureCUBE::FACE_POSITIVE_Z == texture::kFacePositiveZ,
- FACE_POSITIVE_Z_enums_don_t_match);
-COMPILE_ASSERT(TextureCUBE::FACE_NEGATIVE_Z == texture::kFaceNegativeZ,
- FACE_NEGATIVE_Z_enums_don_t_match);
-
-// Writes the data information into a buffer to be sent to the server side.
-void SetTextureDataBuffer(Texture::Format format,
- const void* src_data,
- int src_pitch,
- unsigned src_width,
- unsigned src_height,
- void* dst_buffer,
- unsigned int dst_pitch) {
- const uint8* src = static_cast<const uint8*>(src_data);
- uint8* dst = static_cast<uint8*>(dst_buffer);
-
- size_t bytes_per_row = image::ComputePitch(format, src_width);
- unsigned num_rows = src_height;
- if (Texture::IsCompressedFormat(format)) {
- num_rows = (num_rows + 3) / 4;
- }
-
- for (unsigned yy = 0; yy < num_rows; ++yy) {
- memcpy(dst, src, bytes_per_row);
- src += src_pitch;
- dst += dst_pitch;
- }
-}
-
-// Sends the SetTextureData command after formatting the args properly.
-void SetTextureData(RendererCB *renderer,
- ResourceId texture_id,
- unsigned int x,
- unsigned int y,
- unsigned int mip_width,
- unsigned int mip_height,
- unsigned int z,
- unsigned int depth,
- unsigned int level,
- TextureCUBE::CubeFace face,
- int pitch,
- size_t mip_size,
- unsigned char* mip_data) {
- FencedAllocatorWrapper *allocator = renderer->allocator();
- O3DCmdHelper* helper = renderer->helper();
- helper->SetTextureData(
- texture_id,
- x, y, z,
- mip_width, mip_height, depth,
- level, static_cast<texture::Face>(face),
- pitch,
- 0, // slice_pitch
- mip_size,
- renderer->transfer_shm_id(),
- allocator->GetOffset(mip_data));
- allocator->FreePendingToken(mip_data, helper->InsertToken());
-}
-// Updates a command buffer texture resource from a bitmap, rescaling if
-// necessary.
-void UpdateResourceFromBitmap(RendererCB *renderer,
- ResourceId texture_id,
- unsigned int level,
- TextureCUBE::CubeFace face,
- const Bitmap &bitmap) {
- DCHECK(bitmap.image_data());
- FencedAllocatorWrapper *allocator = renderer->allocator();
- O3DCmdHelper* helper = renderer->helper();
- unsigned int mip_width = std::max(1U, bitmap.width() >> level);
- unsigned int mip_height = std::max(1U, bitmap.height() >> level);
- unsigned char *mip_data = bitmap.GetMipData(level);
- size_t mip_size =
- image::ComputeBufferSize(mip_width, mip_height, bitmap.format());
- unsigned char *buffer = allocator->AllocTyped<unsigned char>(mip_size);
- DCHECK(buffer);
- memcpy(buffer, mip_data, mip_size);
- mip_data = buffer;
-
- size_t pitch = image::ComputeBufferSize(mip_width, 1, bitmap.format());
- SetTextureData(renderer,
- texture_id,
- 0,
- 0,
- mip_width,
- mip_height,
- 0,
- 1,
- level,
- face,
- pitch,
- mip_size,
- mip_data);
-}
-
-// Copies back texture resource data into a bitmap.
-void CopyBackResourceToBitmap(RendererCB *renderer,
- ResourceId texture_id,
- unsigned int level,
- TextureCUBE::CubeFace face,
- const Bitmap &bitmap) {
- DCHECK(bitmap.image_data());
- FencedAllocatorWrapper *allocator = renderer->allocator();
- O3DCmdHelper* helper = renderer->helper();
- unsigned int mip_width = std::max(1U, bitmap.width() >> level);
- unsigned int mip_height = std::max(1U, bitmap.height() >> level);
- size_t mip_size =
- image::ComputeBufferSize(mip_width, mip_height, bitmap.format());
- unsigned char *buffer = allocator->AllocTyped<unsigned char>(mip_size);
- DCHECK(buffer);
-
- size_t pitch = image::ComputeBufferSize(mip_width, 1, bitmap.format());
-
- helper->GetTextureData(
- texture_id,
- 0,
- 0,
- 0,
- mip_width,
- mip_height,
- 1,
- level,
- static_cast<texture::Face>(face),
- pitch,
- 0,
- mip_size,
- renderer->transfer_shm_id(),
- allocator->GetOffset(buffer));
- helper->Finish();
- memcpy(bitmap.GetMipData(level), buffer, mip_size);
- allocator->Free(buffer);
-}
-
-} // anonymous namespace
-
-static const unsigned int kMaxTextureSize = 2048;
-
-// Texture2DCB -----------------------------------------------------------------
-
-// Constructs a 2D texture object from an existing command-buffer 2D texture
-// resource.
-// NOTE: the Texture2DCB now owns the texture resource and will destroy it on
-// exit.
-Texture2DCB::Texture2DCB(ServiceLocator* service_locator,
- ResourceId resource_id,
- Texture::Format format,
- int levels,
- int width,
- int height,
- bool enable_render_surfaces)
- : Texture2D(service_locator,
- width,
- height,
- format,
- levels,
- enable_render_surfaces),
- renderer_(static_cast<RendererCB*>(
- service_locator->GetService<Renderer>())),
- resource_id_(resource_id),
- backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))),
- has_levels_(0),
- locked_levels_(0) {
- DCHECK_NE(format, Texture::UNKNOWN_FORMAT);
-}
-
-Texture2DCB::~Texture2DCB() {
- if (resource_id_ != command_buffer::kInvalidResource) {
- renderer_->helper()->DestroyTexture(resource_id_);
- }
-}
-
-// Creates a new texture object from scratch.
-Texture2DCB* Texture2DCB::Create(ServiceLocator* service_locator,
- Texture::Format format,
- int levels,
- int width,
- int height,
- bool enable_render_surfaces) {
- DCHECK_NE(format, Texture::UNKNOWN_FORMAT);
- RendererCB *renderer = static_cast<RendererCB *>(
- service_locator->GetService<Renderer>());
- texture::Format cb_format = CBFormatFromO3DFormat(format);
- if (cb_format == texture::kUnknown) {
- O3D_ERROR(service_locator)
- << "Unsupported format in Texture2DCB::Create.";
- return NULL;
- }
- if (width > kMaxTextureSize || height > kMaxTextureSize) {
- O3D_ERROR(service_locator) << "Texture dimensions (" << width
- << ", " << height << ") too big.";
- return NULL;
- }
-
- ResourceId texture_id = renderer->texture_ids().AllocateID();
- renderer->helper()->CreateTexture2d(
- texture_id,
- width, height,
- levels, cb_format, enable_render_surfaces);
-
- Texture2DCB *texture = new Texture2DCB(service_locator, texture_id,
- format, levels, width, height,
- enable_render_surfaces);
-
- return texture;
-}
-
-void Texture2DCB::SetRect(int level,
- unsigned dst_left,
- unsigned dst_top,
- unsigned src_width,
- unsigned src_height,
- const void* src_data,
- int src_pitch) {
- if (level >= levels() || level < 0) {
- O3D_ERROR(service_locator())
- << "Trying to SetRect on non-existent level " << level
- << " on Texture \"" << name() << "\"";
- return;
- }
- if (render_surfaces_enabled()) {
- O3D_ERROR(service_locator())
- << "Attempting to SetRect a render-target texture: " << name();
- return;
- }
-
- unsigned mip_width = image::ComputeMipDimension(level, width());
- unsigned mip_height = image::ComputeMipDimension(level, height());
-
- if (dst_left + src_width > mip_width ||
- dst_top + src_height > mip_height) {
- O3D_ERROR(service_locator())
- << "SetRect(" << level << ", " << dst_left << ", " << dst_top << ", "
- << src_width << ", " << src_height << ") out of range for texture << \""
- << name() << "\"";
- return;
- }
-
- bool entire_rect = dst_left == 0 && dst_top == 0 &&
- src_width == mip_width && src_height == mip_height;
- bool compressed = IsCompressed();
-
- if (compressed && !entire_rect) {
- O3D_ERROR(service_locator())
- << "SetRect must be full rectangle for compressed textures";
- return;
- }
- unsigned int dst_pitch = image::ComputePitch(format(), src_width);
- size_t size = dst_pitch * src_height;
-
- FencedAllocatorWrapper *allocator = renderer_->allocator();
- uint8 *buffer = allocator->AllocTyped<uint8>(size);
- DCHECK(buffer);
- SetTextureDataBuffer(format(), src_data, src_pitch, src_width, src_height,
- buffer, dst_pitch);
-
- SetTextureData(renderer_,
- resource_id(),
- dst_left,
- dst_top,
- src_width,
- src_height,
- 0,
- 1,
- level,
- TextureCUBE::CubeFace(0),
- dst_pitch,
- size,
- buffer);
-}
-
-// Locks the given mipmap level of this texture for loading from main memory,
-// and returns a pointer to the buffer.
-bool Texture2DCB::PlatformSpecificLock(
- int level, void** data, int* pitch, AccessMode mode) {
- DCHECK_GE(level, 0);
- DCHECK_LT(level, levels());
- if (!backing_bitmap_->image_data()) {
- DCHECK_EQ(has_levels_, 0);
- backing_bitmap_->Allocate(format(), width(), height(), levels(),
- Bitmap::IMAGE);
- }
- *data = backing_bitmap_->GetMipData(level);
- unsigned int mip_width = image::ComputeMipDimension(level, width());
- unsigned int mip_height = image::ComputeMipDimension(level, height());
- if (!IsCompressed()) {
- *pitch = image::ComputePitch(format(), mip_width);
- } else {
- unsigned blocks_across = (mip_width + 3) / 4;
- unsigned bytes_per_block = format() == Texture::DXT1 ? 8 : 16;
- unsigned bytes_per_row = bytes_per_block * blocks_across;
- *pitch = bytes_per_row;
- }
- if (mode != kWriteOnly && !HasLevel(level)) {
- DCHECK_EQ(backing_bitmap_->width(), width());
- DCHECK_EQ(backing_bitmap_->height(), height());
- DCHECK_EQ(backing_bitmap_->format(), format());
- DCHECK_GT(backing_bitmap_->num_mipmaps(), static_cast<unsigned int>(level));
- CopyBackResourceToBitmap(renderer_, resource_id_, level,
- TextureCUBE::FACE_POSITIVE_X,
- *backing_bitmap_.Get());
- has_levels_ |= 1 << level;
- }
- locked_levels_ |= 1 << level;
- return true;
-}
-
-// Unlocks the given mipmap level of this texture, uploading the main memory
-// data buffer to the command buffer service.
-bool Texture2DCB::PlatformSpecificUnlock(int level) {
- DCHECK_GE(level, 0);
- DCHECK_LT(level, levels());
- DCHECK(backing_bitmap_->image_data());
- DCHECK_EQ(backing_bitmap_->width(), width());
- DCHECK_EQ(backing_bitmap_->height(), height());
- DCHECK_EQ(backing_bitmap_->format(), format());
- DCHECK_GT(backing_bitmap_->num_mipmaps(), static_cast<unsigned int>(level));
- if (LockedMode(level) != kReadOnly) {
- UpdateResourceFromBitmap(renderer_, resource_id_, level,
- TextureCUBE::FACE_POSITIVE_X,
- *backing_bitmap_.Get());
- }
- locked_levels_ &= ~(1 << level);
- if (locked_levels_ == 0) {
- backing_bitmap_->FreeData();
- has_levels_ = 0;
- }
- return true;
-}
-
-RenderSurface::Ref Texture2DCB::PlatformSpecificGetRenderSurface(
- int mip_level) {
- DCHECK_LT(mip_level, levels());
- if (!render_surfaces_enabled()) {
- O3D_ERROR(service_locator())
- << "Attempting to get RenderSurface from non-render-surface-enabled"
- << " Texture: " << name();
- return RenderSurface::Ref(NULL);
- }
- if (mip_level >= levels() || mip_level < 0) {
- O3D_ERROR(service_locator())
- << "Attempting to access non-existent mip_level " << mip_level
- << " in render-target texture \"" << name() << "\".";
- return RenderSurface::Ref(NULL);
- }
-
- return RenderSurface::Ref(new RenderSurfaceCB(service_locator(),
- width() >> mip_level,
- height() >> mip_level,
- mip_level,
- 0,
- this,
- renderer_));
-}
-
-const Texture::RGBASwizzleIndices& Texture2DCB::GetABGR32FSwizzleIndices() {
- return g_cb_abgr32f_swizzle_indices;
-}
-// TextureCUBECB ---------------------------------------------------------------
-
-// Creates a texture from a pre-existing texture resource.
-TextureCUBECB::TextureCUBECB(ServiceLocator* service_locator,
- ResourceId resource_id,
- Texture::Format format,
- int levels,
- int edge_length,
- bool enable_render_surfaces)
- : TextureCUBE(service_locator,
- edge_length,
- format,
- levels,
- enable_render_surfaces),
- renderer_(static_cast<RendererCB*>(
- service_locator->GetService<Renderer>())),
- resource_id_(resource_id) {
- for (int ii = 0; ii < static_cast<int>(NUMBER_OF_FACES); ++ii) {
- backing_bitmaps_[ii] = Bitmap::Ref(new Bitmap(service_locator));
- has_levels_[ii] = 0;
- locked_levels_[ii] = 0;
- }
-}
-
-TextureCUBECB::~TextureCUBECB() {
- if (resource_id_ != command_buffer::kInvalidResource) {
- renderer_->helper()->DestroyTexture(resource_id_);
- }
-}
-
-// Create a new Cube texture from scratch.
-TextureCUBECB* TextureCUBECB::Create(ServiceLocator* service_locator,
- Texture::Format format,
- int levels,
- int edge_length,
- bool enable_render_surfaces) {
- DCHECK_NE(format, Texture::UNKNOWN_FORMAT);
- RendererCB *renderer = static_cast<RendererCB *>(
- service_locator->GetService<Renderer>());
- texture::Format cb_format = CBFormatFromO3DFormat(format);
- if (cb_format == texture::kUnknown) {
- O3D_ERROR(service_locator)
- << "Unsupported format in Texture2DCB::Create.";
- return NULL;
- }
- if (edge_length > kMaxTextureSize) {
- O3D_ERROR(service_locator) << "Texture dimensions (" << edge_length
- << ", " << edge_length << ") too big.";
- return NULL;
- }
-
- ResourceId texture_id = renderer->texture_ids().AllocateID();
- renderer->helper()->CreateTextureCube(
- texture_id,
- edge_length,
- levels, cb_format, enable_render_surfaces);
-
- TextureCUBECB* texture =
- new TextureCUBECB(service_locator, texture_id, format, levels,
- edge_length, enable_render_surfaces);
-
- return texture;
-}
-
-void TextureCUBECB::SetRect(TextureCUBE::CubeFace face,
- int level,
- unsigned dst_left,
- unsigned dst_top,
- unsigned src_width,
- unsigned src_height,
- const void* src_data,
- int src_pitch) {
- if (static_cast<int>(face) < 0 || static_cast<int>(face) >= NUMBER_OF_FACES) {
- O3D_ERROR(service_locator())
- << "Trying to SetRect invalid face " << face << " on Texture \""
- << name() << "\"";
- return;
- }
- if (level >= levels() || level < 0) {
- O3D_ERROR(service_locator())
- << "Trying to SetRect non-existent level " << level
- << " on Texture \"" << name() << "\"";
- return;
- }
- if (render_surfaces_enabled()) {
- O3D_ERROR(service_locator())
- << "Attempting to SetRect a render-target texture: " << name();
- return;
- }
-
- unsigned mip_width = image::ComputeMipDimension(level, edge_length());
- unsigned mip_height = mip_width;
-
- if (dst_left + src_width > mip_width ||
- dst_top + src_height > mip_height) {
- O3D_ERROR(service_locator())
- << "SetRect(" << level << ", " << dst_left << ", " << dst_top << ", "
- << src_width << ", " << src_height << ") out of range for texture << \""
- << name() << "\"";
- return;
- }
-
- bool entire_rect = dst_left == 0 && dst_top == 0 &&
- src_width == mip_width && src_height == mip_height;
- bool compressed = IsCompressed();
-
- if (compressed && !entire_rect) {
- O3D_ERROR(service_locator())
- << "SetRect must be full rectangle for compressed textures";
- return;
- }
-
- unsigned int dst_pitch = image::ComputePitch(format(), src_width);
- size_t size = dst_pitch * src_height;
-
- FencedAllocatorWrapper *allocator = renderer_->allocator();
- uint8 *buffer = allocator->AllocTyped<uint8>(size);
- DCHECK(buffer);
- SetTextureDataBuffer(format(), src_data, src_pitch, src_width, src_height,
- buffer, dst_pitch);
-
- SetTextureData(renderer_,
- resource_id(),
- dst_left,
- dst_top,
- src_width,
- src_height,
- 0,
- 1,
- level,
- face,
- dst_pitch,
- size,
- buffer);
-}
-
-// Locks the given face and mipmap level of this texture for loading from
-// main memory, and returns a pointer to the buffer.
-bool TextureCUBECB::PlatformSpecificLock(
- CubeFace face, int level, void** data, int* pitch,
- Texture::AccessMode mode) {
- DCHECK(data);
- DCHECK(pitch);
- DCHECK_GE(level, 0);
- DCHECK_LT(level, levels());
- Bitmap* backing_bitmap = backing_bitmaps_[face].Get();
- if (!backing_bitmap->image_data()) {
- DCHECK_EQ(has_levels_[face], 0);
- backing_bitmap->Allocate(format(), edge_length(), edge_length(), levels(),
- Bitmap::IMAGE);
- }
- *data = backing_bitmap->GetMipData(level);
- unsigned int mip_width = image::ComputeMipDimension(level, edge_length());
- if (!IsCompressed()) {
- *pitch = image::ComputePitch(format(), mip_width);
- } else {
- unsigned blocks_across = (mip_width + 3) / 4;
- unsigned bytes_per_block = format() == Texture::DXT1 ? 8 : 16;
- unsigned bytes_per_row = bytes_per_block * blocks_across;
- *pitch = bytes_per_row;
- }
- if (mode != kWriteOnly && !HasLevel(face, level)) {
- DCHECK_EQ(backing_bitmap->width(), edge_length());
- DCHECK_EQ(backing_bitmap->height(), edge_length());
- DCHECK_EQ(backing_bitmap->format(), format());
- DCHECK_GT(backing_bitmap->num_mipmaps(), static_cast<unsigned int>(level));
- CopyBackResourceToBitmap(renderer_, resource_id_, level,
- TextureCUBE::FACE_POSITIVE_X, *backing_bitmap);
- has_levels_[face] |= 1 << level;
- }
- locked_levels_[face] |= 1 << level;
- return false;
-}
-
-// Unlocks the given face and mipmap level of this texture.
-bool TextureCUBECB::PlatformSpecificUnlock(CubeFace face, int level) {
- DCHECK_GE(level, 0);
- DCHECK_LT(level, levels());
- Bitmap* backing_bitmap = backing_bitmaps_[face].Get();
- DCHECK(backing_bitmap->image_data());
- DCHECK_EQ(backing_bitmap->width(), edge_length());
- DCHECK_EQ(backing_bitmap->height(), edge_length());
- DCHECK_EQ(backing_bitmap->format(), format());
- DCHECK_GT(backing_bitmap->num_mipmaps(), static_cast<unsigned int>(level));
-
- if (LockedMode(face, level) != kReadOnly) {
- UpdateResourceFromBitmap(renderer_, resource_id_, level, face,
- *backing_bitmap);
- }
- locked_levels_[face] &= ~(1 << level);
- if (locked_levels_[face] == 0) {
- backing_bitmap->FreeData();
- has_levels_[face] = 0;
- }
- return false;
-}
-
-RenderSurface::Ref TextureCUBECB::PlatformSpecificGetRenderSurface(
- TextureCUBE::CubeFace face,
- int mip_level) {
- DCHECK_LT(mip_level, levels());
- if (!render_surfaces_enabled()) {
- O3D_ERROR(service_locator())
- << "Attempting to get RenderSurface from non-render-surface-enabled"
- << " Texture: " << name();
- return RenderSurface::Ref(NULL);
- }
- if (mip_level >= levels() || mip_level < 0) {
- O3D_ERROR(service_locator())
- << "Attempting to access non-existent mip_level " << mip_level
- << " in render-target texture \"" << name() << "\".";
- return RenderSurface::Ref(NULL);
- }
-
- int edge = edge_length() >> mip_level;
- return RenderSurface::Ref(new RenderSurfaceCB(service_locator(),
- edge,
- edge,
- mip_level,
- face,
- this,
- renderer_));
-}
-
-const Texture::RGBASwizzleIndices& TextureCUBECB::GetABGR32FSwizzleIndices() {
- return g_cb_abgr32f_swizzle_indices;
-}
-
-} // namespace o3d
diff --git a/o3d/core/cross/command_buffer/texture_cb.h b/o3d/core/cross/command_buffer/texture_cb.h
deleted file mode 100644
index 9e37023..0000000
--- a/o3d/core/cross/command_buffer/texture_cb.h
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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 declarations for Texture2DCB and TextureCUBECB.
-
-#ifndef O3D_CORE_CROSS_COMMAND_BUFFER_TEXTURE_CB_H_
-#define O3D_CORE_CROSS_COMMAND_BUFFER_TEXTURE_CB_H_
-
-#include <vector>
-#include "core/cross/bitmap.h"
-#include "core/cross/texture.h"
-#include "core/cross/types.h"
-#include "gpu/command_buffer/common/resource.h"
-#include "core/cross/command_buffer/render_surface_cb.h"
-
-namespace o3d {
-
-class RendererCB;
-
-// Texture2DCB -----------------------------------------------------------------
-
-// Texture2DCB implements the Texture2D interface for command buffers.
-class Texture2DCB : public Texture2D {
- public:
- typedef SmartPointer<Texture2DCB> Ref;
-
- virtual ~Texture2DCB();
-
- // Creates a new Texture2DCB with the given specs. If the texture creation
- // fails then it returns NULL otherwise it returns a pointer to the newly
- // created Texture object.
- // The created texture takes ownership of the bitmap data.
- static Texture2DCB* Create(ServiceLocator* service_locator,
- Texture::Format format,
- int levels,
- int width,
- int height,
- bool enable_render_surfaces);
-
- // Overridden from Texture2D
- virtual void SetRect(int level,
- unsigned left,
- unsigned top,
- unsigned width,
- unsigned height,
- const void* src_data,
- int src_pitch);
-
- // Returns the implementation-specific texture handle for this texture.
- virtual void* GetTextureHandle() const {
- return reinterpret_cast<void*>(resource_id_);
- }
-
- // Gets the texture resource ID.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- // Gets a RGBASwizzleIndices that contains a mapping from
- // RGBA to the internal format used by the rendering API.
- virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices();
-
- protected:
- // Overridden from Texture2D
- virtual bool PlatformSpecificLock(
- int level, void** texture_data, int* pitch, AccessMode mode);
-
- // Overridden from Texture2D
- virtual bool PlatformSpecificUnlock(int level);
-
- // Overridden from Texture2D
- virtual RenderSurface::Ref PlatformSpecificGetRenderSurface(int mip_level);
-
- private:
- // Initializes the Texture2DCB from a preexisting OpenCB texture handle
- // and raw Bitmap data.
- // The texture takes ownership of the bitmap data.
- Texture2DCB(ServiceLocator* service_locator,
- command_buffer::ResourceId resource_id,
- Texture::Format format,
- int levels,
- int width,
- int height,
- bool enable_render_surfaces);
-
- // Returns true if the backing bitmap has the data for the level.
- bool HasLevel(unsigned int level) {
- DCHECK_LT(level, static_cast<unsigned int>(levels()));
- return (has_levels_ & (1 << level)) != 0;
- }
-
- RendererCB* renderer_;
- command_buffer::ResourceId resource_id_;
-
- // A bitmap used to back the NPOT textures on POT-only hardware, and to back
- // the pixel buffer for Lock().
- Bitmap::Ref backing_bitmap_;
-
- // Bitfield that indicates mip levels that are currently stored in the
- // backing bitmap.
- unsigned int has_levels_;
-
- // Bitfield that indicates which mip levels are currently locked.
- unsigned int locked_levels_;
-};
-
-// TextureCUBECB ---------------------------------------------------------------
-
-// TextureCUBECB implements the TextureCUBE interface with OpenCB.
-class TextureCUBECB : public TextureCUBE {
- public:
- typedef SmartPointer<TextureCUBECB> Ref;
- virtual ~TextureCUBECB();
-
- // Create a new Cube texture from scratch.
- static TextureCUBECB* TextureCUBECB::Create(ServiceLocator* service_locator,
- Texture::Format format,
- int levels,
- int edge_length,
- bool enable_render_surfaces);
-
- // Overridden from TextureCUBE
- virtual void SetRect(CubeFace face,
- int level,
- unsigned dst_left,
- unsigned dst_top,
- unsigned width,
- unsigned height,
- const void* src_data,
- int src_pitch);
-
- // Returns the implementation-specific texture handle for this texture.
- virtual void* GetTextureHandle() const {
- return reinterpret_cast<void*>(resource_id_);
- }
-
- // Gets the texture resource ID.
- command_buffer::ResourceId resource_id() const { return resource_id_; }
-
- // Gets a RGBASwizzleIndices that contains a mapping from
- // RGBA to the internal format used by the rendering API.
- virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices();
-
- protected:
- // Overridden from TextureCUBE
- virtual bool PlatformSpecificLock(
- CubeFace face, int level, void** texture_data, int* pitch,
- AccessMode mode);
-
- // Overridden from TextureCUBE
- virtual bool PlatformSpecificUnlock(CubeFace face, int level);
-
- // Overridden from TextureCUBE.
- virtual RenderSurface::Ref PlatformSpecificGetRenderSurface(CubeFace face,
- int level);
- private:
- // Creates a texture from a pre-existing texture resource.
- TextureCUBECB(ServiceLocator* service_locator,
- command_buffer::ResourceId texture,
- Texture::Format format,
- int levels,
- int edge_length,
- bool enable_render_surfaces);
-
-
- // Returns true if the backing bitmap has the data for the level.
- bool HasLevel(CubeFace face, unsigned int level) {
- DCHECK_LT(level, static_cast<unsigned int>(levels()));
- return (has_levels_[face] & (1 << level)) != 0;
- }
-
- RendererCB* renderer_;
- command_buffer::ResourceId resource_id_;
-
- // Bitmaps used to back the NPOT textures on POT-only hardware.
- Bitmap::Ref backing_bitmaps_[NUMBER_OF_FACES];
-
- // Bitfields that indicates mip levels that are currently stored in the
- // backing bitmap, one per face.
- unsigned int has_levels_[NUMBER_OF_FACES];
-
- // Bitfields that indicates which levels are currently locked, one per face.
- unsigned int locked_levels_[NUMBER_OF_FACES];
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_COMMAND_BUFFER_TEXTURE_CB_H_