diff options
53 files changed, 21 insertions, 15325 deletions
diff --git a/o3d/build/common.gypi b/o3d/build/common.gypi index ea2c179..e03653d 100644 --- a/o3d/build/common.gypi +++ b/o3d/build/common.gypi @@ -21,8 +21,8 @@ 'skiadir': 'third_party/skia/include', 'zlibdir': 'third_party/zlib', - # Hack to ensure that these variables (specifically "renderer" and - # "cb_service") are available later in the file. Long term solution is late + # Hack to ensure that these variables (specifically "renderer") are + # available later in the file. Long term solution is late # evaluation of variables. 'variables': { # If the DEPS file exists two levels up, then we're in a Chrome tree. @@ -35,7 +35,6 @@ { 'cgdir': 'third_party/cg/files/win', 'renderer%': 'd3d9', - 'cb_service%': 'none', 'swiftshaderdir': 'o3d-internal/third_party/swiftshader/files', }, ], @@ -43,7 +42,6 @@ { 'cgdir': 'third_party/cg/files/mac', 'renderer%': 'gl', - 'cb_service%': 'none', 'swiftshaderdir': '', }, ], @@ -51,7 +49,6 @@ { 'cgdir': 'third_party/cg/files/linux', 'renderer%': 'gl', - 'cb_service%': 'none', 'swiftshaderdir': '', }, ], @@ -61,7 +58,6 @@ 'renderer%': '<(renderer)', 'cgdir%': '<(cgdir)', 'swiftshaderdir%': '<(swiftshaderdir)', - 'cb_service%': '<(cb_service)', # We default to building everything only if the assets exist. # (and the teapot is the least likely asset to change). @@ -69,24 +65,6 @@ 'o3d_developer%': '<!(python <(DEPTH)/o3d/build/file_exists.py ' '<(DEPTH)/o3d/o3d_assets/samples/convert_assets/teapot.zip)', 'selenium_screenshots%': 0, - - 'conditions' : [ - ['o3d_in_chrome == "True"', - { - 'renderer': 'cb', - 'conditions': [ - ['OS == "win"', - { - 'cb_service': 'd3d9', - }, - { - 'cb_service': 'gl', - }, - ], - ], - }, - ], - ], }, 'target_defaults': { 'defines': [ @@ -135,13 +113,6 @@ ], }, ], - ['renderer == "cb"', - { - 'defines': [ - 'RENDERER_CB', - ], - }, - ], ], }, }, @@ -181,13 +152,6 @@ ], }, ], - ['renderer == "cb"', - { - 'defines': [ - 'RENDERER_CB', - ], - }, - ], ], }, }, @@ -216,40 +180,6 @@ ], }, ], - ['renderer == "cb"', - { - 'defines': [ - 'RENDERER_CB', - ], - }, - ], - ], - }, - }, - ], - ['cb_service == "d3d9"', - { - 'target_defaults': { - 'defines': [ - 'CB_SERVICE_D3D9', - ], - }, - }, - ], - ['cb_service == "gl"', - { - 'target_defaults': { - 'defines': [ - 'CB_SERVICE_GL', - ], - }, - }, - ], - ['cb_service == "remote"', - { - 'target_defaults': { - 'defines': [ - 'CB_SERVICE_REMOTE', ], }, }, diff --git a/o3d/build/o3d_all.gyp b/o3d/build/o3d_all.gyp index d2ab921..b545bd0 100644 --- a/o3d/build/o3d_all.gyp +++ b/o3d/build/o3d_all.gyp @@ -36,6 +36,8 @@ ['OS=="win"', { 'dependencies': [ + '../gpu/gpu.gyp:gles2_demo', + '../gpu/gpu.gyp:gpu_all_unittests', '../plugin/plugin.gyp:o3d_host', ], }, @@ -47,20 +49,6 @@ ], }, ], - ['renderer=="cb"', - { - 'dependencies': [ - '../gpu/gpu.gyp:gpu_all_unittests', - ], - }, - ], - ['renderer=="cb" and cb_service=="gl"', - { - 'dependencies': [ - '../gpu/gpu.gyp:gles2_demo', - ], - }, - ], ], }, ], diff --git a/o3d/core/core.gyp b/o3d/core/core.gyp index 11b4d33..f2773ec 100644 --- a/o3d/core/core.gyp +++ b/o3d/core/core.gyp @@ -395,45 +395,6 @@ ], }, ], - ['renderer == "cb"', - { - 'dependencies': [ - '../gpu/gpu.gyp:command_buffer_client', - '../gpu/gpu.gyp:np_utils', - ], - 'sources': [ - 'cross/command_buffer/buffer_cb.cc', - 'cross/command_buffer/buffer_cb.h', - 'cross/command_buffer/effect_cb.cc', - 'cross/command_buffer/effect_cb.h', - 'cross/command_buffer/install_check.cc', - 'cross/command_buffer/install_check.h', - 'cross/command_buffer/param_cache_cb.cc', - 'cross/command_buffer/param_cache_cb.h', - 'cross/command_buffer/primitive_cb.cc', - 'cross/command_buffer/primitive_cb.h', - 'cross/command_buffer/renderer_cb.cc', - 'cross/command_buffer/renderer_cb.h', - 'cross/command_buffer/render_surface_cb.cc', - 'cross/command_buffer/render_surface_cb.h', - 'cross/command_buffer/sampler_cb.cc', - 'cross/command_buffer/sampler_cb.h', - 'cross/command_buffer/states_cb.cc', - 'cross/command_buffer/states_cb.h', - 'cross/command_buffer/stream_bank_cb.cc', - 'cross/command_buffer/stream_bank_cb.h', - 'cross/command_buffer/texture_cb.cc', - 'cross/command_buffer/texture_cb.h', - ], - }, - ], - ['renderer == "cb" and cb_service != "remote"', - { - 'dependencies': [ - '../gpu/gpu.gyp:command_buffer_service', - ], - }, - ], ], }, { diff --git a/o3d/core/cross/renderer_platform.h b/o3d/core/cross/renderer_platform.h index f512d9a..639459e 100644 --- a/o3d/core/cross/renderer_platform.h +++ b/o3d/core/cross/renderer_platform.h @@ -64,8 +64,6 @@ #include "core/win/d3d9/renderer_d3d9.h" #elif defined(RENDERER_GL) #include "core/cross/gl/renderer_gl.h" -#elif defined(RENDERER_CB) -#include "core/cross/command_buffer/renderer_cb.h" #else #error Renderer not recognized. #endif diff --git a/o3d/core/cross/renderer_test.cc b/o3d/core/cross/renderer_test.cc index 2cde1a9..190aabc 100644 --- a/o3d/core/cross/renderer_test.cc +++ b/o3d/core/cross/renderer_test.cc @@ -81,7 +81,6 @@ TEST_F(RendererTest, InitAndDestroyRenderer) { // TODO(apatrick): This test will not work as is with command buffers because // it attempts to create a Renderer using the same ring buffer as the // Renderer created in main. -#if !defined(RENDERER_CB) scoped_ptr<Renderer> renderer( Renderer::CreateDefaultRenderer(service_locator())); EXPECT_TRUE(renderer->Init(*g_display_window, false)); @@ -104,7 +103,6 @@ TEST_F(RendererTest, InitAndDestroyRenderer) { // check that the renderer no longer has a Cg Context. EXPECT_FALSE(gl_renderer->cg_context() != NULL); #endif -#endif // RENDERER_CB } // Offscreen is only supported on D3D currently diff --git a/o3d/gpu/command_buffer/client/effect_helper.cc b/o3d/gpu/command_buffer/client/effect_helper.cc deleted file mode 100644 index f3daaae..0000000 --- a/o3d/gpu/command_buffer/client/effect_helper.cc +++ /dev/null @@ -1,250 +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 EffectHelper class. - -#include "gpu/command_buffer/common/o3d_cmd_format.h" -#include "gpu/command_buffer/client/cmd_buffer_helper.h" -#include "gpu/command_buffer/client/effect_helper.h" -#include "gpu/command_buffer/client/fenced_allocator.h" -#include "gpu/command_buffer/client/id_allocator.h" - -// TODO: write a unit test. - -namespace command_buffer { - -bool EffectHelper::CreateEffectParameters(ResourceId effect_id, - std::vector<EffectParamDesc> *descs) { - using effect_param::Desc; - DCHECK_NE(effect_id, kInvalidResource); - DCHECK(descs); - descs->clear(); - - // Get the param count. - Uint32 *retval = shm_allocator_->AllocTyped<Uint32>(1); - helper_->GetParamCount(effect_id, sizeof(*retval), - shm_id_, shm_allocator_->GetOffset(retval)); - // Finish has to be called to get the result. - helper_->Finish(); - - // We could have failed if the effect_id is invalid. - if (helper_->GetParseError() != parse_error::kParseNoError) { - shm_allocator_->Free(retval); - return false; - } - unsigned int param_count = *retval; - - shm_allocator_->Free(retval); - unsigned int max_buffer_size = shm_allocator_->GetLargestFreeOrPendingSize(); - if (max_buffer_size < sizeof(Desc)) { // NOLINT - // Not enough memory to get at least 1 param desc. - return false; - } - descs->resize(param_count); - for (unsigned int i = 0; i < param_count; ++i) { - EffectParamDesc *desc = &((*descs)[i]); - desc->id = param_id_allocator_->AllocateID(); - helper_->CreateParam(desc->id, effect_id, i); - } - - // Read param descriptions in batches. We use as much shared memory as - // possible so that we only call Finish as little as possible. - unsigned int max_param_per_batch = - std::min(static_cast<unsigned>(param_count), - static_cast<unsigned>(max_buffer_size / sizeof(Desc))); // NOLINT - Desc *raw_descs = shm_allocator_->AllocTyped<Desc>(max_param_per_batch); - DCHECK(raw_descs); - for (unsigned int i = 0; i < param_count; i += max_param_per_batch) { - unsigned int count = std::min(param_count - i, max_param_per_batch); - for (unsigned int j = 0 ; j < count; ++j) { - EffectParamDesc *desc = &((*descs)[i + j]); - Desc *raw_desc = raw_descs + j; - helper_->GetParamDesc(desc->id, sizeof(*raw_desc), - shm_id_, - shm_allocator_->GetOffset(raw_desc)); - } - // Finish to get the results. - helper_->Finish(); - DCHECK_EQ(helper_->GetParseError(), parse_error::kParseNoError); - for (unsigned int j = 0 ; j < count; ++j) { - EffectParamDesc *desc = &((*descs)[i + j]); - Desc *raw_desc = raw_descs + j; - desc->data_type = raw_desc->data_type; - desc->data_size = raw_desc->data_size; - desc->num_elements = raw_desc->num_elements; - desc->cmd_desc_size = raw_desc->size; - } - } - shm_allocator_->Free(raw_descs); - return true; -} - -bool EffectHelper::GetParamStrings(EffectParamDesc *desc) { - using effect_param::Desc; - DCHECK(desc); - DCHECK_NE(desc->id, kInvalidResource); - // desc may not have come directly from CreateEffectParameters, so it may be - // less than the minimum required size. - unsigned int size = std::max(static_cast<unsigned>(desc->cmd_desc_size), - static_cast<unsigned>(sizeof(Desc))); // NOLINT - Desc *raw_desc = static_cast<Desc *>(shm_allocator_->Alloc(size)); - if (!raw_desc) { - // Not enough memory to get the param desc. - return false; - } - helper_->GetParamDesc(desc->id, size, - shm_id_, - shm_allocator_->GetOffset(raw_desc)); - - // Finish to get the results. - helper_->Finish(); - - // We could have failed if the param ID is invalid. - if (helper_->GetParseError() != parse_error::kParseNoError) { - shm_allocator_->Free(raw_desc); - return false; - } - - if (raw_desc->size > size) { - // We had not allocated enough memory the first time (e.g. if the - // EffectParamDesc didn't come from CreateEffectParameters, so the user had - // no way of knowing what size was needed for the strings), so re-allocate - // and try again. - size = raw_desc->size; - desc->cmd_desc_size = size; - shm_allocator_->Free(raw_desc); - raw_desc = static_cast<Desc *>(shm_allocator_->Alloc(size)); - if (!raw_desc) { - // Not enough memory to get the param desc. - return false; - } - helper_->GetParamDesc(desc->id, size, - shm_id_, - shm_allocator_->GetOffset(raw_desc)); - // Finish to get the results. - helper_->Finish(); - DCHECK_EQ(helper_->GetParseError(), parse_error::kParseNoError); - DCHECK_EQ(raw_desc->size, size); - } - - const char *raw_desc_string = reinterpret_cast<char *>(raw_desc); - if (raw_desc->name_offset) { - DCHECK_LE(raw_desc->name_offset + raw_desc->name_size, raw_desc->size); - DCHECK_GT(raw_desc->name_size, 0U); - DCHECK_EQ(raw_desc_string[raw_desc->name_offset + raw_desc->name_size - 1], - 0); - desc->name = String(raw_desc_string + raw_desc->name_offset, - raw_desc->name_size - 1); - } else { - desc->name.clear(); - } - if (raw_desc->semantic_offset) { - DCHECK_LE(raw_desc->semantic_offset + raw_desc->semantic_size, - raw_desc->size); - DCHECK_GT(raw_desc->semantic_size, 0U); - DCHECK_EQ(raw_desc_string[raw_desc->semantic_offset + - raw_desc->semantic_size - 1], - 0); - desc->semantic = String(raw_desc_string + raw_desc->semantic_offset, - raw_desc->semantic_size - 1); - } else { - desc->semantic.clear(); - } - shm_allocator_->Free(raw_desc); - return true; -} - -void EffectHelper::DestroyEffectParameters( - const std::vector<EffectParamDesc> &descs) { - for (unsigned int i = 0; i < descs.size(); ++i) { - const EffectParamDesc &desc = descs[i]; - helper_->DestroyParam(desc.id); - param_id_allocator_->FreeID(desc.id); - } -} - -bool EffectHelper::GetEffectStreams(ResourceId effect_id, - std::vector<EffectStreamDesc> *descs) { - using effect_stream::Desc; - DCHECK_NE(effect_id, kInvalidResource); - - // Get the param count. - Uint32 *retval = shm_allocator_->AllocTyped<Uint32>(1); - helper_->GetStreamCount(effect_id, sizeof(*retval), - shm_id_, - shm_allocator_->GetOffset(retval)); - // Finish has to be called to get the result. - helper_->Finish(); - - // We could have failed if the effect_id is invalid. - if (helper_->GetParseError() != parse_error::kParseNoError) { - shm_allocator_->Free(retval); - return false; - } - unsigned int stream_count = *retval; - shm_allocator_->Free(retval); - unsigned int max_buffer_size = shm_allocator_->GetLargestFreeOrPendingSize(); - if (max_buffer_size < sizeof(Desc)) { // NOLINT - // Not enough memory to get at least 1 stream desc. - return false; - } - descs->resize(stream_count); - - // Read stream descriptions in batches. We use as much shared memory as - // possible so that we only call Finish as little as possible. - unsigned int max_stream_per_batch = - std::min(static_cast<unsigned>(stream_count), - static_cast<unsigned>(max_buffer_size / sizeof(Desc))); // NOLINT - Desc *raw_descs = shm_allocator_->AllocTyped<Desc>(max_stream_per_batch); - DCHECK(raw_descs); - for (unsigned int i = 0; i < stream_count; i += max_stream_per_batch) { - unsigned int count = std::min(stream_count - i, max_stream_per_batch); - for (unsigned int j = 0 ; j < count; ++j) { - Desc *raw_desc = raw_descs + j; - helper_->GetStreamDesc(effect_id, i + j, sizeof(*raw_desc), - shm_id_, - shm_allocator_->GetOffset(raw_desc)); - } - // Finish to get the results. - helper_->Finish(); - DCHECK_EQ(helper_->GetParseError(), parse_error::kParseNoError); - for (unsigned int j = 0 ; j < count; ++j) { - EffectStreamDesc *desc = &((*descs)[i + j]); - Desc *raw_desc = raw_descs + j; - desc->semantic = static_cast<vertex_struct::Semantic>(raw_desc->semantic); - desc->semantic_index = raw_desc->semantic_index; - } - } - shm_allocator_->Free(raw_descs); - return true; -} -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/client/effect_helper.h b/o3d/gpu/command_buffer/client/effect_helper.h deleted file mode 100644 index dc11b24..0000000 --- a/o3d/gpu/command_buffer/client/effect_helper.h +++ /dev/null @@ -1,156 +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 EffectHelper class. - -#ifndef GPU_COMMAND_BUFFER_CLIENT_CROSS_EFFECT_HELPER_H_ -#define GPU_COMMAND_BUFFER_CLIENT_CROSS_EFFECT_HELPER_H_ - -#include <vector> -#include "gpu/command_buffer/common/resource.h" -#include "gpu/command_buffer/client/o3d_cmd_helper.h" - -namespace command_buffer { - -class FencedAllocatorWrapper; -class IdAllocator; -class CommandBufferHelper; - -// A helper class to find parameters in an effect. -class EffectHelper { - public: - // A more usable version of effect_param::Desc - struct EffectParamDesc { - ResourceId id; // The resource ID for the param. - String name; // The name of the param. - String semantic; // The semantic of the param. - effect_param::DataType data_type; // The data type of a param. - unsigned int data_size; // The size of the data for a param. - int num_elements; // The number of array entries if the - // parameter is an array, 0 otherwise. - unsigned int cmd_desc_size; // The size of the effect_param::Desc - // structure (counting strings) for a - // param. - }; - struct EffectStreamDesc { - vertex_struct::Semantic semantic; // The semantic enum type. - unsigned int semantic_index; - }; - - EffectHelper(O3DCmdHelper *helper, - FencedAllocatorWrapper *shm_allocator, - unsigned int shm_id, - IdAllocator *param_id_allocator) - : helper_(helper), - shm_allocator_(shm_allocator), - shm_id_(shm_id), - param_id_allocator_(param_id_allocator) { - DCHECK(helper); - DCHECK(shm_allocator); - DCHECK(param_id_allocator); - } - - // Creates all the parameters in an effect and gets their descriptions. The - // strings will not be retrieved, so name and semantic will be empty. The - // cmd_desc_size field will be set to the proper size to be able to get the - // strings with a single command within GetParamStrings, so it should be left - // alone. - // - // The ResourceIDs will be allocated in the param_id_allocator. - // Temporary buffers will be allocated in the shm_allocator, but they will be - // freed before the function returns (possibly pending a token). At least - // sizeof(effect_param::Desc) must be available for this function to succeed. - // This function will call Finish(), hence will block. - // - // Parameters: - // effect_id: the ResourceId of the effect. - // descs: A pointer to a vector containing the returned descriptions. - // The pointed vector will be cleared. - // Returns: - // true if successful. Reasons for failure are: - // - invalid effect_id, - // - not enough memory in the shm_allocator_. - bool CreateEffectParameters(ResourceId effect_id, - std::vector<EffectParamDesc> *descs); - - // Gets the strings for a desc. This will fill in the values for the name and - // semantic fields. - // Temporary buffers will be allocated in the shm_allocator, but they will be - // freed before the function returns (possibly pending a token). At least - // desc.cmd_desc_size (as returned by CreateEffectParameters) must be - // available for this function to succeed. - // This function will call Finish(), hence will block. - // - // Parameters: - // desc: a pointer to the description for a parameter. The id field should - // be set to the ResourceId of the parameter. - // Returns: - // true if successful. Reasons for failure are: - // - invalid parameter ResourceId, - // - not enough memory in the shm_allocator_. - bool GetParamStrings(EffectParamDesc *desc); - - // Destroys all parameter resources referenced by the descriptions. The - // ResourceId will be freed from the param_id_allocator. - // Parameters: - // descs: the vector of descriptions containing the ResourceIDs of the - // parameters to destroy. - void DestroyEffectParameters(const std::vector<EffectParamDesc> &descs); - - // Gets all the input stream semantics and semantic indices in an - // array. These will be retrieved as many as possible at a time. At least - // sizeof(effect_param::Desc) must be available for this function to succeed. - // This function will call Finish(), hence will block. - // - // Parameters: - // effect_id: the ResourceId of the effect. - // descs: A pointer to a vector containing the returned descriptions. - // The pointed vector will be cleared. - // Returns: - // true if successful. Reasons for failure are: - // - invalid effect_id, - // - not enough memory in the shm_allocator_. - bool GetEffectStreams(ResourceId effect_id, - std::vector<EffectStreamDesc> *descs); - - private: - O3DCmdHelper *helper_; - FencedAllocatorWrapper *shm_allocator_; - unsigned int shm_id_; - IdAllocator *param_id_allocator_; - - DISALLOW_COPY_AND_ASSIGN(EffectHelper); -}; - -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_CLIENT_CROSS_EFFECT_HELPER_H_ diff --git a/o3d/gpu/command_buffer/client/o3d_cmd_helper.cc b/o3d/gpu/command_buffer/client/o3d_cmd_helper.cc deleted file mode 100644 index 85c6a27..0000000 --- a/o3d/gpu/command_buffer/client/o3d_cmd_helper.cc +++ /dev/null @@ -1,42 +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 o3d buffer helper class. - -#include "gpu/command_buffer/client/o3d_cmd_helper.h" - -namespace command_buffer { - -// Currently this is a place holder. - -} // namespace command_buffer - diff --git a/o3d/gpu/command_buffer/client/o3d_cmd_helper.h b/o3d/gpu/command_buffer/client/o3d_cmd_helper.h deleted file mode 100644 index 535da21..0000000 --- a/o3d/gpu/command_buffer/client/o3d_cmd_helper.h +++ /dev/null @@ -1,632 +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 o3d command buffer helper class. - -#ifndef GPU_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ -#define GPU_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ - -#include "gpu/command_buffer/client/cmd_buffer_helper.h" -#include "gpu/command_buffer/common/logging.h" -#include "gpu/command_buffer/common/constants.h" -#include "gpu/command_buffer/common/o3d_cmd_format.h" - -namespace command_buffer { - -// A helper for O3D command buffers. -class O3DCmdHelper : public CommandBufferHelper { - public: - explicit O3DCmdHelper(command_buffer::CommandBuffer* command_buffer) - : CommandBufferHelper(command_buffer) { - } - virtual ~O3DCmdHelper() { - } - - // ------------------ Individual commands ---------------------- - - void BeginFrame() { - o3d::BeginFrame& cmd = GetCmdSpace<o3d::BeginFrame>(); - cmd.Init(); - } - - - void EndFrame() { - o3d::EndFrame& cmd = GetCmdSpace<o3d::EndFrame>(); - cmd.Init(); - } - - void Clear( - uint32 buffers, - float red, float green, float blue, float alpha, - float depth, uint32 stencil) { - o3d::Clear& cmd = GetCmdSpace<o3d::Clear>(); - cmd.Init(buffers, red, green, blue, alpha, depth, stencil); - } - - void SetViewport( - uint32 left, - uint32 top, - uint32 width, - uint32 height, - float z_min, - float z_max) { - o3d::SetViewport& cmd = GetCmdSpace<o3d::SetViewport>(); - cmd.Init(left, top, width, height, z_min, z_max); - } - - void CreateVertexBuffer( - ResourceId vertex_buffer_id, uint32 size, vertex_buffer::Flags flags) { - o3d::CreateVertexBuffer& cmd = GetCmdSpace<o3d::CreateVertexBuffer>(); - cmd.Init(vertex_buffer_id, size, flags); - } - - void DestroyVertexBuffer(ResourceId vertex_buffer_id) { - o3d::DestroyVertexBuffer& cmd = GetCmdSpace<o3d::DestroyVertexBuffer>(); - cmd.Init(vertex_buffer_id); - } - - void SetVertexBufferDataImmediate( - ResourceId vertex_buffer_id, uint32 offset, - const void* data, uint32 size) { - o3d::SetVertexBufferDataImmediate& cmd = - GetImmediateCmdSpace<o3d::SetVertexBufferDataImmediate>(size); - cmd.Init(vertex_buffer_id, offset, data, size); - } - - void SetVertexBufferData( - ResourceId vertex_buffer_id, uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::SetVertexBufferData& cmd = - GetCmdSpace<o3d::SetVertexBufferData>(); - cmd.Init(vertex_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - } - - void GetVertexBufferData( - ResourceId vertex_buffer_id, uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetVertexBufferData& cmd = - GetCmdSpace<o3d::GetVertexBufferData>(); - cmd.Init(vertex_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - } - - void CreateIndexBuffer( - ResourceId index_buffer_id, uint32 size, index_buffer::Flags flags) { - o3d::CreateIndexBuffer& cmd = - GetCmdSpace<o3d::CreateIndexBuffer>(); - cmd.Init(index_buffer_id, size, flags); - } - - void DestroyIndexBuffer(ResourceId index_buffer_id) { - o3d::DestroyIndexBuffer& cmd = GetCmdSpace<o3d::DestroyIndexBuffer>(); - cmd.Init(index_buffer_id); - } - - void SetIndexBufferDataImmediate( - ResourceId index_buffer_id, uint32 offset, - const void* data, uint32 size) { - o3d::SetIndexBufferDataImmediate& cmd = - GetImmediateCmdSpace<o3d::SetIndexBufferDataImmediate>(size); - cmd.Init(index_buffer_id, offset, data, size); - } - - void SetIndexBufferData( - ResourceId index_buffer_id, uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::SetIndexBufferData& cmd = GetCmdSpace<o3d::SetIndexBufferData>(); - cmd.Init(index_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - } - - void GetIndexBufferData( - ResourceId index_buffer_id, uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetIndexBufferData& cmd = GetCmdSpace<o3d::GetIndexBufferData>(); - cmd.Init(index_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - } - - void CreateVertexStruct(ResourceId vertex_struct_id, uint32 input_count) { - o3d::CreateVertexStruct& cmd = GetCmdSpace<o3d::CreateVertexStruct>(); - cmd.Init(vertex_struct_id, input_count); - } - - void DestroyVertexStruct(ResourceId vertex_struct_id) { - o3d::DestroyVertexStruct& cmd = GetCmdSpace<o3d::DestroyVertexStruct>(); - cmd.Init(vertex_struct_id); - } - - void SetVertexInput( - ResourceId vertex_struct_id, - uint32 input_index, - ResourceId vertex_buffer_id, - uint32 offset, - vertex_struct::Semantic semantic, - uint32 semantic_index, - vertex_struct::Type type, - uint32 stride) { - o3d::SetVertexInput& cmd = GetCmdSpace<o3d::SetVertexInput>(); - cmd.Init( - vertex_struct_id, - input_index, - vertex_buffer_id, - offset, - semantic, - semantic_index, - type, - stride); - } - - void SetVertexStruct(ResourceId vertex_struct_id) { - o3d::SetVertexStruct& cmd = GetCmdSpace<o3d::SetVertexStruct>(); - cmd.Init(vertex_struct_id); - } - - void Draw(o3d::PrimitiveType primitive_type, uint32 first, uint32 count) { - o3d::Draw& cmd = GetCmdSpace<o3d::Draw>(); - cmd.Init(primitive_type, first, count); - } - - void DrawIndexed( - o3d::PrimitiveType primitive_type, - ResourceId index_buffer_id, - uint32 first, - uint32 count, - uint32 min_index, - uint32 max_index) { - o3d::DrawIndexed& cmd = GetCmdSpace<o3d::DrawIndexed>(); - cmd.Init( - primitive_type, - index_buffer_id, - first, - count, - min_index, - max_index); - } - - void CreateEffect( - ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::CreateEffect& cmd = GetCmdSpace<o3d::CreateEffect>(); - cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); - } - - void CreateEffectImmediate( - ResourceId effect_id, uint32 size, const void* data) { - o3d::CreateEffectImmediate& cmd = - GetImmediateCmdSpace<o3d::CreateEffectImmediate>(size); - cmd.Init(effect_id, size, data); - } - - void DestroyEffect(ResourceId effect_id) { - o3d::DestroyEffect& cmd = GetCmdSpace<o3d::DestroyEffect>(); - cmd.Init(effect_id); - } - - void SetEffect(ResourceId effect_id) { - o3d::SetEffect& cmd = GetCmdSpace<o3d::SetEffect>(); - cmd.Init(effect_id); - } - - void GetParamCount( - ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetParamCount& cmd = GetCmdSpace<o3d::GetParamCount>(); - cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); - } - - void CreateParam(ResourceId param_id, ResourceId effect_id, uint32 index) { - o3d::CreateParam& cmd = GetCmdSpace<o3d::CreateParam>(); - cmd.Init(param_id, effect_id, index); - } - - void CreateParamByName( - ResourceId param_id, ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::CreateParamByName& cmd = GetCmdSpace<o3d::CreateParamByName>(); - cmd.Init(param_id, effect_id, size, shared_memory_id, shared_memory_offset); - } - - void CreateParamByNameImmediate( - ResourceId param_id, ResourceId effect_id, - uint32 size, const void* data) { - o3d::CreateParamByNameImmediate& cmd = - GetImmediateCmdSpace<o3d::CreateParamByNameImmediate>(size); - cmd.Init(param_id, effect_id, size, data); - } - - void DestroyParam(ResourceId param_id) { - o3d::DestroyParam& cmd = GetCmdSpace<o3d::DestroyParam>(); - cmd.Init(param_id); - } - - void SetParamData( - ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::SetParamData& cmd = GetCmdSpace<o3d::SetParamData>(); - cmd.Init(param_id, size, shared_memory_id, shared_memory_offset); - } - - void SetParamDataImmediate( - ResourceId param_id, uint32 size, const void* data) { - o3d::SetParamDataImmediate& cmd = - GetImmediateCmdSpace<o3d::SetParamDataImmediate>(size); - cmd.Init(param_id, size, data); - } - - void GetParamDesc( - ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetParamDesc& cmd = GetCmdSpace<o3d::GetParamDesc>(); - cmd.Init(param_id, size, shared_memory_id, shared_memory_offset); - } - - void GetStreamCount( - ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetStreamCount& cmd = GetCmdSpace<o3d::GetStreamCount>(); - cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); - } - - void GetStreamDesc( - ResourceId effect_id, uint32 index, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - o3d::GetStreamDesc& cmd = GetCmdSpace<o3d::GetStreamDesc>(); - cmd.Init(effect_id, index, size, shared_memory_id, shared_memory_offset); - } - - void DestroyTexture(ResourceId texture_id) { - o3d::DestroyTexture& cmd = GetCmdSpace<o3d::DestroyTexture>(); - cmd.Init(texture_id); - } - - void CreateTexture2d( - ResourceId texture_id, - uint32 width, uint32 height, - uint32 levels, texture::Format format, - bool enable_render_surfaces) { - o3d::CreateTexture2d& cmd = GetCmdSpace<o3d::CreateTexture2d>(); - cmd.Init(texture_id, - width, height, levels, format, - enable_render_surfaces); - } - - void CreateTexture3d( - ResourceId texture_id, - uint32 width, uint32 height, uint32 depth, - uint32 levels, texture::Format format, - bool enable_render_surfaces) { - o3d::CreateTexture3d& cmd = GetCmdSpace<o3d::CreateTexture3d>(); - cmd.Init(texture_id, - width, height, depth, - levels, format, - enable_render_surfaces); - } - - void CreateTextureCube( - ResourceId texture_id, - uint32 edge_length, uint32 levels, texture::Format format, - bool enable_render_surfaces) { - o3d::CreateTextureCube& cmd = GetCmdSpace<o3d::CreateTextureCube>(); - cmd.Init(texture_id, - edge_length, levels, format, - enable_render_surfaces); - } - - void SetTextureData( - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - o3d::SetTextureData& cmd = GetCmdSpace<o3d::SetTextureData>(); - cmd.Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - shared_memory_id, - shared_memory_offset); - } - - void SetTextureDataImmediate( - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - const void* data) { - o3d::SetTextureDataImmediate& cmd = - GetImmediateCmdSpace<o3d::SetTextureDataImmediate>(size); - cmd.Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - data); - } - - void GetTextureData( - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - o3d::GetTextureData& cmd = GetCmdSpace<o3d::GetTextureData>(); - cmd.Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - shared_memory_id, - shared_memory_offset); - } - - void CreateSampler(ResourceId sampler_id) { - o3d::CreateSampler& cmd = GetCmdSpace<o3d::CreateSampler>(); - cmd.Init(sampler_id); - } - - void DestroySampler(ResourceId sampler_id) { - o3d::DestroySampler& cmd = GetCmdSpace<o3d::DestroySampler>(); - cmd.Init(sampler_id); - } - - void SetSamplerStates( - ResourceId sampler_id, - sampler::AddressingMode address_u_value, - sampler::AddressingMode address_v_value, - sampler::AddressingMode address_w_value, - sampler::FilteringMode mag_filter_value, - sampler::FilteringMode min_filter_value, - sampler::FilteringMode mip_filter_value, - uint8 max_anisotropy) { - o3d::SetSamplerStates& cmd = GetCmdSpace<o3d::SetSamplerStates>(); - cmd.Init( - sampler_id, - address_u_value, - address_v_value, - address_w_value, - mag_filter_value, - min_filter_value, - mip_filter_value, - max_anisotropy); - } - - void SetSamplerBorderColor( - ResourceId sampler_id, - float red, float green, float blue, float alpha) { - o3d::SetSamplerBorderColor& cmd = - GetCmdSpace<o3d::SetSamplerBorderColor>(); - cmd.Init(sampler_id, red, green, blue, alpha); - } - - void SetSamplerTexture(ResourceId sampler_id, ResourceId texture_id) { - o3d::SetSamplerTexture& cmd = GetCmdSpace<o3d::SetSamplerTexture>(); - cmd.Init(sampler_id, texture_id); - } - - void SetScissor( - uint32 x, - uint32 y, - uint32 width, - uint32 height, - bool enable) { - o3d::SetScissor& cmd = GetCmdSpace<o3d::SetScissor>(); - cmd.Init( - x, - y, - width, - height, - enable); - } - - void SetPolygonOffset(float slope_factor, float units) { - o3d::SetPolygonOffset& cmd = GetCmdSpace<o3d::SetPolygonOffset>(); - cmd.Init(slope_factor, units); - } - - void SetPointLineRaster( - bool line_smooth_enable, bool point_sprite_enable, float point_size) { - o3d::SetPointLineRaster& cmd = GetCmdSpace<o3d::SetPointLineRaster>(); - cmd.Init(line_smooth_enable, point_sprite_enable, point_size); - } - - void SetPolygonRaster(o3d::PolygonMode fill_mode, - o3d::FaceCullMode cull_mode) { - o3d::SetPolygonRaster& cmd = GetCmdSpace<o3d::SetPolygonRaster>(); - cmd.Init(fill_mode, cull_mode); - } - - void SetAlphaTest(o3d::Comparison func, bool enable, float value) { - o3d::SetAlphaTest& cmd = GetCmdSpace<o3d::SetAlphaTest>(); - cmd.Init(func, enable, value); - } - - void SetDepthTest(o3d::Comparison func, bool write_enable, bool enable) { - o3d::SetDepthTest& cmd = GetCmdSpace<o3d::SetDepthTest>(); - cmd.Init(func, write_enable, enable); - } - - void SetStencilTest( - uint8 write_mask, - uint8 compare_mask, - uint8 reference_value, - bool separate_ccw, - bool enable, - o3d::Comparison cw_func, - o3d::StencilOp cw_pass_op, - o3d::StencilOp cw_fail_op, - o3d::StencilOp cw_z_fail_op, - o3d::Comparison ccw_func, - o3d::StencilOp ccw_pass_op, - o3d::StencilOp ccw_fail_op, - o3d::StencilOp ccw_z_fail_op) { - o3d::SetStencilTest& cmd = GetCmdSpace<o3d::SetStencilTest>(); - cmd.Init( - write_mask, - compare_mask, - reference_value, - separate_ccw, - enable, - cw_func, - cw_pass_op, - cw_fail_op, - cw_z_fail_op, - ccw_func, - ccw_pass_op, - ccw_fail_op, - ccw_z_fail_op); - } - - void SetColorWrite(uint8 mask, bool dither_enable) { - o3d::SetColorWrite& cmd = GetCmdSpace<o3d::SetColorWrite>(); - cmd.Init(mask, dither_enable); - } - - void SetBlending( - o3d::BlendFunc color_src_func, - o3d::BlendFunc color_dst_func, - o3d::BlendEq color_eq, - o3d::BlendFunc alpha_src_func, - o3d::BlendFunc alpha_dst_func, - o3d::BlendEq alpha_eq, - bool separate_alpha, - bool enable) { - o3d::SetBlending& cmd = GetCmdSpace<o3d::SetBlending>(); - cmd.Init( - color_src_func, - color_dst_func, - color_eq, - alpha_src_func, - alpha_dst_func, - alpha_eq, - separate_alpha, - enable); - } - - void SetBlendingColor(float red, float green, float blue, float alpha) { - o3d::SetBlendingColor& cmd = GetCmdSpace<o3d::SetBlendingColor>(); - cmd.Init(red, green, blue, alpha); - } - - void CreateRenderSurface( - ResourceId render_surface_id, ResourceId texture_id, - uint32 width, uint32 height, - uint32 level, uint32 side) { - o3d::CreateRenderSurface& cmd = GetCmdSpace<o3d::CreateRenderSurface>(); - cmd.Init(render_surface_id, texture_id, width, height, level, side); - } - - void DestroyRenderSurface(ResourceId render_surface_id) { - o3d::DestroyRenderSurface& cmd = - GetCmdSpace<o3d::DestroyRenderSurface>(); - cmd.Init(render_surface_id); - } - - void CreateDepthSurface( - ResourceId depth_surface_id, uint32 width, uint32 height) { - o3d::CreateDepthSurface& cmd = GetCmdSpace<o3d::CreateDepthSurface>(); - cmd.Init(depth_surface_id, width, height); - } - - void DestroyDepthSurface(ResourceId depth_surface_id) { - o3d::DestroyDepthSurface& cmd = GetCmdSpace<o3d::DestroyDepthSurface>(); - cmd.Init(depth_surface_id); - } - - void SetRenderSurface( - ResourceId render_surface_id, ResourceId depth_surface_id) { - o3d::SetRenderSurface& cmd = GetCmdSpace<o3d::SetRenderSurface>(); - cmd.Init(render_surface_id, depth_surface_id); - } - - void SetBackSurfaces() { - o3d::SetBackSurfaces& cmd = GetCmdSpace<o3d::SetBackSurfaces>(); - cmd.Init(); - } -}; - -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ - diff --git a/o3d/gpu/command_buffer/common/gapi_interface.h b/o3d/gpu/command_buffer/common/gapi_interface.h deleted file mode 100644 index a032f0e..0000000 --- a/o3d/gpu/command_buffer/common/gapi_interface.h +++ /dev/null @@ -1,833 +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 interface class for the low-level graphics API -// (GAPI). - -#ifndef GPU_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H_ -#define GPU_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H_ - -#include "gpu/command_buffer/common/constants.h" -#include "gpu/command_buffer/common/resource.h" -#include "gpu/command_buffer/common/o3d_cmd_format.h" - -namespace command_buffer { -namespace o3d { - -// RBGA color definition. -struct RGBA { - float red; - float green; - float blue; - float alpha; -}; - -// This class defines the low-level graphics API, as a pure interface class. -class GAPIInterface { - public: - typedef parse_error::ParseError ParseError; - - GAPIInterface() {} - virtual ~GAPIInterface() {} - - // Initializes the graphics context. - // Returns: - // true if successful. - virtual bool Initialize() = 0; - - // Destroys the graphics context. - virtual void Destroy() = 0; - - // Starts a frame. Rendering should occur between BeginFrame and EndFrame. - virtual void BeginFrame() = 0; - - // Ends the frame, and bring the back buffer to front. Rendering should occur - // between BeginFrame and EndFrame. - virtual void EndFrame() = 0; - - // Clear buffers, filling them with a constant value. - // Parameters: - // buffers: which buffers to clear. Can be a combination (bitwise or) of - // values from ClearBuffer. - // color: the RGBA color to clear the color target with. - // depth: the depth to clear the depth buffer with. - // stencil: the stencil value to clear the stencil buffer with. - virtual void Clear(unsigned int buffers, - const RGBA &color, - float depth, - unsigned int stencil) = 0; - - // Creates a vertex buffer. - // Parameters: - // id: the resource ID for the new vertex buffer. - // size: the size of the vertex buffer, in bytes. - // flags: the vertex buffer flags, as a combination of vertex_buffer::Flags - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateVertexBuffer(ResourceId id, - unsigned int size, - unsigned int flags) = 0; - - // Destroys a vertex buffer. - // Parameters: - // id: the resource ID of the vertex buffer. - // Returns: - // parse_error::kParseInvalidArguments if an invalid vertex buffer - // ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyVertexBuffer(ResourceId id) = 0; - - // Sets data into a vertex buffer. - // Parameters: - // id: the resource ID of the vertex buffer. - // offset: the offset into the vertex buffer where to place the data. - // size: the size of the data. - // data: the source data. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments were - // passed: invalid resource ID, or offset or size out of range. - // parse_error::kParseNoError otherwise. - virtual ParseError SetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) = 0; - - // Gets data from a vertex buffer. - // Parameters: - // id: the resource ID of the vertex buffer. - // offset: the offset into the vertex buffer where to get the data. - // size: the size of the data. - // data: the destination buffer. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments were - // passed: invalid resource ID, or offset or size out of range. - // parse_error::kParseNoError otherwise. - virtual ParseError GetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data) = 0; - - // Creates an index buffer. - // Parameters: - // id: the resource ID for the new index buffer. - // size: the size of the index buffer, in bytes. - // flags: the index buffer flags, as a combination of index_buffer::Flags. - // Note that indices are 16 bits unless the index_buffer::INDEX_32BIT - // flag is specified. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateIndexBuffer(ResourceId id, - unsigned int size, - unsigned int flags) = 0; - - // Destroys an index buffer. - // Parameters: - // id: the resource ID of the index buffer. - // Returns: - // parse_error::kParseInvalidArguments if an invalid index buffer - // ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyIndexBuffer(ResourceId id) = 0; - - // Sets data into an index buffer. - // Parameters: - // id: the resource ID of the index buffer. - // offset: the offset into the index buffer where to place the data. - // size: the size of the data. - // data: the source data. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments were - // passed: invalid resource ID, or offset or size out of range. - // parse_error::kParseNoError otherwise. - virtual ParseError SetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) = 0; - - // Gets data from an index buffer. - // Parameters: - // id: the resource ID of the index buffer. - // offset: the offset into the index buffer where to get the data. - // size: the size of the data. - // data: the destination buffer. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments were - // passed: invalid resource ID, or offset or size out of range. - // parse_error::kParseNoError otherwise. - virtual ParseError GetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data) = 0; - - // Creates a vertex struct. A vertex struct describes the input vertex - // attribute streams. - // Parameters: - // id: the resource ID of the vertex struct. - // input_count: the number of input vertex attributes. - // returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateVertexStruct(ResourceId id, - unsigned int input_count) = 0; - - // Destroys a vertex struct. - // Parameters: - // id: the resource ID of the vertex struct. - // Returns: - // parse_error::kParseInvalidArguments if an invalid vertex struct - // ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyVertexStruct(ResourceId id) = 0; - - // Sets an input into a vertex struct. - // Parameters: - // vertex_struct_id: the resource ID of the vertex struct. - // input_index: the index of the input being set. - // vertex_buffer_id: the resource ID of the vertex buffer containing the - // data. - // offset: the offset into the vertex buffer of the input data, in bytes. - // stride: the stride of the input data, in bytes. - // type: the type of the input data. - // semantic: the semantic of the input. - // semantic_index: the semantic index of the input. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError SetVertexInput(ResourceId vertex_struct_id, - unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index) = 0; - - // Sets the current vertex struct for drawing. - // Parameters: - // id: the resource ID of the vertex struct. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed (invalid vertex struct), parse_error::kParseNoError - // otherwise. - virtual ParseError SetVertexStruct(ResourceId id) = 0; - - // Draws primitives, using the current vertex struct and the current effect. - // Parameters: - // primitive_type: the type of primitive to draw. - // first: the index of the first vertex. - // count: the number of primitives to draw. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError Draw(PrimitiveType primitive_type, - unsigned int first, - unsigned int count) = 0; - - // Draws primitives, using the current vertex struct and the current effect, - // as well as an index buffer. - // Parameters: - // primitive_type: the type of primitive to draw. - // index_buffer_id: the resource ID of the index buffer. - // first: the index into the index buffer of the first index to draw. - // count: the number of primitives to draw. - // min_index: the lowest index being drawn. - // max_index: the highest index being drawn. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError DrawIndexed(PrimitiveType primitive_type, - ResourceId index_buffer_id, - unsigned int first, - unsigned int count, - unsigned int min_index, - unsigned int max_index) = 0; - - // Creates an effect, from source code. - // Parameters: - // id: the resource ID of the effect. - // size: the size of data. - // data: the source code for the effect. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed or the effect failed to compile, - // parse_error::kParseNoError otherwise. - virtual ParseError CreateEffect(ResourceId id, - unsigned int size, - const void *data) = 0; - - // Destroys an effect. - // Parameters: - // id: the resource ID of the effect. - // Returns: - // parse_error::kParseInvalidArguments if an invalid effect ID - // was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyEffect(ResourceId id) = 0; - - // Sets the active effect for drawing. - // Parameters: - // id: the resource ID of the effect. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError SetEffect(ResourceId id) = 0; - - // Gets the number of parameters in an effect, returning it in a memory - // buffer as a Uint32. - // Parameters: - // id: the resource ID of the effect. - // size: the size of the data buffer. Must be at least 4 (the size of the - // Uint32). - // data: the buffer receiving the data. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError GetParamCount(ResourceId id, - unsigned int size, - void *data) = 0; - - // Creates an effect parameter by index. - // Parameters: - // param_id: the resource ID of the parameter being created. - // effect_id: the resource ID of the effect containing the parameter. - // data_type: the data type for the parameter. Must match the data type in - // the effect source. - // index: the index of the parameter. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, such as invalid effect ID, unmatching data type or invalid - // index, parse_error::kParseNoError otherwise. - virtual ParseError CreateParam(ResourceId param_id, - ResourceId effect_id, - unsigned int index) = 0; - - // Creates an effect parameter by name. - // Parameters: - // param_id: the resource ID of the parameter being created. - // effect_id: the resource ID of the effect containing the parameter. - // data_type: the data type for the parameter. Must match the data type in - // the effect source. - // size: the size of the parameter name. - // name: the parameter name, as an array of char. Doesn't have to be - // nul-terminated (though nul will terminate the string). - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, such as invalid effect ID, unmatching data type or no parameter - // was found with this name, parse_error::kParseNoError otherwise. - virtual ParseError CreateParamByName(ResourceId param_id, - ResourceId effect_id, - unsigned int size, - const void *name) = 0; - - // Destroys an effect parameter. - // Parameters: - // id: the resource ID of the parameter. - // Returns: - // parse_error::kParseInvalidArguments if an invalid parameter ID - // was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyParam(ResourceId id) = 0; - - // Sets the effect parameter data. - // Parameters: - // id: the resource ID of the parameter. - // size: the size of the data. Must be at least the size of the parameter - // as described by its type. - // data: the parameter data. - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, such as invalid parameter ID, or unmatching data size, - // parse_error::kParseNoError otherwise. - virtual ParseError SetParamData(ResourceId id, - unsigned int size, - const void *data) = 0; - - // Gets the parameter description, storing it into a memory buffer. The - // parameter is described by a effect_param::Desc structure. The size must be - // at least the size of that structure. The name and semantic fields are only - // filled if the character strings fit into the memory buffer. In any case, - // the size field (in the effect_param::Desc) is filled with the size needed - // to fill in the structure, the name and the semantic (if any). Thus to get - // the complete information, GetParamDesc can be called twice, once to get - // the size, and, after allocating a big enough buffer, again to fill in the - // complete information including the text strings. - // Parameters: - // id: the resource ID of the parameter. - // size: the size of the memory buffer that wil receive the parameter - // description. Must be at least sizeof(effect_param::Desc). - // data: the memory buffer. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, such as invalid parameter ID, or unsufficient data size, - // parse_error::kParseNoError otherwise. Note that - // parse_error::kParseNoError will be returned if the structure - // itself fits, not necessarily the names. To make sure all the information - // is available, the caller should compare the returned size member of the - // effect_param::Desc structure to the size parameter passed in. - virtual ParseError GetParamDesc(ResourceId id, - unsigned int size, - void *data) = 0; - - // Gets the number of input streams for an effect, returning it in a memory - // buffer as a Uint32. - // Parameters: - // id: the resource ID of the effect. - // size: the size of the data buffer. Must be at least 4 (the size of the - // Uint32). - // data: the buffer receiving the data. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError GetStreamCount(ResourceId id, - unsigned int size, - void *data) = 0; - - // Gets the stream semantics, storing them in the data buffer. The stream - // is described by an effect_stream::Desc structure which contains a - // semantic type and a semantic index. - // Parameters: - // id: the resource ID of the effect. - // index: which stream semantic to get - // size: the size of the data buffer. Must be at least 8 (the size of two - // Uint32). - // data: the buffer receiving the data. - virtual ParseError GetStreamDesc(ResourceId id, - unsigned int index, - unsigned int size, - void *data) = 0; - - // Creates a 2D texture resource. - // Parameters: - // id: the resource ID of the texture. - // width: the texture width. Must be positive. - // height: the texture height. Must be positive. - // levels: the number of mipmap levels in the texture, or 0 to use the - // maximum. - // format: the format of the texels in the texture. - // flags: the texture flags, as a combination of texture::Flags. - // enable_render_surfaces: bool for whether to enable render surfaces - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateTexture2D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) = 0; - - // Creates a 3D texture resource. - // Parameters: - // id: the resource ID of the texture. - // width: the texture width. Must be positive. - // height: the texture height. Must be positive. - // depth: the texture depth. Must be positive. - // levels: the number of mipmap levels in the texture, or 0 to use the - // maximum. - // format: the format of the pixels in the texture. - // flags: the texture flags, as a combination of texture::Flags. - // enable_render_surfaces: bool for whether to enable render surfaces - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateTexture3D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) = 0; - - // Creates a cube map texture resource. - // Parameters: - // id: the resource ID of the texture. - // side: the texture side length. Must be positive. - // levels: the number of mipmap levels in the texture, or 0 to use the - // maximum. - // format: the format of the pixels in the texture. - // flags: the texture flags, as a combination of texture::Flags. - // enable_render_surfaces: bool for whether to enable render surfaces - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateTextureCube(ResourceId id, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) = 0; - - // Sets texel data into a texture resource. This is a common function for - // each of the texture types, but some restrictions exist based on the - // texture type. The specified rectangle or volume of data, defined by x, y, - // width, height and possibly z and depth must fit into the selected mimmap - // level. Data is encoded by rows of 2D blocks, whose size depends on the - // texel format, usually 1x1 texel, but can be 4x4 for DXT* formats. See - // texture::GetBytesPerBlock, texture::GetBlockSizeX and - // texture::GetBlockSizeY. - // Parameters: - // id: the resource ID of the texture. - // x: the x position of the texel corresponding to the first byte of data. - // y: the y position of the texel corresponding to the first byte of data. - // z: the z position of the texel corresponding to the first byte of data. - // Must be 0 for non-3D textures. - // width: the width of the data rectangle/volume. - // height: the height of the data rectangle/volume. - // depth: the depth of the data volume. Must be 1 for non-3D textures. - // level: the mipmap level to put the data into. - // face: which face of the cube to put the data into. Is ignored for - // non-cube map textures. - // row_pitch: the number of bytes between two consecutive rows of blocks, - // in the source data. - // slice_pitch: the number of bytes between two consecutive slices of - // blocks, in the source data. Is ignored for non-3D textures. - // size: the size of the data. - // data: the texel data. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, for example invalid size, or out-of-bounds rectangle/volume, - // parse_error::kParseNoError otherwise. - virtual ParseError SetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) = 0; - - // Gets texel data from a texture resource. This is a common function for - // each of the texture types, but some restrictions exist based on the - // texture type. The specified rectangle or volume of data, defined by x, y, - // width, height and possibly z and depth must fit into the selected mimmap - // level. Data is encoded by rows of 2D blocks, whose size depends on the - // texel format, usually 1x1 texel, but can be 4x4 for DXT* formats. See - // texture::GetBytesPerBlock, texture::GetBlockSizeX and - // texture::GetBlockSizeY. - // Parameters: - // id: the resource ID of the texture. - // x: the x position of the texel corresponding to the first byte of data. - // y: the y position of the texel corresponding to the first byte of data. - // z: the z position of the texel corresponding to the first byte of data. - // Must be 0 for non-3D textures. - // width: the width of the data rectangle/volume. - // height: the height of the data rectangle/volume. - // depth: the depth of the data volume. Must be 1 for non-3D textures. - // level: the mipmap level to put the data into. - // face: which face of the cube to put the data into. Is ignored for - // non-cube map textures. - // row_pitch: the number of bytes between two consecutive rows of blocks, - // in the destination buffer. - // slice_pitch: the number of bytes between two consecutive slices of - // blocks, in the destination buffer. Is ignored for non-3D textures. - // size: the size of the data. - // data: the destination buffer. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, for example invalid size, or out-of-bounds rectangle/volume, - // parse_error::kParseNoError otherwise. - virtual ParseError GetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) = 0; - - // Destroys a texture resource. - // Parameters: - // id: the resource ID of the texture. - // Returns: - // parse_error::kParseInvalidArguments if an invalid texture - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyTexture(ResourceId id) = 0; - - // Creates a sampler resource. - // Parameters: - // id: the resource ID of the sampler. - // Returns: - // parse_error::kParseNoError. - virtual ParseError CreateSampler(ResourceId id) = 0; - - // Destroys a sampler resource. - // Parameters: - // id: the resource ID of the sampler. - // Returns: - // parse_error::kParseInvalidArguments if an invalid sampler - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroySampler(ResourceId id) = 0; - - // Sets the states in a sampler resource. - // Parameters: - // id: the resource ID of the sampler. - // addressing_u: the addressing mode for the U coordinate. - // addressing_v: the addressing mode for the V coordinate. - // addressing_w: the addressing mode for the W coordinate. - // mag_filter: the filtering mode when magnifying textures. - // min_filter: the filtering mode when minifying textures. - // mip_filter: the filtering mode for mip-map interpolation textures. - // max_anisotropy: the maximum anisotropy. - // Returns: - // parse_error::kParseInvalidArguments if an invalid sampler - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError SetSamplerStates(ResourceId id, - sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy) = 0; - - // Sets the color of border pixels. - // Parameters: - // id: the resource ID of the sampler. - // color: the border color. - // Returns: - // parse_error::kParseInvalidArguments if an invalid sampler - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError SetSamplerBorderColor(ResourceId id, - const RGBA &color) = 0; - - // Sets the texture resource used by a sampler resource. - // Parameters: - // id: the resource ID of the sampler. - // texture_id: the resource id of the texture. - // Returns: - // parse_error::kParseInvalidArguments if an invalid sampler - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError SetSamplerTexture(ResourceId id, - ResourceId texture_id) = 0; - - // Sets the viewport, and depth range. - // Parameters: - // x, y: upper left corner of the viewport. - // width, height: dimensions of the viewport. - // z_min, z_max: depth range. - virtual void SetViewport(unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height, - float z_min, - float z_max) = 0; - - // Sets the scissor test enable flag and rectangle. - // Parameters: - // enable: whether or not scissor test is enabled. - // x, y: upper left corner of the scissor rectangle. - // width, height: dimensions of the scissor rectangle. - virtual void SetScissor(bool enable, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height) = 0; - - // Sets the point and line rasterization state. - // Parameters: - // line_smooth: Whether or not line anti-aliasing is enabled. - // point_sprite: Whether or not point sprites are enabled. - // point_size: The point size. - virtual void SetPointLineRaster(bool line_smooth, - bool point_sprite, - float point_size) = 0; - - // Sets the polygon rasterization state. - // Parameters: - // fill_mode: The polygon filling mode. - // cull_mode: The polygon face culling mode. - virtual void SetPolygonRaster(PolygonMode fill_mode, - FaceCullMode cull_mode) = 0; - - // Sets the polygon offset state. Polygon offset is enabled if slope_factor - // or units is not 0. - // The applied offset (in window coordinates) is: - // o = max_slope * slope_factor + r * units - // Where max_slope is the maximum slope of the polygon (in window - // coordinates again), and r is the minimum resolvable z unit. - // Parameters: - // slope_factor: slope factor for the offset. - // units: constant factor for the offset. - virtual void SetPolygonOffset(float slope_factor, float units) = 0; - - // Sets the alpha test states. - // Parameters: - // enable: alpha test enable state. - // reference: reference value for comparison. - // comp: alpha comparison function. - virtual void SetAlphaTest(bool enable, - float reference, - Comparison comp) = 0; - - // Sets the depth test states. - // Note: if the depth test is disabled, z values are not written to the z - // buffer (i.e enable/kAlways is different from disable/*). - // Parameters: - // enable: depth test enable state. - // write_enable: depth write enable state. - // comp: depth comparison function. - virtual void SetDepthTest(bool enable, - bool write_enable, - Comparison comp) = 0; - - // Sets the stencil test states. - // Parameters: - // enable: stencil test enable state. - // separate_ccw: whether or not counter-clockwise faces use separate - // functions/operations (2-sided stencil). - // write_mask: stencil write mask. - // compare_mask: stencil compare mask. - // ref: stencil reference value. - // func_ops: stencil test function and operations for both clockwise and - // counter-clockwise faces. This is a bitfield following the following - // description (little-endian addressing): - // bits 0 - 11: clockwise functions/operations - // bits 12 - 15: must be 0. - // bits 16 - 28: counter-clockwise functions/operations - // bits 29 - 32: must be 0. - virtual void SetStencilTest(bool enable, - bool separate_ccw, - unsigned int write_mask, - unsigned int compare_mask, - unsigned int ref, - Uint32 func_ops) = 0; - - // Sets the color write paramters. - // Parameters: - // red: enable red write. - // green: enable green write. - // blue: enable blue write. - // alpha: enable alpha write. - // dither: enable dithering. - virtual void SetColorWrite(bool red, - bool green, - bool blue, - bool alpha, - bool dither) = 0; - - // Sets the blending mode. - // Parameters: - // enable: whether or not to enable blending. - // separate_alpha: whether or not alpha uses separate Equation/Functions - // (if false, it uses the color ones). - // color_eq: the equation for blending of color values. - // color_src_func: the source function for blending of color values. - // color_dst_func: the destination function for blending of color values. - // alpha_eq: the equation for blending of alpha values. - // alpha_src_func: the source function for blending of alpha values. - // alpha_dst_func: the destination function for blending of alpha values. - virtual void SetBlending(bool enable, - bool separate_alpha, - BlendEq color_eq, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq alpha_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func) = 0; - - // Sets the blending color. - virtual void SetBlendingColor(const RGBA &color) = 0; - - // Creates a render surface resource. - // Parameters: - // id: the resource ID of the render surface. - // width: the texture width. Must be positive. - // height: the texture height. Must be positive. - // texture_id: the resource id of the texture. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateRenderSurface(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int mip_level, - unsigned int side, - ResourceId texture_id) = 0; - - // Destroys a render surface resource. - // Parameters: - // id: the resource ID of the render surface. - // Returns: - // parse_error::kParseInvalidArguments if an invalid render - // surface - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyRenderSurface(ResourceId id) = 0; - - // Creates a depth stencil surface resource. - // Parameters: - // id: the resource ID of the depth stencil surface. - // width: the texture width. Must be positive. - // height: the texture height. Must be positive. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError CreateDepthSurface(ResourceId id, - unsigned int width, - unsigned int height) = 0; - - // Destroys a depth stencil surface resource. - // Parameters: - // id: the resource ID of the depth stencil surface. - // Returns: - // parse_error::kParseInvalidArguments if an invalid render - // surface - // resource ID was passed, parse_error::kParseNoError otherwise. - virtual ParseError DestroyDepthSurface(ResourceId id) = 0; - - // Switches the render surface and depth stencil surface to those - // corresponding to the passed in IDs. - // Parameters: - // render_surface_id: the resource ID of the render surface. - // depth_stencil_id: the resource ID of the render depth stencil surface. - // Returns: - // parse_error::kParseInvalidArguments if invalid arguments are - // passed, parse_error::kParseNoError otherwise. - virtual ParseError SetRenderSurface(ResourceId render_surface_id, - ResourceId depth_stencil_id) = 0; - - // Switch the render surface and depth stencil surface back to the main - // surfaces stored in the render - virtual void SetBackSurfaces() = 0; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_COMMON_CROSS_GAPI_INTERFACE_H_ diff --git a/o3d/gpu/command_buffer/common/o3d_cmd_format.cc b/o3d/gpu/command_buffer/common/o3d_cmd_format.cc deleted file mode 100644 index c70dde7..0000000 --- a/o3d/gpu/command_buffer/common/o3d_cmd_format.cc +++ /dev/null @@ -1,57 +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 binary format definition of the command buffer and -// command buffer commands. - -#include "gpu/command_buffer/common/o3d_cmd_format.h" - -namespace command_buffer { -namespace o3d { - -const char* GetCommandName(CommandId command_id) { - static const char* const names[] = { - #define O3D_COMMAND_BUFFER_CMD_OP(name) # name, - - O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) - - #undef O3D_COMMAND_BUFFER_CMD_OP - }; - - int id = static_cast<int>(command_id); - return (id > kStartPoint && id < kNumCommands) ? - names[id - kStartPoint - 1] : "*unknown-command*"; -} - -} // namespace o3d -} // namespace command_buffer - diff --git a/o3d/gpu/command_buffer/common/o3d_cmd_format.h b/o3d/gpu/command_buffer/common/o3d_cmd_format.h deleted file mode 100644 index 86503f4..0000000 --- a/o3d/gpu/command_buffer/common/o3d_cmd_format.h +++ /dev/null @@ -1,3155 +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 binary format definition of the command buffer and -// command buffer commands. -// It is recommended you use the CommandBufferHelper object to create commands -// but if you want to go lower level you can use the structures here to help. -// -// A few ways to use them: -// -// Fill out a structure in place: -// -// cmd::SetViewport::Set(ptrToSomeSharedMemory, -// left, right, width, height, z_min, z_max); -// -// Fill out consecutive commands: -// -// Note that each cmd::XXX::Set function returns a pointer to the place -// the next command should go. -// -// void* dest = ptrToSomeSharedMemory; -// dest = cmd::SetViewport::Set(dest, left, right, width, height, min, max); -// dest = cmd::Clear::Set(dest, buffers, r, g, b, a, depth, stencil); -// dest = cmd::Draw::Set(dest, primitive_type, first, count); -// -// NOTE: The types in this file must be POD types. That means they can not have -// constructors, destructors, virtual functions or inheritance and they can only -// use other POD types or intrinsics as members. - -#ifndef GPU_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ -#define GPU_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ - -#include "gpu/command_buffer/common/cmd_buffer_common.h" -#include "gpu/command_buffer/common/resource.h" - -namespace command_buffer { -namespace o3d { - -// This macro is used to safely and convienently expand the list of commnad -// buffer commands in to various lists and never have them get out of sync. To -// add a new command, add it this list, create the corresponding structure below -// and then add a function in gapi_decoder.cc called Handle_COMMAND_NAME where -// COMMAND_NAME is the name of your command structure. -// -// NOTE: THE ORDER OF THESE MUST NOT CHANGE (their id is derived by order) -#define O3D_COMMAND_BUFFER_CMDS(OP) \ - OP(BeginFrame) /* 1024 */ \ - OP(EndFrame) /* 1025 */ \ - OP(Clear) /* 1026 */ \ - OP(CreateVertexBuffer) /* 1027 */ \ - OP(DestroyVertexBuffer) /* 1028 */ \ - OP(SetVertexBufferData) /* 1029 */ \ - OP(SetVertexBufferDataImmediate) /* 1030 */ \ - OP(GetVertexBufferData) /* 1031 */ \ - OP(CreateIndexBuffer) /* 1032 */ \ - OP(DestroyIndexBuffer) /* 1033 */ \ - OP(SetIndexBufferData) /* 1034 */ \ - OP(SetIndexBufferDataImmediate) /* 1035 */ \ - OP(GetIndexBufferData) /* 1036 */ \ - OP(CreateVertexStruct) /* 1037 */ \ - OP(DestroyVertexStruct) /* 1038 */ \ - OP(SetVertexInput) /* 1039 */ \ - OP(SetVertexStruct) /* 1040 */ \ - OP(Draw) /* 1041 */ \ - OP(DrawIndexed) /* 1042 */ \ - OP(CreateEffect) /* 1043 */ \ - OP(CreateEffectImmediate) /* 1044 */ \ - OP(DestroyEffect) /* 1045 */ \ - OP(SetEffect) /* 1046 */ \ - OP(GetParamCount) /* 1047 */ \ - OP(CreateParam) /* 1048 */ \ - OP(CreateParamByName) /* 1049 */ \ - OP(CreateParamByNameImmediate) /* 1050 */ \ - OP(DestroyParam) /* 1051 */ \ - OP(SetParamData) /* 1052 */ \ - OP(SetParamDataImmediate) /* 1053 */ \ - OP(GetParamDesc) /* 1054 */ \ - OP(GetStreamCount) /* 1055 */ \ - OP(GetStreamDesc) /* 1056 */ \ - OP(DestroyTexture) /* 1057 */ \ - OP(CreateTexture2d) /* 1058 */ \ - OP(CreateTexture3d) /* 1059 */ \ - OP(CreateTextureCube) /* 1060 */ \ - OP(SetTextureData) /* 1061 */ \ - OP(SetTextureDataImmediate) /* 1062 */ \ - OP(GetTextureData) /* 1063 */ \ - OP(CreateSampler) /* 1064 */ \ - OP(DestroySampler) /* 1065 */ \ - OP(SetSamplerStates) /* 1066 */ \ - OP(SetSamplerBorderColor) /* 1067 */ \ - OP(SetSamplerTexture) /* 1068 */ \ - OP(SetViewport) /* 1069 */ \ - OP(SetScissor) /* 1070 */ \ - OP(SetPointLineRaster) /* 1071 */ \ - OP(SetPolygonRaster) /* 1072 */ \ - OP(SetPolygonOffset) /* 1073 */ \ - OP(SetAlphaTest) /* 1074 */ \ - OP(SetDepthTest) /* 1075 */ \ - OP(SetStencilTest) /* 1076 */ \ - OP(SetBlending) /* 1077 */ \ - OP(SetBlendingColor) /* 1078 */ \ - OP(SetColorWrite) /* 1079 */ \ - OP(CreateRenderSurface) /* 1080 */ \ - OP(DestroyRenderSurface) /* 1081 */ \ - OP(CreateDepthSurface) /* 1082 */ \ - OP(DestroyDepthSurface) /* 1083 */ \ - OP(SetRenderSurface) /* 1084 */ \ - OP(SetBackSurfaces) /* 1085 */ \ - - -// GAPI commands. -enum CommandId { - kStartPoint = cmd::kLastCommonId, // All O3D commands start after this. - #define GPU_COMMAND_BUFFER_CMD_OP(name) k ## name, - - O3D_COMMAND_BUFFER_CMDS(GPU_COMMAND_BUFFER_CMD_OP) - - #undef GPU_COMMAND_BUFFER_CMD_OP - - kNumCommands, -}; - -// Bit definitions for buffers to clear. -enum ClearBuffer { - kColor = 0x1, - kDepth = 0x2, - kStencil = 0x4, - kAllBuffers = kColor | kDepth | kStencil -}; - -// Polygon mode for SetPolygonRaster -enum PolygonMode { - kPolygonModePoints, - kPolygonModeLines, - kPolygonModeFill, - kNumPolygonMode -}; - -// Face culling mode for SetPolygonRaster -enum FaceCullMode { - kCullNone, - kCullCW, - kCullCCW, - kNumFaceCullMode -}; - -// Primitive type for Draw and DrawIndexed. -enum PrimitiveType { - kPoints, - kLines, - kLineStrips, - kTriangles, - kTriangleStrips, - kTriangleFans, - kMaxPrimitiveType -}; - -// Comparison function for alpha or depth test -enum Comparison { - kNever, - kLess, - kEqual, - kLEqual, - kGreater, - kNotEqual, - kGEqual, - kAlways, - kNumComparison -}; - -// Stencil operation -enum StencilOp { - kKeep, - kZero, - kReplace, - kIncNoWrap, - kDecNoWrap, - kInvert, - kIncWrap, - kDecWrap, - kNumStencilOp -}; - -// Blend Equation -enum BlendEq { - kBlendEqAdd, - kBlendEqSub, - kBlendEqRevSub, - kBlendEqMin, - kBlendEqMax, - kNumBlendEq -}; - -// Blend Funtion -enum BlendFunc { - kBlendFuncZero, - kBlendFuncOne, - kBlendFuncSrcColor, - kBlendFuncInvSrcColor, - kBlendFuncSrcAlpha, - kBlendFuncInvSrcAlpha, - kBlendFuncDstAlpha, - kBlendFuncInvDstAlpha, - kBlendFuncDstColor, - kBlendFuncInvDstColor, - kBlendFuncSrcAlphaSaturate, - kBlendFuncBlendColor, - kBlendFuncInvBlendColor, - kNumBlendFunc -}; - -const char* GetCommandName(CommandId id); - -// Make sure the compiler does not add extra padding to any of the command -// structures. -#pragma pack(push, 1) - -struct BeginFrame { - typedef BeginFrame ValueType; - static const CommandId kCmdId = kBeginFrame; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init() { - SetHeader(); - } - static void* Set(void* cmd) { - static_cast<ValueType*>(cmd)->Init(); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; -}; - -COMPILE_ASSERT(sizeof(BeginFrame) == 4, Sizeof_BeginFrame_is_not_4); -COMPILE_ASSERT(offsetof(BeginFrame, header) == 0, - OffsetOf_BeginFrame_header_not_0); - -struct EndFrame { - typedef EndFrame ValueType; - static const CommandId kCmdId = kEndFrame; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init() { - SetHeader(); - } - static void* Set(void* cmd) { - static_cast<ValueType*>(cmd)->Init(); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; -}; - -COMPILE_ASSERT(sizeof(EndFrame) == 4, Sizeof_EndFrame_is_not_4); -COMPILE_ASSERT(offsetof(EndFrame, header) == 0, - OffsetOf_EndFrame_header_not_0); - -struct Clear { - typedef Clear ValueType; - static const CommandId kCmdId = kClear; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(uint32 _buffers, float _red, float _green, float _blue, - float _alpha, float _depth, uint32 _stencil) { - SetHeader(); - buffers = _buffers; - red = _red; - green = _green; - blue = _blue; - alpha = _alpha; - depth = _depth; - stencil = _stencil; - } - - static void* Set(void* cmd, uint32 buffers, - float red, float green, float blue, float alpha, - float depth, - uint32 stencil) { - static_cast<ValueType*>(cmd)->Init( - buffers, red, green, blue, alpha, depth, stencil); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - uint32 buffers; - float red; - float green; - float blue; - float alpha; - float depth; - uint32 stencil; -}; - -COMPILE_ASSERT(sizeof(Clear) == 32, Sizeof_Clear_is_not_32); -COMPILE_ASSERT(offsetof(Clear, header) == 0, - OffsetOf_Clear_header_not_0); -COMPILE_ASSERT(offsetof(Clear, buffers) == 4, - OffsetOf_Clear_buffers_not_4); -COMPILE_ASSERT(offsetof(Clear, red) == 8, - OffsetOf_Clear_red_not_8); -COMPILE_ASSERT(offsetof(Clear, green) == 12, - OffsetOf_Clear_green_not_12); -COMPILE_ASSERT(offsetof(Clear, blue) == 16, - OffsetOf_Clear_blue_not_16); -COMPILE_ASSERT(offsetof(Clear, alpha) == 20, - OffsetOf_Clear_alpha_not_20); -COMPILE_ASSERT(offsetof(Clear, depth) == 24, - OffsetOf_Clear_depth_not_24); -COMPILE_ASSERT(offsetof(Clear, stencil) == 28, - OffsetOf_Clear_stencil_not_28); - -struct SetViewport { - typedef SetViewport ValueType; - static const CommandId kCmdId = kSetViewport; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - uint32 _left, - uint32 _top, - uint32 _width, - uint32 _height, - float _z_min, - float _z_max) { - SetHeader(); - left = _left; - top = _top; - width = _width; - height = _height; - z_min = _z_min; - z_max = _z_max; - } - - static void* Set(void* cmd, - uint32 left, - uint32 top, - uint32 width, - uint32 height, - float z_min, - float z_max) { - static_cast<ValueType*>(cmd)->Init( - left, - top, - width, - height, - z_min, - z_max); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - uint32 left; - uint32 top; - uint32 width; - uint32 height; - float z_min; - float z_max; -}; - -COMPILE_ASSERT(sizeof(SetViewport) == 28, Sizeof_SetViewport_is_not_28); -COMPILE_ASSERT(offsetof(SetViewport, header) == 0, - OffsetOf_SetViewport_header_not_0); -COMPILE_ASSERT(offsetof(SetViewport, left) == 4, - OffsetOf_SetViewport_left_not_4); -COMPILE_ASSERT(offsetof(SetViewport, top) == 8, - OffsetOf_SetViewport_top_not_8); -COMPILE_ASSERT(offsetof(SetViewport, width) == 12, - OffsetOf_SetViewport_width_not_12); -COMPILE_ASSERT(offsetof(SetViewport, height) == 16, - OffsetOf_SetViewport_height_not_16); -COMPILE_ASSERT(offsetof(SetViewport, z_min) == 20, - OffsetOf_SetViewport_z_min_not_20); -COMPILE_ASSERT(offsetof(SetViewport, z_max) == 24, - OffsetOf_SetViewport_z_max_not_24); - -struct CreateVertexBuffer { - typedef CreateVertexBuffer ValueType; - static const CommandId kCmdId = kCreateVertexBuffer; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_buffer_id, uint32 _size, - vertex_buffer::Flags _flags) { - SetHeader(); - vertex_buffer_id = _vertex_buffer_id; - size = _size; - flags = static_cast<uint32>(_flags); - } - - static void* Set(void* cmd, ResourceId vertex_buffer_id, - uint32 size, vertex_buffer::Flags flags) { - static_cast<ValueType*>(cmd)->Init(vertex_buffer_id, size, flags); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_buffer_id; - uint32 size; - uint32 flags; -}; - -COMPILE_ASSERT(sizeof(CreateVertexBuffer) == 16, - Sizeof_CreateVertexBuffer_is_not_16); -COMPILE_ASSERT(offsetof(CreateVertexBuffer, header) == 0, - OffsetOf_CreateVertexBuffer_header_not_0); -COMPILE_ASSERT(offsetof(CreateVertexBuffer, vertex_buffer_id) == 4, - OffsetOf_CreateVertexBuffer_vertex_buffer_id_not_4); -COMPILE_ASSERT(offsetof(CreateVertexBuffer, size) == 8, - OffsetOf_CreateVertexBuffer_size_not_8); -COMPILE_ASSERT(offsetof(CreateVertexBuffer, flags) == 12, - OffsetOf_CreateVertexBuffer_flags_not_12); - -struct DestroyVertexBuffer { - typedef DestroyVertexBuffer ValueType; - static const CommandId kCmdId = kDestroyVertexBuffer; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_buffer_id) { - SetHeader(); - vertex_buffer_id = _vertex_buffer_id; - } - - static void* Set(void* cmd, ResourceId vertex_buffer_id) { - static_cast<ValueType*>(cmd)->Init(vertex_buffer_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_buffer_id; -}; - -COMPILE_ASSERT(sizeof(DestroyVertexBuffer) == 8, - Sizeof_DestroyVertexBuffer_is_not_8); -COMPILE_ASSERT(offsetof(DestroyVertexBuffer, header) == 0, - OffsetOf_DestroyVertexBuffer_header_not_0); -COMPILE_ASSERT(offsetof(DestroyVertexBuffer, vertex_buffer_id) == 4, - OffsetOf_DestroyVertexBuffer_vertex_buffer_id_not_4); - -struct SetVertexBufferDataImmediate { - typedef SetVertexBufferDataImmediate ValueType; - static const CommandId kCmdId = kSetVertexBufferDataImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init(ResourceId _vertex_buffer_id, uint32 _offset, - const void* data, uint32 size) { - SetHeader(size); - vertex_buffer_id = _vertex_buffer_id; - offset = _offset; - memcpy(ImmediateDataAddress(this), data, size); - } - - static void* Set(void* cmd, ResourceId vertex_buffer_id, uint32 offset, - const void* data, uint32 size) { - static_cast<ValueType*>(cmd)->Init(vertex_buffer_id, offset, data, size); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - CommandHeader header; - ResourceId vertex_buffer_id; - uint32 offset; -}; - -COMPILE_ASSERT(sizeof(SetVertexBufferDataImmediate) == 12, - Sizeof_SetVertexBufferDataImmediate_is_not_12); -COMPILE_ASSERT(offsetof(SetVertexBufferDataImmediate, header) == 0, - OffsetOf_SetVertexBufferDataImmediate_header_not_0); -COMPILE_ASSERT(offsetof(SetVertexBufferDataImmediate, vertex_buffer_id) == 4, - OffsetOf_SetVertexBufferDataImmediate_vertex_buffer_id_not_4); -COMPILE_ASSERT(offsetof(SetVertexBufferDataImmediate, offset) == 8, - OffsetOf_SetVertexBufferDataImmediate_offset_not_8); - -struct SetVertexBufferData { - typedef SetVertexBufferData ValueType; - static const CommandId kCmdId = kSetVertexBufferData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_buffer_id, uint32 _offset, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - vertex_buffer_id = _vertex_buffer_id; - offset = _offset; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId vertex_buffer_id, - uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(vertex_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_buffer_id; - uint32 offset; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(SetVertexBufferData) == 24, - Sizeof_SetVertexBufferData_is_not_24); -COMPILE_ASSERT(offsetof(SetVertexBufferData, header) == 0, - OffsetOf_SetVertexBufferData_header_not_0); -COMPILE_ASSERT(offsetof(SetVertexBufferData, vertex_buffer_id) == 4, - OffsetOf_SetVertexBufferData_vertex_buffer_id_not_4); -COMPILE_ASSERT(offsetof(SetVertexBufferData, offset) == 8, - OffsetOf_SetVertexBufferData_offset_not_8); -COMPILE_ASSERT(offsetof(SetVertexBufferData, size) == 12, - OffsetOf_SetVertexBufferData_size_not_12); -COMPILE_ASSERT(offsetof(SetVertexBufferData, shared_memory) == 16, - OffsetOf_SetVertexBufferData_shared_memory_not_16); - -struct GetVertexBufferData { - typedef GetVertexBufferData ValueType; - static const CommandId kCmdId = kGetVertexBufferData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_buffer_id, uint32 _offset, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - vertex_buffer_id = _vertex_buffer_id; - offset = _offset; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId vertex_buffer_id, - uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(vertex_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_buffer_id; - uint32 offset; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetVertexBufferData) == 24, - Sizeof_GetVertexBufferData_is_not_24); -COMPILE_ASSERT(offsetof(GetVertexBufferData, header) == 0, - OffsetOf_GetVertexBufferData_header_not_0); -COMPILE_ASSERT(offsetof(GetVertexBufferData, vertex_buffer_id) == 4, - OffsetOf_GetVertexBufferData_vertex_buffer_id_not_4); -COMPILE_ASSERT(offsetof(GetVertexBufferData, offset) == 8, - OffsetOf_GetVertexBufferData_offset_not_8); -COMPILE_ASSERT(offsetof(GetVertexBufferData, size) == 12, - OffsetOf_GetVertexBufferData_size_not_12); -COMPILE_ASSERT(offsetof(GetVertexBufferData, shared_memory) == 16, - OffsetOf_GetVertexBufferData_shared_memory_not_16); - -struct CreateIndexBuffer { - typedef CreateIndexBuffer ValueType; - static const CommandId kCmdId = kCreateIndexBuffer; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _index_buffer_id, uint32 _size, - index_buffer::Flags _flags) { - SetHeader(); - index_buffer_id = _index_buffer_id; - size = _size; - flags = static_cast<uint32>(_flags); - } - - static void* Set(void* cmd, ResourceId index_buffer_id, - uint32 size, index_buffer::Flags flags) { - static_cast<ValueType*>(cmd)->Init(index_buffer_id, size, flags); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId index_buffer_id; - uint32 size; - uint32 flags; -}; - -COMPILE_ASSERT(sizeof(CreateIndexBuffer) == 16, - Sizeof_CreateIndexBuffer_is_not_16); -COMPILE_ASSERT(offsetof(CreateIndexBuffer, header) == 0, - OffsetOf_CreateIndexBuffer_header_not_0); -COMPILE_ASSERT(offsetof(CreateIndexBuffer, index_buffer_id) == 4, - OffsetOf_CreateIndexBuffer_index_buffer_id_not_4); -COMPILE_ASSERT(offsetof(CreateIndexBuffer, size) == 8, - OffsetOf_CreateIndexBuffer_size_not_8); -COMPILE_ASSERT(offsetof(CreateIndexBuffer, flags) == 12, - OffsetOf_CreateIndexBuffer_flags_not_12); - -struct DestroyIndexBuffer { - typedef DestroyIndexBuffer ValueType; - static const CommandId kCmdId = kDestroyIndexBuffer; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _index_buffer_id) { - SetHeader(); - index_buffer_id = _index_buffer_id; - } - - static void* Set(void* cmd, ResourceId index_buffer_id) { - static_cast<ValueType*>(cmd)->Init(index_buffer_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId index_buffer_id; -}; - -COMPILE_ASSERT(sizeof(DestroyIndexBuffer) == 8, - Sizeof_DestroyIndexBuffer_is_not_8); -COMPILE_ASSERT(offsetof(DestroyIndexBuffer, header) == 0, - OffsetOf_DestroyIndexBuffer_header_not_0); -COMPILE_ASSERT(offsetof(DestroyIndexBuffer, index_buffer_id) == 4, - OffsetOf_DestroyIndexBuffer_index_buffer_id_not_4); - -struct SetIndexBufferDataImmediate { - typedef SetIndexBufferDataImmediate ValueType; - static const CommandId kCmdId = kSetIndexBufferDataImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init(ResourceId _index_buffer_id, uint32 _offset, - const void* data, uint32 size) { - SetHeader(size); - index_buffer_id = _index_buffer_id; - offset = _offset; - memcpy(ImmediateDataAddress(this), data, size); - } - - static void* Set(void* cmd, ResourceId index_buffer_id, uint32 offset, - const void* data, uint32 size) { - static_cast<ValueType*>(cmd)->Init(index_buffer_id, offset, data, size); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - CommandHeader header; - ResourceId index_buffer_id; - uint32 offset; -}; - -COMPILE_ASSERT(sizeof(SetIndexBufferDataImmediate) == 12, - Sizeof_SetIndexBufferDataImmediate_is_not_12); -COMPILE_ASSERT(offsetof(SetIndexBufferDataImmediate, header) == 0, - OffsetOf_SetIndexBufferDataImmediate_header_not_0); -COMPILE_ASSERT(offsetof(SetIndexBufferDataImmediate, index_buffer_id) == 4, - OffsetOf_SetIndexBufferDataImmediate_index_buffer_id_not_4); -COMPILE_ASSERT(offsetof(SetIndexBufferDataImmediate, offset) == 8, - OffsetOf_SetIndexBufferDataImmediate_offset_not_8); - -struct SetIndexBufferData { - typedef SetIndexBufferData ValueType; - static const CommandId kCmdId = kSetIndexBufferData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _index_buffer_id, uint32 _offset, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - index_buffer_id = _index_buffer_id; - offset = _offset; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, - ResourceId index_buffer_id, uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(index_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId index_buffer_id; - uint32 offset; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(SetIndexBufferData) == 24, - Sizeof_SetIndexBufferData_is_not_24); -COMPILE_ASSERT(offsetof(SetIndexBufferData, header) == 0, - OffsetOf_SetIndexBufferData_header_not_0); -COMPILE_ASSERT(offsetof(SetIndexBufferData, index_buffer_id) == 4, - OffsetOf_SetIndexBufferData_index_buffer_id_not_4); -COMPILE_ASSERT(offsetof(SetIndexBufferData, offset) == 8, - OffsetOf_SetIndexBufferData_offset_not_8); -COMPILE_ASSERT(offsetof(SetIndexBufferData, size) == 12, - OffsetOf_SetIndexBufferData_size_not_12); -COMPILE_ASSERT(offsetof(SetIndexBufferData, shared_memory) == 16, - OffsetOf_SetIndexBufferData_shared_memory_not_16); - -struct GetIndexBufferData { - typedef GetIndexBufferData ValueType; - static const CommandId kCmdId = kGetIndexBufferData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _index_buffer_id, uint32 _offset, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - index_buffer_id = _index_buffer_id; - offset = _offset; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId index_buffer_id, - uint32 offset, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(index_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId index_buffer_id; - uint32 offset; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetIndexBufferData) == 24, - Sizeof_GetIndexBufferData_is_not_24); -COMPILE_ASSERT(offsetof(GetIndexBufferData, header) == 0, - OffsetOf_GetIndexBufferData_header_not_0); -COMPILE_ASSERT(offsetof(GetIndexBufferData, index_buffer_id) == 4, - OffsetOf_GetIndexBufferData_index_buffer_id_not_4); -COMPILE_ASSERT(offsetof(GetIndexBufferData, offset) == 8, - OffsetOf_GetIndexBufferData_offset_not_8); -COMPILE_ASSERT(offsetof(GetIndexBufferData, size) == 12, - OffsetOf_GetIndexBufferData_size_not_12); -COMPILE_ASSERT(offsetof(GetIndexBufferData, shared_memory) == 16, - OffsetOf_GetIndexBufferData_shared_memory_not_16); - -struct CreateVertexStruct { - typedef CreateVertexStruct ValueType; - static const CommandId kCmdId = kCreateVertexStruct; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_struct_id, uint32 _input_count) { - SetHeader(); - vertex_struct_id = _vertex_struct_id; - input_count = _input_count; - } - - static void* Set(void* cmd, ResourceId vertex_struct_id, uint32 input_count) { - static_cast<ValueType*>(cmd)->Init(vertex_struct_id, input_count); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_struct_id; - uint32 input_count; -}; - -COMPILE_ASSERT(sizeof(CreateVertexStruct) == 12, - Sizeof_CreateVertexStruct_is_not_12); -COMPILE_ASSERT(offsetof(CreateVertexStruct, header) == 0, - OffsetOf_CreateVertexStruct_header_not_0); -COMPILE_ASSERT(offsetof(CreateVertexStruct, vertex_struct_id) == 4, - OffsetOf_CreateVertexStruct_vertex_struct_id_not_4); -COMPILE_ASSERT(offsetof(CreateVertexStruct, input_count) == 8, - OffsetOf_CreateVertexStruct_input_count_not_8); - -struct DestroyVertexStruct { - typedef DestroyVertexStruct ValueType; - static const CommandId kCmdId = kDestroyVertexStruct; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_struct_id) { - SetHeader(); - vertex_struct_id = _vertex_struct_id; - } - - static void* Set(void* cmd, ResourceId vertex_struct_id) { - static_cast<ValueType*>(cmd)->Init(vertex_struct_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_struct_id; -}; - -COMPILE_ASSERT(sizeof(DestroyVertexStruct) == 8, - Sizeof_DestroyVertexStruct_is_not_8); -COMPILE_ASSERT(offsetof(DestroyVertexStruct, header) == 0, - OffsetOf_DestroyVertexStruct_header_not_0); -COMPILE_ASSERT(offsetof(DestroyVertexStruct, vertex_struct_id) == 4, - OffsetOf_DestroyVertexStruct_vertex_struct_id_not_4); - -struct SetVertexInput { - typedef SetVertexInput ValueType; - static const CommandId kCmdId = kSetVertexInput; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // type_stride_semantic field. - typedef BitField<0, 4> SemanticIndex; - typedef BitField<4, 4> Semantic; - typedef BitField<8, 8> Type; - typedef BitField<16, 16> Stride; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_struct_id, - uint32 _input_index, - ResourceId _vertex_buffer_id, - uint32 _offset, - vertex_struct::Semantic _semantic, - uint32 _semantic_index, - vertex_struct::Type _type, - uint32 _stride) { - SetHeader(); - vertex_struct_id = _vertex_struct_id; - input_index = _input_index; - vertex_buffer_id = _vertex_buffer_id; - offset = _offset; - type_stride_semantic = - Semantic::MakeValue(_semantic) | - SemanticIndex::MakeValue(_semantic_index) | - Type::MakeValue(_type) | - Stride::MakeValue(_stride); - } - - static void* Set( - void* cmd, - ResourceId vertex_struct_id, - uint32 input_index, - ResourceId vertex_buffer_id, - uint32 offset, - vertex_struct::Semantic semantic, - uint32 semantic_index, - vertex_struct::Type type, - uint32 stride) { - static_cast<ValueType*>(cmd)->Init( - vertex_struct_id, - input_index, - vertex_buffer_id, - offset, - semantic, - semantic_index, - type, - stride); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_struct_id; - uint32 input_index; - ResourceId vertex_buffer_id; - uint32 offset; - uint32 type_stride_semantic; -}; - -COMPILE_ASSERT(sizeof(SetVertexInput) == 24, - Sizeof_SetVertexInput_is_not_24); -COMPILE_ASSERT(offsetof(SetVertexInput, header) == 0, - OffsetOf_SetVertexInput_header_not_0); -COMPILE_ASSERT(offsetof(SetVertexInput, vertex_struct_id) == 4, - OffsetOf_SetVertexInput_vertex_struct_id_not_4); -COMPILE_ASSERT(offsetof(SetVertexInput, input_index) == 8, - OffsetOf_SetVertexInput_input_index_not_8); -COMPILE_ASSERT(offsetof(SetVertexInput, vertex_buffer_id) == 12, - OffsetOf_SetVertexInput_vertex_buffer_id_not_12); -COMPILE_ASSERT(offsetof(SetVertexInput, offset) == 16, - OffsetOf_SetVertexInput_offset_not_16); -COMPILE_ASSERT(offsetof(SetVertexInput, type_stride_semantic) == 20, - OffsetOf_SetVertexInput_type_stride_semantic_not_20); - -struct SetVertexStruct { - typedef SetVertexStruct ValueType; - static const CommandId kCmdId = kSetVertexStruct; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _vertex_struct_id) { - SetHeader(); - vertex_struct_id = _vertex_struct_id; - } - - static void* Set(void* cmd, ResourceId vertex_struct_id) { - static_cast<ValueType*>(cmd)->Init(vertex_struct_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId vertex_struct_id; -}; - -COMPILE_ASSERT(sizeof(SetVertexStruct) == 8, - Sizeof_SetVertexStruct_is_not_8); -COMPILE_ASSERT(offsetof(SetVertexStruct, header) == 0, - OffsetOf_SetVertexStruct_header_not_0); -COMPILE_ASSERT(offsetof(SetVertexStruct, vertex_struct_id) == 4, - OffsetOf_SetVertexStruct_vertex_struct_id_not_4); - -struct Draw { - typedef Draw ValueType; - static const CommandId kCmdId = kDraw; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(PrimitiveType _primitive_type, uint32 _first, uint32 _count) { - SetHeader(); - primitive_type = _primitive_type; - first = _first; - count = _count; - } - - static void* Set(void* cmd, PrimitiveType primitive_type, uint32 first, - uint32 count) { - static_cast<ValueType*>(cmd)->Init(primitive_type, first, count); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - uint32 primitive_type; - uint32 first; - uint32 count; -}; - -COMPILE_ASSERT(sizeof(Draw) == 16, Sizeof_DRAW_is_not_16); -COMPILE_ASSERT(offsetof(Draw, header) == 0, - OffsetOf_Draw_header_not_0); -COMPILE_ASSERT(offsetof(Draw, primitive_type) == 4, - OffsetOf_Draw_primitive_type_not_4); -COMPILE_ASSERT(offsetof(Draw, first) == 8, - OffsetOf_Draw_first_not_8); -COMPILE_ASSERT(offsetof(Draw, count) == 12, - OffsetOf_Draw_count_not_12); - -struct DrawIndexed { - typedef DrawIndexed ValueType; - static const CommandId kCmdId = kDrawIndexed; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - PrimitiveType _primitive_type, - ResourceId _index_buffer_id, - uint32 _first, - uint32 _count, - uint32 _min_index, - uint32 _max_index) { - SetHeader(); - primitive_type = _primitive_type; - index_buffer_id = _index_buffer_id; - first = _first; - count = _count; - min_index = _min_index; - max_index = _max_index; - } - - static void* Set(void* cmd, - PrimitiveType primitive_type, - ResourceId index_buffer_id, - uint32 first, - uint32 count, - uint32 min_index, - uint32 max_index) { - static_cast<ValueType*>(cmd)->Init( - primitive_type, - index_buffer_id, - first, - count, - min_index, - max_index); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - uint32 primitive_type; - ResourceId index_buffer_id; - uint32 first; - uint32 count; - uint32 min_index; - uint32 max_index; -}; - -COMPILE_ASSERT(sizeof(DrawIndexed) == 28, Sizeof_DrawIndexed_is_not_28); -COMPILE_ASSERT(offsetof(DrawIndexed, header) == 0, - OffsetOf_DrawIndexed_header_not_0); -COMPILE_ASSERT(offsetof(DrawIndexed, primitive_type) == 4, - OffsetOf_DrawIndexed_primitive_type_not_4); -COMPILE_ASSERT(offsetof(DrawIndexed, index_buffer_id) == 8, - OffsetOf_DrawIndexed_index_buffer_id_not_8); -COMPILE_ASSERT(offsetof(DrawIndexed, first) == 12, - OffsetOf_DrawIndexed_first_not_12); -COMPILE_ASSERT(offsetof(DrawIndexed, count) == 16, - OffsetOf_DrawIndexed_count_not_16); -COMPILE_ASSERT(offsetof(DrawIndexed, min_index) == 20, - OffsetOf_DrawIndexed_min_index_not_20); -COMPILE_ASSERT(offsetof(DrawIndexed, max_index) == 24, - OffsetOf_DrawIndexed_max_index_not_24); - -struct CreateEffect { - typedef CreateEffect ValueType; - static const CommandId kCmdId = kCreateEffect; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - effect_id = _effect_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(effect_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(CreateEffect) == 20, Sizeof_CreateEffect_is_not_20); -COMPILE_ASSERT(offsetof(CreateEffect, header) == 0, - OffsetOf_CreateEffect_header_not_0); -COMPILE_ASSERT(offsetof(CreateEffect, effect_id) == 4, - OffsetOf_CreateEffect_effect_id_not_4); -COMPILE_ASSERT(offsetof(CreateEffect, size) == 8, - OffsetOf_CreateEffect_size_not_8); -COMPILE_ASSERT(offsetof(CreateEffect, shared_memory) == 12, - OffsetOf_CreateEffect_shared_memory_not_12); - -struct CreateEffectImmediate { - typedef CreateEffectImmediate ValueType; - static const CommandId kCmdId = kCreateEffectImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init(ResourceId _effect_id, uint32 _size, const void* data) { - SetHeader(_size); - effect_id = _effect_id; - size = _size; - } - - static void* Set(void* cmd, - ResourceId effect_id, uint32 size, const void* data) { - static_cast<ValueType*>(cmd)->Init(effect_id, size, data); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - CommandHeader header; - ResourceId effect_id; - uint32 size; -}; - -COMPILE_ASSERT(sizeof(CreateEffectImmediate) == 12, - Sizeof_CreateEffectImmediate_is_not_12); -COMPILE_ASSERT(offsetof(CreateEffectImmediate, header) == 0, - OffsetOf_CreateEffectImmediate_header_not_0); -COMPILE_ASSERT(offsetof(CreateEffectImmediate, effect_id) == 4, - OffsetOf_CreateEffectImmediate_effect_id_not_4); -COMPILE_ASSERT(offsetof(CreateEffectImmediate, size) == 8, - OffsetOf_CreateEffectImmediate_size_not_8); - -struct DestroyEffect { - typedef DestroyEffect ValueType; - static const CommandId kCmdId = kDestroyEffect; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id) { - SetHeader(); - effect_id = _effect_id; - } - - static void* Set(void* cmd, ResourceId effect_id) { - static_cast<ValueType*>(cmd)->Init(effect_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; -}; - -COMPILE_ASSERT(sizeof(DestroyEffect) == 8, Sizeof_DestroyEffect_is_not_8); -COMPILE_ASSERT(offsetof(DestroyEffect, header) == 0, - OffsetOf_DestroyEffect_header_not_0); -COMPILE_ASSERT(offsetof(DestroyEffect, effect_id) == 4, - OffsetOf_DestroyEffect_effect_id_not_4); - -struct SetEffect { - typedef SetEffect ValueType; - static const CommandId kCmdId = kSetEffect; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id) { - SetHeader(); - effect_id = _effect_id; - } - - static void* Set(void* cmd, ResourceId effect_id) { - static_cast<ValueType*>(cmd)->Init(effect_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; -}; - -COMPILE_ASSERT(sizeof(SetEffect) == 8, Sizeof_SetEffect_is_not_8); -COMPILE_ASSERT(offsetof(SetEffect, header) == 0, - OffsetOf_SetEffect_header_not_0); -COMPILE_ASSERT(offsetof(SetEffect, effect_id) == 4, - OffsetOf_SetEffect_effect_id_not_4); - -struct GetParamCount { - typedef GetParamCount ValueType; - static const CommandId kCmdId = kGetParamCount; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - effect_id = _effect_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(effect_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetParamCount) == 20, Sizeof_GetParamCount_is_not_20); -COMPILE_ASSERT(offsetof(GetParamCount, header) == 0, - OffsetOf_GetParamCount_header_not_0); -COMPILE_ASSERT(offsetof(GetParamCount, effect_id) == 4, - OffsetOf_GetParamCount_effect_id_not_4); -COMPILE_ASSERT(offsetof(GetParamCount, size) == 8, - OffsetOf_GetParamCount_size_not_8); -COMPILE_ASSERT(offsetof(GetParamCount, shared_memory) == 12, - OffsetOf_GetParamCount_shared_memory_not_12); - -struct CreateParam { - typedef CreateParam ValueType; - static const CommandId kCmdId = kCreateParam; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _param_id, ResourceId _effect_id, uint32 _index) { - SetHeader(); - param_id = _param_id; - effect_id = _effect_id; - index = _index; - } - - static void* Set(void* cmd, - ResourceId param_id, ResourceId effect_id, uint32 index) { - static_cast<ValueType*>(cmd)->Init(param_id, effect_id, index); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId param_id; - ResourceId effect_id; - uint32 index; -}; - -COMPILE_ASSERT(sizeof(CreateParam) == 16, Sizeof_CreateParam_is_not_16); -COMPILE_ASSERT(offsetof(CreateParam, header) == 0, - OffsetOf_CreateParam_header_not_0); -COMPILE_ASSERT(offsetof(CreateParam, param_id) == 4, - OffsetOf_CreateParam_param_id_not_4); -COMPILE_ASSERT(offsetof(CreateParam, effect_id) == 8, - OffsetOf_CreateParam_effect_id_not_8); -COMPILE_ASSERT(offsetof(CreateParam, index) == 12, - OffsetOf_CreateParam_index_not_12); - -struct CreateParamByName { - typedef CreateParamByName ValueType; - static const CommandId kCmdId = kCreateParamByName; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _param_id, ResourceId _effect_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - param_id = _param_id; - effect_id = _effect_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId param_id, ResourceId effect_id, - uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(param_id, effect_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId param_id; - ResourceId effect_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(CreateParamByName) == 24, - Sizeof_CreateParamByName_is_not_24); -COMPILE_ASSERT(offsetof(CreateParamByName, header) == 0, - OffsetOf_CreateParamByName_header_not_0); -COMPILE_ASSERT(offsetof(CreateParamByName, param_id) == 4, - OffsetOf_CreateParamByName_param_id_not_4); -COMPILE_ASSERT(offsetof(CreateParamByName, effect_id) == 8, - OffsetOf_CreateParamByName_effect_id_not_8); -COMPILE_ASSERT(offsetof(CreateParamByName, size) == 12, - OffsetOf_CreateParamByName_size_not_12); -COMPILE_ASSERT(offsetof(CreateParamByName, shared_memory) == 16, - OffsetOf_CreateParamByName_shared_memory_not_16); - -struct CreateParamByNameImmediate { - typedef CreateParamByNameImmediate ValueType; - static const CommandId kCmdId = kCreateParamByNameImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init(ResourceId _param_id, ResourceId _effect_id, uint32 _size, - const void* data) { - SetHeader(_size); - param_id = _param_id; - effect_id = _effect_id; - size = _size; - memcpy(ImmediateDataAddress(this), data, _size); - } - - static void* Set(void* cmd, ResourceId param_id, ResourceId effect_id, - uint32 size, const void* data) { - static_cast<ValueType*>(cmd)->Init(param_id, effect_id, size, data); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - CommandHeader header; - ResourceId param_id; - ResourceId effect_id; - uint32 size; -}; - -COMPILE_ASSERT(sizeof(CreateParamByNameImmediate) == 16, - Sizeof_CreateParamByNameImmediate_is_not_16); -COMPILE_ASSERT(offsetof(CreateParamByNameImmediate, header) == 0, - OffsetOf_CreateParamByNameImmediate_header_not_0); -COMPILE_ASSERT(offsetof(CreateParamByNameImmediate, param_id) == 4, - OffsetOf_CreateParamByNameImmediate_param_id_not_4); -COMPILE_ASSERT(offsetof(CreateParamByNameImmediate, effect_id) == 8, - OffsetOf_CreateParamByNameImmediate_effect_id_not_8); -COMPILE_ASSERT(offsetof(CreateParamByNameImmediate, size) == 12, - OffsetOf_CreateParamByNameImmediate_size_not_12); - -struct DestroyParam { - typedef DestroyParam ValueType; - static const CommandId kCmdId = kDestroyParam; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _param_id) { - SetHeader(); - param_id = _param_id; - } - - static void* Set(void* cmd, ResourceId param_id) { - static_cast<ValueType*>(cmd)->Init(param_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId param_id; -}; - -COMPILE_ASSERT(sizeof(DestroyParam) == 8, Sizeof_DestroyParam_is_not_8); -COMPILE_ASSERT(offsetof(DestroyParam, header) == 0, - OffsetOf_DestroyParam_header_not_0); -COMPILE_ASSERT(offsetof(DestroyParam, param_id) == 4, - OffsetOf_DestroyParam_param_id_not_4); - -struct SetParamData { - typedef SetParamData ValueType; - static const CommandId kCmdId = kSetParamData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _param_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - param_id = _param_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(param_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId param_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(SetParamData) == 20, Sizeof_SetParamData_is_not_20); -COMPILE_ASSERT(offsetof(SetParamData, header) == 0, - OffsetOf_SetParamData_header_not_0); -COMPILE_ASSERT(offsetof(SetParamData, param_id) == 4, - OffsetOf_SetParamData_param_id_not_4); -COMPILE_ASSERT(offsetof(SetParamData, size) == 8, - OffsetOf_SetParamData_size_not_8); -COMPILE_ASSERT(offsetof(SetParamData, shared_memory) == 12, - OffsetOf_SetParamData_shared_memory_not_12); - -struct SetParamDataImmediate { - typedef SetParamDataImmediate ValueType; - static const CommandId kCmdId = kSetParamDataImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init(ResourceId _param_id, uint32 _size, const void* data) { - SetHeader(_size); - param_id = _param_id; - size = _size; - memcpy(ImmediateDataAddress(this), data, _size); - } - - static void* Set(void* cmd, ResourceId param_id, - uint32 size, const void* data) { - static_cast<ValueType*>(cmd)->Init(param_id, size, data); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - CommandHeader header; - ResourceId param_id; - uint32 size; -}; - -COMPILE_ASSERT(sizeof(SetParamDataImmediate) == 12, - Sizeof_SetParamDataImmediate_is_not_12); -COMPILE_ASSERT(offsetof(SetParamDataImmediate, header) == 0, - OffsetOf_SetParamDataImmediate_header_not_0); -COMPILE_ASSERT(offsetof(SetParamDataImmediate, param_id) == 4, - OffsetOf_SetParamDataImmediate_param_id_not_4); -COMPILE_ASSERT(offsetof(SetParamDataImmediate, size) == 8, - OffsetOf_SetParamDataImmediate_size_not_8); - -struct GetParamDesc { - typedef GetParamDesc ValueType; - static const CommandId kCmdId = kGetParamDesc; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _param_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - param_id = _param_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(param_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId param_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetParamDesc) == 20, Sizeof_GetParamDesc_is_not_20); -COMPILE_ASSERT(offsetof(GetParamDesc, header) == 0, - OffsetOf_GetParamDesc_header_not_0); -COMPILE_ASSERT(offsetof(GetParamDesc, param_id) == 4, - OffsetOf_GetParamDesc_id_not_4); -COMPILE_ASSERT(offsetof(GetParamDesc, size) == 8, - OffsetOf_GetParamDesc_size_not_8); -COMPILE_ASSERT(offsetof(GetParamDesc, shared_memory) == 12, - OffsetOf_GetParamDesc_shared_memory_not_12); - -struct GetStreamCount { - typedef GetStreamCount ValueType; - static const CommandId kCmdId = kGetStreamCount; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - effect_id = _effect_id; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(effect_id, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetStreamCount) == 20, - Sizeof_GetStreamCount_is_not_20); -COMPILE_ASSERT(offsetof(GetStreamCount, header) == 0, - OffsetOf_GetStreamCount_header_not_0); -COMPILE_ASSERT(offsetof(GetStreamCount, effect_id) == 4, - OffsetOf_GetStreamCount_effect_id_not_4); -COMPILE_ASSERT(offsetof(GetStreamCount, size) == 8, - OffsetOf_GetStreamCount_size_not_8); -COMPILE_ASSERT(offsetof(GetStreamCount, shared_memory) == 12, - OffsetOf_GetStreamCount_shared_memory_not_12); - -struct GetStreamDesc { - typedef GetStreamDesc ValueType; - static const CommandId kCmdId = kGetStreamDesc; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _effect_id, uint32 _index, uint32 _size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - SetHeader(); - effect_id = _effect_id; - index = _index; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set(void* cmd, ResourceId effect_id, uint32 index, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init(effect_id, index, size, - shared_memory_id, shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId effect_id; - uint32 index; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetStreamDesc) == 24, Sizeof_GetStreamDesc_is_not_24); -COMPILE_ASSERT(offsetof(GetStreamDesc, header) == 0, - OffsetOf_GetStreamDesc_header_not_0); -COMPILE_ASSERT(offsetof(GetStreamDesc, effect_id) ==4 , - OffsetOf_GetStreamDesc_effect_id_not_4); -COMPILE_ASSERT(offsetof(GetStreamDesc, index) == 8, - OffsetOf_GetStreamDesc_index_not_8); -COMPILE_ASSERT(offsetof(GetStreamDesc, size) == 12, - OffsetOf_GetStreamDesc_size_not_12); -COMPILE_ASSERT(offsetof(GetStreamDesc, shared_memory) == 16, - OffsetOf_GetStreamDesc_shared_memory_not_16); - -struct DestroyTexture { - typedef DestroyTexture ValueType; - static const CommandId kCmdId = kDestroyTexture; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _texture_id) { - SetHeader(); - texture_id = _texture_id; - } - - static void* Set(void* cmd, ResourceId texture_id) { - static_cast<ValueType*>(cmd)->Init(texture_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId texture_id; -}; - -COMPILE_ASSERT(sizeof(DestroyTexture) == 8, Sizeof_DestroyTexture_is_not_8); -COMPILE_ASSERT(offsetof(DestroyTexture, header) == 0, - OffsetOf_DestroyTexture_header_not_0); -COMPILE_ASSERT(offsetof(DestroyTexture, texture_id) == 4, - OffsetOf_DestroyTexture_texture_id_not_4); - -struct CreateTexture2d { - typedef CreateTexture2d ValueType; - static const CommandId kCmdId = kCreateTexture2d; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 2 - typedef BitField<0, 4> Levels; - typedef BitField<4, 4> Unused; - typedef BitField<8, 8> Format; - typedef BitField<16, 16> Flags; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _texture_id, - uint32 _width, uint32 _height, uint32 _levels, - texture::Format _format, - bool _enable_render_surfaces) { - SetHeader(); - texture_id = _texture_id; - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - levels_format_flags = - Levels::MakeValue(_levels) | - Format::MakeValue(_format) | - Flags::MakeValue(_enable_render_surfaces ? 1 : 0); - } - - static void* Set(void* cmd, ResourceId texture_id, - uint32 width, uint32 height, uint32 levels, - texture::Format format, - bool enable_render_surfaces) { - static_cast<ValueType*>(cmd)->Init(texture_id, - width, height, levels, format, - enable_render_surfaces); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 width_height; - uint32 levels_format_flags; -}; - -COMPILE_ASSERT(sizeof(CreateTexture2d) == 16, - Sizeof_CreateTexture2d_is_not_16); -COMPILE_ASSERT(offsetof(CreateTexture2d, header) == 0, - OffsetOf_CreateTexture2d_header_not_0); -COMPILE_ASSERT(offsetof(CreateTexture2d, texture_id) == 4, - OffsetOf_CreateTexture2d_texture_id_not_4); -COMPILE_ASSERT(offsetof(CreateTexture2d, width_height) == 8, - OffsetOf_CreateTexture2d_width_height_not_8); -COMPILE_ASSERT(offsetof(CreateTexture2d, levels_format_flags) == 12, - OffsetOf_CreateTexture2d_levels_format_flags_not_12); - -struct CreateTexture3d { - typedef CreateTexture3d ValueType; - static const CommandId kCmdId = kCreateTexture3d; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 2 - typedef BitField<0, 16> Depth; - typedef BitField<16, 16> Unused1; - // argument 3 - typedef BitField<0, 4> Levels; - typedef BitField<4, 4> Unused2; - typedef BitField<8, 8> Format; - typedef BitField<16, 16> Flags; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _texture_id, - uint32 _width, uint32 _height, uint32 _depth, - uint32 _levels, texture::Format _format, - bool _enable_render_surfaces) { - SetHeader(); - texture_id = _texture_id; - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - depth_unused = Depth::MakeValue(_depth); - levels_format_flags = - Levels::MakeValue(_levels) | - Format::MakeValue(_format) | - Flags::MakeValue(_enable_render_surfaces ? 1 : 0); - } - - static void* Set(void* cmd, ResourceId texture_id, - uint32 width, uint32 height, uint32 depth, - uint32 levels, texture::Format format, - bool enable_render_surfaces) { - static_cast<ValueType*>(cmd)->Init(texture_id, - width, height, depth, - levels, format, - enable_render_surfaces); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 width_height; - uint32 depth_unused; - uint32 levels_format_flags; -}; - -COMPILE_ASSERT(sizeof(CreateTexture3d) == 20, - Sizeof_CreateTexture3d_is_not_20); -COMPILE_ASSERT(offsetof(CreateTexture3d, header) == 0, - OffsetOf_CreateTexture3d_header_not_0); -COMPILE_ASSERT(offsetof(CreateTexture3d, texture_id) == 4, - OffsetOf_CreateTexture3d_texture_id_not_4); -COMPILE_ASSERT(offsetof(CreateTexture3d, width_height) == 8, - OffsetOf_CreateTexture3d_width_height_not_8); -COMPILE_ASSERT(offsetof(CreateTexture3d, depth_unused) == 12, - OffsetOf_CreateTexture3d_depth_unused_not_12); -COMPILE_ASSERT(offsetof(CreateTexture3d, levels_format_flags) == 16, - OffsetOf_CreateTexture3d_levels_format_flags_not_16); - -struct CreateTextureCube { - typedef CreateTextureCube ValueType; - static const CommandId kCmdId = kCreateTextureCube; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> Side; - typedef BitField<16, 16> Unused1; - // argument 2 - typedef BitField<0, 4> Levels; - typedef BitField<4, 4> Unused2; - typedef BitField<8, 8> Format; - typedef BitField<16, 16> Flags; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _texture_id, - uint32 _edge_length, uint32 _levels, texture::Format _format, - bool _enable_render_surfaces) { - SetHeader(); - texture_id = _texture_id; - edge_length = _edge_length; - levels_format_flags = - Levels::MakeValue(_levels) | - Format::MakeValue(_format) | - Flags::MakeValue(_enable_render_surfaces ? 1 : 0); - } - - static void* Set(void* cmd, ResourceId texture_id, - uint32 edge_length, uint32 levels, texture::Format format, - bool enable_render_surfaces) { - static_cast<ValueType*>(cmd)->Init(texture_id, - edge_length, levels, format, - enable_render_surfaces); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 edge_length; - uint32 levels_format_flags; -}; - -COMPILE_ASSERT(sizeof(CreateTextureCube) == 16, - Sizeof_CreateTextureCube_is_not_16); -COMPILE_ASSERT(offsetof(CreateTextureCube, header) == 0, - OffsetOf_CreateTextureCube_header_not_0); -COMPILE_ASSERT(offsetof(CreateTextureCube, texture_id) == 4, - OffsetOf_CreateTextureCube_texture_id_not_4); -COMPILE_ASSERT(offsetof(CreateTextureCube, edge_length) == 8, - OffsetOf_CreateTextureCube_edge_length_not_8); -COMPILE_ASSERT(offsetof(CreateTextureCube, levels_format_flags) == 12, - OffsetOf_CreateTextureCube_levels_format_flags_not_12); - -struct SetTextureData { - typedef SetTextureData ValueType; - static const CommandId kCmdId = kSetTextureData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> X; - typedef BitField<16, 16> Y; - // argument 2 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 3 - typedef BitField<0, 16> Z; - typedef BitField<16, 16> Depth; - // argument 4 - typedef BitField<0, 4> Level; - typedef BitField<4, 3> Face; - typedef BitField<7, 25> Unused; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - ResourceId _texture_id, - uint32 _x, - uint32 _y, - uint32 _z, - uint32 _width, - uint32 _height, - uint32 _depth, - uint32 _level, - texture::Face _face, - uint32 _row_pitch, - uint32 _slice_pitch, - uint32 _size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - SetHeader(); - texture_id = _texture_id; - x_y = X::MakeValue(_x) | Y::MakeValue(_y); - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - z_depth = Z::MakeValue(_z) | Depth::MakeValue(_depth); - level_face = Level::MakeValue(_level) | Face::MakeValue(_face); - row_pitch = _row_pitch; - slice_pitch = _slice_pitch; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set( - void* cmd, - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - shared_memory_id, - shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 x_y; - uint32 width_height; - uint32 z_depth; - uint32 level_face; - uint32 row_pitch; - uint32 slice_pitch; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(SetTextureData) == 44, - Sizeof_SetTextureData_is_not_44); -COMPILE_ASSERT(offsetof(SetTextureData, header) == 0, - OffsetOf_SetTextureData_header_not_0); -COMPILE_ASSERT(offsetof(SetTextureData, texture_id) == 4, - OffsetOf_SetTextureData_texture_id_not_4); -COMPILE_ASSERT(offsetof(SetTextureData, x_y) == 8, - OffsetOf_SetTextureData_x_y_not_8); -COMPILE_ASSERT(offsetof(SetTextureData, width_height) == 12, - OffsetOf_SetTextureData_width_height_not_12); -COMPILE_ASSERT(offsetof(SetTextureData, z_depth) == 16, - OffsetOf_SetTextureData_z_depth_not_16); -COMPILE_ASSERT(offsetof(SetTextureData, level_face) == 20, - OffsetOf_SetTextureData_level_face_not_20); -COMPILE_ASSERT(offsetof(SetTextureData, row_pitch) == 24, - OffsetOf_SetTextureData_row_pitch_not_24); -COMPILE_ASSERT(offsetof(SetTextureData, slice_pitch) == 28, - OffsetOf_SetTextureData_slice_pitch_not_28); -COMPILE_ASSERT(offsetof(SetTextureData, size) == 32, - OffsetOf_SetTextureData_size_not_32); -COMPILE_ASSERT(offsetof(SetTextureData, shared_memory) == 36, - OffsetOf_SetTextureData_shared_memory_not_36); - -struct SetTextureDataImmediate { - typedef SetTextureDataImmediate ValueType; - static const CommandId kCmdId = kSetTextureDataImmediate; - static const cmd::ArgFlags kArgFlags = cmd::kAtLeastN; - - // argument 1 - typedef BitField<0, 16> X; - typedef BitField<16, 16> Y; - // argument 2 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 3 - typedef BitField<0, 16> Z; - typedef BitField<16, 16> Depth; - // argument 4 - typedef BitField<0, 4> Level; - typedef BitField<4, 3> Face; - typedef BitField<7, 25> Unused; - - void SetHeader(uint32 size) { - header.SetCmdBySize<ValueType>(size); - } - - void Init( - ResourceId _texture_id, - uint32 _x, - uint32 _y, - uint32 _z, - uint32 _width, - uint32 _height, - uint32 _depth, - uint32 _level, - texture::Face _face, - uint32 _row_pitch, - uint32 _slice_pitch, - uint32 _size, - const void* data) { - SetHeader(_size); - texture_id = _texture_id; - x_y = X::MakeValue(_x) | Y::MakeValue(_y); - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - z_depth = Z::MakeValue(_z) | Depth::MakeValue(_depth); - level_face = Level::MakeValue(_level) | Face::MakeValue(_face); - row_pitch = _row_pitch; - slice_pitch = _slice_pitch; - size = _size; - memcpy(ImmediateDataAddress(this), data, _size); - } - - static void* Set( - void* cmd, - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - const void* data) { - static_cast<ValueType*>(cmd)->Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - data); - return NextImmediateCmdAddress<ValueType>(cmd, size); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 x_y; - uint32 width_height; - uint32 z_depth; - uint32 level_face; - uint32 row_pitch; - uint32 slice_pitch; - uint32 size; -}; - -COMPILE_ASSERT(sizeof(SetTextureDataImmediate) == 36, - Sizeof_SetTextureDataImmediate_is_not_36); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, header) == 0, - OffsetOf_SetTextureDataImmediate_header_not_0); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, texture_id) == 4, - OffsetOf_SetTextureDataImmediate_texture_id_not_4); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, x_y) == 8, - OffsetOf_SetTextureDataImmediate_x_y_not_8); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, width_height) == 12, - OffsetOf_SetTextureDataImmediate_width_height_not_12); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, z_depth) == 16, - OffsetOf_SetTextureDataImmediate_z_depth_not_16); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, level_face) == 20, - OffsetOf_SetTextureDataImmediate_level_face_not_20); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, row_pitch) == 24, - OffsetOf_SetTextureDataImmediate_row_pitch_not_24); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, slice_pitch) == 28, - OffsetOf_SetTextureDataImmediate_slice_pitch_not_28); -COMPILE_ASSERT(offsetof(SetTextureDataImmediate, size) == 32, - OffsetOf_SetTextureDataImmediate_size_not_32); - -struct GetTextureData { - typedef GetTextureData ValueType; - static const CommandId kCmdId = kGetTextureData; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> X; - typedef BitField<16, 16> Y; - // argument 2 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 3 - typedef BitField<0, 16> Z; - typedef BitField<16, 16> Depth; - // argument 4 - typedef BitField<0, 4> Level; - typedef BitField<4, 3> Face; - typedef BitField<7, 25> Unused; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - ResourceId _texture_id, - uint32 _x, - uint32 _y, - uint32 _z, - uint32 _width, - uint32 _height, - uint32 _depth, - uint32 _level, - texture::Face _face, - uint32 _row_pitch, - uint32 _slice_pitch, - uint32 _size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - SetHeader(); - texture_id = _texture_id; - x_y = X::MakeValue(_x) | Y::MakeValue(_y); - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - z_depth = Z::MakeValue(_z) | Depth::MakeValue(_depth); - level_face = Level::MakeValue(_level) | Face::MakeValue(_face); - row_pitch = _row_pitch; - slice_pitch = _slice_pitch; - size = _size; - shared_memory.Init(shared_memory_id, shared_memory_offset); - } - - static void* Set( - void* cmd, - ResourceId texture_id, - uint32 x, - uint32 y, - uint32 z, - uint32 width, - uint32 height, - uint32 depth, - uint32 level, - texture::Face face, - uint32 row_pitch, - uint32 slice_pitch, - uint32 size, - uint32 shared_memory_id, - uint32 shared_memory_offset) { - static_cast<ValueType*>(cmd)->Init( - texture_id, - x, - y, - z, - width, - height, - depth, - level, - face, - row_pitch, - slice_pitch, - size, - shared_memory_id, - shared_memory_offset); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId texture_id; - uint32 x_y; - uint32 width_height; - uint32 z_depth; - uint32 level_face; - uint32 row_pitch; - uint32 slice_pitch; - uint32 size; - SharedMemory shared_memory; -}; - -COMPILE_ASSERT(sizeof(GetTextureData) == 44, - Sizeof_GetTextureData_is_not_44); -COMPILE_ASSERT(offsetof(GetTextureData, header) == 0, - OffsetOf_GetTextureData_header_not_0); -COMPILE_ASSERT(offsetof(GetTextureData, texture_id) == 4, - OffsetOf_GetTextureData_texture_id_not_4); -COMPILE_ASSERT(offsetof(GetTextureData, x_y) == 8, - OffsetOf_GetTextureData_x_y_not_8); -COMPILE_ASSERT(offsetof(GetTextureData, width_height) == 12, - OffsetOf_GetTextureData_width_height_not_12); -COMPILE_ASSERT(offsetof(GetTextureData, z_depth) == 16, - OffsetOf_GetTextureData_z_depth_not_16); -COMPILE_ASSERT(offsetof(GetTextureData, level_face) == 20, - OffsetOf_GetTextureData_level_face_not_20); -COMPILE_ASSERT(offsetof(GetTextureData, row_pitch) == 24, - OffsetOf_GetTextureData_row_pitch_not_24); -COMPILE_ASSERT(offsetof(GetTextureData, slice_pitch) == 28, - OffsetOf_GetTextureData_slice_pitch_not_28); -COMPILE_ASSERT(offsetof(GetTextureData, size) == 32, - OffsetOf_GetTextureData_size_not_32); -COMPILE_ASSERT(offsetof(GetTextureData, shared_memory) == 36, - OffsetOf_GetTextureData_shared_memory_not_36); - -struct CreateSampler { - typedef CreateSampler ValueType; - static const CommandId kCmdId = kCreateSampler; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _sampler_id) { - SetHeader(); - sampler_id = _sampler_id; - } - - static void* Set(void* cmd, ResourceId sampler_id) { - static_cast<ValueType*>(cmd)->Init(sampler_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId sampler_id; -}; - -COMPILE_ASSERT(sizeof(CreateSampler) == 8, Sizeof_CreateSampler_is_not_8); -COMPILE_ASSERT(offsetof(CreateSampler, header) == 0, - OffsetOf_CreateSampler_header_not_0); -COMPILE_ASSERT(offsetof(CreateSampler, sampler_id) == 4, - OffsetOf_CreateSampler_sampler_id_not_4); - -struct DestroySampler { - typedef DestroySampler ValueType; - static const CommandId kCmdId = kDestroySampler; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _sampler_id) { - SetHeader(); - sampler_id = _sampler_id; - } - - static void* Set(void* cmd, ResourceId sampler_id) { - static_cast<ValueType*>(cmd)->Init(sampler_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId sampler_id; -}; - -COMPILE_ASSERT(sizeof(DestroySampler) == 8, Sizeof_DestroySampler_is_not_8); -COMPILE_ASSERT(offsetof(DestroySampler, header) == 0, - OffsetOf_DestroySampler_header_not_0); -COMPILE_ASSERT(offsetof(DestroySampler, sampler_id) == 4, - OffsetOf_DestroySampler_sampler_id_not_4); - -struct SetSamplerStates { - typedef SetSamplerStates ValueType; - static const CommandId kCmdId = kSetSamplerStates; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 2 - typedef BitField<0, 3> AddressingU; - typedef BitField<3, 3> AddressingV; - typedef BitField<6, 3> AddressingW; - typedef BitField<9, 3> MagFilter; - typedef BitField<12, 3> MinFilter; - typedef BitField<15, 3> MipFilter; - typedef BitField<18, 6> Unused; - typedef BitField<24, 8> MaxAnisotropy; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - ResourceId _sampler_id, - sampler::AddressingMode _address_u_value, - sampler::AddressingMode _address_v_value, - sampler::AddressingMode _address_w_value, - sampler::FilteringMode _mag_filter_value, - sampler::FilteringMode _min_filter_value, - sampler::FilteringMode _mip_filter_value, - uint8 _max_anisotropy) { - SetHeader(); - sampler_id = _sampler_id; - sampler_states = - AddressingU::MakeValue(_address_u_value) | - AddressingV::MakeValue(_address_v_value) | - AddressingW::MakeValue(_address_w_value) | - MagFilter::MakeValue(_mag_filter_value) | - MinFilter::MakeValue(_min_filter_value) | - MipFilter::MakeValue(_mip_filter_value) | - MaxAnisotropy::MakeValue(_max_anisotropy); - } - - static void* Set(void* cmd, - ResourceId sampler_id, - sampler::AddressingMode address_u_value, - sampler::AddressingMode address_v_value, - sampler::AddressingMode address_w_value, - sampler::FilteringMode mag_filter_value, - sampler::FilteringMode min_filter_value, - sampler::FilteringMode mip_filter_value, - uint8 max_anisotropy) { - static_cast<ValueType*>(cmd)->Init( - sampler_id, - address_u_value, - address_v_value, - address_w_value, - mag_filter_value, - min_filter_value, - mip_filter_value, - max_anisotropy); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId sampler_id; - uint32 sampler_states; -}; - -COMPILE_ASSERT(sizeof(SetSamplerStates) == 12, - Sizeof_SetSamplerStates_is_not_12); -COMPILE_ASSERT(offsetof(SetSamplerStates, header) == 0, - OffsetOf_SetSamplerStates_header_not_0); -COMPILE_ASSERT(offsetof(SetSamplerStates, sampler_id) == 4, - OffsetOf_SetSamplerStates_sampler_id_not_4); -COMPILE_ASSERT(offsetof(SetSamplerStates, sampler_states) == 8, - OffsetOf_SetSamplerStates_sampler_states_not_8); - -struct SetSamplerBorderColor { - typedef SetSamplerBorderColor ValueType; - static const CommandId kCmdId = kSetSamplerBorderColor; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _sampler_id, - float _red, float _green, float _blue, float _alpha) { - SetHeader(); - sampler_id = _sampler_id; - red = _red; - green = _green; - blue = _blue; - alpha = _alpha; - } - - static void* Set(void* cmd, ResourceId sampler_id, - float red, float green, float blue, float alpha) { - static_cast<ValueType*>(cmd)->Init(sampler_id, red, green, blue, alpha); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId sampler_id; - float red; - float blue; - float green; - float alpha; -}; - -COMPILE_ASSERT(sizeof(SetSamplerBorderColor) == 24, - Sizeof_SetSamplerBorderColor_is_not_24); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, header) == 0, - OffsetOf_SetSamplerBorderColor_header_not_0); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, sampler_id) == 4, - OffsetOf_SetSamplerBorderColor_sampler_id_not_4); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, red) == 8, - OffsetOf_SetSamplerBorderColor_red_not_8); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, blue) == 12, - OffsetOf_SetSamplerBorderColor_blue_not_12); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, green) == 16, - OffsetOf_SetSamplerBorderColor_green_not_16); -COMPILE_ASSERT(offsetof(SetSamplerBorderColor, alpha) == 20, - OffsetOf_SetSamplerBorderColor_alpha_not_20); - -struct SetSamplerTexture { - typedef SetSamplerTexture ValueType; - static const CommandId kCmdId = kSetSamplerTexture; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _sampler_id, ResourceId _texture_id) { - SetHeader(); - sampler_id = _sampler_id; - texture_id = _texture_id; - } - - static void* Set(void* cmd, ResourceId sampler_id, ResourceId texture_id) { - static_cast<ValueType*>(cmd)->Init(sampler_id, texture_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId sampler_id; - ResourceId texture_id; -}; - -COMPILE_ASSERT(sizeof(SetSamplerTexture) == 12, - Sizeof_SetSamplerTexture_is_not_12); -COMPILE_ASSERT(offsetof(SetSamplerTexture, header) == 0, - OffsetOf_SetSamplerTexture_header_not_0); -COMPILE_ASSERT(offsetof(SetSamplerTexture, sampler_id) == 4, - OffsetOf_SetSamplerTexture_sampler_id_not_4); -COMPILE_ASSERT(offsetof(SetSamplerTexture, texture_id) == 8, - OffsetOf_SetSamplerTexture_texture_id_not_8); - -struct SetScissor { - typedef SetScissor ValueType; - static const CommandId kCmdId = kSetScissor; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 15> X; - typedef BitField<15, 1> Unused; - typedef BitField<16, 15> Y; - typedef BitField<31, 1> Enable; - // argument 1 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(uint32 _x, - uint32 _y, - uint32 _width, - uint32 _height, - bool _enable) { - SetHeader(); - x_y_enable = - X::MakeValue(_x) | - Y::MakeValue(_y) | - Enable::MakeValue(_enable ? 1 : 0); - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - } - - static void* Set( - void* cmd, - uint32 x, - uint32 y, - uint32 width, - uint32 height, - bool enable) { - static_cast<ValueType*>(cmd)->Init( - x, - y, - width, - height, - enable); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 x_y_enable; - uint32 width_height; -}; - -COMPILE_ASSERT(sizeof(SetScissor) == 12, Sizeof_SetScissor_is_not_12); -COMPILE_ASSERT(offsetof(SetScissor, header) == 0, - OffsetOf_SetScissor_header_not_0); -COMPILE_ASSERT(offsetof(SetScissor, x_y_enable) == 4, - OffsetOf_SetScissor_x_y_enable_not_4); -COMPILE_ASSERT(offsetof(SetScissor, width_height) == 8, - OffsetOf_SetScissor_width_height_not_8); - -struct SetPolygonOffset { - typedef SetPolygonOffset ValueType; - static const CommandId kCmdId = kSetPolygonOffset; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(float _slope_factor, float _units) { - SetHeader(); - slope_factor = _slope_factor; - units = _units; - } - - static void* Set(void* cmd, float slope_factor, float units) { - static_cast<ValueType*>(cmd)->Init(slope_factor, units); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - float slope_factor; - float units; -}; - -COMPILE_ASSERT(sizeof(SetPolygonOffset) == 12, - Sizeof_SetPolygonOffset_is_not_12); -COMPILE_ASSERT(offsetof(SetPolygonOffset, header) == 0, - OffsetOf_SetPolygonOffset_header_not_0); -COMPILE_ASSERT(offsetof(SetPolygonOffset, slope_factor) == 4, - OffsetOf_SetPolygonOffset_slope_factor_not_4); -COMPILE_ASSERT(offsetof(SetPolygonOffset, units) == 8, - OffsetOf_SetPolygonOffset_units_not_8); - -struct SetPointLineRaster { - typedef SetPointLineRaster ValueType; - static const CommandId kCmdId = kSetPointLineRaster; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 1> LineSmoothEnable; - typedef BitField<1, 1> PointSpriteEnable; - typedef BitField<2, 30> Unused; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(bool _line_smooth_enable, bool _point_sprite_enable, - float _point_size) { - SetHeader(); - enables = - LineSmoothEnable::MakeValue(_line_smooth_enable ? 1 : 0) | - PointSpriteEnable::MakeValue(_point_sprite_enable ? 1 : 0); - point_size = _point_size; - } - - static void* Set(void* cmd, bool line_smooth_enable, bool point_sprite_enable, - float point_size) { - static_cast<ValueType*>(cmd)->Init(line_smooth_enable, point_sprite_enable, - point_size); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 enables; - float point_size; -}; - -COMPILE_ASSERT(sizeof(SetPointLineRaster) == 12, - Sizeof_SetPointLineRaster_is_not_12); -COMPILE_ASSERT(offsetof(SetPointLineRaster, header) == 0, - OffsetOf_SetPointLineRaster_header_not_0); -COMPILE_ASSERT(offsetof(SetPointLineRaster, enables) == 4, - OffsetOf_SetPointLineRaster_enables_not_4); -COMPILE_ASSERT(offsetof(SetPointLineRaster, point_size) == 8, - OffsetOf_SetPointLineRaster_point_size_not_8); - -struct SetPolygonRaster { - typedef SetPolygonRaster ValueType; - static const CommandId kCmdId = kSetPolygonRaster; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 2> FillMode; - typedef BitField<2, 2> CullMode; - typedef BitField<4, 28> Unused; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(PolygonMode _fill_mode, FaceCullMode _cull_mode) { - SetHeader(); - fill_cull = FillMode::MakeValue(_fill_mode) | - CullMode::MakeValue(_cull_mode); - } - - static void* Set(void* cmd, PolygonMode fill_mode, FaceCullMode cull_mode) { - static_cast<ValueType*>(cmd)->Init(fill_mode, cull_mode); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 fill_cull; -}; - -COMPILE_ASSERT(sizeof(SetPolygonRaster) == 8, - Sizeof_SetPolygonRaster_is_not_8); -COMPILE_ASSERT(offsetof(SetPolygonRaster, header) == 0, - OffsetOf_SetPolygonRaster_header_not_0); -COMPILE_ASSERT(offsetof(SetPolygonRaster, fill_cull) == 4, - OffsetOf_SetPolygonRaster_fill_cull_not_4); - -struct SetAlphaTest { - typedef SetAlphaTest ValueType; - static const CommandId kCmdId = kSetAlphaTest; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 3> Func; - typedef BitField<3, 28> Unused; - typedef BitField<31, 1> Enable; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(Comparison _func, bool _enable, float _value) { - SetHeader(); - func_enable = Func::MakeValue(_func) | Enable::MakeValue(_enable ? 1 : 0); - value = _value; - } - - static void* Set(void* cmd, Comparison func, bool enable, float value) { - static_cast<ValueType*>(cmd)->Init(func, enable, value); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 func_enable; - float value; -}; - -COMPILE_ASSERT(sizeof(SetAlphaTest) == 12, Sizeof_SetAlphaTest_is_not_12); -COMPILE_ASSERT(offsetof(SetAlphaTest, header) == 0, - OffsetOf_SetAlphaTest_header_not_0); -COMPILE_ASSERT(offsetof(SetAlphaTest, func_enable) == 4, - OffsetOf_SetAlphaTest_func_enable_not_4); -COMPILE_ASSERT(offsetof(SetAlphaTest, value) == 8, - OffsetOf_SetAlphaTest_value_not_8); - -struct SetDepthTest { - typedef SetDepthTest ValueType; - static const CommandId kCmdId = kSetDepthTest; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 3> Func; - typedef BitField<3, 27> Unused; - typedef BitField<30, 1> WriteEnable; - typedef BitField<31, 1> Enable; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(Comparison _func, bool _write_enable, bool _enable) { - SetHeader(); - func_enable = - Func::MakeValue(_func) | - WriteEnable::MakeValue(_write_enable ? 1 : 0) | - Enable::MakeValue(_enable ? 1 : 0); - } - - static void* Set(void* cmd, - Comparison func, bool write_enable, bool enable) { - static_cast<ValueType*>(cmd)->Init(func, write_enable, enable); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 func_enable; -}; - -COMPILE_ASSERT(sizeof(SetDepthTest) == 8, Sizeof_SetDepthTest_is_not_8); -COMPILE_ASSERT(offsetof(SetDepthTest, header) == 0, - OffsetOf_SetDepthTest_header_not_0); -COMPILE_ASSERT(offsetof(SetDepthTest, func_enable) == 4, - OffsetOf_SetDepthTest_func_enable_not_4); - -struct SetStencilTest { - typedef SetStencilTest ValueType; - static const CommandId kCmdId = kSetStencilTest; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 8> WriteMask; - typedef BitField<8, 8> CompareMask; - typedef BitField<16, 8> ReferenceValue; - typedef BitField<24, 6> Unused0; - typedef BitField<30, 1> SeparateCCW; - typedef BitField<31, 1> Enable; - // argument 1 - typedef BitField<0, 3> CWFunc; - typedef BitField<3, 3> CWPassOp; - typedef BitField<6, 3> CWFailOp; - typedef BitField<9, 3> CWZFailOp; - typedef BitField<12, 4> Unused1; - typedef BitField<16, 3> CCWFunc; - typedef BitField<19, 3> CCWPassOp; - typedef BitField<22, 3> CCWFailOp; - typedef BitField<25, 3> CCWZFailOp; - typedef BitField<28, 4> Unused2; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(uint8 _write_mask, - uint8 _compare_mask, - uint8 _reference_value, - bool _separate_ccw, - bool _enable, - Comparison _cw_func, - StencilOp _cw_pass_op, - StencilOp _cw_fail_op, - StencilOp _cw_z_fail_op, - Comparison _ccw_func, - StencilOp _ccw_pass_op, - StencilOp _ccw_fail_op, - StencilOp _ccw_z_fail_op) { - SetHeader(); - stencil_args0 = - WriteMask::MakeValue(_write_mask) | - CompareMask::MakeValue(_compare_mask) | - ReferenceValue::MakeValue(_reference_value) | - SeparateCCW::MakeValue(_separate_ccw ? 1 : 0) | - Enable::MakeValue(_enable ? 1 : 0); - stencil_args1 = - CWFunc::MakeValue(_cw_func) | - CWPassOp::MakeValue(_cw_pass_op) | - CWFailOp::MakeValue(_cw_fail_op) | - CWZFailOp::MakeValue(_cw_z_fail_op) | - CCWFunc::MakeValue(_ccw_func) | - CCWPassOp::MakeValue(_ccw_pass_op) | - CCWFailOp::MakeValue(_ccw_fail_op) | - CCWZFailOp::MakeValue(_ccw_z_fail_op); - } - - static void* Set( - void* cmd, - uint8 write_mask, - uint8 compare_mask, - uint8 reference_value, - bool separate_ccw, - bool enable, - Comparison cw_func, - StencilOp cw_pass_op, - StencilOp cw_fail_op, - StencilOp cw_z_fail_op, - Comparison ccw_func, - StencilOp ccw_pass_op, - StencilOp ccw_fail_op, - StencilOp ccw_z_fail_op) { - static_cast<ValueType*>(cmd)->Init( - write_mask, - compare_mask, - reference_value, - separate_ccw, - enable, - cw_func, - cw_pass_op, - cw_fail_op, - cw_z_fail_op, - ccw_func, - ccw_pass_op, - ccw_fail_op, - ccw_z_fail_op); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 stencil_args0; - uint32 stencil_args1; -}; - -COMPILE_ASSERT(sizeof(SetStencilTest) == 12, - Sizeof_SetStencilTest_is_not_12); -COMPILE_ASSERT(offsetof(SetStencilTest, header) == 0, - OffsetOf_SetStencilTest_header_not_0); -COMPILE_ASSERT(offsetof(SetStencilTest, stencil_args0) == 4, - OffsetOf_SetStencilTest_stencil_args0_not_4); -COMPILE_ASSERT(offsetof(SetStencilTest, stencil_args1) == 8, - OffsetOf_SetStencilTest_stencil_args1_not_8); - -struct SetColorWrite { - typedef SetColorWrite ValueType; - static const CommandId kCmdId = kSetColorWrite; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 1> RedMask; - typedef BitField<1, 1> GreenMask; - typedef BitField<2, 1> BlueMask; - typedef BitField<3, 1> AlphaMask; - typedef BitField<0, 4> AllColorsMask; // alias for RGBA - typedef BitField<4, 27> Unused; - typedef BitField<31, 1> DitherEnable; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(uint8 _mask, bool _dither_enable) { - SetHeader(); - flags = - RedMask::MakeValue((_mask | 0x01) != 0 ? 1 : 0) | - GreenMask::MakeValue((_mask | 0x02) != 0 ? 1 : 0) | - BlueMask::MakeValue((_mask | 0x02) != 0 ? 1 : 0) | - AlphaMask::MakeValue((_mask | 0x02) != 0 ? 1 : 0) | - DitherEnable::MakeValue(_dither_enable ? 1 : 0); - } - - static void* Set(void* cmd, uint8 mask, bool dither_enable) { - static_cast<ValueType*>(cmd)->Init(mask, dither_enable); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - uint32 flags; -}; - -COMPILE_ASSERT(sizeof(SetColorWrite) == 8, Sizeof_SetColorWrite_is_not_8); -COMPILE_ASSERT(offsetof(SetColorWrite, header) == 0, - OffsetOf_SetColorWrite_header_not_0); -COMPILE_ASSERT(offsetof(SetColorWrite, flags) == 4, - OffsetOf_SetColorWrite_flags_not_4); - -struct SetBlending { - typedef SetBlending ValueType; - static const CommandId kCmdId = kSetBlending; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 0 - typedef BitField<0, 4> ColorSrcFunc; - typedef BitField<4, 4> ColorDstFunc; - typedef BitField<8, 3> ColorEq; - typedef BitField<11, 5> Unused0; - typedef BitField<16, 4> AlphaSrcFunc; - typedef BitField<20, 4> AlphaDstFunc; - typedef BitField<24, 3> AlphaEq; - typedef BitField<27, 3> Unused1; - typedef BitField<30, 1> SeparateAlpha; - typedef BitField<31, 1> Enable; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init( - BlendFunc _color_src_func, - BlendFunc _color_dst_func, - BlendEq _color_eq, - BlendFunc _alpha_src_func, - BlendFunc _alpha_dst_func, - BlendEq _alpha_eq, - bool _separate_alpha, - bool _enable) { - SetHeader(); - blend_settings = - ColorSrcFunc::MakeValue(_color_src_func) | - ColorDstFunc::MakeValue(_color_dst_func) | - ColorEq::MakeValue(_color_eq) | - AlphaSrcFunc::MakeValue(_alpha_src_func) | - AlphaDstFunc::MakeValue(_alpha_dst_func) | - AlphaEq::MakeValue(_alpha_eq) | - SeparateAlpha::MakeValue(_separate_alpha ? 1 : 0) | - Enable::MakeValue(_enable ? 1 : 0); - } - - static void* Set( - void* cmd, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq color_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func, - BlendEq alpha_eq, - bool separate_alpha, - bool enable) { - static_cast<ValueType*>(cmd)->Init( - color_src_func, - color_dst_func, - color_eq, - alpha_src_func, - alpha_dst_func, - alpha_eq, - separate_alpha, - enable); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - uint32 blend_settings; -}; - -COMPILE_ASSERT(sizeof(SetBlending) == 8, Sizeof_SetBlending_is_not_8); -COMPILE_ASSERT(offsetof(SetBlending, header) == 0, - OffsetOf_SetBlending_header_not_0); -COMPILE_ASSERT(offsetof(SetBlending, blend_settings) == 4, - OffsetOf_SetBlending_blend_settings_not_4); - -struct SetBlendingColor { - typedef SetBlendingColor ValueType; - static const CommandId kCmdId = kSetBlendingColor; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(float _red, float _green, float _blue, float _alpha) { - SetHeader(); - red = _red; - green = _green; - blue = _blue; - alpha = _alpha; - } - - static void* Set(void* cmd, - float red, float green, float blue, float alpha) { - static_cast<ValueType*>(cmd)->Init(red, green, blue, alpha); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - float red; - float blue; - float green; - float alpha; -}; - -COMPILE_ASSERT(sizeof(SetBlendingColor) == 20, - Sizeof_SetBlendingColor_is_not_20); -COMPILE_ASSERT(offsetof(SetBlendingColor, header) == 0, - OffsetOf_SetBlendingColor_header_not_0); -COMPILE_ASSERT(offsetof(SetBlendingColor, red) == 4, - OffsetOf_SetBlendingColor_red_not_4); -COMPILE_ASSERT(offsetof(SetBlendingColor, blue) == 8, - OffsetOf_SetBlendingColor_blue_not_8); -COMPILE_ASSERT(offsetof(SetBlendingColor, green) == 12, - OffsetOf_SetBlendingColor_green_not_12); -COMPILE_ASSERT(offsetof(SetBlendingColor, alpha) == 16, - OffsetOf_SetBlendingColor_alpha_not_16); - -struct CreateRenderSurface { - typedef CreateRenderSurface ValueType; - static const CommandId kCmdId = kCreateRenderSurface; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - // argument 2 may refer to side or depth - typedef BitField<0, 16> Levels; - typedef BitField<16, 16> Side; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _render_surface_id, - ResourceId _texture_id, uint32 _width, uint32 _height, - uint32 _level, uint32 _side) { - SetHeader(); - render_surface_id = _render_surface_id; - // TODO(gman): Why does this need a width and height. It's inherited from - // the texture isn't it? - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - levels_side = Levels::MakeValue(_level) | Side::MakeValue(_side); - texture_id = _texture_id; - } - - static void* Set(void* cmd, - ResourceId render_surface_id, ResourceId texture_id, - uint32 width, uint32 height, - uint32 level, uint32 side) { - static_cast<ValueType*>(cmd)->Init(render_surface_id, texture_id, - width, height, - level, side); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId render_surface_id; - uint32 width_height; - uint32 levels_side; - ResourceId texture_id; -}; - -COMPILE_ASSERT(sizeof(CreateRenderSurface) == 20, - Sizeof_CreateRenderSurface_is_not_20); -COMPILE_ASSERT(offsetof(CreateRenderSurface, header) == 0, - OffsetOf_CreateRenderSurface_header_not_0); -COMPILE_ASSERT(offsetof(CreateRenderSurface, render_surface_id) == 4, - OffsetOf_CreateRenderSurface_render_surface_id_not_4); -COMPILE_ASSERT(offsetof(CreateRenderSurface, width_height) == 8, - OffsetOf_CreateRenderSurface_width_height_not_8); -COMPILE_ASSERT(offsetof(CreateRenderSurface, levels_side) == 12, - OffsetOf_CreateRenderSurface_levels_side_not_12); -COMPILE_ASSERT(offsetof(CreateRenderSurface, texture_id) == 16, - OffsetOf_CreateRenderSurface_texture_id_not_16); - -struct DestroyRenderSurface { - typedef DestroyRenderSurface ValueType; - static const CommandId kCmdId = kDestroyRenderSurface; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _render_surface_id) { - SetHeader(); - render_surface_id = _render_surface_id; - } - - static void* Set(void* cmd, ResourceId render_surface_id) { - static_cast<ValueType*>(cmd)->Init(render_surface_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId render_surface_id; -}; - -COMPILE_ASSERT(sizeof(DestroyRenderSurface) == 8, - Sizeof_DestroyRenderSurface_is_not_8); -COMPILE_ASSERT(offsetof(DestroyRenderSurface, header) == 0, - OffsetOf_DestroyRenderSurface_header_not_0); -COMPILE_ASSERT(offsetof(DestroyRenderSurface, render_surface_id) == 4, - OffsetOf_DestroyRenderSurface_render_surface_id_not_4); - -struct CreateDepthSurface { - typedef CreateDepthSurface ValueType; - static const CommandId kCmdId = kCreateDepthSurface; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - // argument 1 - typedef BitField<0, 16> Width; - typedef BitField<16, 16> Height; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _depth_surface_id, uint32 _width, uint32 _height) { - SetHeader(); - depth_surface_id = _depth_surface_id; - width_height = Width::MakeValue(_width) | Height::MakeValue(_height); - } - - static void* Set(void* cmd, ResourceId depth_surface_id, - uint32 width, uint32 height) { - static_cast<ValueType*>(cmd)->Init(depth_surface_id, width, height); - return NextCmdAddress<ValueType>(cmd); - } - - // TODO(gman): fix this to not use obfusticated fields. - CommandHeader header; - ResourceId depth_surface_id; - uint32 width_height; -}; - -COMPILE_ASSERT(sizeof(CreateDepthSurface) == 12, - Sizeof_CreateDepthSurface_is_not_12); -COMPILE_ASSERT(offsetof(CreateDepthSurface, header) == 0, - OffsetOf_CreateDepthSurface_header_not_0); -COMPILE_ASSERT(offsetof(CreateDepthSurface, depth_surface_id) == 4, - OffsetOf_CreateDepthSurface_depth_surface_id_not_4); -COMPILE_ASSERT(offsetof(CreateDepthSurface, width_height) == 8, - OffsetOf_CreateDepthSurface_width_height_not_8); - -struct DestroyDepthSurface { - typedef DestroyDepthSurface ValueType; - static const CommandId kCmdId = kDestroyDepthSurface; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _depth_surface_id) { - SetHeader(); - depth_surface_id = _depth_surface_id; - } - - static void* Set(void* cmd, ResourceId depth_surface_id) { - static_cast<ValueType*>(cmd)->Init(depth_surface_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId depth_surface_id; -}; - -COMPILE_ASSERT(sizeof(DestroyDepthSurface) == 8, - Sizeof_DestroyDepthSurface_is_not_8); -COMPILE_ASSERT(offsetof(DestroyDepthSurface, header) == 0, - OffsetOf_DestroyDepthSurface_header_not_0); -COMPILE_ASSERT(offsetof(DestroyDepthSurface, depth_surface_id) == 4, - OffsetOf_DestroyDepthdepth_surface_id_not_4); - -struct SetRenderSurface { - typedef SetRenderSurface ValueType; - static const CommandId kCmdId = kSetRenderSurface; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init(ResourceId _render_surface_id, ResourceId _depth_surface_id) { - SetHeader(); - render_surface_id = _render_surface_id; - depth_surface_id = _depth_surface_id; - } - - static void* Set(void* cmd, - ResourceId render_surface_id, ResourceId depth_surface_id) { - static_cast<ValueType*>(cmd)->Init(render_surface_id, depth_surface_id); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; - ResourceId render_surface_id; - ResourceId depth_surface_id; -}; - -COMPILE_ASSERT(sizeof(SetRenderSurface) == 12, - Sizeof_SetRenderSurface_is_not_12); -COMPILE_ASSERT(offsetof(SetRenderSurface, header) == 0, - OffsetOf_SetRenderSurface_header_not_0); -COMPILE_ASSERT(offsetof(SetRenderSurface, render_surface_id) == 4, - OffsetOf_SetRenderSurface_render_surface_id_not_4); -COMPILE_ASSERT(offsetof(SetRenderSurface, depth_surface_id) == 8, - OffsetOf_SetRenderSurface_depth_surface_id_not_8); - -struct SetBackSurfaces { - typedef SetBackSurfaces ValueType; - static const CommandId kCmdId = kSetBackSurfaces; - static const cmd::ArgFlags kArgFlags = cmd::kFixed; - - void SetHeader() { - header.SetCmd<ValueType>(); - } - - void Init() { - SetHeader(); - } - - static void* Set(void* cmd) { - static_cast<ValueType*>(cmd)->Init(); - return NextCmdAddress<ValueType>(cmd); - } - - CommandHeader header; -}; - -COMPILE_ASSERT(sizeof(SetBackSurfaces) == 4, - Sizeof_SetBackSurfaces_is_not_4); -COMPILE_ASSERT(offsetof(SetBackSurfaces, header) == 0, - OffsetOf_SetBackSurfaces_header_not_0); - -#pragma pack(pop) - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ diff --git a/o3d/gpu/command_buffer/service/big_test_main.cc b/o3d/gpu/command_buffer/service/big_test_main.cc deleted file mode 100644 index cda7d0e..0000000 --- a/o3d/gpu/command_buffer/service/big_test_main.cc +++ /dev/null @@ -1,124 +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 entry to the big test program, for linux. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/cross/big_test_helpers.h" -#include "gpu/command_buffer/service/cross/gl/gapi_gl.h" -#include "gpu/command_buffer/service/linux/x_utils.h" - -namespace command_buffer { - -String *g_program_path = NULL; -GAPIInterface *g_gapi = NULL; - -bool ProcessSystemMessages() { - return true; -} - -} // namespace command_buffer - -using o3d::String; -using o3d::command_buffer::g_program_path; -using o3d::command_buffer::g_gapi; -using o3d::command_buffer::GAPIGL; -using o3d::command_buffer::XWindowWrapper; - - -// Creates a GL-compatible window of specified dimensions. -Window CreateWindow(Display *display, unsigned int width, unsigned int height) { - int attribs[] = { - GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_RED_SIZE, 1, - GLX_GREEN_SIZE, 1, - GLX_BLUE_SIZE, 1, - None - }; - XVisualInfo *visualInfo = glXChooseVisual(display, - DefaultScreen(display), - attribs); - Window root_window = RootWindow(display, visualInfo->screen); - Colormap colorMap = XCreateColormap(display, root_window, visualInfo->visual, - AllocNone); - - XSetWindowAttributes windowAttributes; - windowAttributes.colormap = colorMap; - windowAttributes.border_pixel = 0; - windowAttributes.event_mask = StructureNotifyMask; - Window window = XCreateWindow(display, root_window, - 0, 0, width, height, 0, visualInfo->depth, - InputOutput, visualInfo->visual, - CWBorderPixel|CWColormap|CWEventMask, - &windowAttributes); - if (!window) return 0; - XMapWindow(display, window); - XSync(display, True); - return window; -} - -// Creates a window, initializes the GAPI instance. -int main(int argc, char *argv[]) { - String program_path = argv[0]; - - // Remove all characters starting with last '/'. - size_t backslash_pos = program_path.rfind('/'); - if (backslash_pos != String::npos) { - program_path.erase(backslash_pos); - } - g_program_path = &program_path; - - GAPIGL gl_gapi; - g_gapi = &gl_gapi; - - Display *display = XOpenDisplay(0); - if (!display) { - LOG(FATAL) << "Could not open the display."; - return 1; - } - - Window window = CreateWindow(display, 300, 300); - if (!window) { - LOG(FATAL) << "Could not create a window."; - return 1; - } - - XWindowWrapper wrapper(display, window); - gl_gapi.set_window_wrapper(&wrapper); - - int ret = big_test_main(argc, argv); - - g_gapi = NULL; - g_program_path = NULL; - return ret; -} diff --git a/o3d/gpu/command_buffer/service/cmd_parser.cc b/o3d/gpu/command_buffer/service/cmd_parser.cc index b3486ec..019e7b2 100644 --- a/o3d/gpu/command_buffer/service/cmd_parser.cc +++ b/o3d/gpu/command_buffer/service/cmd_parser.cc @@ -34,8 +34,6 @@ #include "gpu/command_buffer/service/precompile.h" #include "gpu/command_buffer/service/cmd_parser.h" -// TODO(gman): remove this so we can use this code for different formats. -#include "gpu/command_buffer/common/o3d_cmd_format.h" namespace command_buffer { diff --git a/o3d/gpu/command_buffer/service/d3d9_utils.h b/o3d/gpu/command_buffer/service/d3d9_utils.h deleted file mode 100644 index 5938ac0..0000000 --- a/o3d/gpu/command_buffer/service/d3d9_utils.h +++ /dev/null @@ -1,145 +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 a few utilities for Direct3D. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_D3D9_UTILS_H_ -#define GPU_COMMAND_BUFFER_SERVICE_D3D9_UTILS_H_ - -#ifndef NOMINMAX -// windows.h defines min() and max() as macros, conflicting with std::min and -// std::max unless NOMINMAX is defined. -#define NOMINMAX -#endif -#include <windows.h> -#include <d3d9.h> -#include <d3dx9.h> -#include <dxerr.h> -#include <algorithm> -#include "gpu/command_buffer/common/gapi_interface.h" - -#if defined (_DEBUG) - -#ifndef HR -#define HR(x) { \ - HRESULT hr = x; \ - if (FAILED(hr)) { \ - LOG(ERROR) << "DirectX error at " << __FILE__ << ":" << __LINE__ \ - << " when calling " << #x << ": " << DXGetErrorStringA(hr); \ - } \ - } -#endif - -#else // _DEBUG - -#ifndef HR -#define HR(x) x; -#endif - -#endif // _DEBUG - -namespace command_buffer { - -union FloatAndDWORD { - float float_value; - DWORD dword_value; -}; - -// Bit casts a float into a DWORD. That's what D3D expects for some values. -inline DWORD FloatAsDWORD(float value) { - volatile FloatAndDWORD float_and_dword; - float_and_dword.float_value = value; - return float_and_dword.dword_value; -} - -// Clamps a float to [0 .. 1] and maps it to [0 .. 255] -inline unsigned int FloatToClampedByte(float value) { - value = std::min(1.f, std::max(0.f, value)); - return static_cast<unsigned int>(value * 255); -} - -// Converts a RGBA color into a D3DCOLOR -inline D3DCOLOR RGBAToD3DCOLOR(const o3d::RGBA &color) { - return D3DCOLOR_RGBA(FloatToClampedByte(color.red), - FloatToClampedByte(color.green), - FloatToClampedByte(color.blue), - FloatToClampedByte(color.alpha)); -} - -static bool D3DSemanticToCBSemantic( - D3DDECLUSAGE 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 ? - // TODO(gman): This is just plain wrong! Fix it. Converting binormal to - // texcoord 7 means there will be conflicts if I have both a Binormal and a - // texcoord 7 or 2 binormals both of which we have examples of already in O3D! - switch (semantic) { - case D3DDECLUSAGE_POSITION: - if (semantic_index != 0) return false; - *out_semantic = vertex_struct::kPosition; - *out_semantic_index = 0; - return true; - case D3DDECLUSAGE_NORMAL: - if (semantic_index != 0) return false; - *out_semantic = vertex_struct::kNormal; - *out_semantic_index = 0; - return true; - case D3DDECLUSAGE_TANGENT: - if (semantic_index != 0) return false; - *out_semantic = vertex_struct::kTexCoord; - *out_semantic_index = 6; - return true; - case D3DDECLUSAGE_BINORMAL: - if (semantic_index != 0) return false; - *out_semantic = vertex_struct::kTexCoord; - *out_semantic_index = 7; - return true; - case D3DDECLUSAGE_COLOR: - if (semantic_index > 1) return false; - *out_semantic = vertex_struct::kColor; - *out_semantic_index = semantic_index; - return true; - case D3DDECLUSAGE_TEXCOORD: - *out_semantic = vertex_struct::kTexCoord; - *out_semantic_index = semantic_index; - return true; - default: - return false; - } -} -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_D3D9_UTILS_H_ diff --git a/o3d/gpu/command_buffer/service/effect_d3d9.cc b/o3d/gpu/command_buffer/service/effect_d3d9.cc deleted file mode 100644 index 4bfae53..0000000 --- a/o3d/gpu/command_buffer/service/effect_d3d9.cc +++ /dev/null @@ -1,679 +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 D3D9 versions of the -// Effect resource. -// This file also contains the related GAPID3D9 function implementations. - -#include "gpu/command_buffer/service/precompile.h" - -#include <algorithm> -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/geometry_d3d9.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" -#include "gpu/command_buffer/service/effect_d3d9.h" -#include "gpu/command_buffer/service/sampler_d3d9.h" -#include "gpu/command_buffer/service/effect_utils.h" - -// TODO: remove link-dependency on D3DX. - -namespace command_buffer { -namespace o3d { - -// Logs the D3D effect error, from either the buffer, or GetLastError(). -static void LogFXError(LPD3DXBUFFER error_buffer) { - if (error_buffer) { - LPVOID compile_errors = error_buffer->GetBufferPointer(); - LOG(ERROR) << "Failed to compile effect: " - << static_cast<char *>(compile_errors); - } else { - HLOCAL hLocal = NULL; - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER, - NULL, - GetLastError(), - 0, - reinterpret_cast<wchar_t*>(&hLocal), - 0, - NULL); - wchar_t* msg = reinterpret_cast<wchar_t*>(LocalLock(hLocal)); - LOG(ERROR) << "Failed to compile effect: " << msg; - LocalFree(hLocal); - } -} - -EffectD3D9::EffectD3D9(GAPID3D9 *gapi, - ID3DXEffect *d3d_effect, - ID3DXConstantTable *fs_constant_table, - IDirect3DVertexShader9 *d3d_vertex_shader) - : gapi_(gapi), - d3d_effect_(d3d_effect), - fs_constant_table_(fs_constant_table), - d3d_vertex_shader_(d3d_vertex_shader), - sync_parameters_(false) { - for (unsigned int i = 0; i < kMaxSamplerUnits; ++i) { - samplers_[i] = kInvalidResource; - } - SetStreams(); -} -// Releases the D3D effect. -EffectD3D9::~EffectD3D9() { - for (ParamList::iterator it = params_.begin(); it != params_.end(); ++it) { - (*it)->ResetEffect(); - } - DCHECK(d3d_effect_); - d3d_effect_->Release(); - DCHECK(fs_constant_table_); - fs_constant_table_->Release(); - DCHECK(d3d_vertex_shader_); - d3d_vertex_shader_->Release(); -} - -// Compiles the effect, and checks that the effect conforms to what we expect -// (no extra technique or pass in the effect code, since one is implicitly added -// using the program entry points) and that it validates. If successful, wrap -// the D3D effect into a new EffectD3D9. -EffectD3D9 *EffectD3D9::Create(GAPID3D9 *gapi, - const String& effect_code, - const String& vertex_program_entry, - const String& fragment_program_entry) { - String prepared_effect = effect_code + - "technique Shaders { " - " pass p0 { " - " VertexShader = compile vs_2_0 " + vertex_program_entry + "();" - " PixelShader = compile ps_2_0 " + fragment_program_entry + "();" - " }" - "};"; - ID3DXEffect *d3d_effect = NULL; - LPD3DXBUFFER error_buffer; - IDirect3DDevice9 *device = gapi->d3d_device(); - if (gapi->D3DXCreateEffect(device, - prepared_effect.c_str(), - prepared_effect.size(), - NULL, - NULL, - 0, - NULL, - &d3d_effect, - &error_buffer) != D3D_OK) { - LogFXError(error_buffer); - return NULL; - } - // check that . - D3DXEFFECT_DESC effect_desc; - HR(d3d_effect->GetDesc(&effect_desc)); - if (effect_desc.Techniques != 1) { - LOG(ERROR) << "Only 1 technique is allowed in an effect."; - d3d_effect->Release(); - return NULL; - } - D3DXHANDLE technique = d3d_effect->GetTechnique(0); - DCHECK(technique); - if (d3d_effect->ValidateTechnique(technique) != D3D_OK) { - LOG(ERROR) << "Technique doesn't validate."; - d3d_effect->Release(); - return NULL; - } - D3DXTECHNIQUE_DESC technique_desc; - HR(d3d_effect->GetTechniqueDesc(technique, &technique_desc)); - if (technique_desc.Passes != 1) { - LOG(ERROR) << "Only 1 pass is allowed in an effect."; - d3d_effect->Release(); - return NULL; - } - d3d_effect->SetTechnique(technique); - D3DXHANDLE pass = d3d_effect->GetPass(technique, 0); - D3DXPASS_DESC pass_desc; - HR(d3d_effect->GetPassDesc(pass, &pass_desc)); - ID3DXConstantTable *table = NULL; - HR(gapi->D3DXGetShaderConstantTable(pass_desc.pPixelShaderFunction, - &table)); - if (!table) { - LOG(ERROR) << "Could not get the constant table."; - d3d_effect->Release(); - return NULL; - } - IDirect3DVertexShader9 *d3d_vertex_shader = NULL; - HR(device->CreateVertexShader(pass_desc.pVertexShaderFunction, - &d3d_vertex_shader)); - if (!d3d_vertex_shader) { - d3d_effect->Release(); - table->Release(); - DLOG(ERROR) << "Failed to create vertex shader"; - return NULL; - } - - return new EffectD3D9(gapi, d3d_effect, table, d3d_vertex_shader); -} - -// Begins rendering with the effect, setting all the appropriate states. -bool EffectD3D9::Begin() { - UINT numpasses; - HR(d3d_effect_->Begin(&numpasses, 0)); - HR(d3d_effect_->BeginPass(0)); - sync_parameters_ = false; - return SetSamplers(); -} - -// Terminates rendering with the effect, resetting all the appropriate states. -void EffectD3D9::End() { - HR(d3d_effect_->EndPass()); - HR(d3d_effect_->End()); -} - -// Gets the parameter count from the D3D effect description. -unsigned int EffectD3D9::GetParamCount() { - D3DXEFFECT_DESC effect_desc; - HR(d3d_effect_->GetDesc(&effect_desc)); - return effect_desc.Parameters; -} - -// Gets the number of input streams from the shader. -unsigned int EffectD3D9::GetStreamCount() { - return streams_.size(); -} - -// Retrieves the matching DataType from a D3D parameter description. -static effect_param::DataType GetDataTypeFromD3D( - const D3DXPARAMETER_DESC &desc) { - switch (desc.Type) { - case D3DXPT_FLOAT: - switch (desc.Class) { - case D3DXPC_SCALAR: - return effect_param::kFloat1; - case D3DXPC_VECTOR: - switch (desc.Columns) { - case 2: - return effect_param::kFloat2; - case 3: - return effect_param::kFloat3; - case 4: - return effect_param::kFloat4; - default: - return effect_param::kUnknown; - } - case D3DXPC_MATRIX_ROWS: - case D3DXPC_MATRIX_COLUMNS: - if (desc.Columns == 4 && desc.Rows == 4) { - return effect_param::kMatrix4; - } else { - return effect_param::kUnknown; - } - default: - return effect_param::kUnknown; - } - case D3DXPT_INT: - if (desc.Class == D3DXPC_SCALAR) { - return effect_param::kInt; - } else { - return effect_param::kUnknown; - } - case D3DXPT_BOOL: - if (desc.Class == D3DXPC_SCALAR) { - return effect_param::kBool; - } else { - return effect_param::kUnknown; - } - case D3DXPT_SAMPLER: - case D3DXPT_SAMPLER2D: - case D3DXPT_SAMPLER3D: - case D3DXPT_SAMPLERCUBE: - if (desc.Class == D3DXPC_OBJECT) { - return effect_param::kSampler; - } else { - return effect_param::kUnknown; - } - case D3DXPT_TEXTURE: - case D3DXPT_TEXTURE1D: - case D3DXPT_TEXTURE2D: - case D3DXPT_TEXTURE3D: - case D3DXPT_TEXTURECUBE: - if (desc.Class == D3DXPC_OBJECT) { - return effect_param::kTexture; - } else { - return effect_param::kUnknown; - } - default: - return effect_param::kUnknown; - } -} - -// Gets a handle to the selected parameter, and wraps it into an -// EffectParamD3D9 if successful. -EffectParamD3D9 *EffectD3D9::CreateParam(unsigned int index) { - D3DXHANDLE handle = d3d_effect_->GetParameter(NULL, index); - if (!handle) return NULL; - return EffectParamD3D9::Create(this, handle); -} - -// Gets a handle to the selected parameter, and wraps it into an -// EffectParamD3D9 if successful. -EffectParamD3D9 *EffectD3D9::CreateParamByName(const char *name) { - D3DXHANDLE handle = d3d_effect_->GetParameterByName(NULL, name); - if (!handle) return NULL; - return EffectParamD3D9::Create(this, handle); -} - -bool EffectD3D9::CommitParameters() { - if (sync_parameters_) { - sync_parameters_ = false; - d3d_effect_->CommitChanges(); - return SetSamplers(); - } else { - return true; - } -} - -bool EffectD3D9::SetSamplers() { - IDirect3DDevice9 *d3d_device = gapi_->d3d_device(); - bool result = true; - for (unsigned int i = 0; i < kMaxSamplerUnits; ++i) { - SamplerD3D9 *sampler = gapi_->GetSampler(samplers_[i]); - if (sampler) { - result &= sampler->ApplyStates(gapi_, i); - } else { - HR(d3d_device->SetTexture(i, NULL)); - } - } - return result; -} - -bool EffectD3D9::SetStreams() { - if (!d3d_vertex_shader_) { - return false; - } - UINT size; - d3d_vertex_shader_->GetFunction(NULL, &size); - scoped_array<DWORD> function(new DWORD[size]); - d3d_vertex_shader_->GetFunction(function.get(), &size); - - UINT num_semantics; - HR(gapi_->D3DXGetShaderInputSemantics(function.get(), - NULL, - &num_semantics)); - scoped_array<D3DXSEMANTIC> semantics(new D3DXSEMANTIC[num_semantics]); - HR(gapi_->D3DXGetShaderInputSemantics(function.get(), - semantics.get(), - &num_semantics)); - - streams_.resize(num_semantics); - for (UINT i = 0; i < num_semantics; ++i) { - vertex_struct::Semantic semantic; - unsigned int semantic_index; - if (D3DSemanticToCBSemantic(static_cast<D3DDECLUSAGE>(semantics[i].Usage), - static_cast<int>(semantics[i].UsageIndex), - &semantic, &semantic_index)) { - streams_[i].semantic = semantic; - streams_[i].semantic_index = semantic_index; - } - } - return true; -} - -void EffectD3D9::LinkParam(EffectParamD3D9 *param) { - params_.push_back(param); -} - -void EffectD3D9::UnlinkParam(EffectParamD3D9 *param) { - std::remove(params_.begin(), params_.end(), param); -} - -// Fills the Desc structure, appending name and semantic if any, and if enough -// room is available in the buffer. -bool EffectD3D9::GetStreamDesc(unsigned int index, - unsigned int size, - void *data) { - using effect_stream::Desc; - if (size < sizeof(Desc)) // NOLINT - return false; - - Desc *desc = static_cast<Desc *>(data); - *desc = streams_[index]; - return true; -} - -EffectParamD3D9::EffectParamD3D9(effect_param::DataType data_type, - EffectD3D9 *effect, - D3DXHANDLE handle) - : EffectParam(data_type), - effect_(effect), - handle_(handle), - sampler_units_(NULL), - sampler_unit_count_(0) { - DCHECK(effect_); - effect_->LinkParam(this); -} - -EffectParamD3D9::~EffectParamD3D9() { - if (effect_) effect_->UnlinkParam(this); -} - -EffectParamD3D9 *EffectParamD3D9::Create(EffectD3D9 *effect, - D3DXHANDLE handle) { - DCHECK(effect); - D3DXPARAMETER_DESC desc; - HR(effect->d3d_effect_->GetParameterDesc(handle, &desc)); - effect_param::DataType data_type = GetDataTypeFromD3D(desc); - EffectParamD3D9 *param = new EffectParamD3D9(data_type, effect, handle); - if (data_type == effect_param::kSampler) { - ID3DXConstantTable *table = effect->fs_constant_table_; - DCHECK(table); - D3DXHANDLE sampler_handle = table->GetConstantByName(NULL, desc.Name); - if (sampler_handle) { - D3DXCONSTANT_DESC desc_array[kMaxSamplerUnits]; - unsigned int num_desc = kMaxSamplerUnits; - table->GetConstantDesc(sampler_handle, desc_array, &num_desc); - // We have no good way of querying how many descriptions would really be - // returned as we're capping the number to kMaxSamplerUnits (which should - // be more than sufficient). If however we do end up with the max number - // there's a chance that there were actually more so let's log it. - if (num_desc == kMaxSamplerUnits) { - DLOG(WARNING) << "Number of constant descriptions might have exceeded " - << "the maximum of " << kMaxSamplerUnits; - } - param->sampler_unit_count_ = 0; - if (num_desc > 0) { - param->sampler_units_.reset(new unsigned int[num_desc]); - for (unsigned int desc_index = 0; desc_index < num_desc; desc_index++) { - D3DXCONSTANT_DESC constant_desc = desc_array[desc_index]; - if (constant_desc.Class == D3DXPC_OBJECT && - (constant_desc.Type == D3DXPT_SAMPLER || - constant_desc.Type == D3DXPT_SAMPLER2D || - constant_desc.Type == D3DXPT_SAMPLER3D || - constant_desc.Type == D3DXPT_SAMPLERCUBE)) { - param->sampler_units_[param->sampler_unit_count_++] = - constant_desc.RegisterIndex; - } - } - } - } - // if the sampler hasn't been found in the constant table, that means it - // isn't referenced, hence it doesn't use any sampler unit. - } - return param; -} - -// Fills the Desc structure, appending name and semantic if any, and if enough -// room is available in the buffer. -bool EffectParamD3D9::GetDesc(unsigned int size, void *data) { - using effect_param::Desc; - if (size < sizeof(Desc)) // NOLINT - return false; - if (!effect_) - return false; - ID3DXEffect *d3d_effect = effect_->d3d_effect_; - D3DXPARAMETER_DESC d3d_desc; - HR(d3d_effect->GetParameterDesc(handle_, &d3d_desc)); - unsigned int name_size = - d3d_desc.Name ? static_cast<unsigned int>(strlen(d3d_desc.Name)) + 1 : 0; - unsigned int semantic_size = d3d_desc.Semantic ? - static_cast<unsigned int>(strlen(d3d_desc.Semantic)) + 1 : 0; - unsigned int total_size = sizeof(Desc) + name_size + semantic_size; // NOLINT - - Desc *desc = static_cast<Desc *>(data); - memset(desc, 0, sizeof(*desc)); - desc->size = total_size; - desc->data_type = data_type(); - desc->data_size = GetDataSize(data_type()); - desc->name_offset = 0; - desc->name_size = name_size; - desc->num_elements = d3d_desc.Elements; - desc->semantic_offset = 0; - desc->semantic_size = semantic_size; - unsigned int current_offset = sizeof(Desc); - if (d3d_desc.Name && current_offset + name_size <= size) { - desc->name_offset = current_offset; - memcpy(static_cast<char *>(data) + current_offset, - d3d_desc.Name, name_size); - current_offset += name_size; - } - if (d3d_desc.Semantic && current_offset + semantic_size <= size) { - desc->semantic_offset = current_offset; - memcpy(static_cast<char *>(data) + current_offset, - d3d_desc.Semantic, semantic_size); - current_offset += semantic_size; - } - return true; -} - -// Sets the data into the D3D effect parameter, using the appropriate D3D call. -bool EffectParamD3D9::SetData(GAPID3D9 *gapi, - unsigned int size, - const void * data) { - if (!effect_) - return false; - ID3DXEffect *d3d_effect = effect_->d3d_effect_; - effect_param::DataType type = data_type(); - if (size < effect_param::GetDataSize(type)) return false; - switch (type) { - case effect_param::kFloat1: - HR(d3d_effect->SetFloat(handle_, *static_cast<const float *>(data))); - break; - case effect_param::kFloat2: - HR(d3d_effect->SetFloatArray(handle_, static_cast<const float *>(data), - 2)); - break; - case effect_param::kFloat3: - HR(d3d_effect->SetFloatArray(handle_, static_cast<const float *>(data), - 3)); - break; - case effect_param::kFloat4: - HR(d3d_effect->SetFloatArray(handle_, static_cast<const float *>(data), - 4)); - break; - case effect_param::kMatrix4: - HR(d3d_effect->SetMatrix(handle_, - reinterpret_cast<const D3DXMATRIX *>(data))); - break; - case effect_param::kInt: - HR(d3d_effect->SetInt(handle_, *static_cast<const int *>(data))); - break; - case effect_param::kBool: - HR(d3d_effect->SetBool(handle_, *static_cast<const bool *>(data)?1:0)); - break; - case effect_param::kSampler: { - ResourceId id = *static_cast<const ResourceId *>(data); - for (unsigned int i = 0; i < sampler_unit_count_; ++i) { - effect_->samplers_[sampler_units_[i]] = id; - } - break; - } - case effect_param::kTexture: { - // TODO(rlp): finish - break; - } - default: - DLOG(ERROR) << "Invalid parameter type."; - return false; - } - if (effect_ == gapi->current_effect()) { - effect_->sync_parameters_ = true; - } - return true; -} - -// Calls EffectD3D9::Create, and assign the result to the resource ID. -// If changing the current effect, dirty it. -parse_error::ParseError GAPID3D9::CreateEffect( - ResourceId id, - unsigned int size, - const void *data) { - if (id == current_effect_id_) DirtyEffect(); - // Even though Assign would Destroy the effect at id, we do it explicitly in - // case the creation fails. - effects_.Destroy(id); - // Data is vp_main \0 fp_main \0 effect_text. - String vertex_program_entry; - String fragment_program_entry; - String effect_code; - if (!ParseEffectData(size, data, - &vertex_program_entry, - &fragment_program_entry, - &effect_code)) { - return parse_error::kParseInvalidArguments; - } - EffectD3D9 * effect = EffectD3D9::Create(this, effect_code, - vertex_program_entry, - fragment_program_entry); - if (!effect) return parse_error::kParseInvalidArguments; - effects_.Assign(id, effect); - return parse_error::kParseNoError; -} - -// Destroys the Effect resource. -// If destroying the current effect, dirty it. -parse_error::ParseError GAPID3D9::DestroyEffect(ResourceId id) { - if (id == current_effect_id_) DirtyEffect(); - return effects_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Sets the current effect ID, dirtying the current effect. -parse_error::ParseError GAPID3D9::SetEffect(ResourceId id) { - DirtyEffect(); - current_effect_id_ = id; - return parse_error::kParseNoError; -} - -// Gets the param count from the effect and store it in the memory buffer. -parse_error::ParseError GAPID3D9::GetParamCount( - ResourceId id, - unsigned int size, - void *data) { - EffectD3D9 *effect = effects_.Get(id); - if (!effect || size < sizeof(Uint32)) // NOLINT - return parse_error::kParseInvalidArguments; - *static_cast<Uint32 *>(data) = effect->GetParamCount(); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::CreateParam( - ResourceId param_id, - ResourceId effect_id, - unsigned int index) { - EffectD3D9 *effect = effects_.Get(effect_id); - if (!effect) return parse_error::kParseInvalidArguments; - EffectParamD3D9 *param = effect->CreateParam(index); - if (!param) return parse_error::kParseInvalidArguments; - effect_params_.Assign(param_id, param); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::CreateParamByName( - ResourceId param_id, - ResourceId effect_id, - unsigned int size, - const void *name) { - EffectD3D9 *effect = effects_.Get(effect_id); - if (!effect) return parse_error::kParseInvalidArguments; - std::string string_name(static_cast<const char *>(name), size); - EffectParamD3D9 *param = effect->CreateParamByName(string_name.c_str()); - if (!param) return parse_error::kParseInvalidArguments; - effect_params_.Assign(param_id, param); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::DestroyParam(ResourceId id) { - return effect_params_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPID3D9::SetParamData( - ResourceId id, - unsigned int size, - const void *data) { - EffectParamD3D9 *param = effect_params_.Get(id); - if (!param) return parse_error::kParseInvalidArguments; - return param->SetData(this, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPID3D9::GetParamDesc( - ResourceId id, - unsigned int size, - void *data) { - EffectParamD3D9 *param = effect_params_.Get(id); - if (!param) return parse_error::kParseInvalidArguments; - return param->GetDesc(size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Gets the stream count from the effect and stores it in the memory buffer. -parse_error::ParseError GAPID3D9::GetStreamCount( - ResourceId id, - unsigned int size, - void *data) { - EffectD3D9 *effect = effects_.Get(id); - if (!effect || size < sizeof(Uint32)) // NOLINT - return parse_error::kParseInvalidArguments; - *static_cast<Uint32 *>(data) = effect->GetStreamCount(); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::GetStreamDesc( - ResourceId id, - unsigned int index, - unsigned int size, - void *data) { - EffectD3D9 *effect = effects_.Get(id); - if (!effect) return parse_error::kParseInvalidArguments; - return effect->GetStreamDesc(index, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - - -// If the current effect is valid, call End on it, and tag for revalidation. -void GAPID3D9::DirtyEffect() { - if (validate_effect_) return; - DCHECK(current_effect_); - current_effect_->End(); - current_effect_ = NULL; - validate_effect_ = true; -} - -// Gets the current effect, and calls Begin on it (if successful). -// Should only be called if the current effect is not valid. -bool GAPID3D9::ValidateEffect() { - DCHECK(validate_effect_); - DCHECK(!current_effect_); - current_effect_ = effects_.Get(current_effect_id_); - if (!current_effect_) return false; - validate_effect_ = false; - return current_effect_->Begin(); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/effect_d3d9.h b/o3d/gpu/command_buffer/service/effect_d3d9.h deleted file mode 100644 index db2df41..0000000 --- a/o3d/gpu/command_buffer/service/effect_d3d9.h +++ /dev/null @@ -1,139 +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 D3D9 versions of effect-related -// resource classes. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_EFFECT_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_EFFECT_D3D9_H_ - -#include <vector> -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/resource.h" - -namespace command_buffer { -namespace o3d { - -class GAPID3D9; -class EffectD3D9; - -// ps_2_0 limit -static const unsigned int kMaxSamplerUnits = 16; - -// D3D version of EffectParam. This class keeps a reference to the D3D effect. -class EffectParamD3D9: public EffectParam { - public: - EffectParamD3D9(effect_param::DataType data_type, - EffectD3D9 *effect, - D3DXHANDLE handle); - virtual ~EffectParamD3D9(); - - // Sets the data into the D3D effect parameter. - bool SetData(GAPID3D9 *gapi, unsigned int size, const void * data); - - // Gets the description of the parameter. - bool GetDesc(unsigned int size, void *data); - - // Resets the effect back-pointer. This is called when the effect gets - // destroyed, to invalidate the parameter. - void ResetEffect() { effect_ = NULL; } - - static EffectParamD3D9 *Create(EffectD3D9 *effect, D3DXHANDLE handle); - private: - EffectD3D9 *effect_; - D3DXHANDLE handle_; - unsigned int sampler_unit_count_; - scoped_array<unsigned int> sampler_units_; -}; - -// D3D9 version of Effect. -class EffectD3D9 : public Effect { - public: - EffectD3D9(GAPID3D9 *gapi, - ID3DXEffect *d3d_effect, - ID3DXConstantTable *fs_constant_table, - IDirect3DVertexShader9 *d3d_vertex_shader); - virtual ~EffectD3D9(); - // Compiles and creates an effect from source code. - static EffectD3D9 *Create(GAPID3D9 *gapi, - const String &effect_code, - const String &vertex_program_entry, - const String &fragment_program_entry); - // Applies the effect states (vertex shader, pixel shader) to D3D. - bool Begin(); - // Resets the effect states (vertex shader, pixel shader) to D3D. - void End(); - // Commits parameters to D3D, if they were modified while the effect is - // active. - bool CommitParameters(); - - // Gets the number of parameters in the effect. - unsigned int GetParamCount(); - // Creates an effect parameter with the specified index. - EffectParamD3D9 *CreateParam(unsigned int index); - // Creates an effect parameter of the specified name. - EffectParamD3D9 *CreateParamByName(const char *name); - // Gets the number of stream inputs for the effect. - unsigned int GetStreamCount(); - // Gets the stream data with the specified index. - bool GetStreamDesc(unsigned int index, unsigned int size, void *data); - private: - typedef std::vector<EffectParamD3D9 *> ParamList; - typedef std::vector<effect_stream::Desc> StreamList; - - // Links a param into this effect. - void LinkParam(EffectParamD3D9 *param); - // Unlinks a param into this effect. - void UnlinkParam(EffectParamD3D9 *param); - // Sets sampler states. - bool SetSamplers(); - // Sets streams vector. - bool SetStreams(); - - GAPID3D9* gapi_; - ID3DXEffect *d3d_effect_; - IDirect3DVertexShader9 *d3d_vertex_shader_; - ID3DXConstantTable *fs_constant_table_; - ParamList params_; - StreamList streams_; - bool sync_parameters_; - ResourceId samplers_[kMaxSamplerUnits]; - - friend class EffectParamD3D9; - DISALLOW_COPY_AND_ASSIGN(EffectD3D9); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_EFFECT_D3D9_H_ diff --git a/o3d/gpu/command_buffer/service/effect_gl.cc b/o3d/gpu/command_buffer/service/effect_gl.cc deleted file mode 100644 index b8f9601..0000000 --- a/o3d/gpu/command_buffer/service/effect_gl.cc +++ /dev/null @@ -1,852 +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 EffectParamGL and EffectGL -// classes, as well as the effect-related GAPI functions on GL. - -#include "gpu/command_buffer/service/precompile.h" - -#include <map> - -#include "base/cross/std_functional.h" -#include "gpu/command_buffer/service/effect_gl.h" -#include "gpu/command_buffer/service/gapi_gl.h" -#include "gpu/command_buffer/service/effect_utils.h" - -namespace command_buffer { -namespace o3d { - -EffectParamGL::EffectParamGL(effect_param::DataType data_type, - EffectGL *effect, - unsigned int param_index) - : EffectParam(data_type), - effect_(effect), - low_level_param_index_(param_index) { - DCHECK(effect_); - effect_->LinkParam(this); -} - -EffectParamGL::~EffectParamGL() { - if (effect_) - effect_->UnlinkParam(this); -} - -static effect_param::DataType CgTypeToCBType(CGtype cg_type) { - switch (cg_type) { - case CG_FLOAT: - case CG_FLOAT1: - return effect_param::kFloat1; - case CG_FLOAT2: - return effect_param::kFloat2; - case CG_FLOAT3: - return effect_param::kFloat3; - case CG_FLOAT4: - return effect_param::kFloat4; - case CG_INT: - case CG_INT1: - return effect_param::kInt; - case CG_BOOL: - case CG_BOOL1: - return effect_param::kBool; - case CG_FLOAT4x4: - return effect_param::kMatrix4; - case CG_SAMPLER: - case CG_SAMPLER1D: - case CG_SAMPLER2D: - case CG_SAMPLER3D: - case CG_SAMPLERCUBE: - return effect_param::kSampler; - case CG_TEXTURE: - return effect_param::kTexture; - default : { - DLOG(INFO) << "Cannot convert CGtype " - << cgGetTypeString(cg_type) - << " to a Param type."; - return effect_param::kUnknown; - } - } -} - -EffectParamGL *EffectParamGL::Create(EffectGL *effect, - unsigned int index) { - DCHECK(effect); - const EffectGL::LowLevelParam &low_level_param = - effect->low_level_params_[index]; - CGparameter cg_param = EffectGL::GetEitherCgParameter(low_level_param); - CGtype cg_type = cgGetParameterType(cg_param); - if (cg_type == CG_ARRAY) { - cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); - } - effect_param::DataType type = CgTypeToCBType(cg_type); - - if (type == effect_param::kUnknown) - return NULL; - return new EffectParamGL(type, effect, index); -} - -// Fills the Desc structure, appending name and semantic if any, and if enough -// room is available in the buffer. -bool EffectParamGL::GetDesc(unsigned int size, void *data) { - using effect_param::Desc; - if (size < sizeof(Desc)) // NOLINT - return false; - if (!effect_) - return false; - const EffectGL::LowLevelParam &low_level_param = - effect_->low_level_params_[low_level_param_index_]; - CGparameter cg_param = EffectGL::GetEitherCgParameter(low_level_param); - const char *name = low_level_param.name; - const char* semantic = cgGetParameterSemantic(cg_param); - int num_elements = cgGetArraySize(cg_param, 0); - unsigned int name_size = - name ? static_cast<unsigned int>(strlen(name)) + 1 : 0; - unsigned int semantic_size = semantic ? - static_cast<unsigned int>(strlen(semantic)) + 1 : 0; - unsigned int total_size = sizeof(Desc) + name_size + semantic_size; // NOLINT - - Desc *desc = static_cast<Desc *>(data); - memset(desc, 0, sizeof(*desc)); - desc->size = total_size; - desc->data_type = data_type(); - desc->data_size = GetDataSize(data_type()); - desc->name_offset = 0; - desc->name_size = name_size; - desc->semantic_offset = 0; - desc->num_elements = num_elements; - desc->semantic_size = semantic_size; - unsigned int current_offset = sizeof(Desc); - if (name && current_offset + name_size <= size) { - desc->name_offset = current_offset; - memcpy(static_cast<char *>(data) + current_offset, name, name_size); - current_offset += name_size; - } - if (semantic && current_offset + semantic_size <= size) { - desc->semantic_offset = current_offset; - memcpy(static_cast<char *>(data) + current_offset, semantic, semantic_size); - current_offset += semantic_size; - } - return true; -} - -// Sets the data into the Cg effect parameter, using the appropriate Cg call. -bool EffectParamGL::SetData(GAPIGL *gapi, - unsigned int size, - const void * data) { - if (!effect_) - return false; - - EffectGL::LowLevelParam &low_level_param = - effect_->low_level_params_[low_level_param_index_]; - - if (low_level_param.num_elements != 0) { - DLOG(ERROR) << "Attempt to set array parameter to value."; - return false; - } - - CGparameter vp_param = low_level_param.vp_param; - CGparameter fp_param = low_level_param.fp_param; - effect_param::DataType type = data_type(); - if (size < effect_param::GetDataSize(type)) - return false; - - switch (type) { - case effect_param::kFloat1: - if (vp_param) - cgSetParameter1f(vp_param, *static_cast<const float *>(data)); - if (fp_param) - cgSetParameter1f(fp_param, *static_cast<const float *>(data)); - break; - case effect_param::kFloat2: - if (vp_param) - cgSetParameter2fv(vp_param, static_cast<const float *>(data)); - if (fp_param) - cgSetParameter2fv(fp_param, static_cast<const float *>(data)); - break; - case effect_param::kFloat3: - if (vp_param) - cgSetParameter3fv(vp_param, static_cast<const float *>(data)); - if (fp_param) - cgSetParameter3fv(fp_param, static_cast<const float *>(data)); - break; - case effect_param::kFloat4: - if (vp_param) - cgSetParameter4fv(vp_param, static_cast<const float *>(data)); - if (fp_param) - cgSetParameter4fv(fp_param, static_cast<const float *>(data)); - break; - case effect_param::kMatrix4: - if (vp_param) - cgSetMatrixParameterfr(vp_param, static_cast<const float *>(data)); - if (fp_param) - cgSetMatrixParameterfr(fp_param, static_cast<const float *>(data)); - break; - case effect_param::kInt: - if (vp_param) cgSetParameter1i(vp_param, *static_cast<const int *>(data)); - if (fp_param) cgSetParameter1i(fp_param, *static_cast<const int *>(data)); - break; - case effect_param::kBool: { - int bool_value = *static_cast<const bool *>(data)?1:0; - if (vp_param) cgSetParameter1i(vp_param, bool_value); - if (fp_param) cgSetParameter1i(fp_param, bool_value); - break; - } - case effect_param::kSampler: { - DCHECK_GE(low_level_param.sampler_ids.size(), 1U); - low_level_param.sampler_ids[0] = *static_cast<const ResourceId *>(data); - if (effect_ == gapi->current_effect()) { - gapi->DirtyEffect(); - } - break; - } - default: - DLOG(ERROR) << "Invalid parameter type."; - return false; - } - return true; -} -EffectGL::EffectGL(CGprogram vertex_program, - CGprogram fragment_program) - : vertex_program_(vertex_program), - fragment_program_(fragment_program), - update_samplers_(true) { -} - -EffectGL::~EffectGL() { - for (ParamList::iterator it = params_.begin(); - it != params_.end(); ++it) { - (*it)->ResetEffect(); - } -} - -void EffectGL::LinkParam(EffectParamGL *param) { - params_.push_back(param); -} - -void EffectGL::UnlinkParam(EffectParamGL *param) { - std::remove(params_.begin(), params_.end(), param); -} - -// Rewrites vertex program assembly code to match GL semantics for clipping. -// This parses the source, breaking it down into pieces: -// - declaration ("!!ARBvp1.0") -// - comments (that contain the parameter information) -// - instructions -// - "END" token. -// Then it rewrites the instructions so that 'result.position' doesn't get -// written directly, instead it is written to a temporary variable. Then a -// transformation is done on that variable before outputing to -// 'result.position': -// - offset x an y by half a pixel (times w). -// - remap z from [0..w] to [-w..w]. -// -// Note that for the 1/2 pixel offset, we need a parameter that depends on the -// current viewport. This is done through 'program.env[0]' which is shared -// across all programs (so we only have to update it once when we change the -// viewport), because Cg won't use them currently (it uses 'program.local' -// instead). -static bool RewriteVertexProgramSource(String *source) { - String::size_type pos = source->find('\n'); - if (pos == String::npos) { - DLOG(ERROR) << "could not find program declaration"; - return false; - } - String decl(*source, 0, pos + 1); - String::size_type start_comments = pos + 1; - // skip the comments that contain the parameters etc. - for (; pos < source->size(); pos = source->find('\n', pos)) { - ++pos; - if (pos >= source->size()) - break; - if ((*source)[pos] != '#') - break; - } - if (pos >= source->size()) { - // we only found comments. - return false; - } - String comments(*source, start_comments, pos - start_comments); - - String::size_type end_token = source->find("\nEND", pos + 1); - if (end_token == String::npos) { - DLOG(ERROR) << "Compiled shader doesn't have an END token"; - return false; - } - String instructions(*source, pos, end_token + 1 - pos); - - // Replace accesses to 'result.position' by accesses to our temp variable - // '$O3D_HPOS'. - // '$' is a valid symbol for identifiers, but Cg doesn't seem to be using - // it, so we can use it to ensure we don't have name conflicts. - static const char kOutPositionRegister[] = "result.position"; - for (String::size_type i = instructions.find(kOutPositionRegister); - i < String::npos; i = instructions.find(kOutPositionRegister, i)) { - instructions.replace(i, strlen(kOutPositionRegister), "$O3D_HPOS"); - } - - *source = decl + - comments + - // .x = 1/viewport.width; .y = 1/viewport.height; .z = 2.0; - "PARAM $O3D_HELPER = program.env[0];\n" - "TEMP $O3D_HPOS;\n" + - instructions + - // hpos.x <- hpos.x + hpos.w / viewport.width; - // hpos.y <- hpos.y - hpos.w / viewport.height; - "MAD $O3D_HPOS.xy, $O3D_HELPER.xyyy, $O3D_HPOS.w, $O3D_HPOS.xyyy;\n" - // hpos.z <- hpos.z * 2 - hpos.w - "MAD $O3D_HPOS.z, $O3D_HPOS.z, $O3D_HELPER.z, -$O3D_HPOS.w;\n" - "MOV result.position, $O3D_HPOS;\n" - "END\n"; - return true; -} - -EffectGL *EffectGL::Create(GAPIGL *gapi, - const String& effect_code, - const String& vertex_program_entry, - const String& fragment_program_entry) { - CGcontext context = gapi->cg_context(); - // Compile the original vertex program once, to get the ARBVP1 assembly code. - CGprogram original_vp = cgCreateProgram( - context, CG_SOURCE, effect_code.c_str(), CG_PROFILE_ARBVP1, - vertex_program_entry.c_str(), NULL); - const char* listing = cgGetLastListing(context); - if (original_vp == NULL) { - DLOG(ERROR) << "Effect Compile Error: " << cgGetErrorString(cgGetError()) - << " : " << listing; - return NULL; - } - - if (listing && listing[0] != 0) { - DLOG(WARNING) << "Effect Compile Warnings: " << listing; - } - - String vp_assembly = cgGetProgramString(original_vp, CG_COMPILED_PROGRAM); - cgDestroyProgram(original_vp); - if (!RewriteVertexProgramSource(&vp_assembly)) { - return NULL; - } - CGprogram vertex_program = cgCreateProgram( - context, CG_OBJECT, vp_assembly.c_str(), CG_PROFILE_ARBVP1, - vertex_program_entry.c_str(), NULL); - listing = cgGetLastListing(context); - if (vertex_program == NULL) { - DLOG(ERROR) << "Effect post-rewrite Compile Error: " - << cgGetErrorString(cgGetError()) << " : " << listing; - return false; - } - - if (listing && listing[0] != 0) { - DLOG(WARNING) << "Effect post-rewrite compile warnings: " << listing; - } - - CHECK_GL_ERROR(); - - // If the program rewrite introduced some syntax or semantic errors, we won't - // know it until we load the program (through a GL error). - // So flush all GL errors first... - do {} while (glGetError() != GL_NO_ERROR); - - // ... Then load the program ... - cgGLLoadProgram(vertex_program); - - // ... And check for GL errors. - if (glGetError() != GL_NO_ERROR) { - DLOG(ERROR) << "Effect post-rewrite GL Error: " - << glGetString(GL_PROGRAM_ERROR_STRING_ARB) - << "\nSource: \n" - << vp_assembly; - return NULL; - } - - CGprogram fragment_program = cgCreateProgram( - context, CG_SOURCE, effect_code.c_str(), CG_PROFILE_ARBFP1, - fragment_program_entry.c_str(), NULL); - listing = cgGetLastListing(context); - if (fragment_program == NULL) { - DLOG(ERROR) << "Effect Compile Error: " - << cgGetErrorString(cgGetError()) << " : " - << listing; - return NULL; - } - - if (listing && listing[0] != 0) { - DLOG(WARNING) << "Effect Compile Warnings: " << listing; - } - - cgGLLoadProgram(fragment_program); - - // Also check for GL errors, in case Cg managed to compile, but generated a - // bad program. - if (glGetError() != GL_NO_ERROR) { - DLOG(ERROR) << "Effect GL Error: " - << glGetString(GL_PROGRAM_ERROR_STRING_ARB); - return false; - } - EffectGL *effect = new EffectGL(vertex_program, fragment_program); - effect->Initialize(); - return effect; -} - -int EffectGL::GetLowLevelParamIndexByName(const char *name) { - DCHECK(name); - for (unsigned int index = 0; index < low_level_params_.size(); ++index) { - if (!strcmp(name, low_level_params_[index].name)) { - return index; - } - } - return -1; -} - -void EffectGL::AddLowLevelParams(CGprogram prog, CGenum name_space, bool vp) { - // Iterate through parameters and add them to the vector of low level - // parameters, visiting only CGparameters that have had storage allocated to - // them, and add the params to the low_level_params_ vector. - for (CGparameter cg_param = cgGetFirstParameter(prog, name_space); - cg_param != NULL; - cg_param = cgGetNextParameter(cg_param)) { - CGenum variability = cgGetParameterVariability(cg_param); - if (variability != CG_UNIFORM) - continue; - CGenum direction = cgGetParameterDirection(cg_param); - if (direction != CG_IN) - continue; - const char *name = cgGetParameterName(cg_param); - if (!name) - continue; - - CGtype cg_type = cgGetParameterType(cg_param); - - int num_elements; - if (cg_type == CG_ARRAY) { - num_elements = cgGetArraySize(cg_param, 0); - // Substitute the first element's type for our type. - cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); - } else { - num_elements = 0; - } - - int index = GetLowLevelParamIndexByName(name); - if (index < 0) { - LowLevelParam param; - param.name = name; - param.vp_param = NULL; - param.fp_param = NULL; - param.num_elements = num_elements; - - index = low_level_params_.size(); - if (cg_type == CG_SAMPLER || - cg_type == CG_SAMPLER1D || - cg_type == CG_SAMPLER2D || - cg_type == CG_SAMPLER3D || - cg_type == CG_SAMPLERCUBE) { - sampler_params_.push_back(index); - if (num_elements == 0) { - param.sampler_ids.push_back(kInvalidResource); - } else { - param.sampler_ids.resize(num_elements); - std::vector<ResourceId>::iterator iter; - for (iter = param.sampler_ids.begin(); - iter != param.sampler_ids.end(); - ++iter) { - *iter = kInvalidResource; - } - } - } - low_level_params_.push_back(param); - } - - if (vp) { - low_level_params_[index].vp_param = cg_param; - } else { - low_level_params_[index].fp_param = cg_param; - } - } -} - -typedef std::pair<String, effect_stream::Desc> SemanticMapElement; -typedef std::map<String, effect_stream::Desc> SemanticMap; - -// The map batween the semantics on vertex program varying parameters names -// and vertex attribute indices under the VP_30 profile. -// TODO(gman): remove this. -SemanticMapElement semantic_map_array[] = { - SemanticMapElement("POSITION", - effect_stream::Desc(vertex_struct::kPosition, 0)), - SemanticMapElement("ATTR0", - effect_stream::Desc(vertex_struct::kPosition, 0)), - SemanticMapElement("BLENDWEIGHT", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("ATTR1", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("NORMAL", - effect_stream::Desc(vertex_struct::kNormal, 0)), - SemanticMapElement("ATTR2", - effect_stream::Desc(vertex_struct::kNormal, 0)), - SemanticMapElement("COLOR0", - effect_stream::Desc(vertex_struct::kColor, 0)), - SemanticMapElement("DIFFUSE", - effect_stream::Desc(vertex_struct::kColor, 0)), - SemanticMapElement("ATTR3", - effect_stream::Desc(vertex_struct::kColor, 0)), - SemanticMapElement("COLOR1", - effect_stream::Desc(vertex_struct::kColor, 1)), - SemanticMapElement("SPECULAR", - effect_stream::Desc(vertex_struct::kColor, 1)), - SemanticMapElement("ATTR4", - effect_stream::Desc(vertex_struct::kColor, 1)), - SemanticMapElement("TESSFACTOR", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("FOGCOORD", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("ATTR5", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("PSIZE", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("ATTR6", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("BLENDINDICES", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("ATTR7", - effect_stream::Desc(vertex_struct::kUnknownSemantic, 0)), - SemanticMapElement("TEXCOORD0", - effect_stream::Desc(vertex_struct::kTexCoord, 0)), - SemanticMapElement("ATTR8", - effect_stream::Desc(vertex_struct::kTexCoord, 0)), - SemanticMapElement("TEXCOORD1", - effect_stream::Desc(vertex_struct::kTexCoord, 1)), - SemanticMapElement("ATTR9", - effect_stream::Desc(vertex_struct::kTexCoord, 1)), - SemanticMapElement("TEXCOORD2", - effect_stream::Desc(vertex_struct::kTexCoord, 2)), - SemanticMapElement("ATTR10", - effect_stream::Desc(vertex_struct::kTexCoord, 2)), - SemanticMapElement("TEXCOORD3", - effect_stream::Desc(vertex_struct::kTexCoord, 3)), - SemanticMapElement("ATTR11", - effect_stream::Desc(vertex_struct::kTexCoord, 3)), - SemanticMapElement("TEXCOORD4", - effect_stream::Desc(vertex_struct::kTexCoord, 4)), - SemanticMapElement("ATTR12", - effect_stream::Desc(vertex_struct::kTexCoord, 4)), - SemanticMapElement("TEXCOORD5", - effect_stream::Desc(vertex_struct::kTexCoord, 5)), - SemanticMapElement("ATTR13", - effect_stream::Desc(vertex_struct::kTexCoord, 5)), - SemanticMapElement("TEXCOORD6", - effect_stream::Desc(vertex_struct::kTexCoord, 6)), - SemanticMapElement("TANGENT", - effect_stream::Desc(vertex_struct::kTexCoord, 6)), - SemanticMapElement("ATTR14", - effect_stream::Desc(vertex_struct::kTexCoord, 7)), - SemanticMapElement("TEXCOORD7", - effect_stream::Desc(vertex_struct::kTexCoord, 7)), - SemanticMapElement("BINORMAL", - effect_stream::Desc(vertex_struct::kTexCoord, 8)), - SemanticMapElement("ATTR15", - effect_stream::Desc(vertex_struct::kTexCoord, 8)) -}; - -static SemanticMap semantic_map(semantic_map_array, - semantic_map_array + - arraysize(semantic_map_array)); - -void EffectGL::Initialize() { - AddLowLevelParams(vertex_program_, CG_PROGRAM, true); - AddLowLevelParams(vertex_program_, CG_GLOBAL, true); - AddLowLevelParams(fragment_program_, CG_PROGRAM, false); - AddLowLevelParams(fragment_program_, CG_GLOBAL, false); - - AddStreams(vertex_program_, CG_PROGRAM); - AddStreams(vertex_program_, CG_GLOBAL); -} - -// Loop over all leaf parameters, and find the ones that are bound to a -// semantic. -void EffectGL::AddStreams(CGprogram prog, CGenum name_space) { - for (CGparameter cg_param = cgGetFirstLeafParameter(prog, name_space); - cg_param != NULL; - cg_param = cgGetNextLeafParameter(cg_param)) { - CGenum variability = cgGetParameterVariability(cg_param); - if (variability != CG_VARYING) - continue; - CGenum direction = cgGetParameterDirection(cg_param); - if (direction != CG_IN) - continue; - const char* cg_semantic = cgGetParameterSemantic(cg_param); - if (cg_semantic == NULL) - continue; - - SemanticMap::iterator iter = semantic_map.find(String(cg_semantic)); - if (iter == semantic_map.end()) { - streams_.push_back(effect_stream::Desc( - vertex_struct::kUnknownSemantic, 0)); - } else { - streams_.push_back(iter->second); - } - } -} - -// Begins rendering with the effect, setting all the appropriate states. -bool EffectGL::Begin(GAPIGL *gapi) { - cgGLBindProgram(vertex_program_); - cgGLBindProgram(fragment_program_); - - // sampler->ApplyStates will mess with the texture binding on unit 0, so we - // do 2 passes. - // First to set the sampler states on the texture - for (unsigned int i = 0; i < sampler_params_.size(); ++i) { - unsigned int param_index = sampler_params_[i]; - std::vector<ResourceId> &ids = low_level_params_[param_index].sampler_ids; - for (std::vector<ResourceId>::iterator iter = ids.begin(); - iter != ids.end(); - ++iter) { - ResourceId id = *iter; - if (id != kInvalidResource) { - SamplerGL *sampler = gapi->GetSampler(id); - if (!sampler->ApplyStates(gapi)) { - return false; - } - } - } - } - // Second to enable/disable the sampler params. - for (unsigned int i = 0; i < sampler_params_.size(); ++i) { - unsigned int param_index = sampler_params_[i]; - const LowLevelParam &ll_param = low_level_params_[param_index]; - std::vector<ResourceId> &ids = low_level_params_[param_index].sampler_ids; - // TODO(petersont): Rewrite the following so it handles arrays of samplers - // instead of simply bailing. - if (cgGetParameterType(ll_param.fp_param) == CG_ARRAY) - return false; - for (std::vector<ResourceId>::iterator iter = ids.begin(); - iter != ids.end(); - ++iter) { - ResourceId id = *iter; - if (id != kInvalidResource) { - SamplerGL *sampler = gapi->GetSampler(id); - GLuint gl_texture = sampler->gl_texture(); - cgGLSetTextureParameter(ll_param.fp_param, gl_texture); - cgGLEnableTextureParameter(ll_param.fp_param); - } else { - cgGLSetTextureParameter(ll_param.fp_param, 0); - cgGLDisableTextureParameter(ll_param.fp_param); - } - } - } - return true; -} - -// Terminates rendering with the effect, resetting all the appropriate states. -void EffectGL::End(GAPIGL *gapi) { -} - -// Gets the parameter count from the list. -unsigned int EffectGL::GetParamCount() const { - return low_level_params_.size(); -} - -// Gets the number of input streams from the shader. -unsigned int EffectGL::GetStreamCount() const { - return streams_.size(); -} - -// Gets a handle to the selected parameter, and wraps it into an -// EffectParamGL if successful. -EffectParamGL *EffectGL::CreateParam(unsigned int index) { - if (index >= GetParamCount()) - return NULL; - return EffectParamGL::Create(this, index); -} - -// Provided enough room is available in the buffer, fills the Desc structure, -// appending name and semantic if any. -bool EffectGL::GetStreamDesc(unsigned int index, - unsigned int size, - void *data) { - using effect_stream::Desc; - if (size < sizeof(Desc) || index >= streams_.size()) // NOLINT - return false; - - Desc *desc = static_cast<Desc *>(data); - *desc = streams_[index]; - return true; -} - -// Gets a handle to the selected parameter, and wraps it into an -// EffectParamGL if successful. -EffectParamGL *EffectGL::CreateParamByName(const char *name) { - int index = GetLowLevelParamIndexByName(name); - if (index < 0) return NULL; - return EffectParamGL::Create(this, index); -} - -parse_error::ParseError GAPIGL::CreateEffect(ResourceId id, - unsigned int size, - const void *data) { - if (id == current_effect_id_) DirtyEffect(); - // Even though Assign would Destroy the effect at id, we do it explicitly in - // case the creation fails. - effects_.Destroy(id); - // Data is vp_main \0 fp_main \0 effect_text. - String vertex_program_entry; - String fragment_program_entry; - String effect_code; - if (!ParseEffectData(size, data, - &vertex_program_entry, - &fragment_program_entry, - &effect_code)) { - return parse_error::kParseInvalidArguments; - } - EffectGL * effect = EffectGL::Create(this, effect_code, - vertex_program_entry, - fragment_program_entry); - if (!effect) return parse_error::kParseInvalidArguments; - effects_.Assign(id, effect); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyEffect(ResourceId id) { - if (id == current_effect_id_) DirtyEffect(); - return effects_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetEffect(ResourceId id) { - DirtyEffect(); - current_effect_id_ = id; - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::GetParamCount(ResourceId id, - unsigned int size, - void *data) { - EffectGL *effect = effects_.Get(id); - if (!effect || size < sizeof(Uint32)) // NOLINT - return parse_error::kParseInvalidArguments; - *static_cast<Uint32 *>(data) = effect->GetParamCount(); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::CreateParam(ResourceId param_id, - ResourceId effect_id, - unsigned int index) { - EffectGL *effect = effects_.Get(effect_id); - if (!effect) return parse_error::kParseInvalidArguments; - EffectParamGL *param = effect->CreateParam(index); - if (!param) return parse_error::kParseInvalidArguments; - effect_params_.Assign(param_id, param); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::CreateParamByName(ResourceId param_id, - ResourceId effect_id, - unsigned int size, - const void *name) { - EffectGL *effect = effects_.Get(effect_id); - if (!effect) return parse_error::kParseInvalidArguments; - std::string string_name(static_cast<const char *>(name), size); - EffectParamGL *param = effect->CreateParamByName(string_name.c_str()); - if (!param) return parse_error::kParseInvalidArguments; - effect_params_.Assign(param_id, param); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyParam(ResourceId id) { - return effect_params_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetParamData(ResourceId id, - unsigned int size, - const void *data) { - EffectParamGL *param = effect_params_.Get(id); - if (!param) return parse_error::kParseInvalidArguments; - return param->SetData(this, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::GetParamDesc(ResourceId id, - unsigned int size, - void *data) { - EffectParamGL *param = effect_params_.Get(id); - if (!param) return parse_error::kParseInvalidArguments; - return param->GetDesc(size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::GetStreamCount( - ResourceId id, - unsigned int size, - void *data) { - EffectGL *effect = effects_.Get(id); - if (!effect || size < sizeof(Uint32)) // NOLINT - return parse_error::kParseInvalidArguments; - *static_cast<Uint32 *>(data) = effect->GetStreamCount(); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::GetStreamDesc(ResourceId id, - unsigned int index, - unsigned int size, - void *data) { - EffectGL *effect = effects_.Get(id); - if (!effect) return parse_error::kParseInvalidArguments; - return effect->GetStreamDesc(index, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// If the current effect is valid, call End on it, and tag for revalidation. -void GAPIGL::DirtyEffect() { - if (validate_effect_) return; - DCHECK(current_effect_); - current_effect_->End(this); - current_effect_ = NULL; - validate_effect_ = true; -} - -// Gets the current effect, and calls Begin on it (if successful). -// Should only be called if the current effect is not valid. -bool GAPIGL::ValidateEffect() { - DCHECK(validate_effect_); - DCHECK(!current_effect_); - current_effect_ = effects_.Get(current_effect_id_); - if (!current_effect_) return false; - validate_effect_ = false; - return current_effect_->Begin(this); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/effect_gl.h b/o3d/gpu/command_buffer/service/effect_gl.h deleted file mode 100644 index b38cc92..0000000 --- a/o3d/gpu/command_buffer/service/effect_gl.h +++ /dev/null @@ -1,162 +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 EffectParamGL and EffectGL classes. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_EFFECT_GL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_EFFECT_GL_H_ - -#include <vector> - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/resource.h" -#include "gpu/command_buffer/service/gl_utils.h" - -namespace command_buffer { -namespace o3d { - -class GAPIGL; -class EffectGL; - -// GL version of EffectParam. -class EffectParamGL: public EffectParam { - public: - EffectParamGL(effect_param::DataType data_type, - EffectGL *effect, - unsigned int param_index); - virtual ~EffectParamGL(); - - // Sets the data into the GL effect parameter. - bool SetData(GAPIGL *gapi, unsigned int size, const void * data); - - // Gets the description of the parameter. - bool GetDesc(unsigned int size, void *data); - - // Resets the effect back-pointer. This is called when the effect gets - // destroyed, to invalidate the parameter. - void ResetEffect() { effect_ = NULL; } - - // Creates an EffectParamGL from the EffectGL, by index. - static EffectParamGL *Create(EffectGL *effect, - unsigned int index); - private: - EffectGL *effect_; - unsigned int low_level_param_index_; - DISALLOW_COPY_AND_ASSIGN(EffectParamGL); -}; - -// GL version of Effect. -class EffectGL : public Effect { - public: - EffectGL(CGprogram vertex_program, - CGprogram fragment_program); - virtual ~EffectGL(); - - // Compiles and creates an effect from source code. - static EffectGL *Create(GAPIGL *gapi, - const String &effect_code, - const String &vertex_program_entry, - const String &fragment_program_entry); - - // Applies the effect states (vertex shader, pixel shader) to GL. - bool Begin(GAPIGL *gapi); - - // Resets the effect states (vertex shader, pixel shader) to GL. - void End(GAPIGL *gapi); - - // Gets the number of parameters in the effect. - unsigned int GetParamCount() const; - - // Gets the number of streams in the effect. - unsigned int GetStreamCount() const; - - // Creates an effect parameter with the specified index. - EffectParamGL *CreateParam(unsigned int index); - - // Gets the stream data with the specified index. - bool GetStreamDesc(unsigned int index, unsigned int size, void *data); - - // Creates an effect parameter of the specified name. - EffectParamGL *CreateParamByName(const char *name); - - private: - struct LowLevelParam { - const char *name; - CGparameter vp_param; - CGparameter fp_param; - int num_elements; - std::vector<ResourceId> sampler_ids; - }; - typedef std::vector<LowLevelParam> LowLevelParamList; - typedef std::vector<EffectParamGL *> ParamList; - typedef std::vector<effect_stream::Desc> StreamList; - - static CGparameter GetEitherCgParameter( - const LowLevelParam &low_level_param) { - return low_level_param.vp_param ? - low_level_param.vp_param : low_level_param.fp_param; - } - - int GetLowLevelParamIndexByName(const char *name); - void AddLowLevelParams(CGprogram prog, CGenum name_space, bool vp); - void AddStreams(CGprogram prog, CGenum name_space); - - // Creates the low level structures. - void Initialize(); - - // Links a param into this effect. - void LinkParam(EffectParamGL *param); - - // Unlinks a param into this effect. - void UnlinkParam(EffectParamGL *param); - - CGprogram vertex_program_; - CGprogram fragment_program_; - // List of all the Params created. - ParamList params_; - StreamList streams_; - // List of all the Cg parameters present in either the vertex program or the - // fragment program. - LowLevelParamList low_level_params_; - - // List of the indices of the low level params that are samplers. - std::vector<unsigned int> sampler_params_; - bool update_samplers_; - - friend class EffectParamGL; - DISALLOW_COPY_AND_ASSIGN(EffectGL); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_EFFECT_GL_H_ diff --git a/o3d/gpu/command_buffer/service/effect_utils.cc b/o3d/gpu/command_buffer/service/effect_utils.cc deleted file mode 100644 index 021b49f..0000000 --- a/o3d/gpu/command_buffer/service/effect_utils.cc +++ /dev/null @@ -1,69 +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 effect related utilities. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/effect_utils.h" - -namespace command_buffer { - -bool ParseEffectData(unsigned int size, - const void *data, - String *vertex_program_entry, - String *fragment_program_entry, - String *effect_code) { - const char *data_char = static_cast<const char *>(data); - unsigned int index = 0; - - for (; index < size && data_char[index]; ++index) { } - if (index >= size) return false; - *vertex_program_entry = String(data_char, index); - ++index; // skip \0 - unsigned int fragment_program_entry_begin = index; - - for (; index < size && data_char[index]; ++index) { } - if (index >= size) return false; - *fragment_program_entry = String(data_char + fragment_program_entry_begin, - index - fragment_program_entry_begin); - ++index; // skip \0 - unsigned int effect_code_begin = index; - - // text doesn't have to be 0-terminated, but look for one so that we don't - // construct a std::string with a '\0' in it. - for (; index < size && data_char[index]; ++index) { } - *effect_code = String(data_char + effect_code_begin, - index - effect_code_begin); - return true; -} - -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/effect_utils.h b/o3d/gpu/command_buffer/service/effect_utils.h deleted file mode 100644 index ae22fb9..0000000 --- a/o3d/gpu/command_buffer/service/effect_utils.h +++ /dev/null @@ -1,54 +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 declares some effect related utilities. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_EFFECT_UTILS_H_ -#define GPU_COMMAND_BUFFER_SERVICE_CROSS_EFFECT_UTILS_H_ - -#include "gpu/command_buffer/common/types.h" - -namespace command_buffer { - -// This function parses the data passed to the CreateEffect commands, which -// follows the following format: -// vertex_program_entry \0 fragment_program_entry \0 effect_code -// It returns the various components. -bool ParseEffectData(unsigned int size, - const void *data, - String *vertex_program_entry, - String *fragment_program_entry, - String *effect_code); - -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_CROSS_EFFECT_UTILS_H_ diff --git a/o3d/gpu/command_buffer/service/effect_utils_test.cc b/o3d/gpu/command_buffer/service/effect_utils_test.cc deleted file mode 100644 index 4e42762..0000000 --- a/o3d/gpu/command_buffer/service/effect_utils_test.cc +++ /dev/null @@ -1,87 +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 unit tests for the effect utilities. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/cross/effect_utils.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace o3d { -namespace command_buffer { - -TEST(ParseEffectDataTest, ValidData) { - // Tests well-formed data. - const char kEffect[] = "vertex_entry\0fragment_entry\0effect code"; - String vertex_program_entry; - String fragment_program_entry; - String effect_code; - EXPECT_TRUE(ParseEffectData(sizeof(kEffect), kEffect, &vertex_program_entry, - &fragment_program_entry, &effect_code)); - EXPECT_EQ(vertex_program_entry, "vertex_entry"); - EXPECT_EQ(fragment_program_entry, "fragment_entry"); - EXPECT_EQ(effect_code, "effect code"); - - // The terminal \0 isn't needed, check that we parse correctly without it. - EXPECT_TRUE(ParseEffectData(sizeof(kEffect)-1, kEffect, - &vertex_program_entry, &fragment_program_entry, - &effect_code)); - EXPECT_EQ(vertex_program_entry, "vertex_entry"); - EXPECT_EQ(fragment_program_entry, "fragment_entry"); - EXPECT_EQ(effect_code, "effect code"); -} - -TEST(ParseEffectDataTest, InvalidData) { - const char kEffect[] = "vertex_entry\0fragment_entry\0effect code"; - String vertex_program_entry; - String fragment_program_entry; - String effect_code; - // 0-size - EXPECT_FALSE(ParseEffectData(0, kEffect, - &vertex_program_entry, &fragment_program_entry, - &effect_code)); - // Only vertex_entry, no \0 - EXPECT_FALSE(ParseEffectData(strlen("vertex_entry"), kEffect, - &vertex_program_entry, &fragment_program_entry, - &effect_code)); - // Only vertex_entry\0 - EXPECT_FALSE(ParseEffectData(strlen("vertex_entry") + 1, kEffect, - &vertex_program_entry, &fragment_program_entry, - &effect_code)); - // Only vertex_entry\0fragment_entry, no \0 - EXPECT_FALSE(ParseEffectData(strlen("vertex_entry.fragment_entry"), kEffect, - &vertex_program_entry, &fragment_program_entry, - &effect_code)); -} - -} // namespace command_buffer -} // namespace o3d diff --git a/o3d/gpu/command_buffer/service/gapi_d3d9.cc b/o3d/gpu/command_buffer/service/gapi_d3d9.cc deleted file mode 100644 index 8ca8cfd..0000000 --- a/o3d/gpu/command_buffer/service/gapi_d3d9.cc +++ /dev/null @@ -1,393 +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 GAPID3D9 class. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" - -namespace command_buffer { -namespace o3d { - -GAPID3D9::GAPID3D9() - : d3d_module_(NULL), - d3dx_module_(NULL), - d3d_(NULL), - d3d_device_(NULL), - hwnd_(NULL), - current_vertex_struct_(0), - validate_streams_(true), - max_vertices_(0), - current_effect_id_(0), - validate_effect_(true), - current_effect_(NULL), - vertex_buffers_(), - index_buffers_(), - vertex_structs_(), - back_buffer_surface_(NULL), - back_buffer_depth_surface_(NULL), - current_surface_id_(kInvalidResource), - current_depth_surface_id_(kInvalidResource), - direct3d_create9_(NULL), - get_shader_constant_table_(NULL), - create_effect_(NULL), - get_shader_input_semantics_(NULL) {} - -GAPID3D9::~GAPID3D9() {} - -// Initializes a D3D interface and device, and sets basic states. -bool GAPID3D9::Initialize() { - if (!FindDirect3DFunctions()) { - Destroy(); - return false; - } - - d3d_ = Direct3DCreate(D3D_SDK_VERSION); - if (NULL == d3d_) { - LOG(ERROR) << "Failed to create the initial D3D9 Interface"; - Destroy(); - return false; - } - d3d_device_ = NULL; - - D3DDISPLAYMODE d3ddm; - d3d_->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm); - // NOTE: make sure the backbuffer matches this format, as it is - // currently currently assumed to be 32-bit 8X8R8G8B - - D3DPRESENT_PARAMETERS d3dpp; - ZeroMemory(&d3dpp, sizeof(d3dpp)); - d3dpp.Windowed = TRUE; - d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - d3dpp.BackBufferFormat = d3ddm.Format; - d3dpp.EnableAutoDepthStencil = TRUE; - d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; - d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; // wait for vsync - // Note: SwapEffect=DISCARD is req. for multisample to function - // Note: AutoDepthStencilFormat is 16-bit (not the usual 8-bit) - - // query multisampling - const int kNumTypesToCheck = 4; - D3DMULTISAMPLE_TYPE multisample_types[] = { D3DMULTISAMPLE_5_SAMPLES, - D3DMULTISAMPLE_4_SAMPLES, - D3DMULTISAMPLE_2_SAMPLES, - D3DMULTISAMPLE_NONE }; - DWORD multisample_quality = 0; - for (int i = 0; i < kNumTypesToCheck; ++i) { - // check back-buffer for multisampling at level "i"; - // back buffer = 32-bit XRGB (i.e. no alpha) - if (SUCCEEDED(d3d_->CheckDeviceMultiSampleType( - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - D3DFMT_X8R8G8B8, - true, // result is windowed - multisample_types[i], - &multisample_quality))) { - // back buffer succeeded, now check depth-buffer - // depth buffer = 24-bit, stencil = 8-bit - // NOTE: 8-bit not 16-bit like the D3DPRESENT_PARAMETERS - if (SUCCEEDED(d3d_->CheckDeviceMultiSampleType( - D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - D3DFMT_D24S8, - true, // result is windowed - multisample_types[i], - &multisample_quality))) { - d3dpp.MultiSampleType = multisample_types[i]; - d3dpp.MultiSampleQuality = multisample_quality - 1; - break; - } - } - } - // D3DCREATE_FPU_PRESERVE is there because Firefox 3 relies on specific FPU - // flags for its UI rendering. Apparently Firefox 2 does not, though we don't - // currently propagate that info. - // TODO: check if FPU_PRESERVE has a significant perf hit, in which - // case find out if we can disable it for Firefox 2/other browsers, and/or if - // it makes sense to switch FPU flags before/after every DX call. - DWORD flags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE; - if (!SUCCEEDED(d3d_->CreateDevice(D3DADAPTER_DEFAULT, - D3DDEVTYPE_HAL, - hwnd_, - flags, - &d3dpp, - &d3d_device_))) { - LOG(ERROR) << "Failed to create the D3D Device"; - Destroy(); - return false; - } - // initialise the d3d graphics state. - HR(d3d_device_->SetRenderState(D3DRS_LIGHTING, FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_ZENABLE, TRUE)); - HR(d3d_device_->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE)); - return true; -} - -// Deletes the D3D9 Device and releases the D3D interface. -void GAPID3D9::Destroy() { - vertex_buffers_.DestroyAllResources(); - index_buffers_.DestroyAllResources(); - vertex_structs_.DestroyAllResources(); - effects_.DestroyAllResources(); - effect_params_.DestroyAllResources(); - textures_.DestroyAllResources(); - samplers_.DestroyAllResources(); - render_surfaces_.DestroyAllResources(); - depth_surfaces_.DestroyAllResources(); - if (d3d_device_) { - d3d_device_->Release(); - d3d_device_ = NULL; - } - if (d3d_) { - d3d_->Release(); - d3d_ = NULL; - } - if (d3dx_module_) { - FreeLibrary(d3dx_module_); - d3dx_module_ = NULL; - get_shader_constant_table_ = NULL; - create_effect_ = NULL; - get_shader_input_semantics_ = NULL; - } - if (d3d_module_) { - FreeLibrary(d3d_module_); - d3d_module_ = NULL; - direct3d_create9_ = NULL; - } -} - -// Begins the frame. -void GAPID3D9::BeginFrame() { - HR(d3d_device_->GetRenderTarget(0, &back_buffer_surface_)); - HR(d3d_device_->GetDepthStencilSurface(&back_buffer_depth_surface_)); - HR(d3d_device_->BeginScene()); -} - -// Ends the frame, presenting the back buffer. -void GAPID3D9::EndFrame() { - DirtyEffect(); - HR(d3d_device_->EndScene()); - HR(d3d_device_->Present(NULL, NULL, NULL, NULL)); - - // Release the back-buffer references. - back_buffer_surface_ = NULL; - back_buffer_depth_surface_ = NULL; -} - -// Clears the selected buffers. -void GAPID3D9::Clear(unsigned int buffers, - const RGBA &color, - float depth, - unsigned int stencil) { - DWORD flags = (buffers & kColor ? D3DCLEAR_TARGET : 0) | - (buffers & kDepth ? D3DCLEAR_ZBUFFER : 0) | - (buffers & kStencil ? D3DCLEAR_STENCIL : 0); - HR(d3d_device_->Clear(0, - NULL, - flags, - D3DCOLOR_COLORVALUE(color.red, - color.green, - color.blue, - color.alpha), - depth, - stencil)); -} - -// Sets the viewport. -void GAPID3D9::SetViewport(unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height, - float z_min, - float z_max) { - D3DVIEWPORT9 viewport = {x, y, width, height, z_min, z_max}; - HR(d3d_device_->SetViewport(&viewport)); -} - -// Converts an unsigned int RGBA color into an unsigned int ARGB (DirectX) -// color. -static unsigned int RGBAToARGB(unsigned int rgba) { - return (rgba >> 8) | (rgba << 24); -} - -// Sets the current VertexStruct. Just keep track of the ID. -parse_error::ParseError GAPID3D9::SetVertexStruct(ResourceId id) { - current_vertex_struct_ = id; - validate_streams_ = true; - return parse_error::kParseNoError; -} - -bool GAPID3D9::FindDirect3DFunctions() { - d3d_module_ = LoadLibrary(TEXT("d3d9.dll")); - if (NULL == d3d_module_) { - LOG(ERROR) << "Failed to load d3d9.dll"; - return false; - } - - direct3d_create9_ = reinterpret_cast<Direct3DCreate9Proc>( - GetProcAddress(d3d_module_, "Direct3DCreate9")); - if (NULL == direct3d_create9_) { - LOG(ERROR) << "Failed to find Direct3DCreate9 in d3d9.dll"; - Destroy(); - return false; - } - - d3dx_module_ = LoadLibrary(TEXT("d3dx9_36.dll")); - if (NULL == d3d_module_) { - LOG(ERROR) << "Failed to load d3dx9_36.dll"; - return false; - } - - get_shader_constant_table_ = reinterpret_cast<D3DXGetShaderConstantTableProc>( - GetProcAddress(d3dx_module_, "D3DXGetShaderConstantTable")); - if (NULL == get_shader_constant_table_) { - LOG(ERROR) << "Failed to find D3DXGetShaderConstantTable in d3dx9_36.dll"; - Destroy(); - return false; - } - - create_effect_ = reinterpret_cast<D3DXCreateEffectProc>( - GetProcAddress(d3dx_module_, "D3DXCreateEffect")); - if (NULL == create_effect_) { - LOG(ERROR) << "Failed to find D3DXCreateEffect in d3dx9_36.dll"; - Destroy(); - return false; - } - - get_shader_input_semantics_ = - reinterpret_cast<D3DXGetShaderInputSemanticsProc>( - GetProcAddress(d3dx_module_, "D3DXGetShaderInputSemantics")); - if (NULL == get_shader_input_semantics_) { - LOG(ERROR) << "Failed to find D3DXGetShaderInputSemantics in d3dx9_36.dll"; - Destroy(); - return false; - } - - return true; -} - -// Sets in D3D the input streams of the current vertex struct. -bool GAPID3D9::ValidateStreams() { - DCHECK(validate_streams_); - VertexStructD3D9 *vertex_struct = vertex_structs_.Get(current_vertex_struct_); - if (!vertex_struct) { - LOG(ERROR) << "Drawing with invalid streams."; - return false; - } - max_vertices_ = vertex_struct->SetStreams(this); - validate_streams_ = false; - return max_vertices_ > 0; -} - -// Converts a GAPID3D9::PrimitiveType to a D3DPRIMITIVETYPE. -static D3DPRIMITIVETYPE D3DPrimitive( - PrimitiveType primitive_type) { - switch (primitive_type) { - case kPoints: - return D3DPT_POINTLIST; - case kLines: - return D3DPT_LINELIST; - case kLineStrips: - return D3DPT_LINESTRIP; - case kTriangles: - return D3DPT_TRIANGLELIST; - case kTriangleStrips: - return D3DPT_TRIANGLESTRIP; - case kTriangleFans: - return D3DPT_TRIANGLEFAN; - default: - LOG(FATAL) << "Invalid primitive type"; - return D3DPT_POINTLIST; - } -} - -// Draws with the current vertex struct. -parse_error::ParseError GAPID3D9::Draw( - PrimitiveType primitive_type, - unsigned int first, - unsigned int count) { - if (validate_streams_ && !ValidateStreams()) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - if (validate_effect_ && !ValidateEffect()) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - DCHECK(current_effect_); - if (!current_effect_->CommitParameters()) { - return parse_error::kParseInvalidArguments; - } - if (first + count > max_vertices_) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - HR(d3d_device_->DrawPrimitive(D3DPrimitive(primitive_type), first, count)); - return parse_error::kParseNoError; -} - -// Draws with the current vertex struct. -parse_error::ParseError GAPID3D9::DrawIndexed( - PrimitiveType primitive_type, - ResourceId index_buffer_id, - unsigned int first, - unsigned int count, - unsigned int min_index, - unsigned int max_index) { - IndexBufferD3D9 *index_buffer = index_buffers_.Get(index_buffer_id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - if (validate_streams_ && !ValidateStreams()) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - if (validate_effect_ && !ValidateEffect()) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - DCHECK(current_effect_); - if (!current_effect_->CommitParameters()) { - return parse_error::kParseInvalidArguments; - } - if ((min_index >= max_vertices_) || (max_index > max_vertices_)) { - // TODO: add proper error management - return parse_error::kParseInvalidArguments; - } - - HR(d3d_device_->SetIndices(index_buffer->d3d_index_buffer())); - HR(d3d_device_->DrawIndexedPrimitive(D3DPrimitive(primitive_type), 0, - min_index, max_index - min_index + 1, - first, count)); - return parse_error::kParseNoError; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/gapi_d3d9.h b/o3d/gpu/command_buffer/service/gapi_d3d9.h deleted file mode 100644 index 1056dc1..0000000 --- a/o3d/gpu/command_buffer/service/gapi_d3d9.h +++ /dev/null @@ -1,508 +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 GAPID3D9 class, implementing the GAPI interface for -// D3D9. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_GAPI_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_GAPI_D3D9_H_ - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/geometry_d3d9.h" -#include "gpu/command_buffer/service/effect_d3d9.h" -#include "gpu/command_buffer/service/texture_d3d9.h" -#include "gpu/command_buffer/service/sampler_d3d9.h" -#include "gpu/command_buffer/service/render_surface_d3d9.h" - -namespace command_buffer { -namespace o3d { - -// This class implements the GAPI interface for D3D9. -class GAPID3D9 : public GAPIInterface { - public: - GAPID3D9(); - virtual ~GAPID3D9(); - - void set_hwnd(HWND hwnd) { hwnd_ = hwnd; } - HWND hwnd() const { return hwnd_; } - - // Initializes the graphics context, bound to a window. - // Returns: - // true if successful. - virtual bool Initialize(); - - // Destroys the graphics context. - virtual void Destroy(); - - // Implements the BeginFrame function for D3D9. - virtual void BeginFrame(); - - // Implements the EndFrame function for D3D9. - virtual void EndFrame(); - - // Implements the Clear function for D3D9. - virtual void Clear(unsigned int buffers, - const RGBA &color, - float depth, - unsigned int stencil); - - // Implements the SetViewport function for D3D9. - virtual void SetViewport(unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height, - float z_min, - float z_max); - - // Implements the CreateVertexBuffer function for D3D9. - virtual ParseError CreateVertexBuffer(ResourceId id, - unsigned int size, - unsigned int flags); - - // Implements the DestroyVertexBuffer function for D3D9. - virtual ParseError DestroyVertexBuffer(ResourceId id); - - // Implements the SetVertexBufferData function for D3D9. - virtual ParseError SetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data); - - // Implements the GetVertexBufferData function for D3D9. - virtual ParseError GetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data); - - // Implements the CreateIndexBuffer function for D3D9. - virtual ParseError CreateIndexBuffer(ResourceId id, - unsigned int size, - unsigned int flags); - - // Implements the DestroyIndexBuffer function for D3D9. - virtual ParseError DestroyIndexBuffer(ResourceId id); - - // Implements the SetIndexBufferData function for D3D9. - virtual ParseError SetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data); - - // Implements the GetIndexBufferData function for D3D9. - virtual ParseError GetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data); - - // Implements the CreateVertexStruct function for D3D9. - virtual ParseError CreateVertexStruct(ResourceId id, - unsigned int input_count); - - // Implements the DestroyVertexStruct function for D3D9. - virtual ParseError DestroyVertexStruct(ResourceId id); - - // Implements the SetVertexInput function for D3D9. - virtual ParseError SetVertexInput(ResourceId vertex_struct_id, - unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index); - - // Implements the SetVertexStruct function for D3D9. - virtual ParseError SetVertexStruct(ResourceId id); - - // Implements the Draw function for D3D9. - virtual ParseError Draw(PrimitiveType primitive_type, - unsigned int first, - unsigned int count); - - // Implements the DrawIndexed function for D3D9. - virtual ParseError DrawIndexed(PrimitiveType primitive_type, - ResourceId index_buffer_id, - unsigned int first, - unsigned int count, - unsigned int min_index, - unsigned int max_index); - - // Implements the CreateEffect function for D3D9. - virtual ParseError CreateEffect(ResourceId id, - unsigned int size, - const void *data); - - // Implements the DestroyEffect function for D3D9. - virtual ParseError DestroyEffect(ResourceId id); - - // Implements the SetEffect function for D3D9. - virtual ParseError SetEffect(ResourceId id); - - // Implements the GetParamCount function for D3D9. - virtual ParseError GetParamCount(ResourceId id, - unsigned int size, - void *data); - - // Implements the CreateParam function for D3D9. - virtual ParseError CreateParam(ResourceId param_id, - ResourceId effect_id, - unsigned int index); - - // Implements the CreateParamByName function for D3D9. - virtual ParseError CreateParamByName(ResourceId param_id, - ResourceId effect_id, - unsigned int size, - const void *name); - - // Implements the DestroyParam function for D3D9. - virtual ParseError DestroyParam(ResourceId id); - - // Implements the SetParamData function for D3D9. - virtual ParseError SetParamData(ResourceId id, - unsigned int size, - const void *data); - - // Implements the GetParamDesc function for D3D9. - virtual ParseError GetParamDesc(ResourceId id, - unsigned int size, - void *data); - - // Implements the GetStreamCount function for D3D9. - virtual ParseError GetStreamCount(ResourceId id, - unsigned int size, - void *data); - - // Implements the GetStreamDesc function for D3D9. - virtual ParseError GetStreamDesc(ResourceId id, - unsigned int index, - unsigned int size, - void *data); - - // Implements the CreateTexture2D function for D3D9. - virtual ParseError CreateTexture2D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the CreateTexture3D function for D3D9. - virtual ParseError CreateTexture3D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the CreateTextureCube function for D3D9. - virtual ParseError CreateTextureCube(ResourceId id, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the SetTextureData function for D3D9. - virtual ParseError SetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - - // Implements the GetTextureData function for D3D9. - virtual ParseError GetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - - // Implements the DestroyTexture function for D3D9. - virtual ParseError DestroyTexture(ResourceId id); - - // Implements the CreateSampler function for D3D9. - virtual ParseError CreateSampler(ResourceId id); - - // Implements the DestroySampler function for D3D9. - virtual ParseError DestroySampler(ResourceId id); - - // Implements the SetSamplerStates function for D3D9. - virtual ParseError SetSamplerStates(ResourceId id, - sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy); - - // Implements the SetSamplerBorderColor function for D3D9. - virtual ParseError SetSamplerBorderColor(ResourceId id, const RGBA &color); - - // Implements the SetSamplerTexture function for D3D9. - virtual ParseError SetSamplerTexture(ResourceId id, ResourceId texture_id); - - // Implements the SetScissor function for D3D9. - virtual void SetScissor(bool enable, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height); - - // Implements the SetPointLineRaster function for D3D9. - virtual void SetPointLineRaster(bool line_smooth, - bool point_sprite, - float point_size); - - // Implements the SetPolygonOffset function for D3D9. - virtual void SetPolygonOffset(float slope_factor, float units); - - // Implements the SetPolygonRaster function for D3D9. - virtual void SetPolygonRaster(PolygonMode fill_mode, - FaceCullMode cull_mode); - - // Implements the SetAlphaTest function for D3D9. - virtual void SetAlphaTest(bool enable, - float reference, - Comparison comp); - - // Implements the SetDepthTest function for D3D9. - virtual void SetDepthTest(bool enable, - bool write_enable, - Comparison comp); - - // Implements the SetStencilTest function for D3D9. - virtual void SetStencilTest(bool enable, - bool separate_ccw, - unsigned int write_mask, - unsigned int compare_mask, - unsigned int ref, - Uint32 func_ops); - - // Implements the SetColorWritefunction for D3D9. - virtual void SetColorWrite(bool red, - bool green, - bool blue, - bool alpha, - bool dither); - - // Implements the SetBlending function for D3D9. - virtual void SetBlending(bool enable, - bool separate_alpha, - BlendEq color_eq, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq alpha_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func); - - // Implements the SetBlendingColor function for D3D9. - virtual void SetBlendingColor(const RGBA &color); - - // Implements the CreateRenderSurface function for D3D9. - virtual ParseError CreateRenderSurface(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int mip_level, - unsigned int side, - ResourceId texture_id); - - // Implements the DestroyRenderSurface function for D3D9. - virtual ParseError DestroyRenderSurface(ResourceId id); - - // Implements the CreateDepthSurface function for D3D9. - virtual ParseError CreateDepthSurface(ResourceId id, - unsigned int width, - unsigned int height); - - // Implements teh DestroyDepthSurface function for D3D9. - virtual ParseError DestroyDepthSurface(ResourceId id); - - // Implements the SetRenderSurface function for D3D9. - virtual ParseError SetRenderSurface(ResourceId render_surface_id, - ResourceId depth_stencil_id); - - // Implements the SetBackSurfaces function for D3D9. - virtual void SetBackSurfaces(); - - // Gets the D3D9 device. - IDirect3DDevice9 *d3d_device() const { return d3d_device_; } - - // Gets a vertex buffer by resource ID. - VertexBufferD3D9 *GetVertexBuffer(ResourceId id) { - return vertex_buffers_.Get(id); - } - - // Gets a texture by resource ID. - TextureD3D9 *GetTexture(ResourceId id) { - return textures_.Get(id); - } - - // Gets a sampler by resource ID. - SamplerD3D9 *GetSampler(ResourceId id) { - return samplers_.Get(id); - } - - EffectD3D9 *current_effect() { return current_effect_; } - - // Direct3D functions cannot be called directly because the DLLs are loaded - // dynamically via LoadLibrary. If you need to add another Direct3D function - // add another function here, a typedef matching the signature and a member - // variable of that type below. Then add code to FindDirect3DFunctions to - // get the address of that function out of the DLL and assign it to the - // member variable. Be careful to initialize the value of the variable to - // NULL in the constructor and to set it to again NULL in Destroy. - - IDirect3D9* Direct3DCreate(UINT version) { - DCHECK(direct3d_create9_); - return direct3d_create9_(version); - } - - HRESULT D3DXGetShaderConstantTable(const DWORD* function, - LPD3DXCONSTANTTABLE* table) { - DCHECK(get_shader_constant_table_); - return get_shader_constant_table_(function, table); - } - - HRESULT D3DXCreateEffect(LPDIRECT3DDEVICE9 device, - LPCVOID src_data, - UINT src_data_len, - CONST D3DXMACRO * defines, - LPD3DXINCLUDE include, - DWORD flags, - LPD3DXEFFECTPOOL pool, - LPD3DXEFFECT * effect, - LPD3DXBUFFER * compilation_errors) { - DCHECK(create_effect_); - return create_effect_(device, src_data, src_data_len, defines, include, - flags, pool, effect, compilation_errors); - } - - HRESULT D3DXGetShaderInputSemantics(const DWORD* function, - D3DXSEMANTIC* semantics, - UINT* count) { - DCHECK(get_shader_input_semantics_); - return get_shader_input_semantics_(function, semantics, count); - } - - private: - bool FindDirect3DFunctions(); - - // Validates the current vertex struct to D3D, setting the streams. - bool ValidateStreams(); - // Validates the current effect to D3D. This sends the effect states to D3D. - bool ValidateEffect(); - // "Dirty" the current effect. This resets the effect states to D3D, and - // requires ValidateEffect() to be called before further draws occur. - void DirtyEffect(); - - // Module handle for d3d9.dll. - HMODULE d3d_module_; - - // Module handle for d3dx9_n.dll - HMODULE d3dx_module_; - - LPDIRECT3D9 d3d_; - LPDIRECT3DDEVICE9 d3d_device_; - HWND hwnd_; - ResourceId current_vertex_struct_; - bool validate_streams_; - unsigned int max_vertices_; - ResourceId current_effect_id_; - bool validate_effect_; - EffectD3D9 *current_effect_; - IDirect3DSurface9* back_buffer_surface_; - IDirect3DSurface9* back_buffer_depth_surface_; - ResourceId current_surface_id_; - ResourceId current_depth_surface_id_; - - ResourceMap<VertexBufferD3D9> vertex_buffers_; - ResourceMap<IndexBufferD3D9> index_buffers_; - ResourceMap<VertexStructD3D9> vertex_structs_; - ResourceMap<EffectD3D9> effects_; - ResourceMap<EffectParamD3D9> effect_params_; - ResourceMap<TextureD3D9> textures_; - ResourceMap<SamplerD3D9> samplers_; - ResourceMap<RenderSurfaceD3D9> render_surfaces_; - ResourceMap<RenderDepthStencilSurfaceD3D9> depth_surfaces_; - - typedef IDirect3D9* (WINAPI *Direct3DCreate9Proc)(UINT version); - Direct3DCreate9Proc direct3d_create9_; - - typedef HRESULT (WINAPI *D3DXGetShaderConstantTableProc)( - const DWORD* function, - LPD3DXCONSTANTTABLE* table); - D3DXGetShaderConstantTableProc get_shader_constant_table_; - - typedef HRESULT (WINAPI *D3DXCreateEffectProc)( - LPDIRECT3DDEVICE9 device, - LPCVOID src_data, - UINT src_data_len, - CONST D3DXMACRO * defines, - LPD3DXINCLUDE include, - DWORD flags, - LPD3DXEFFECTPOOL pool, - LPD3DXEFFECT * effect, - LPD3DXBUFFER * compilation_errors); - D3DXCreateEffectProc create_effect_; - - typedef HRESULT (WINAPI *D3DXGetShaderInputSemanticsProc)( - const DWORD* function, - D3DXSEMANTIC* semantics, - UINT* count); - D3DXGetShaderInputSemanticsProc get_shader_input_semantics_; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_GAPI_D3D9_H_ - diff --git a/o3d/gpu/command_buffer/service/gapi_decoder.h b/o3d/gpu/command_buffer/service/gapi_decoder.h deleted file mode 100644 index e043598..0000000 --- a/o3d/gpu/command_buffer/service/gapi_decoder.h +++ /dev/null @@ -1,81 +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 GAPI decoder class. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_GAPI_DECODER_H_ -#define GPU_COMMAND_BUFFER_SERVICE_CROSS_GAPI_DECODER_H_ - -#include "gpu/command_buffer/service/common_decoder.h" -#include "gpu/command_buffer/common/o3d_cmd_format.h" - -namespace command_buffer { -namespace o3d { - -class GAPIInterface; - -// This class implements the AsyncAPIInterface interface, decoding GAPI -// commands and sending them to a GAPI interface. -class GAPIDecoder : public CommonDecoder { - public: - typedef parse_error::ParseError ParseError; - - explicit GAPIDecoder(GAPIInterface *gapi) : gapi_(gapi) {} - virtual ~GAPIDecoder() {} - - // Overridden from AsyncAPIInterface. - virtual ParseError DoCommand(unsigned int command, - unsigned int arg_count, - const void* args); - - // Overridden from AsyncAPIInterface. - virtual const char* GetCommandName(unsigned int command_id) const; - - private: - // Generate a member function prototype for each command in an automated and - // typesafe way. - #define GPU_COMMAND_BUFFER_CMD_OP(name) \ - ParseError Handle ## name( \ - unsigned int arg_count, \ - const o3d::name& args); \ - - O3D_COMMAND_BUFFER_CMDS(GPU_COMMAND_BUFFER_CMD_OP) - - #undef GPU_COMMAND_BUFFER_CMD_OP - - GAPIInterface *gapi_; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_CROSS_GAPI_DECODER_H_ diff --git a/o3d/gpu/command_buffer/service/gapi_gl.cc b/o3d/gpu/command_buffer/service/gapi_gl.cc deleted file mode 100644 index c5f82de..0000000 --- a/o3d/gpu/command_buffer/service/gapi_gl.cc +++ /dev/null @@ -1,420 +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 GAPIGL class. - -#include "gpu/command_buffer/service/precompile.h" - -#include <build/build_config.h> - -#include "gpu/command_buffer/service/gapi_gl.h" - -#ifdef OS_LINUX -#include "gpu/command_buffer/service/linux/x_utils.h" -#endif // OS_LINUX - -namespace command_buffer { -namespace o3d { - -GAPIGL::GAPIGL() - : cg_context_(NULL), -#ifdef OS_LINUX - window_(NULL), -#endif -#ifdef OS_WIN - hwnd_(NULL), - device_context_(NULL), - gl_context_(NULL), -#endif - anti_aliased_(false), - current_vertex_struct_(kInvalidResource), - validate_streams_(true), - max_vertices_(0), - current_effect_id_(kInvalidResource), - validate_effect_(true), - current_effect_(NULL) { -} - -GAPIGL::~GAPIGL() { -} - -bool GAPIGL::Initialize() { - if (!InitPlatformSpecific()) - return false; - if (!InitCommon()) - return false; - CHECK_GL_ERROR(); - return true; -} - -#if defined(OS_WIN) -static const PIXELFORMATDESCRIPTOR kPixelFormatDescriptor = { - sizeof(kPixelFormatDescriptor), // Size of structure. - 1, // Default version. - PFD_DRAW_TO_WINDOW | // Window drawing support. - PFD_SUPPORT_OPENGL | // OpenGL support. - PFD_DOUBLEBUFFER, // Double buffering support (not stereo). - PFD_TYPE_RGBA, // RGBA color mode (not indexed). - 24, // 24 bit color mode. - 0, 0, 0, 0, 0, 0, // Don't set RGB bits & shifts. - 8, 0, // 8 bit alpha - 0, // No accumulation buffer. - 0, 0, 0, 0, // Ignore accumulation bits. - 24, // 24 bit z-buffer size. - 8, // 8-bit stencil buffer. - 0, // No aux buffer. - PFD_MAIN_PLANE, // Main drawing plane (not overlay). - 0, // Reserved. - 0, 0, 0, // Layer masks ignored. -}; - -LRESULT CALLBACK IntermediateWindowProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param) { - return ::DefWindowProc(window, message, w_param, l_param); -} - -// Helper routine that returns the highest quality pixel format supported on -// the current platform. Returns true upon success. -static bool GetWindowsPixelFormat(HWND window, - bool anti_aliased, - int* pixel_format) { - // We must initialize a GL context before we can determine the multi-sampling - // supported on the current hardware, so we create an intermediate window - // and context here. - HINSTANCE module_handle; - if (!::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT | - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, - reinterpret_cast<wchar_t*>(IntermediateWindowProc), - &module_handle)) { - return false; - } - - WNDCLASS intermediate_class; - intermediate_class.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - intermediate_class.lpfnWndProc = IntermediateWindowProc; - intermediate_class.cbClsExtra = 0; - intermediate_class.cbWndExtra = 0; - intermediate_class.hInstance = module_handle; - intermediate_class.hIcon = LoadIcon(NULL, IDI_APPLICATION); - intermediate_class.hCursor = LoadCursor(NULL, IDC_ARROW); - intermediate_class.hbrBackground = NULL; - intermediate_class.lpszMenuName = NULL; - intermediate_class.lpszClassName = L"Intermediate GL Window"; - - ATOM class_registration = ::RegisterClass(&intermediate_class); - if (!class_registration) { - return false; - } - - HWND intermediate_window = ::CreateWindow( - reinterpret_cast<wchar_t*>(class_registration), - L"", - WS_OVERLAPPEDWINDOW, - 0, 0, - CW_USEDEFAULT, CW_USEDEFAULT, - NULL, - NULL, - NULL, - NULL); - - if (!intermediate_window) { - ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), - module_handle); - return false; - } - - HDC intermediate_dc = ::GetDC(intermediate_window); - int format_index = ::ChoosePixelFormat(intermediate_dc, - &kPixelFormatDescriptor); - if (format_index == 0) { - DLOG(ERROR) << "Unable to get the pixel format for GL context."; - ::ReleaseDC(intermediate_window, intermediate_dc); - ::DestroyWindow(intermediate_window); - ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), - module_handle); - return false; - } - if (!::SetPixelFormat(intermediate_dc, format_index, - &kPixelFormatDescriptor)) { - DLOG(ERROR) << "Unable to set the pixel format for GL context."; - ::ReleaseDC(intermediate_window, intermediate_dc); - ::DestroyWindow(intermediate_window); - ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), - module_handle); - return false; - } - - // Store the pixel format without multisampling. - *pixel_format = format_index; - HGLRC gl_context = ::wglCreateContext(intermediate_dc); - if (::wglMakeCurrent(intermediate_dc, gl_context)) { - // GL context was successfully created and applied to the window's DC. - // Startup GLEW, the GL extensions wrangler. - GLenum glew_error = ::glewInit(); - if (glew_error == GLEW_OK) { - DLOG(INFO) << "Initialized GLEW " << ::glewGetString(GLEW_VERSION); - } else { - DLOG(ERROR) << "Unable to initialise GLEW : " - << ::glewGetErrorString(glew_error); - ::wglMakeCurrent(intermediate_dc, NULL); - ::wglDeleteContext(gl_context); - ::ReleaseDC(intermediate_window, intermediate_dc); - ::DestroyWindow(intermediate_window); - ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), - module_handle); - return false; - } - - // If the multi-sample extensions are present, query the api to determine - // the pixel format. - if (anti_aliased && WGLEW_ARB_pixel_format && WGLEW_ARB_multisample) { - int pixel_attributes[] = { - WGL_SAMPLES_ARB, 4, - WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, - WGL_SUPPORT_OPENGL_ARB, GL_TRUE, - WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, - WGL_COLOR_BITS_ARB, 24, - WGL_ALPHA_BITS_ARB, 8, - WGL_DEPTH_BITS_ARB, 24, - WGL_STENCIL_BITS_ARB, 8, - WGL_DOUBLE_BUFFER_ARB, GL_TRUE, - WGL_SAMPLE_BUFFERS_ARB, GL_TRUE, - 0, 0}; - - float pixel_attributes_f[] = {0, 0}; - int msaa_pixel_format; - unsigned int num_formats; - - // Query for the highest sampling rate supported, starting at 4x. - static const int kSampleCount[] = {4, 2}; - static const int kNumSamples = 2; - for (int sample = 0; sample < kNumSamples; ++sample) { - pixel_attributes[1] = kSampleCount[sample]; - if (GL_TRUE == ::wglChoosePixelFormatARB(intermediate_dc, - pixel_attributes, - pixel_attributes_f, - 1, - &msaa_pixel_format, - &num_formats)) { - *pixel_format = msaa_pixel_format; - break; - } - } - } - } - - ::wglMakeCurrent(intermediate_dc, NULL); - ::wglDeleteContext(gl_context); - ::ReleaseDC(intermediate_window, intermediate_dc); - ::DestroyWindow(intermediate_window); - ::UnregisterClass(reinterpret_cast<wchar_t*>(class_registration), - module_handle); - return true; -} -#endif - -bool GAPIGL::InitPlatformSpecific() { -#if defined(OS_WIN) - device_context_ = ::GetDC(hwnd_); - - int pixel_format; - - if (!GetWindowsPixelFormat(hwnd_, - anti_aliased(), - &pixel_format)) { - DLOG(ERROR) << "Unable to determine optimal pixel format for GL context."; - return false; - } - - if (!::SetPixelFormat(device_context_, pixel_format, - &kPixelFormatDescriptor)) { - DLOG(ERROR) << "Unable to set the pixel format for GL context."; - return false; - } - - gl_context_ = ::wglCreateContext(device_context_); - if (!gl_context_) { - DLOG(ERROR) << "Failed to create GL context."; - return false; - } - - if (!::wglMakeCurrent(device_context_, gl_context_)) { - DLOG(ERROR) << "Unable to make gl context current."; - return false; - } -#elif defined(OS_LINUX) - DCHECK(window_); - if (!window_->Initialize()) - return false; - if (!window_->MakeCurrent()) - return false; -#endif - - return true; -} - -bool GAPIGL::InitCommon() { - if (!InitGlew()) - return false; - InitCG(); - - // Initialize global GL settings. - // Tell GL that texture buffers can be single-byte aligned. - glPixelStorei(GL_PACK_ALIGNMENT, 1); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); - // Get the initial viewport (set to the window size) to set up the helper - // constant. - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); - SetViewport(viewport[0], viewport[1], viewport[2], viewport[3], 0.f, 1.f); - CHECK_GL_ERROR(); - - ::glGenFramebuffersEXT(1, &render_surface_framebuffer_); - CHECK_GL_ERROR(); - return true; -} - -void GAPIGL::InitCG() { - cg_context_ = cgCreateContext(); - // Set up all Cg State Assignments for OpenGL. - cgGLRegisterStates(cg_context_); - cgGLSetDebugMode(CG_FALSE); - // Enable the profiles we use. - cgGLEnableProfile(CG_PROFILE_ARBVP1); - cgGLEnableProfile(CG_PROFILE_ARBFP1); -} - -bool GAPIGL::InitGlew() { - DLOG(INFO) << "Initializing GL and GLEW for GAPI."; - - GLenum glew_error = glewInit(); - if (glew_error != GLEW_OK) { - DLOG(ERROR) << "Unable to initialise GLEW : " - << ::glewGetErrorString(glew_error); - return false; - } - - // Check to see that we can use the OpenGL vertex attribute APIs - // TODO(petersont): Return false if this check fails, but because some - // Intel hardware does not support OpenGL 2.0, yet does support all of the - // extensions we require, we only log an error. A future CL should change - // this check to ensure that all of the extension strings we require are - // present. - if (!GLEW_VERSION_2_0) { - DLOG(ERROR) << "GL drivers do not have OpenGL 2.0 functionality."; - } - - bool extensions_found = true; - if (!GLEW_ARB_vertex_buffer_object) { - // NOTE: Linux NVidia drivers claim to support OpenGL 2.0 when using - // indirect rendering (e.g. remote X), but it is actually lying. The - // ARB_vertex_buffer_object functions silently no-op (!) when using - // indirect rendering, leading to crashes. Fortunately, in that case, the - // driver claims to not support ARB_vertex_buffer_object, so fail in that - // case. - DLOG(ERROR) << "GL drivers do not support vertex buffer objects."; - extensions_found = false; - } - if (!GLEW_EXT_framebuffer_object) { - DLOG(ERROR) << "GL drivers do not support framebuffer objects."; - extensions_found = false; - } - // Check for necessary extensions - if (!GLEW_VERSION_2_0 && !GLEW_EXT_stencil_two_side) { - DLOG(ERROR) << "Two sided stencil extension missing."; - extensions_found = false; - } - if (!GLEW_VERSION_1_4 && !GLEW_EXT_blend_func_separate) { - DLOG(ERROR) <<"Separate blend func extension missing."; - extensions_found = false; - } - if (!GLEW_VERSION_2_0 && !GLEW_EXT_blend_equation_separate) { - DLOG(ERROR) << "Separate blend function extension missing."; - extensions_found = false; - } - if (!extensions_found) - return false; - - return true; -} - -void GAPIGL::Destroy() { - vertex_buffers_.DestroyAllResources(); - index_buffers_.DestroyAllResources(); - vertex_structs_.DestroyAllResources(); - effects_.DestroyAllResources(); - effect_params_.DestroyAllResources(); - // textures_.DestroyAllResources(); - // samplers_.DestroyAllResources(); - cgDestroyContext(cg_context_); - cg_context_ = NULL; -#ifdef OS_LINUX - DCHECK(window_); - window_->Destroy(); -#endif -} - -void GAPIGL::BeginFrame() { -} - -void GAPIGL::EndFrame() { -#ifdef OS_WIN - ::SwapBuffers(device_context_); -#endif - -#ifdef OS_LINUX - DCHECK(window_); - window_->SwapBuffers(); -#endif - - CHECK_GL_ERROR(); -} - -void GAPIGL::Clear(unsigned int buffers, - const RGBA &color, - float depth, - unsigned int stencil) { - glClearColor(color.red, color.green, color.blue, color.alpha); - glClearDepth(depth); - glClearStencil(stencil); - glClear((buffers & kColor ? GL_COLOR_BUFFER_BIT : 0) | - (buffers & kDepth ? GL_DEPTH_BUFFER_BIT : 0) | - (buffers & kStencil ? GL_STENCIL_BUFFER_BIT : 0)); - CHECK_GL_ERROR(); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/gapi_gl.h b/o3d/gpu/command_buffer/service/gapi_gl.h deleted file mode 100644 index 0719fba..0000000 --- a/o3d/gpu/command_buffer/service/gapi_gl.h +++ /dev/null @@ -1,465 +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 GAPIGL class, implementing the GAPI interface for -// GL. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_GAPI_GL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_GAPI_GL_H_ - -#include <build/build_config.h> -#include <GL/glew.h> -#include <Cg/cg.h> -#include <Cg/cgGL.h> -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/gl_utils.h" -#include "gpu/command_buffer/service/effect_gl.h" -#include "gpu/command_buffer/service/geometry_gl.h" -#include "gpu/command_buffer/service/render_surface_gl.h" -#include "gpu/command_buffer/service/sampler_gl.h" -#include "gpu/command_buffer/service/texture_gl.h" - -namespace command_buffer { -namespace o3d { -#if defined(OS_LINUX) -class XWindowWrapper; -#endif // defined(OS_LINUX) - -// This class implements the GAPI interface for GL. -class GAPIGL : public GAPIInterface { - public: - GAPIGL(); - virtual ~GAPIGL(); - -#if defined(OS_LINUX) - void set_window_wrapper(XWindowWrapper *window) { window_ = window; } -#elif defined(OS_WIN) - void set_hwnd(HWND hwnd) { hwnd_ = hwnd; } - - HWND hwnd() const { - return hwnd_; - } -#endif - - // Initializes the graphics context, bound to a window. - // Returns: - // true if successful. - virtual bool Initialize(); - - // Initailizes Cg. - void InitCG(); - - // Helper function for Initailize that inits just glew. - bool InitGlew(); - - // Destroys the graphics context. - virtual void Destroy(); - - // Implements the BeginFrame function for GL. - virtual void BeginFrame(); - - // Implements the EndFrame function for GL. - virtual void EndFrame(); - - // Implements the Clear function for GL. - virtual void Clear(unsigned int buffers, - const RGBA &color, - float depth, - unsigned int stencil); - - // Implements the SetViewport function for GL. - virtual void SetViewport(unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height, - float z_min, - float z_max); - - // Implements the CreateVertexBuffer function for GL. - virtual ParseError CreateVertexBuffer(ResourceId id, - unsigned int size, - unsigned int flags); - - // Implements the DestroyVertexBuffer function for GL. - virtual ParseError DestroyVertexBuffer(ResourceId id); - - // Implements the SetVertexBufferData function for GL. - virtual ParseError SetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data); - - // Implements the GetVertexBufferData function for GL. - virtual ParseError GetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data); - - // Implements the CreateIndexBuffer function for GL. - virtual ParseError CreateIndexBuffer(ResourceId id, - unsigned int size, - unsigned int flags); - - // Implements the DestroyIndexBuffer function for GL. - virtual ParseError DestroyIndexBuffer(ResourceId id); - - // Implements the SetIndexBufferData function for GL. - virtual ParseError SetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data); - - // Implements the GetIndexBufferData function for GL. - virtual ParseError GetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data); - - // Implements the CreateVertexStruct function for GL. - virtual ParseError CreateVertexStruct(ResourceId id, - unsigned int input_count); - - // Implements the DestroyVertexStruct function for GL. - virtual ParseError DestroyVertexStruct(ResourceId id); - - // Implements the SetVertexInput function for GL. - virtual ParseError SetVertexInput(ResourceId vertex_struct_id, - unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index); - - // Implements the SetVertexStruct function for GL. - virtual ParseError SetVertexStruct(ResourceId id); - - // Implements the Draw function for GL. - virtual ParseError Draw(PrimitiveType primitive_type, - unsigned int first, - unsigned int count); - - // Implements the DrawIndexed function for GL. - virtual ParseError DrawIndexed(PrimitiveType primitive_type, - ResourceId index_buffer_id, - unsigned int first, - unsigned int count, - unsigned int min_index, - unsigned int max_index); - - // Implements the CreateEffect function for GL. - virtual ParseError CreateEffect(ResourceId id, - unsigned int size, - const void *data); - - // Implements the DestroyEffect function for GL. - virtual ParseError DestroyEffect(ResourceId id); - - // Implements the SetEffect function for GL. - virtual ParseError SetEffect(ResourceId id); - - // Implements the GetParamCount function for GL. - virtual ParseError GetParamCount(ResourceId id, - unsigned int size, - void *data); - - // Implements the CreateParam function for GL. - virtual ParseError CreateParam(ResourceId param_id, - ResourceId effect_id, - unsigned int index); - - // Implements the CreateParamByName function for GL. - virtual ParseError CreateParamByName(ResourceId param_id, - ResourceId effect_id, - unsigned int size, - const void *name); - - // Implements the DestroyParam function for GL. - virtual ParseError DestroyParam(ResourceId id); - - // Implements the SetParamData function for GL. - virtual ParseError SetParamData(ResourceId id, - unsigned int size, - const void *data); - - // Implements the GetParamDesc function for GL. - virtual ParseError GetParamDesc(ResourceId id, - unsigned int size, - void *data); - - // Implements the GetStreamCount function for GL. - virtual ParseError GetStreamCount(ResourceId id, - unsigned int size, - void *data); - - // Implements the GetStreamDesc function for GL. - virtual ParseError GetStreamDesc(ResourceId id, - unsigned int index, - unsigned int size, - void *data); - - // Implements the CreateTexture2D function for GL. - virtual ParseError CreateTexture2D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the CreateTexture3D function for GL. - virtual ParseError CreateTexture3D(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the CreateTextureCube function for GL. - virtual ParseError CreateTextureCube(ResourceId id, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Implements the SetTextureData function for GL. - virtual ParseError SetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - - // Implements the GetTextureData function for GL. - virtual ParseError GetTextureData(ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - - // Implements the DestroyTexture function for GL. - virtual ParseError DestroyTexture(ResourceId id); - - // Implements the CreateSampler function for GL. - virtual ParseError CreateSampler(ResourceId id); - - // Implements the DestroySampler function for GL. - virtual ParseError DestroySampler(ResourceId id); - - // Implements the SetSamplerStates function for GL. - virtual ParseError SetSamplerStates(ResourceId id, - sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy); - - // Implements the SetSamplerBorderColor function for GL. - virtual ParseError SetSamplerBorderColor(ResourceId id, const RGBA &color); - - // Implements the SetSamplerTexture function for GL. - virtual ParseError SetSamplerTexture(ResourceId id, ResourceId texture_id); - - // Implements the SetScissor function for GL. - virtual void SetScissor(bool enable, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height); - - // Implements the SetPointLineRaster function for GL. - virtual void SetPointLineRaster(bool line_smooth, - bool point_sprite, - float point_size); - - // Implements the SetPolygonOffset function for GL. - virtual void SetPolygonOffset(float slope_factor, float units); - - // Implements the SetPolygonRaster function for GL. - virtual void SetPolygonRaster(PolygonMode fill_mode, - FaceCullMode cull_mode); - - // Implements the SetAlphaTest function for GL. - virtual void SetAlphaTest(bool enable, - float reference, - Comparison comp); - - // Implements the SetDepthTest function for GL. - virtual void SetDepthTest(bool enable, - bool write_enable, - Comparison comp); - - // Implements the SetStencilTest function for GL. - virtual void SetStencilTest(bool enable, - bool separate_ccw, - unsigned int write_mask, - unsigned int compare_mask, - unsigned int ref, - Uint32 func_ops); - - // Implements the SetColorWritefunction for GL. - virtual void SetColorWrite(bool red, - bool green, - bool blue, - bool alpha, - bool dither); - - // Implements the SetBlending function for GL. - virtual void SetBlending(bool enable, - bool separate_alpha, - BlendEq color_eq, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq alpha_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func); - - // Implements the SetBlendingColor function for GL. - virtual void SetBlendingColor(const RGBA &color); - - // Implements the CreateRenderSurface function for GL. - virtual ParseError CreateRenderSurface(ResourceId id, - unsigned int width, - unsigned int height, - unsigned int mip_level, - unsigned int side, - ResourceId texture_id); - - // Implements the DestroyRenderSurface function for GL. - virtual ParseError DestroyRenderSurface(ResourceId id); - - // Implements the CreateDepthSurface function for GL. - virtual ParseError CreateDepthSurface(ResourceId id, - unsigned int width, - unsigned int height); - - // Implements the DestroyDepthSurface function for GL. - virtual ParseError DestroyDepthSurface(ResourceId id); - - // Implements the SetRenderSurface function for GL. - virtual ParseError SetRenderSurface(ResourceId render_surface_id, - ResourceId depth_stencil_id); - - // Implements the SetBackSurfaces function for GL. - virtual void SetBackSurfaces(); - - // Gets a vertex buffer by resource ID. - VertexBufferGL *GetVertexBuffer(ResourceId id) { - return vertex_buffers_.Get(id); - } - - // Gets a texture by resource ID. - TextureGL *GetTexture(ResourceId id) { - return textures_.Get(id); - } - - // Gets a sampler by resource ID. - SamplerGL *GetSampler(ResourceId id) { - return samplers_.Get(id); - } - void set_anti_aliased(bool anti_aliased) { anti_aliased_ = anti_aliased; } - - bool anti_aliased() const { return anti_aliased_; } - - CGcontext cg_context() const { return cg_context_; } - - EffectGL *current_effect() const { return current_effect_; } - // "Dirty" the current effect. This resets the vertex and fragment program, - // and requires ValidateEffect() to be called before further draws occur. - void DirtyEffect(); - private: - bool InitPlatformSpecific(); - bool InitCommon(); - // Validates the current vertex struct to GL, setting the vertex attributes. - bool ValidateStreams(); - // Validates the current effect to GL. This sets the vertex and fragment - // programs, and updates parameters if needed. - bool ValidateEffect(); - - CGcontext cg_context_; - -#if defined(OS_LINUX) - XWindowWrapper *window_; -#elif defined(OS_WIN) - // Handle to the GL device. - HWND hwnd_; - HDC device_context_; - HGLRC gl_context_; -#endif - - bool anti_aliased_; - ResourceId current_vertex_struct_; - bool validate_streams_; - unsigned int max_vertices_; - ResourceId current_effect_id_; - bool validate_effect_; - EffectGL *current_effect_; - ResourceId current_surface_id_; - ResourceId current_depth_surface_id_; - GLuint render_surface_framebuffer_; - - ResourceMap<VertexBufferGL> vertex_buffers_; - ResourceMap<IndexBufferGL> index_buffers_; - ResourceMap<VertexStructGL> vertex_structs_; - ResourceMap<EffectGL> effects_; - ResourceMap<EffectParamGL> effect_params_; - ResourceMap<TextureGL> textures_; - ResourceMap<SamplerGL> samplers_; - ResourceMap<RenderSurfaceGL> render_surfaces_; - ResourceMap<RenderDepthStencilSurfaceGL> depth_surfaces_; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_GAPI_GL_H_ diff --git a/o3d/gpu/command_buffer/service/geometry_d3d9.cc b/o3d/gpu/command_buffer/service/geometry_d3d9.cc deleted file mode 100644 index c3b5eb5..0000000 --- a/o3d/gpu/command_buffer/service/geometry_d3d9.cc +++ /dev/null @@ -1,439 +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 D3D9 versions of the -// VertexBuffer, IndexBuffer and VertexStruct resources. -// This file also contains the related GAPID3D9 function implementations. - -#include "gpu/command_buffer/service/precompile.h" - -#include <algorithm> - -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/geometry_d3d9.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" - -namespace command_buffer { -namespace o3d { - -// Destroys the D3D9 vertex buffer. -VertexBufferD3D9::~VertexBufferD3D9() { - DCHECK(d3d_vertex_buffer_ != NULL); - if (d3d_vertex_buffer_) { - d3d_vertex_buffer_->Release(); - d3d_vertex_buffer_ = NULL; - } -} - -// Creates a D3D9 vertex buffer. -void VertexBufferD3D9::Create(GAPID3D9 *gapi) { - DCHECK(d3d_vertex_buffer_ == NULL); - - DWORD d3d_usage = (flags() & vertex_buffer::kDynamic) ? D3DUSAGE_DYNAMIC : 0; - D3DPOOL d3d_pool = D3DPOOL_MANAGED; - HR(gapi->d3d_device()->CreateVertexBuffer(size(), d3d_usage, 0, d3d_pool, - &d3d_vertex_buffer_, NULL)); -} - -// Sets the data into the D3D9 vertex buffer, using Lock() and memcpy. -bool VertexBufferD3D9::SetData(unsigned int offset, - unsigned int size, - const void *data) { - if (!d3d_vertex_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized VertexBufferD3D9."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on VertexBufferD3D9::SetData."; - return false; - } - void *ptr = NULL; - DWORD lock_flags = 0; - // If we are setting the full buffer, discard the old data. That's only - // possible to do for a dynamic d3d vertex buffer. - if ((offset == 0) && (size == this->size()) && - (flags() & vertex_buffer::kDynamic)) - lock_flags = D3DLOCK_DISCARD; - HR(d3d_vertex_buffer_->Lock(offset, size, &ptr, lock_flags)); - memcpy(ptr, data, size); - HR(d3d_vertex_buffer_->Unlock()); - return true; -} - -// Gets the data from the D3D9 vertex buffer, using Lock() and memcpy. -bool VertexBufferD3D9::GetData(unsigned int offset, - unsigned int size, - void *data) { - if (!d3d_vertex_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized VertexBufferD3D9."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on VertexBufferD3D9::SetData."; - return false; - } - void *ptr = NULL; - DWORD lock_flags = D3DLOCK_READONLY; - HR(d3d_vertex_buffer_->Lock(offset, size, &ptr, lock_flags)); - memcpy(data, ptr, size); - HR(d3d_vertex_buffer_->Unlock()); - return true; -} - -// Destroys the D3D9 index buffer. -IndexBufferD3D9::~IndexBufferD3D9() { - DCHECK(d3d_index_buffer_ != NULL); - if (d3d_index_buffer_) { - d3d_index_buffer_->Release(); - d3d_index_buffer_ = NULL; - } -} - -// Creates a D3D9 index buffer. -void IndexBufferD3D9::Create(GAPID3D9 *gapi) { - DCHECK(d3d_index_buffer_ == NULL); - - DWORD d3d_usage = (flags() & index_buffer::kDynamic) ? D3DUSAGE_DYNAMIC : 0; - D3DFORMAT d3d_format = - (flags() & index_buffer::kIndex32Bit) ? D3DFMT_INDEX32 : D3DFMT_INDEX16; - D3DPOOL d3d_pool = D3DPOOL_MANAGED; - HR(gapi->d3d_device()->CreateIndexBuffer(size(), d3d_usage, d3d_format, - d3d_pool, &d3d_index_buffer_, - NULL)); -} - -// Sets the data into the D3D9 index buffer, using Lock() and memcpy. -bool IndexBufferD3D9::SetData(unsigned int offset, - unsigned int size, - const void *data) { - if (!d3d_index_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized IndexBufferD3D9."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on IndexBufferD3D9::SetData."; - return false; - } - void *ptr = NULL; - DWORD lock_flags = 0; - // If we are setting the full buffer, discard the old data. That's only - // possible to do for a dynamic d3d index buffer. - if ((offset == 0) && (size == this->size()) && - (flags() & index_buffer::kDynamic)) - lock_flags = D3DLOCK_DISCARD; - HR(d3d_index_buffer_->Lock(offset, size, &ptr, lock_flags)); - memcpy(ptr, data, size); - HR(d3d_index_buffer_->Unlock()); - return true; -} - -// Gets the data from the D3D9 index buffer, using Lock() and memcpy. -bool IndexBufferD3D9::GetData(unsigned int offset, - unsigned int size, - void *data) { - if (!d3d_index_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized IndexBufferD3D9."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on IndexBufferD3D9::SetData."; - return false; - } - void *ptr = NULL; - DWORD lock_flags = D3DLOCK_READONLY; - HR(d3d_index_buffer_->Lock(offset, size, &ptr, lock_flags)); - memcpy(data, ptr, size); - HR(d3d_index_buffer_->Unlock()); - return true; -} - -// Sets the input element in the VertexStruct resource. -void VertexStructD3D9::SetInput(unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index) { - Element &element = GetElement(input_index); - element.vertex_buffer = vertex_buffer_id; - element.offset = offset; - element.stride = stride; - element.type = type; - element.semantic = semantic; - element.semantic_index = semantic_index; - dirty_ = true; -} - -// Sets the vdecl and stream sources in D3D9. Compiles them if needed. -unsigned int VertexStructD3D9::SetStreams(GAPID3D9 *gapi) { - IDirect3DDevice9 *d3d_device = gapi->d3d_device(); - if (dirty_) Compile(d3d_device); - HR(d3d_device->SetVertexDeclaration(d3d_vertex_decl_)); - unsigned int max_vertices = UINT_MAX; - for (unsigned int i = 0; i < streams_.size(); ++i) { - const StreamPair &pair = streams_[i]; - VertexBufferD3D9 *vertex_buffer = gapi->GetVertexBuffer(pair.first); - if (!vertex_buffer) { - max_vertices = 0; - continue; - } - HR(d3d_device->SetStreamSource(i, vertex_buffer->d3d_vertex_buffer(), 0, - pair.second)); - - // TODO(apatrick): A zero size stride is valid. It means the first element - // in the vertex buffer will be used for every vertex. There doesn't seem - // to be enough information here to determine whether a zero stride - // vertex buffer is big enough to contain a single element. - if (pair.second != 0) { - max_vertices = std::min(max_vertices, - vertex_buffer->size() / pair.second); - } - } - return max_vertices; -} - -// Converts a vertex_struct::Type to a D3DDECLTYPE. -static D3DDECLTYPE D3DType(vertex_struct::Type type) { - switch (type) { - case vertex_struct::kFloat1: - return D3DDECLTYPE_FLOAT1; - case vertex_struct::kFloat2: - return D3DDECLTYPE_FLOAT2; - case vertex_struct::kFloat3: - return D3DDECLTYPE_FLOAT3; - case vertex_struct::kFloat4: - return D3DDECLTYPE_FLOAT4; - case vertex_struct::kUChar4N: - return D3DDECLTYPE_UBYTE4N; - case vertex_struct::kNumTypes: - break; - } - LOG(FATAL) << "Invalid type"; - return D3DDECLTYPE_FLOAT1; -} - -// Converts a vertex_struct::Semantic to a D3DDECLUSAGE. -static D3DDECLUSAGE D3DUsage(vertex_struct::Semantic semantic) { - switch (semantic) { - case vertex_struct::kPosition: - return D3DDECLUSAGE_POSITION; - case vertex_struct::kNormal: - return D3DDECLUSAGE_NORMAL; - case vertex_struct::kColor: - return D3DDECLUSAGE_COLOR; - case vertex_struct::kTexCoord: - return D3DDECLUSAGE_TEXCOORD; - case vertex_struct::kNumSemantics: - break; - } - LOG(FATAL) << "Invalid type"; - return D3DDECLUSAGE_POSITION; -} - -// Destroys the d3d vertex declaration. -VertexStructD3D9::~VertexStructD3D9() { - Destroy(); -} - -void VertexStructD3D9::Destroy() { - if (d3d_vertex_decl_) { - d3d_vertex_decl_->Release(); - d3d_vertex_decl_ = NULL; - } - streams_.clear(); -} - -// Compiles a stream map and a d3d vertex declaration from the list of inputs. -// 2 inputs that use the same vertex buffer and stride will use the same -// d3d stream. -void VertexStructD3D9::Compile(IDirect3DDevice9 *d3d_device) { - DCHECK(dirty_); - Destroy(); - streams_.reserve(count_); - scoped_array<D3DVERTEXELEMENT9> d3d_elements( - new D3DVERTEXELEMENT9[count_ + 1]); - memset(d3d_elements.get(), 0, sizeof(D3DVERTEXELEMENT9) * (count_ + 1)); - // build streams_ like a set, but the order matters. - for (unsigned int i = 0; i < count_ ; ++i) { - Element &element = GetElement(i); - D3DVERTEXELEMENT9 &d3d_element = d3d_elements[i]; - StreamPair pair(element.vertex_buffer, element.stride); - std::vector<StreamPair>::iterator it = - std::find(streams_.begin(), streams_.end(), pair); - unsigned int stream_index = 0; - if (it == streams_.end()) { - streams_.push_back(pair); - stream_index = static_cast<unsigned int>(streams_.size() - 1); - } else { - stream_index = it - streams_.begin(); - } - d3d_element.Stream = stream_index; - d3d_element.Offset = element.offset; - d3d_element.Type = D3DType(element.type); - d3d_element.Usage = D3DUsage(element.semantic); - d3d_element.UsageIndex = element.semantic_index; - } - D3DVERTEXELEMENT9 &end = d3d_elements[count_]; - end.Stream = 0xFF; - end.Type = D3DDECLTYPE_UNUSED; - HR(d3d_device->CreateVertexDeclaration(d3d_elements.get(), - &d3d_vertex_decl_)); - dirty_ = false; -} - -// Creates and assigns a VertexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::CreateVertexBuffer( - ResourceId id, - unsigned int size, - unsigned int flags) { - VertexBufferD3D9 *vertex_buffer = new VertexBufferD3D9(size, flags); - vertex_buffer->Create(this); - vertex_buffers_.Assign(id, vertex_buffer); - return parse_error::kParseNoError; -} - -// Destroys a VertexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::DestroyVertexBuffer(ResourceId id) { - return vertex_buffers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data into the VertexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::SetVertexBufferData( - ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) { - VertexBufferD3D9 *vertex_buffer = vertex_buffers_.Get(id); - if (!vertex_buffer) return parse_error::kParseInvalidArguments; - return vertex_buffer->SetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data from the VertexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::GetVertexBufferData( - ResourceId id, - unsigned int offset, - unsigned int size, - void *data) { - VertexBufferD3D9 *vertex_buffer = vertex_buffers_.Get(id); - if (!vertex_buffer) return parse_error::kParseInvalidArguments; - return vertex_buffer->GetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Creates and assigns an IndexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::CreateIndexBuffer( - ResourceId id, - unsigned int size, - unsigned int flags) { - IndexBufferD3D9 *index_buffer = new IndexBufferD3D9(size, flags); - index_buffer->Create(this); - index_buffers_.Assign(id, index_buffer); - return parse_error::kParseNoError; -} - -// Destroys an IndexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::DestroyIndexBuffer(ResourceId id) { - return index_buffers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data into the IndexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::SetIndexBufferData( - ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) { - IndexBufferD3D9 *index_buffer = index_buffers_.Get(id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - return index_buffer->SetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data from the IndexBufferD3D9 resource. -parse_error::ParseError GAPID3D9::GetIndexBufferData( - ResourceId id, - unsigned int offset, - unsigned int size, - void *data) { - IndexBufferD3D9 *index_buffer = index_buffers_.Get(id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - return index_buffer->GetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Creates and assigns a VertexStructD3D9 resource. -parse_error::ParseError GAPID3D9::CreateVertexStruct( - ResourceId id, unsigned int input_count) { - if (id == current_vertex_struct_) validate_streams_ = true; - VertexStructD3D9 *vertex_struct = new VertexStructD3D9(input_count); - vertex_structs_.Assign(id, vertex_struct); - return parse_error::kParseNoError; -} - -// Destroys a VertexStructD3D9 resource. -parse_error::ParseError GAPID3D9::DestroyVertexStruct(ResourceId id) { - if (id == current_vertex_struct_) validate_streams_ = true; - return vertex_structs_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Sets an input into a VertexStructD3D9 resource. -parse_error::ParseError GAPID3D9::SetVertexInput( - ResourceId vertex_struct_id, - unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index) { - if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true; - VertexStructD3D9 *vertex_struct = vertex_structs_.Get(vertex_struct_id); - if (!vertex_struct || input_index >= vertex_struct->count()) - return parse_error::kParseInvalidArguments; - vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type, - semantic, semantic_index); - return parse_error::kParseNoError; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/geometry_d3d9.h b/o3d/gpu/command_buffer/service/geometry_d3d9.h deleted file mode 100644 index 50f534d..0000000 --- a/o3d/gpu/command_buffer/service/geometry_d3d9.h +++ /dev/null @@ -1,126 +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 D3D9 versions of geometry-related -// resource classes. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_D3D9_H_ - -#include <vector> -#include <utility> -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/resource.h" - -namespace command_buffer { -namespace o3d { - -class GAPID3D9; - -// D3D9 version of VertexBuffer. -class VertexBufferD3D9 : public VertexBuffer { - public: - VertexBufferD3D9(unsigned int size, unsigned int flags) - : VertexBuffer(size, flags), - d3d_vertex_buffer_(NULL) {} - virtual ~VertexBufferD3D9(); - // Creates the D3D vertex buffer. - void Create(GAPID3D9 *gapi); - // Sets the data into the D3D vertex buffer. - bool SetData(unsigned int offset, unsigned int size, const void *data); - // Gets the data from the D3D vertex buffer. - bool GetData(unsigned int offset, unsigned int size, void *data); - - // Gets the D3D vertex buffer. - IDirect3DVertexBuffer9 * d3d_vertex_buffer() { return d3d_vertex_buffer_; } - private: - IDirect3DVertexBuffer9 *d3d_vertex_buffer_; - DISALLOW_COPY_AND_ASSIGN(VertexBufferD3D9); -}; - -// D3D9 version of IndexBuffer. -class IndexBufferD3D9 : public IndexBuffer { - public: - IndexBufferD3D9(unsigned int size, unsigned int flags) - : IndexBuffer(size, flags), - d3d_index_buffer_(NULL) {} - virtual ~IndexBufferD3D9(); - // Creates the D3D index buffer. - void Create(GAPID3D9 *gapi); - // Sets the data into the D3D index buffer. - bool SetData(unsigned int offset, unsigned int size, const void *data); - // Gets the data from the D3D index buffer. - bool GetData(unsigned int offset, unsigned int size, void *data); - - // Gets the D3D index buffer. - IDirect3DIndexBuffer9 *d3d_index_buffer() const { return d3d_index_buffer_; } - private: - IDirect3DIndexBuffer9 *d3d_index_buffer_; - DISALLOW_COPY_AND_ASSIGN(IndexBufferD3D9); -}; - -// D3D9 version of VertexStruct. -class VertexStructD3D9 : public VertexStruct { - public: - explicit VertexStructD3D9(unsigned int count) - : VertexStruct(count), - dirty_(true), - d3d_vertex_decl_(NULL) {} - virtual ~VertexStructD3D9(); - // Adds an input to the vertex struct. - void SetInput(unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index); - // Sets the input streams to D3D. - unsigned int SetStreams(GAPID3D9 *gapi); - private: - // Destroys the vertex declaration and stream map. - void Destroy(); - // Compiles the vertex declaration and stream map. - void Compile(IDirect3DDevice9 *d3d_device); - - bool dirty_; - typedef std::pair<ResourceId, unsigned int> StreamPair; - std::vector<StreamPair> streams_; - IDirect3DVertexDeclaration9 *d3d_vertex_decl_; - DISALLOW_COPY_AND_ASSIGN(VertexStructD3D9); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_D3D9_H_ diff --git a/o3d/gpu/command_buffer/service/geometry_gl.cc b/o3d/gpu/command_buffer/service/geometry_gl.cc deleted file mode 100644 index 13390a9..0000000 --- a/o3d/gpu/command_buffer/service/geometry_gl.cc +++ /dev/null @@ -1,554 +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 VertexBufferGL, IndexBufferGL -// and VertexStructGL classes, as well as the geometry-related GAPI functions. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_gl.h" -#include "gpu/command_buffer/service/geometry_gl.h" - -namespace command_buffer { -namespace o3d { - -VertexBufferGL::~VertexBufferGL() { - glDeleteBuffers(1, &gl_buffer_); - CHECK_GL_ERROR(); -} - -// Creates the GL buffer object. -void VertexBufferGL::Create() { - glGenBuffers(1, &gl_buffer_); - glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); - GLenum usage = - (flags() & vertex_buffer::kDynamic) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; - glBufferData(GL_ARRAY_BUFFER, size(), NULL, usage); - CHECK_GL_ERROR(); -} - -// Sets the data into the GL buffer object. -bool VertexBufferGL::SetData(unsigned int offset, - unsigned int size, - const void *data) { - if (!gl_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized VertexBufferGL."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on VertexBufferGL::SetData."; - return false; - } - glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); - glBufferSubData(GL_ARRAY_BUFFER, offset, size, data); - CHECK_GL_ERROR(); - return true; -} - -// Gets the data from the GL buffer object. -bool VertexBufferGL::GetData(unsigned int offset, - unsigned int size, - void *data) { - if (!gl_buffer_) { - LOG(ERROR) << "Calling GetData on a non-initialized VertexBufferGL."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on VertexBufferGL::GetData."; - return false; - } - glBindBuffer(GL_ARRAY_BUFFER, gl_buffer_); - glGetBufferSubData(GL_ARRAY_BUFFER, offset, size, data); - CHECK_GL_ERROR(); - return true; -} - -IndexBufferGL::~IndexBufferGL() { - glDeleteBuffers(1, &gl_buffer_); -} - -// Creates the GL buffer object. -void IndexBufferGL::Create() { - glGenBuffers(1, &gl_buffer_); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); - GLenum usage = - (flags() & vertex_buffer::kDynamic) ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; - glBufferData(GL_ELEMENT_ARRAY_BUFFER, size(), NULL, usage); - CHECK_GL_ERROR(); -} - -// Sets the data into the GL buffer object. -bool IndexBufferGL::SetData(unsigned int offset, - unsigned int size, - const void *data) { - if (!gl_buffer_) { - LOG(ERROR) << "Calling SetData on a non-initialized IndexBufferGL."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on IndexBufferGL::SetData."; - return false; - } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, data); - CHECK_GL_ERROR(); - return true; -} - -// Gets the data from the GL buffer object. -bool IndexBufferGL::GetData(unsigned int offset, - unsigned int size, - void *data) { - if (!gl_buffer_) { - LOG(ERROR) << "Calling GetData on a non-initialized IndexBufferGL."; - return false; - } - if ((offset >= this->size()) || (offset + size > this->size())) { - LOG(ERROR) << "Invalid size or offset on IndexBufferGL::GetData."; - return false; - } - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_buffer_); - glGetBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offset, size, data); - CHECK_GL_ERROR(); - return true; -} - -// Sets the input element in the VertexStruct resource. -void VertexStructGL::SetInput(unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index) { - Element &element = GetElement(input_index); - element.vertex_buffer = vertex_buffer_id; - element.offset = offset; - element.stride = stride; - element.type = type; - element.semantic = semantic; - element.semantic_index = semantic_index; - dirty_ = true; -} - -namespace { - -inline ptrdiff_t OffsetToPtrDiff(unsigned int offset) { - return static_cast<ptrdiff_t>(offset); -} - -inline void* OffsetToPtr(ptrdiff_t offset) { - return reinterpret_cast<void*>(offset); -} - -} // anonymous namespace - -unsigned int VertexStructGL::SetStreams(GAPIGL *gapi) { - if (dirty_) Compile(); - unsigned int max_vertices = UINT_MAX; - for (unsigned int i = 0; i < kMaxAttribs; ++i) { - const AttribDesc &attrib = attribs_[i]; - if (attrib.vertex_buffer_id == kInvalidResource) { - if (i == 0) { - glDisableClientState(GL_VERTEX_ARRAY); - } else { - glDisableVertexAttribArray(i); - } - } else { - glEnableVertexAttribArray(i); - VertexBufferGL *vertex_buffer = - gapi->GetVertexBuffer(attrib.vertex_buffer_id); - if (!vertex_buffer) { - glDisableVertexAttribArray(i); - max_vertices = 0; - continue; - } - DCHECK_NE(vertex_buffer->gl_buffer(), 0); - glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer->gl_buffer()); - glVertexAttribPointer(i, attrib.size, attrib.type, attrib.normalized, - attrib.stride, - OffsetToPtr(attrib.offset)); - max_vertices = std::min(max_vertices, - vertex_buffer->size() / attrib.stride); - } - } - CHECK_GL_ERROR(); - return max_vertices; -} - -namespace { - -// from the ARB_vertex_program extension, at -// http://www.opengl.org/registry/specs/ARB/vertex_program.txt -// -// Generic -// Attribute Conventional Attribute Conventional Attribute Command -// --------- ------------------------ ------------------------------ -// 0 vertex position Vertex -// 1 vertex weights 0-3 WeightARB, VertexWeightEXT -// 2 normal Normal -// 3 primary color Color -// 4 secondary color SecondaryColorEXT -// 5 fog coordinate FogCoordEXT -// 6 - - -// 7 - - -// 8 texture coordinate set 0 MultiTexCoord(TEXTURE0, ...) -// 9 texture coordinate set 1 MultiTexCoord(TEXTURE1, ...) -// 10 texture coordinate set 2 MultiTexCoord(TEXTURE2, ...) -// 11 texture coordinate set 3 MultiTexCoord(TEXTURE3, ...) -// 12 texture coordinate set 4 MultiTexCoord(TEXTURE4, ...) -// 13 texture coordinate set 5 MultiTexCoord(TEXTURE5, ...) -// 14 texture coordinate set 6 MultiTexCoord(TEXTURE6, ...) -// 15 texture coordinate set 7 MultiTexCoord(TEXTURE7, ...) -// 8+n texture coordinate set n MultiTexCoord(TEXTURE0+n, ...) -// -// Note: we only accept at most 8 texture coordinates for maximum compatibility -// with DirectX. - -inline unsigned int GetAttribIndex(vertex_struct::Semantic semantic, - unsigned int semantic_index) { - switch (semantic) { - case vertex_struct::kPosition: - DCHECK_EQ(semantic_index, 0); - return 0; - case vertex_struct::kNormal: - DCHECK_EQ(semantic_index, 0); - return 2; - case vertex_struct::kColor: - DCHECK_LT(semantic_index, 2U); - return 3 + semantic_index; - case vertex_struct::kTexCoord: - DCHECK_LT(semantic_index, 8U); - return 8 + semantic_index; - default: - DLOG(FATAL) << "Not reached."; - return 0; - } -} - -inline void ExtractSizeTypeNormalized(vertex_struct::Type type, - GLint *size, - GLenum *gl_type, - GLboolean *normalized) { - switch (type) { - case vertex_struct::kFloat1: - case vertex_struct::kFloat2: - case vertex_struct::kFloat3: - case vertex_struct::kFloat4: - *size = type - vertex_struct::kFloat1 + 1; - *gl_type = GL_FLOAT; - *normalized = false; - break; - case vertex_struct::kUChar4N: - *size = 4; - *gl_type = GL_UNSIGNED_BYTE; - *normalized = true; - break; - default: - DLOG(FATAL) << "Not reached."; - break; - } -} - -} // anonymous namespace - -#ifndef COMPILER_MSVC -// Although required by the spec, this causes problems on MSVC. It is needed by -// GCC. -const unsigned int VertexStructGL::kMaxAttribs; -#endif - -void VertexStructGL::Compile() { - DCHECK(dirty_); - for (unsigned int i = 0; i < kMaxAttribs; ++i) { - attribs_[i].vertex_buffer_id = kInvalidResource; - } - for (unsigned int i = 0; i < count_ ; ++i) { - const Element &element = GetElement(i); - unsigned int index = GetAttribIndex(element.semantic, - element.semantic_index); - DCHECK_LT(index, kMaxAttribs); - AttribDesc &attrib = attribs_[index]; - attrib.vertex_buffer_id = element.vertex_buffer; - ExtractSizeTypeNormalized(element.type, &attrib.size, &attrib.type, - &attrib.normalized); - attrib.stride = element.stride; - attrib.offset = OffsetToPtrDiff(element.offset); - } - dirty_ = false; -} - -parse_error::ParseError GAPIGL::CreateVertexBuffer(ResourceId id, - unsigned int size, - unsigned int flags) { - VertexBufferGL *vertex_buffer = new VertexBufferGL(size, flags); - vertex_buffer->Create(); - vertex_buffers_.Assign(id, vertex_buffer); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyVertexBuffer(ResourceId id) { - return vertex_buffers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) { - VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); - if (!vertex_buffer) return parse_error::kParseInvalidArguments; - return vertex_buffer->SetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::GetVertexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data) { - VertexBufferGL *vertex_buffer = vertex_buffers_.Get(id); - if (!vertex_buffer) return parse_error::kParseInvalidArguments; - return vertex_buffer->GetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::CreateIndexBuffer(ResourceId id, - unsigned int size, - unsigned int flags) { - IndexBufferGL *index_buffer = new IndexBufferGL(size, flags); - index_buffer->Create(); - index_buffers_.Assign(id, index_buffer); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyIndexBuffer(ResourceId id) { - return index_buffers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - const void *data) { - IndexBufferGL *index_buffer = index_buffers_.Get(id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - return index_buffer->SetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::GetIndexBufferData(ResourceId id, - unsigned int offset, - unsigned int size, - void *data) { - IndexBufferGL *index_buffer = index_buffers_.Get(id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - return index_buffer->GetData(offset, size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::CreateVertexStruct( - ResourceId id, - unsigned int input_count) { - if (id == current_vertex_struct_) validate_streams_ = true; - VertexStructGL *vertex_struct = new VertexStructGL(input_count); - vertex_structs_.Assign(id, vertex_struct); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyVertexStruct(ResourceId id) { - if (id == current_vertex_struct_) validate_streams_ = true; - return vertex_structs_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetVertexInput( - ResourceId vertex_struct_id, - unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index) { - switch (semantic) { - case vertex_struct::kPosition: - if (semantic_index != 0) { - return parse_error::kParseInvalidArguments; - } - break; - case vertex_struct::kNormal: - if (semantic_index != 0) { - return parse_error::kParseInvalidArguments; - } - break; - case vertex_struct::kColor: - if (semantic_index >= 2) { - return parse_error::kParseInvalidArguments; - } - break; - case vertex_struct::kTexCoord: - if (semantic_index >= 8) { - return parse_error::kParseInvalidArguments; - } - break; - default: - DLOG(FATAL) << "Not reached."; - break; - } - if (vertex_buffer_id == current_vertex_struct_) validate_streams_ = true; - VertexStructGL *vertex_struct = vertex_structs_.Get(vertex_struct_id); - if (!vertex_struct || input_index >= vertex_struct->count()) - return parse_error::kParseInvalidArguments; - vertex_struct->SetInput(input_index, vertex_buffer_id, offset, stride, type, - semantic, semantic_index); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::SetVertexStruct(ResourceId id) { - current_vertex_struct_ = id; - validate_streams_ = true; - return parse_error::kParseNoError; -} - -bool GAPIGL::ValidateStreams() { - DCHECK(validate_streams_); - VertexStructGL *vertex_struct = vertex_structs_.Get(current_vertex_struct_); - if (!vertex_struct) { - LOG(ERROR) << "Drawing with invalid streams."; - return false; - } - max_vertices_ = vertex_struct->SetStreams(this); - validate_streams_ = false; - return max_vertices_ > 0; -} - -namespace { - -void PrimitiveTypeToGL(o3d::PrimitiveType primitive_type, - GLenum *gl_mode, - unsigned int *count) { - switch (primitive_type) { - case o3d::kPoints: - *gl_mode = GL_POINTS; - break; - case o3d::kLines: - *gl_mode = GL_LINES; - *count *= 2; - break; - case o3d::kLineStrips: - *gl_mode = GL_LINE_STRIP; - ++*count; - break; - case o3d::kTriangles: - *gl_mode = GL_TRIANGLES; - *count *= 3; - break; - case o3d::kTriangleStrips: - *gl_mode = GL_TRIANGLE_STRIP; - *count += 2; - break; - case o3d::kTriangleFans: - *gl_mode = GL_TRIANGLE_FAN; - *count += 2; - break; - default: - LOG(FATAL) << "Invalid primitive type"; - break; - } -} - -} // anonymous namespace - -parse_error::ParseError GAPIGL::Draw(o3d::PrimitiveType primitive_type, - unsigned int first, - unsigned int count) { - if (validate_effect_ && !ValidateEffect()) { - return parse_error::kParseInvalidArguments; - } - DCHECK(current_effect_); - if (validate_streams_ && !ValidateStreams()) { - return parse_error::kParseInvalidArguments; - } - GLenum gl_mode = GL_POINTS; - PrimitiveTypeToGL(primitive_type, &gl_mode, &count); - if (first + count > max_vertices_) { - return parse_error::kParseInvalidArguments; - } - glDrawArrays(gl_mode, first, count); - CHECK_GL_ERROR(); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DrawIndexed( - o3d::PrimitiveType primitive_type, - ResourceId index_buffer_id, - unsigned int first, - unsigned int count, - unsigned int min_index, - unsigned int max_index) { - IndexBufferGL *index_buffer = index_buffers_.Get(index_buffer_id); - if (!index_buffer) return parse_error::kParseInvalidArguments; - if (validate_effect_ && !ValidateEffect()) { - return parse_error::kParseInvalidArguments; - } - DCHECK(current_effect_); - if (validate_streams_ && !ValidateStreams()) { - return parse_error::kParseInvalidArguments; - } - if ((min_index >= max_vertices_) || (max_index > max_vertices_)) { - return parse_error::kParseInvalidArguments; - } - GLenum gl_mode = GL_POINTS; - PrimitiveTypeToGL(primitive_type, &gl_mode, &count); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer->gl_buffer()); - GLenum index_type = (index_buffer->flags() & index_buffer::kIndex32Bit) ? - GL_UNSIGNED_INT : GL_UNSIGNED_SHORT; - GLuint index_size = (index_buffer->flags() & index_buffer::kIndex32Bit) ? - sizeof(GLuint) : sizeof(GLushort); // NOLINT - GLuint offset = first * index_size; - if (offset + count * index_size > index_buffer->size()) { - return parse_error::kParseInvalidArguments; - } - glDrawRangeElements(gl_mode, min_index, max_index, count, index_type, - OffsetToPtr(offset)); - CHECK_GL_ERROR(); - return parse_error::kParseNoError; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/geometry_gl.h b/o3d/gpu/command_buffer/service/geometry_gl.h deleted file mode 100644 index b4d4b5f..0000000 --- a/o3d/gpu/command_buffer/service/geometry_gl.h +++ /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 declares the VertexBufferGL, IndexBufferGL and VertexStructGL -// classes. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_GL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_GL_H_ - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/resource.h" -#include "gpu/command_buffer/service/gl_utils.h" - -namespace command_buffer { -namespace o3d { - -class GAPIGL; - -// GL version of VertexBuffer. -class VertexBufferGL : public VertexBuffer { - public: - VertexBufferGL(unsigned int size, unsigned int flags) - : VertexBuffer(size, flags), - gl_buffer_(0) {} - virtual ~VertexBufferGL(); - - // Creates the GL vertex buffer. - void Create(); - - // Sets the data into the GL vertex buffer. - bool SetData(unsigned int offset, unsigned int size, const void *data); - - // Gets the data from the GL vertex buffer. - bool GetData(unsigned int offset, unsigned int size, void *data); - - // Gets the GL vertex buffer. - GLuint gl_buffer() const { return gl_buffer_; } - - private: - GLuint gl_buffer_; - DISALLOW_COPY_AND_ASSIGN(VertexBufferGL); -}; - -// GL version of IndexBuffer. -class IndexBufferGL : public IndexBuffer { - public: - IndexBufferGL(unsigned int size, unsigned int flags) - : IndexBuffer(size, flags), - gl_buffer_(0) {} - virtual ~IndexBufferGL(); - - // Creates the GL index buffer. - void Create(); - - // Sets the data into the GL index buffer. - bool SetData(unsigned int offset, unsigned int size, const void *data); - - // Gets the data from the GL index buffer. - bool GetData(unsigned int offset, unsigned int size, void *data); - - // Gets the GL index buffer. - GLuint gl_buffer() const { return gl_buffer_; } - - private: - GLuint gl_buffer_; - DISALLOW_COPY_AND_ASSIGN(IndexBufferGL); -}; - -// GL version of VertexStruct. -class VertexStructGL : public VertexStruct { - public: - explicit VertexStructGL(unsigned int count) - : VertexStruct(count), - dirty_(true) {} - virtual ~VertexStructGL() {} - - // Adds an input to the vertex struct. - void SetInput(unsigned int input_index, - ResourceId vertex_buffer_id, - unsigned int offset, - unsigned int stride, - vertex_struct::Type type, - vertex_struct::Semantic semantic, - unsigned int semantic_index); - - // Sets the input streams to GL. - unsigned int SetStreams(GAPIGL *gapi); - - private: - static const unsigned int kMaxAttribs = 16; - - // This struct describes the parameters that are passed to - // glVertexAttribPointer. - struct AttribDesc { - ResourceId vertex_buffer_id; - GLint size; - GLenum type; - GLboolean normalized; - GLsizei stride; - ptrdiff_t offset; - }; - - // Compiles the vertex declaration into the attribute array. - void Compile(); - - bool dirty_; - AttribDesc attribs_[kMaxAttribs]; - DISALLOW_COPY_AND_ASSIGN(VertexStructGL); -}; - - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_GEOMETRY_GL_H_ diff --git a/o3d/gpu/command_buffer/service/gl_utils.h b/o3d/gpu/command_buffer/service/gl_utils.h index 292b2d6..b9c10f5 100644 --- a/o3d/gpu/command_buffer/service/gl_utils.h +++ b/o3d/gpu/command_buffer/service/gl_utils.h @@ -30,7 +30,7 @@ */ -// This file includes all the necessary GL/Cg headers and implements some useful +// This file includes all the necessary GL headers and implements some useful // utilities. #ifndef GPU_COMMAND_BUFFER_SERVICE_GL_UTILS_H_ @@ -40,8 +40,6 @@ #if defined(OS_WIN) #include <GL/wglew.h> #endif -#include <Cg/cg.h> -#include <Cg/cgGL.h> #include <build/build_config.h> #define GL_GLEXT_PROTOTYPES diff --git a/o3d/gpu/command_buffer/service/render_surface_d3d9.cc b/o3d/gpu/command_buffer/service/render_surface_d3d9.cc deleted file mode 100644 index a3880f8..0000000 --- a/o3d/gpu/command_buffer/service/render_surface_d3d9.cc +++ /dev/null @@ -1,230 +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 D3D9 versions of the render surface resources, -// as well as the related GAPID3D9 function implementations. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/render_surface_d3d9.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" -#include "gpu/command_buffer/service/texture_d3d9.h" - - -namespace command_buffer { -namespace o3d { - -RenderSurfaceD3D9::RenderSurfaceD3D9(int width, - int height, - int mip_level, - int side, - TextureD3D9 *texture, - IDirect3DSurface9 *direct3d_surface) - : width_(width), - height_(height), - mip_level_(mip_level), - texture_(texture), - direct3d_surface_(direct3d_surface) { - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - DCHECK_GT(mip_level, -1); - DCHECK(texture); -} - -RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi, - int width, - int height, - int mip_level, - int side, - TextureD3D9 *texture) { - DCHECK(gapi); - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - DCHECK_GT(mip_level, -1); - DCHECK(texture); - CComPtr<IDirect3DSurface9> direct3d_surface_handle; - bool success = - texture->CreateRenderSurface(width, height, mip_level, side, - &direct3d_surface_handle); - if (!success || direct3d_surface_handle == NULL) { - // If the surface was not created properly, delete and return nothing. - return NULL; - } - RenderSurfaceD3D9 *render_surface = - new RenderSurfaceD3D9(width, - height, - mip_level, - side, - texture, - direct3d_surface_handle); - return render_surface; -} - -RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9( - int width, - int height, - IDirect3DSurface9 *direct3d_surface) - : width_(width), - height_(height), - direct3d_surface_(direct3d_surface) { - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); -} - -RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create( - GAPID3D9 *gapi, - int width, - int height) { - DCHECK(gapi); - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - - CComPtr<IDirect3DSurface9> direct3d_surface; - gapi->d3d_device()->CreateDepthStencilSurface( - width, - height, - D3DFMT_D24S8, // d3d format - D3DMULTISAMPLE_NONE, // multisampling type - 0, // multisample quality level - FALSE, // z-buffer discarding disabled - &direct3d_surface, - NULL); // This parameter is required to be NULL. - if (direct3d_surface == NULL) { - return NULL; - } - RenderDepthStencilSurfaceD3D9 *depth_stencil = - new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface); - return depth_stencil; -} - -// GAPI Interface functions --------------------------------------------------- - -// Copies the data from a texture resource. -parse_error::ParseError GAPID3D9::CreateRenderSurface( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int mip_level, - unsigned int side, - ResourceId texture_id) { - if (id == current_surface_id_) { - // This will delete the current surface which would be bad. - return parse_error::kParseInvalidArguments; - } - TextureD3D9 *texture = textures_.Get(texture_id); - if (!texture->render_surfaces_enabled()) { - return parse_error::kParseInvalidArguments; - } else { - RenderSurfaceD3D9 *render_surface = RenderSurfaceD3D9::Create(this, - width, - height, - mip_level, - side, - texture); - if (render_surface == NULL) { - return parse_error::kParseInvalidArguments; - } - render_surfaces_.Assign(id, render_surface); - } - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::DestroyRenderSurface(ResourceId id) { - if (id == current_surface_id_) { - return parse_error::kParseInvalidArguments; - } - return render_surfaces_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPID3D9::CreateDepthSurface( - ResourceId id, - unsigned int width, - unsigned int height) { - if (id == current_depth_surface_id_) { - // This will delete the current surface which would be bad. - return parse_error::kParseInvalidArguments; - } - RenderDepthStencilSurfaceD3D9 *depth_surface = - RenderDepthStencilSurfaceD3D9::Create(this, width, height); - if (depth_surface == NULL) { - return parse_error::kParseInvalidArguments; - } - depth_surfaces_.Assign(id, depth_surface); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::DestroyDepthSurface(ResourceId id) { - if (id == current_depth_surface_id_) { - return parse_error::kParseInvalidArguments; - } - return depth_surfaces_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPID3D9::SetRenderSurface( - ResourceId render_surface_id, - ResourceId depth_stencil_id) { - RenderSurfaceD3D9 *d3d_render_surface = - render_surfaces_.Get(render_surface_id); - RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface = - depth_surfaces_.Get(depth_stencil_id); - - if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) { - return parse_error::kParseInvalidArguments; - } - - IDirect3DSurface9 *d3d_surface = - d3d_render_surface ? d3d_render_surface->direct3d_surface() : NULL; - IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ? - d3d_render_depth_surface->direct3d_surface() : NULL; - - // Get the device and set the render target and the depth stencil surface. - IDirect3DDevice9 *device = this->d3d_device(); - - HR(device->SetRenderTarget(0, d3d_surface)); - HR(device->SetDepthStencilSurface(d3d_depth_surface)); - current_surface_id_ = render_surface_id; - current_depth_surface_id_ = depth_stencil_id; - return parse_error::kParseNoError; -} - -void GAPID3D9::SetBackSurfaces() { - // Get the device and set the render target and the depth stencil surface. - IDirect3DDevice9 *device = this->d3d_device(); - HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_)); - HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_)); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/render_surface_d3d9.h b/o3d/gpu/command_buffer/service/render_surface_d3d9.h deleted file mode 100644 index 4769f1f..0000000 --- a/o3d/gpu/command_buffer/service/render_surface_d3d9.h +++ /dev/null @@ -1,161 +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 GPU_COMMAND_BUFFER_SERVICE_RENDER_SURFACE_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_RENDER_SURFACE_D3D9_H_ - -// This file contains the definition of the D3D9 versions of -// render surface-related resource classes. - -#include <d3d9.h> -#include "base/scoped_ptr.h" -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/resource.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/texture_d3d9.h" - -namespace command_buffer { -namespace o3d { - -class GAPID3D9; - -// The RenderSurfaceD3D class represents a render surface resource in the d3d -// backend of the command buffer server. -class RenderSurfaceD3D9 : public RenderSurface { - public: - - // Creates a render surface resource based on D3D. - // Parameters: - // width - width of the surface to be created. Must match width of texture - // at mip_level. - // height - height of the surface to be created. Must match width of - // texture at mip_level. - // mip_level - mip level of the texture to which the render surface maps. - // side - side of a cube if texture is a cube texture. Does not apply to - // texture 2d's. - // texture - the texture to which this render surface maps. Not owned by - // the RenderSurfaceD3D9. - // direct3d_surface - a surface to be used as this render surface's - // rendering surface. The new RenderSurfaceD3D9 will own the - // direct3d_surface. - RenderSurfaceD3D9(int width, - int height, - int mip_level, - int side, - TextureD3D9 *texture, - IDirect3DSurface9 *direct3d_surface); - - // Destructor for the render surface. - virtual ~RenderSurfaceD3D9() {} - - // Performs the setup necessary to create a render surface resource based on - // D3D and returns a new one if possibe. - // Parameters: - // gapi - the gapi interface to D3D. - // width - width of the surface to be created. Must match width of texture - // at mip_level. - // height - height of the surface to be created. Must match width of - // texture at mip_level. - // mip_level - mip level of the texture to which the render surface maps. - // side - side of a cube if texture is a cube texture. Does not apply to - // texture 2d's. - // texture - the texture to which this render surface maps. - // Returns: - // a new RenderSurfaceD3D9 or NULL on failure - static RenderSurfaceD3D9* Create(GAPID3D9 *gapi, - int width, - int height, - int mip_level, - int side, - TextureD3D9 *texture); - - // Returns a reference to the actual direct3d surface that is rendered to. - IDirect3DSurface9* direct3d_surface() const { - return direct3d_surface_; - } - private: - CComPtr<IDirect3DSurface9> direct3d_surface_; - int width_; - int height_; - int mip_level_; - TextureD3D9 *texture_; - DISALLOW_COPY_AND_ASSIGN(RenderSurfaceD3D9); -}; - -// The RenderDepthStencilSurfaceD3D class represents a depth stencil surface -// resource in the d3d backend of the command buffer server. -class RenderDepthStencilSurfaceD3D9 : public RenderDepthStencilSurface { - public: - - // Creates a depth stencil surface resource based on D3D. - // Parameters: - // width - width of the surface to be created. - // height - height of the surface to be created. - // direct3d_surface - a surface to be used as this depth stencil surface's - // rendering rendering surface. The new RenderDepthStencilSurfaceD3D9 - // will own the direct3d_surface. - RenderDepthStencilSurfaceD3D9(int width, - int height, - IDirect3DSurface9 *direct3d_surface); - - // Destructor for the depth stencil surface. - virtual ~RenderDepthStencilSurfaceD3D9() {} - - - // Performs the setup necessary to create a depth stencil surface resource - // based on D3D and returns a new one if possibe. - // Parameters: - // gapi - the gapi interface to D3D. - // width - width of the surface to be created. - // height - height of the surface to be created. - // Returns: - // a new RenderDepthStencilSurfaceD3D9 or NULL on failure. - static RenderDepthStencilSurfaceD3D9* Create(GAPID3D9 *gapi, - int width, - int height); - - // Returns a reference to the actual direct3d surface that is rendered to. - IDirect3DSurface9* direct3d_surface() const { - return direct3d_surface_; - } - private: - CComPtr<IDirect3DSurface9> direct3d_surface_; - int width_; - int height_; - DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceD3D9); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_RENDER_SURFACE_D3D9_H_ - diff --git a/o3d/gpu/command_buffer/service/render_surface_gl.cc b/o3d/gpu/command_buffer/service/render_surface_gl.cc deleted file mode 100644 index 5485323..0000000 --- a/o3d/gpu/command_buffer/service/render_surface_gl.cc +++ /dev/null @@ -1,262 +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 OpenGL versions of the render surface resources, -// as well as the related GAPIGL function implementations. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_gl.h" -#include "gpu/command_buffer/service/render_surface_gl.h" - - -namespace command_buffer { -namespace o3d { - -RenderSurfaceGL::RenderSurfaceGL(int width, - int height, - int mip_level, - int side, - TextureGL *texture) - : width_(width), height_(height), mip_level_(mip_level), texture_(texture) { -} - -RenderSurfaceGL* RenderSurfaceGL::Create(int width, - int height, - int mip_level, - int side, - TextureGL *texture) { - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - DCHECK_GE(mip_level, 0); - DCHECK(texture); - - RenderSurfaceGL* render_surface = - new RenderSurfaceGL(width, height, mip_level, side, texture); - return render_surface; -} - -RenderDepthStencilSurfaceGL::RenderDepthStencilSurfaceGL( - int width, - int height) - : width_(width), height_(height) { - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - - // If packed depth stencil is supported, create only one buffer for both - // depth and stencil. - if (GLEW_EXT_packed_depth_stencil) { - glGenRenderbuffersEXT(1, render_buffers_); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, render_buffers_[0]); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_DEPTH24_STENCIL8_EXT, - width, - height); - CHECK_GL_ERROR(); - render_buffers_[1] = render_buffers_[0]; - } else { - glGenRenderbuffersEXT(2, render_buffers_); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, render_buffers_[0]); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_DEPTH_COMPONENT24, - width, - height); - CHECK_GL_ERROR(); - - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, render_buffers_[1]); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_STENCIL_INDEX8_EXT, - width, - height); - CHECK_GL_ERROR(); - } -} - -RenderDepthStencilSurfaceGL* RenderDepthStencilSurfaceGL::Create( - int width, - int height) { - DCHECK_GT(width, 0); - DCHECK_GT(height, 0); - - return new RenderDepthStencilSurfaceGL(height, width); -} - -// Copies the data from a texture resource. -parse_error::ParseError GAPIGL::CreateRenderSurface( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int mip_level, - unsigned int side, - ResourceId texture_id) { - if (id == current_surface_id_) { - // This will delete the current surface which would be bad. - return parse_error::kParseInvalidArguments; - } - TextureGL *texture = textures_.Get(texture_id); - if (!texture->render_surfaces_enabled()) { - return parse_error::kParseInvalidArguments; - } else { - RenderSurfaceGL* render_surface = RenderSurfaceGL::Create(width, - height, - mip_level, - side, - texture); - if (render_surface == NULL) { - return parse_error::kParseInvalidArguments; - } - render_surfaces_.Assign(id, render_surface); - } - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyRenderSurface(ResourceId id) { - if (id == current_surface_id_) { - return parse_error::kParseInvalidArguments; - } - return render_surfaces_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::CreateDepthSurface( - ResourceId id, - unsigned int width, - unsigned int height) { - if (id == current_depth_surface_id_) { - // This will delete the current surface which would be bad. - return parse_error::kParseInvalidArguments; - } - RenderDepthStencilSurfaceGL* depth_surface = - RenderDepthStencilSurfaceGL::Create(width, height); - if (depth_surface == NULL) { - return parse_error::kParseInvalidArguments; - } - depth_surfaces_.Assign(id, depth_surface); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::DestroyDepthSurface(ResourceId id) { - if (id == current_depth_surface_id_) { - return parse_error::kParseInvalidArguments; - } - return depth_surfaces_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -void ResetBoundAttachments() { -#ifdef _DEBUG - GLint bound_framebuffer; - ::glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &bound_framebuffer); - DCHECK(bound_framebuffer != 0); -#endif - - // Reset the bound attachments to the current framebuffer object. - ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - GL_RENDERBUFFER_EXT, - 0); - - ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - 0); - - ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - 0); - - CHECK_GL_ERROR(); -} - -bool BindDepthStencilBuffer(const RenderDepthStencilSurfaceGL* gl_surface) { - // Bind both the depth and stencil attachments. - ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - gl_surface->depth_buffer()); - ::glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, - gl_surface->stencil_buffer()); - - // Check for errors. - GLenum framebuffer_status = ::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (GL_FRAMEBUFFER_COMPLETE_EXT != framebuffer_status) { - return false; - } - - CHECK_GL_ERROR(); - return true; -} - -parse_error::ParseError GAPIGL::SetRenderSurface( - ResourceId render_surface_id, - ResourceId depth_stencil_id) { - if (render_surfaces_.Get(render_surface_id) == NULL && - depth_surfaces_.Get(depth_stencil_id) == NULL) { - return parse_error::kParseInvalidArguments; - } - - ::glBindFramebufferEXT(GL_FRAMEBUFFER, render_surface_framebuffer_); - ResetBoundAttachments(); - - RenderSurfaceGL* render_surface = render_surfaces_.Get(render_surface_id); - RenderDepthStencilSurfaceGL* depth_surface = - depth_surfaces_.Get(render_surface_id); - - if (!render_surface->texture()-> - InstallFrameBufferObjects(render_surface) || - !BindDepthStencilBuffer(depth_surface)) { - return parse_error::kParseInvalidArguments; - } - - // RenderSurface rendering is performed with an inverted Y, so the front - // face winding must be changed to clock-wise. See comments for - // UpdateHelperConstant. - glFrontFace(GL_CW); - - current_surface_id_ = render_surface_id; - current_depth_surface_id_ = depth_stencil_id; - return parse_error::kParseNoError; -} - -void GAPIGL::SetBackSurfaces() { - // Bind the default context, and restore the default front-face winding. - ::glBindFramebufferEXT(GL_FRAMEBUFFER, 0); - glFrontFace(GL_CCW); -} - -} // namespace o3d -} // namespace command_buffer - diff --git a/o3d/gpu/command_buffer/service/render_surface_gl.h b/o3d/gpu/command_buffer/service/render_surface_gl.h deleted file mode 100644 index 01d6137..0000000 --- a/o3d/gpu/command_buffer/service/render_surface_gl.h +++ /dev/null @@ -1,117 +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 GPU_COMMAND_BUFFER_SERVICE_RENDER_SURFACE_GL_H__ -#define GPU_COMMAND_BUFFER_SERVICE_RENDER_SURFACE_GL_H__ - -// This file contains the definition of the OpenGL versions of -// render surface-related resource classes. - -#include "gpu/command_buffer/service/texture_gl.h" -#include "gpu/command_buffer/service/resource.h" - -namespace command_buffer { -namespace o3d { - -class RenderSurfaceGL : public RenderSurface { - public: - RenderSurfaceGL(int width, - int height, - int mip_level, - int side, - TextureGL *texture); - virtual ~RenderSurfaceGL() {} - - static RenderSurfaceGL* Create(int width, - int height, - int mip_level, - int side, - TextureGL *texture); - TextureGL* texture() { - return texture_; - } - - int width() { - return width_; - } - - int height() { - return height_; - } - - int mip_level() { - return mip_level_; - } - - int side() { - return side_; - } - private: - unsigned int width_; - unsigned int height_; - unsigned int mip_level_; - unsigned int side_; - TextureGL* texture_; - DISALLOW_COPY_AND_ASSIGN(RenderSurfaceGL); -}; - -class RenderDepthStencilSurfaceGL : public RenderDepthStencilSurface { - public: - RenderDepthStencilSurfaceGL(int width, - int height); - virtual ~RenderDepthStencilSurfaceGL() {} - - static RenderDepthStencilSurfaceGL* Create( - int width, - int height); - - GLuint depth_buffer() const { - return render_buffers_[0]; - } - - GLuint stencil_buffer() const { - return render_buffers_[1]; - } - - private: - // Handles to the depth and stencil render-buffers, respectively. - GLuint render_buffers_[2]; - unsigned int width_; - unsigned int height_; - DISALLOW_COPY_AND_ASSIGN(RenderDepthStencilSurfaceGL); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_WIN_GL_RENDER_SURFACE_GL_H__ - diff --git a/o3d/gpu/command_buffer/service/sampler_d3d9.cc b/o3d/gpu/command_buffer/service/sampler_d3d9.cc deleted file mode 100644 index e4c3b26..0000000 --- a/o3d/gpu/command_buffer/service/sampler_d3d9.cc +++ /dev/null @@ -1,199 +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 SamplerD3D9 class. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" -#include "gpu/command_buffer/service/sampler_d3d9.h" -#include "gpu/command_buffer/service/texture_d3d9.h" - -namespace command_buffer { -namespace o3d { - -namespace { - -// Converts an addressing mode to corresponding D3D values. -D3DTEXTUREADDRESS AddressModeToD3D(sampler::AddressingMode mode) { - switch (mode) { - case sampler::kWrap: - return D3DTADDRESS_WRAP; - case sampler::kMirrorRepeat: - return D3DTADDRESS_MIRROR; - case sampler::kClampToEdge: - return D3DTADDRESS_CLAMP; - case sampler::kClampToBorder: - return D3DTADDRESS_BORDER; - } - DLOG(FATAL) << "Not reached"; - return D3DTADDRESS_WRAP; -} - -// Converts a filtering mode to corresponding D3D values. -D3DTEXTUREFILTERTYPE FilteringModeToD3D(sampler::FilteringMode mode) { - switch (mode) { - case sampler::kNone: - return D3DTEXF_NONE; - case sampler::kPoint: - return D3DTEXF_POINT; - case sampler::kLinear: - return D3DTEXF_LINEAR; - } - DLOG(FATAL) << "Not reached"; - return D3DTEXF_POINT; -} - -} // anonymous namespace - -SamplerD3D9::SamplerD3D9() - : texture_id_(kInvalidResource) { - SetStates(sampler::kClampToEdge, - sampler::kClampToEdge, - sampler::kClampToEdge, - sampler::kLinear, - sampler::kLinear, - sampler::kPoint, - 1); - RGBA black = {0, 0, 0, 1}; - SetBorderColor(black); -} - -bool SamplerD3D9::ApplyStates(GAPID3D9 *gapi, unsigned int unit) const { - DCHECK(gapi); - TextureD3D9 *texture = gapi->GetTexture(texture_id_); - if (!texture) { - return false; - } - IDirect3DDevice9 *d3d_device = gapi->d3d_device(); - HR(d3d_device->SetTexture(unit, texture->d3d_base_texture())); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_ADDRESSU, d3d_address_u_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_ADDRESSV, d3d_address_v_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_ADDRESSW, d3d_address_w_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_MAGFILTER, d3d_mag_filter_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_MINFILTER, d3d_min_filter_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_MIPFILTER, d3d_mip_filter_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_MAXANISOTROPY, - d3d_max_anisotropy_)); - HR(d3d_device->SetSamplerState(unit, D3DSAMP_BORDERCOLOR, d3d_border_color_)); - return true; -} - -void SamplerD3D9::SetStates(sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy) { - // These are validated in GAPIDecoder.cc - DCHECK_NE(mag_filter, sampler::kNone); - DCHECK_NE(min_filter, sampler::kNone); - DCHECK_GT(max_anisotropy, 0U); - d3d_address_u_ = AddressModeToD3D(addressing_u); - d3d_address_v_ = AddressModeToD3D(addressing_v); - d3d_address_w_ = AddressModeToD3D(addressing_w); - d3d_mag_filter_ = FilteringModeToD3D(mag_filter); - d3d_min_filter_ = FilteringModeToD3D(min_filter); - d3d_mip_filter_ = FilteringModeToD3D(mip_filter); - if (max_anisotropy > 1) { - d3d_mag_filter_ = D3DTEXF_ANISOTROPIC; - d3d_min_filter_ = D3DTEXF_ANISOTROPIC; - } - d3d_max_anisotropy_ = max_anisotropy; -} - -void SamplerD3D9::SetBorderColor(const RGBA &color) { - d3d_border_color_ = RGBAToD3DCOLOR(color); -} - -parse_error::ParseError GAPID3D9::CreateSampler( - ResourceId id) { - // Dirty effect, because this sampler id may be used - DirtyEffect(); - samplers_.Assign(id, new SamplerD3D9()); - return parse_error::kParseNoError; -} - -// Destroys the Sampler resource. -parse_error::ParseError GAPID3D9::DestroySampler(ResourceId id) { - // Dirty effect, because this sampler id may be used - DirtyEffect(); - return samplers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPID3D9::SetSamplerStates( - ResourceId id, - sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy) { - SamplerD3D9 *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used - DirtyEffect(); - sampler->SetStates(addressing_u, addressing_v, addressing_w, - mag_filter, min_filter, mip_filter, max_anisotropy); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::SetSamplerBorderColor( - ResourceId id, - const RGBA &color) { - SamplerD3D9 *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used - DirtyEffect(); - sampler->SetBorderColor(color); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPID3D9::SetSamplerTexture( - ResourceId id, - ResourceId texture_id) { - SamplerD3D9 *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used - DirtyEffect(); - sampler->SetTexture(texture_id); - return parse_error::kParseNoError; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/sampler_d3d9.h b/o3d/gpu/command_buffer/service/sampler_d3d9.h deleted file mode 100644 index 55a6e9a..0000000 --- a/o3d/gpu/command_buffer/service/sampler_d3d9.h +++ /dev/null @@ -1,85 +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 SamplerD3D9 class, implementing -// samplers for D3D. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_SAMPLER_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_SAMPLER_D3D9_H_ - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/resource.h" - -namespace command_buffer { -namespace o3d { - -class GAPID3D9; - -// D3D9 version of Sampler. -class SamplerD3D9 : public Sampler { - public: - SamplerD3D9(); - - // Applies sampler states to D3D. - bool ApplyStates(GAPID3D9 *gapi, unsigned int unit) const; - - // Sets sampler states. - void SetStates(sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy); - - // Sets the border color states. - void SetBorderColor(const RGBA &color); - - // Sets the texture. - void SetTexture(ResourceId texture) { texture_id_ = texture; } - private: - D3DTEXTUREADDRESS d3d_address_u_; - D3DTEXTUREADDRESS d3d_address_v_; - D3DTEXTUREADDRESS d3d_address_w_; - D3DTEXTUREFILTERTYPE d3d_mag_filter_; - D3DTEXTUREFILTERTYPE d3d_min_filter_; - D3DTEXTUREFILTERTYPE d3d_mip_filter_; - DWORD d3d_max_anisotropy_; - D3DCOLOR d3d_border_color_; - ResourceId texture_id_; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_SAMPLER_D3D9_H_ diff --git a/o3d/gpu/command_buffer/service/sampler_gl.cc b/o3d/gpu/command_buffer/service/sampler_gl.cc deleted file mode 100644 index 32335e1..0000000 --- a/o3d/gpu/command_buffer/service/sampler_gl.cc +++ /dev/null @@ -1,238 +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 sampler-related GAPI functions on GL. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_gl.h" -#include "gpu/command_buffer/service/sampler_gl.h" - -namespace command_buffer { -namespace o3d { - -namespace { - -// Gets the GL enum corresponding to an addressing mode. -GLenum GLAddressMode(sampler::AddressingMode o3d_mode) { - switch (o3d_mode) { - case sampler::kWrap: - return GL_REPEAT; - case sampler::kMirrorRepeat: - return GL_MIRRORED_REPEAT; - case sampler::kClampToEdge: - return GL_CLAMP_TO_EDGE; - case sampler::kClampToBorder: - return GL_CLAMP_TO_BORDER; - default: - DLOG(FATAL) << "Not Reached"; - return GL_REPEAT; - } -} - -// Gets the GL enum for the minification filter based on the command buffer min -// and mip filtering modes. -GLenum GLMinFilter(sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter) { - switch (min_filter) { - case sampler::kPoint: - if (mip_filter == sampler::kNone) - return GL_NEAREST; - else if (mip_filter == sampler::kPoint) - return GL_NEAREST_MIPMAP_NEAREST; - else if (mip_filter == sampler::kLinear) - return GL_NEAREST_MIPMAP_LINEAR; - case sampler::kLinear: - if (mip_filter == sampler::kNone) - return GL_LINEAR; - else if (mip_filter == sampler::kPoint) - return GL_LINEAR_MIPMAP_NEAREST; - else if (mip_filter == sampler::kLinear) - return GL_LINEAR_MIPMAP_LINEAR; - default: - DLOG(FATAL) << "Not Reached"; - return GL_LINEAR_MIPMAP_NEAREST; - } -} - -// Gets the GL enum for the magnification filter based on the command buffer mag -// filtering mode. -GLenum GLMagFilter(sampler::FilteringMode mag_filter) { - switch (mag_filter) { - case sampler::kPoint: - return GL_NEAREST; - case sampler::kLinear: - return GL_LINEAR; - default: - DLOG(FATAL) << "Not Reached"; - return GL_LINEAR; - } -} - -// Gets the GL enum representing the GL target based on the texture type. -GLenum GLTextureTarget(texture::Type type) { - switch (type) { - case texture::kTexture2d: - return GL_TEXTURE_2D; - case texture::kTexture3d: - return GL_TEXTURE_3D; - case texture::kTextureCube: - return GL_TEXTURE_CUBE_MAP; - default: - DLOG(FATAL) << "Not Reached"; - return GL_TEXTURE_2D; - } -} - -} // anonymous namespace - -SamplerGL::SamplerGL() - : texture_id_(kInvalidResource), - gl_texture_(0) { - SetStates(sampler::kClampToEdge, - sampler::kClampToEdge, - sampler::kClampToEdge, - sampler::kLinear, - sampler::kLinear, - sampler::kPoint, - 1); - RGBA black = {0, 0, 0, 1}; - SetBorderColor(black); -} - -bool SamplerGL::ApplyStates(GAPIGL *gapi) { - DCHECK(gapi); - TextureGL *texture = gapi->GetTexture(texture_id_); - if (!texture) { - gl_texture_ = 0; - return false; - } - GLenum target = GLTextureTarget(texture->type()); - gl_texture_ = texture->gl_texture(); - glBindTexture(target, gl_texture_); - glTexParameteri(target, GL_TEXTURE_WRAP_S, gl_wrap_s_); - glTexParameteri(target, GL_TEXTURE_WRAP_T, gl_wrap_t_); - glTexParameteri(target, GL_TEXTURE_WRAP_R, gl_wrap_r_); - glTexParameteri(target, GL_TEXTURE_MIN_FILTER, gl_min_filter_); - glTexParameteri(target, GL_TEXTURE_MAG_FILTER, gl_mag_filter_); - glTexParameteri(target, GL_TEXTURE_MAX_ANISOTROPY_EXT, gl_max_anisotropy_); - glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, gl_border_color_); - return true; -} - -void SamplerGL::SetStates(sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy) { - // These are validated in GAPIDecoder.cc - DCHECK_NE(mag_filter, sampler::kNone); - DCHECK_NE(min_filter, sampler::kNone); - DCHECK_GT(max_anisotropy, 0U); - gl_wrap_s_ = GLAddressMode(addressing_u); - gl_wrap_t_ = GLAddressMode(addressing_v); - gl_wrap_r_ = GLAddressMode(addressing_w); - gl_mag_filter_ = GLMagFilter(mag_filter); - gl_min_filter_ = GLMinFilter(min_filter, mip_filter); - gl_max_anisotropy_ = max_anisotropy; -} - -void SamplerGL::SetBorderColor(const RGBA &color) { - gl_border_color_[0] = color.red; - gl_border_color_[1] = color.green; - gl_border_color_[2] = color.blue; - gl_border_color_[3] = color.alpha; -} - -parse_error::ParseError GAPIGL::CreateSampler( - ResourceId id) { - // Dirty effect, because this sampler id may be used. - DirtyEffect(); - samplers_.Assign(id, new SamplerGL()); - return parse_error::kParseNoError; -} - -// Destroys the Sampler resource. -parse_error::ParseError GAPIGL::DestroySampler(ResourceId id) { - // Dirty effect, because this sampler id may be used. - DirtyEffect(); - return samplers_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -parse_error::ParseError GAPIGL::SetSamplerStates( - ResourceId id, - sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy) { - SamplerGL *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used. - DirtyEffect(); - sampler->SetStates(addressing_u, addressing_v, addressing_w, - mag_filter, min_filter, mip_filter, max_anisotropy); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::SetSamplerBorderColor( - ResourceId id, - const RGBA &color) { - SamplerGL *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used. - DirtyEffect(); - sampler->SetBorderColor(color); - return parse_error::kParseNoError; -} - -parse_error::ParseError GAPIGL::SetSamplerTexture( - ResourceId id, - ResourceId texture_id) { - SamplerGL *sampler = samplers_.Get(id); - if (!sampler) - return parse_error::kParseInvalidArguments; - // Dirty effect, because this sampler id may be used. - DirtyEffect(); - sampler->SetTexture(texture_id); - return parse_error::kParseNoError; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/sampler_gl.h b/o3d/gpu/command_buffer/service/sampler_gl.h deleted file mode 100644 index 8809ea5..0000000 --- a/o3d/gpu/command_buffer/service/sampler_gl.h +++ /dev/null @@ -1,87 +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 declares the SamplerGL class. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_SAMPLER_GL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_SAMPLER_GL_H_ - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/gl_utils.h" -#include "gpu/command_buffer/service/resource.h" - -namespace command_buffer { -namespace o3d { - -class GAPIGL; - -// GL version of Sampler. -class SamplerGL : public Sampler { - public: - SamplerGL(); - - // Applies sampler states to GL. - bool ApplyStates(GAPIGL *gapi); - - // Sets sampler states. - void SetStates(sampler::AddressingMode addressing_u, - sampler::AddressingMode addressing_v, - sampler::AddressingMode addressing_w, - sampler::FilteringMode mag_filter, - sampler::FilteringMode min_filter, - sampler::FilteringMode mip_filter, - unsigned int max_anisotropy); - - // Sets the border color states. - void SetBorderColor(const o3d::RGBA &color); - - // Sets the texture. - void SetTexture(ResourceId texture) { texture_id_ = texture; } - - GLuint gl_texture() const { return gl_texture_; } - - private: - GLenum gl_wrap_s_; - GLenum gl_wrap_t_; - GLenum gl_wrap_r_; - GLenum gl_mag_filter_; - GLenum gl_min_filter_; - GLuint gl_max_anisotropy_; - GLfloat gl_border_color_[4]; - GLuint gl_texture_; - ResourceId texture_id_; -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_SAMPLER_GL_H_ diff --git a/o3d/gpu/command_buffer/service/states_d3d9.cc b/o3d/gpu/command_buffer/service/states_d3d9.cc deleted file mode 100644 index 7abcada..0000000 --- a/o3d/gpu/command_buffer/service/states_d3d9.cc +++ /dev/null @@ -1,355 +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 state-related GAPID3D9 -// functions. - -#include "gpu/command_buffer/service/precompile.h" - -#include <algorithm> - -#include "gpu/command_buffer/common/o3d_cmd_format.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" - -namespace command_buffer { -namespace o3d { - -namespace { - -// Checks that a command_buffer enum matches a D3D enum so that it can be -// converted quickly. -#define CHECK_CB_ENUM_MATCHES_D3D(CB_ENUM, D3D_ENUM) \ - COMPILE_ASSERT(CB_ENUM + 1 == D3D_ENUM, \ - CB_ENUM ## _plus_1_not_ ## D3D_ENUM) - -// Converts values from the PolygonMode enum to corresponding D3D values -inline D3DFILLMODE PolygonModeToD3D(PolygonMode fill_mode) { - DCHECK_LT(fill_mode, kNumPolygonMode); - - // Check that all acceptable values translate to D3D values by adding 1. - - CHECK_CB_ENUM_MATCHES_D3D(kPolygonModePoints, D3DFILL_POINT); - CHECK_CB_ENUM_MATCHES_D3D(kPolygonModeLines, D3DFILL_WIREFRAME); - CHECK_CB_ENUM_MATCHES_D3D(kPolygonModeFill, D3DFILL_SOLID); - return static_cast<D3DFILLMODE>(fill_mode + 1); -} - -// Converts values from the FaceCullMode enum to corresponding D3D values -inline D3DCULL FaceCullModeToD3D(FaceCullMode cull_mode) { - DCHECK_LT(cull_mode, kNumFaceCullMode); - - // Check that all acceptable values translate to D3D values by adding 1. - CHECK_CB_ENUM_MATCHES_D3D(kCullNone, D3DCULL_NONE); - CHECK_CB_ENUM_MATCHES_D3D(kCullCW, D3DCULL_CW); - CHECK_CB_ENUM_MATCHES_D3D(kCullCCW, D3DCULL_CCW); - return static_cast<D3DCULL>(cull_mode + 1); -} - -// Converts values from the Comparison enum to corresponding D3D values -inline D3DCMPFUNC ComparisonToD3D(Comparison comp) { - DCHECK_LT(comp, kNumComparison); - - // Check that all acceptable values translate to D3D values by adding 1. - CHECK_CB_ENUM_MATCHES_D3D(kNever, D3DCMP_NEVER); - CHECK_CB_ENUM_MATCHES_D3D(kLess, D3DCMP_LESS); - CHECK_CB_ENUM_MATCHES_D3D(kEqual, D3DCMP_EQUAL); - CHECK_CB_ENUM_MATCHES_D3D(kLEqual, D3DCMP_LESSEQUAL); - CHECK_CB_ENUM_MATCHES_D3D(kGreater, D3DCMP_GREATER); - CHECK_CB_ENUM_MATCHES_D3D(kNotEqual, D3DCMP_NOTEQUAL); - CHECK_CB_ENUM_MATCHES_D3D(kGEqual, D3DCMP_GREATEREQUAL); - CHECK_CB_ENUM_MATCHES_D3D(kAlways, D3DCMP_ALWAYS); - return static_cast<D3DCMPFUNC>(comp + 1); -} - -// Converts values from the StencilOp enum to corresponding D3D values -inline D3DSTENCILOP StencilOpToD3D(StencilOp stencil_op) { - DCHECK_LT(stencil_op, kNumStencilOp); - - // Check that all acceptable values translate to D3D values by adding 1. - CHECK_CB_ENUM_MATCHES_D3D(kKeep, D3DSTENCILOP_KEEP); - CHECK_CB_ENUM_MATCHES_D3D(kZero, D3DSTENCILOP_ZERO); - CHECK_CB_ENUM_MATCHES_D3D(kReplace, D3DSTENCILOP_REPLACE); - CHECK_CB_ENUM_MATCHES_D3D(kIncNoWrap, D3DSTENCILOP_INCRSAT); - CHECK_CB_ENUM_MATCHES_D3D(kDecNoWrap, D3DSTENCILOP_DECRSAT); - CHECK_CB_ENUM_MATCHES_D3D(kInvert, D3DSTENCILOP_INVERT); - CHECK_CB_ENUM_MATCHES_D3D(kIncWrap, D3DSTENCILOP_INCR); - CHECK_CB_ENUM_MATCHES_D3D(kDecWrap, D3DSTENCILOP_DECR); - return static_cast<D3DSTENCILOP>(stencil_op + 1); -} - -// Converts values from the BlendEq enum to corresponding D3D values -inline D3DBLENDOP BlendEqToD3D(BlendEq blend_eq) { - DCHECK_LT(blend_eq, kNumBlendEq); - // Check that all acceptable values translate to D3D values by adding 1. - CHECK_CB_ENUM_MATCHES_D3D(kBlendEqAdd, D3DBLENDOP_ADD); - CHECK_CB_ENUM_MATCHES_D3D(kBlendEqSub, D3DBLENDOP_SUBTRACT); - CHECK_CB_ENUM_MATCHES_D3D(kBlendEqRevSub, D3DBLENDOP_REVSUBTRACT); - CHECK_CB_ENUM_MATCHES_D3D(kBlendEqMin, D3DBLENDOP_MIN); - CHECK_CB_ENUM_MATCHES_D3D(kBlendEqMax, D3DBLENDOP_MAX); - return static_cast<D3DBLENDOP>(blend_eq + 1); -} - -// Converts values from the BlendFunc enum to corresponding D3D values -D3DBLEND BlendFuncToD3D(BlendFunc blend_func) { - // The D3DBLEND enum values don't map 1-to-1 to BlendFunc, so we use a switch - // here. - switch (blend_func) { - case kBlendFuncZero: - return D3DBLEND_ZERO; - case kBlendFuncOne: - return D3DBLEND_ONE; - case kBlendFuncSrcColor: - return D3DBLEND_SRCCOLOR; - case kBlendFuncInvSrcColor: - return D3DBLEND_INVSRCCOLOR; - case kBlendFuncSrcAlpha: - return D3DBLEND_SRCALPHA; - case kBlendFuncInvSrcAlpha: - return D3DBLEND_INVSRCALPHA; - case kBlendFuncDstAlpha: - return D3DBLEND_DESTALPHA; - case kBlendFuncInvDstAlpha: - return D3DBLEND_INVDESTALPHA; - case kBlendFuncDstColor: - return D3DBLEND_DESTCOLOR; - case kBlendFuncInvDstColor: - return D3DBLEND_INVDESTCOLOR; - case kBlendFuncSrcAlphaSaturate: - return D3DBLEND_SRCALPHASAT; - case kBlendFuncBlendColor: - return D3DBLEND_BLENDFACTOR; - case kBlendFuncInvBlendColor: - return D3DBLEND_INVBLENDFACTOR; - default: - DLOG(FATAL) << "Invalid BlendFunc"; - return D3DBLEND_ZERO; - } -} - -// Decodes stencil test function and operations from the bitfield. -void DecodeStencilFuncOps(Uint32 params, - Comparison *func, - StencilOp *pass, - StencilOp *fail, - StencilOp *zfail) { - // Sanity check. The value has already been tested in - // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. - DCHECK_EQ(SetStencilTest::Unused1::Get(params), 0); - // Check that the bitmask get cannot generate values outside of the allowed - // range. - COMPILE_ASSERT(SetStencilTest::CWFunc::kMask < - kNumComparison, - set_stencil_test_CWFunc_may_produce_invalid_values); - *func = static_cast<Comparison>(SetStencilTest::CWFunc::Get(params)); - - COMPILE_ASSERT(SetStencilTest::CWPassOp::kMask < - kNumStencilOp, - set_stencil_test_CWPassOp_may_produce_invalid_values); - *pass = static_cast<StencilOp>(SetStencilTest::CWPassOp::Get(params)); - - COMPILE_ASSERT(SetStencilTest::CWFailOp::kMask < - kNumStencilOp, - set_stencil_test_CWFailOp_may_produce_invalid_values); - *fail = static_cast<StencilOp>(SetStencilTest::CWFailOp::Get(params)); - - COMPILE_ASSERT(SetStencilTest::CWZFailOp::kMask < - kNumStencilOp, - set_stencil_test_CWZFailOp_may_produce_invalid_values); - *zfail = static_cast<StencilOp>(SetStencilTest::CWZFailOp::Get(params)); -} - -} // anonymous namespace - -void GAPID3D9::SetScissor(bool enable, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height) { - HR(d3d_device_->SetRenderState(D3DRS_SCISSORTESTENABLE, - enable ? TRUE : FALSE)); - RECT rect = {x, y, x + width, y + height}; - HR(d3d_device_->SetScissorRect(&rect)); -} - -void GAPID3D9::SetPolygonOffset(float slope_factor, float units) { - HR(d3d_device_->SetRenderState(D3DRS_SLOPESCALEDEPTHBIAS, - FloatAsDWORD(slope_factor))); - // TODO: this value is hard-coded currently because we only create a - // 24-bit depth buffer. Move this to a member of GAPID3D9 if this changes. - const float kUnitScale = 1.f / (1 << 24); - HR(d3d_device_->SetRenderState(D3DRS_DEPTHBIAS, - FloatAsDWORD(units * kUnitScale))); -} - -void GAPID3D9::SetPointLineRaster(bool line_smooth, - bool point_sprite, - float point_size) { - HR(d3d_device_->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, - line_smooth ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_POINTSPRITEENABLE, - point_sprite ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_POINTSIZE, - FloatAsDWORD(point_size))); -} - -void GAPID3D9::SetPolygonRaster(PolygonMode fill_mode, - FaceCullMode cull_mode) { - HR(d3d_device_->SetRenderState(D3DRS_FILLMODE, PolygonModeToD3D(fill_mode))); - HR(d3d_device_->SetRenderState(D3DRS_CULLMODE, FaceCullModeToD3D(cull_mode))); -} - -void GAPID3D9::SetAlphaTest(bool enable, - float reference, - Comparison comp) { - HR(d3d_device_->SetRenderState(D3DRS_ALPHABLENDENABLE, - enable ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_ALPHAREF, - FloatToClampedByte(reference))); - HR(d3d_device_->SetRenderState(D3DRS_ALPHAFUNC, ComparisonToD3D(comp))); -} - -void GAPID3D9::SetDepthTest(bool enable, - bool write_enable, - Comparison comp) { - HR(d3d_device_->SetRenderState(D3DRS_ZENABLE, - enable ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_ZWRITEENABLE, - write_enable ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_ZFUNC, ComparisonToD3D(comp))); -} - -void GAPID3D9::SetStencilTest(bool enable, - bool separate_ccw, - unsigned int write_mask, - unsigned int compare_mask, - unsigned int ref, - Uint32 func_ops) { - HR(d3d_device_->SetRenderState(D3DRS_STENCILENABLE, - enable ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_STENCILWRITEMASK, write_mask)); - HR(d3d_device_->SetRenderState(D3DRS_STENCILMASK, compare_mask)); - HR(d3d_device_->SetRenderState(D3DRS_STENCILREF, ref)); - - Comparison func; - StencilOp pass; - StencilOp fail; - StencilOp zfail; - DecodeStencilFuncOps(func_ops, &func, &pass, &fail, &zfail); - HR(d3d_device_->SetRenderState(D3DRS_STENCILFUNC, - ComparisonToD3D(func))); - HR(d3d_device_->SetRenderState(D3DRS_STENCILPASS, - StencilOpToD3D(pass))); - HR(d3d_device_->SetRenderState(D3DRS_STENCILFAIL, - StencilOpToD3D(fail))); - HR(d3d_device_->SetRenderState(D3DRS_STENCILZFAIL, - StencilOpToD3D(zfail))); - - if (separate_ccw) { - HR(d3d_device_->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, TRUE)); - // Check that the definition of the counter-clockwise func/ops match the - // clockwise ones, just shifted by 16 bits, so that we can use - // DecodeStencilFuncOps on both of them. -#define CHECK_CCW_MATCHES_CW(FIELD) \ - COMPILE_ASSERT(SetStencilTest::CW ## FIELD::kLength == \ - SetStencilTest::CCW ## FIELD::kLength, \ - CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ - COMPILE_ASSERT(SetStencilTest::CW ## FIELD::kShift + 16 == \ - SetStencilTest::CCW ## FIELD::kShift, \ - CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) - CHECK_CCW_MATCHES_CW(Func); - CHECK_CCW_MATCHES_CW(PassOp); - CHECK_CCW_MATCHES_CW(FailOp); - CHECK_CCW_MATCHES_CW(ZFailOp); -#undef CHECK_CCW_MATCHES_CW - // Extract upper 16 bits. - Uint32 ccw_func_ops = BitField<16, 16>::Get(func_ops); - - DecodeStencilFuncOps(ccw_func_ops, &func, &pass, &fail, &zfail); - HR(d3d_device_->SetRenderState(D3DRS_CCW_STENCILFUNC, - ComparisonToD3D(func))); - HR(d3d_device_->SetRenderState(D3DRS_CCW_STENCILPASS, - StencilOpToD3D(pass))); - HR(d3d_device_->SetRenderState(D3DRS_CCW_STENCILFAIL, - StencilOpToD3D(fail))); - HR(d3d_device_->SetRenderState(D3DRS_CCW_STENCILZFAIL, - StencilOpToD3D(zfail))); - } else { - HR(d3d_device_->SetRenderState(D3DRS_TWOSIDEDSTENCILMODE, FALSE)); - } -} - -void GAPID3D9::SetColorWrite(bool red, - bool green, - bool blue, - bool alpha, - bool dither) { - Uint32 mask = red ? D3DCOLORWRITEENABLE_RED : 0; - mask |= green ? D3DCOLORWRITEENABLE_GREEN : 0; - mask |= blue ? D3DCOLORWRITEENABLE_BLUE : 0; - mask |= alpha ? D3DCOLORWRITEENABLE_ALPHA : 0; - HR(d3d_device_->SetRenderState(D3DRS_COLORWRITEENABLE, mask)); - HR(d3d_device_->SetRenderState(D3DRS_DITHERENABLE, dither ? TRUE : FALSE)); -} - -void GAPID3D9::SetBlending(bool enable, - bool separate_alpha, - BlendEq color_eq, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq alpha_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func) { - HR(d3d_device_->SetRenderState(D3DRS_ALPHABLENDENABLE, - enable ? TRUE : FALSE)); - HR(d3d_device_->SetRenderState(D3DRS_BLENDOP, BlendEqToD3D(color_eq))); - HR(d3d_device_->SetRenderState(D3DRS_SRCBLEND, - BlendFuncToD3D(color_src_func))); - HR(d3d_device_->SetRenderState(D3DRS_DESTBLEND, - BlendFuncToD3D(color_dst_func))); - if (separate_alpha) { - HR(d3d_device_->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE)); - HR(d3d_device_->SetRenderState(D3DRS_BLENDOP, BlendEqToD3D(alpha_eq))); - HR(d3d_device_->SetRenderState(D3DRS_SRCBLEND, - BlendFuncToD3D(alpha_src_func))); - HR(d3d_device_->SetRenderState(D3DRS_DESTBLEND, - BlendFuncToD3D(alpha_dst_func))); - } else { - HR(d3d_device_->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE)); - } -} - -void GAPID3D9::SetBlendingColor(const RGBA &color) { - HR(d3d_device_->SetRenderState(D3DRS_BLENDFACTOR, RGBAToD3DCOLOR(color))); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/states_gl.cc b/o3d/gpu/command_buffer/service/states_gl.cc deleted file mode 100644 index 2d6fce4..0000000 --- a/o3d/gpu/command_buffer/service/states_gl.cc +++ /dev/null @@ -1,346 +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 render state-related GAPI functions on GL. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/common/o3d_cmd_format.h" -#include "gpu/command_buffer/service/gapi_gl.h" - -namespace command_buffer { -namespace o3d { - -namespace { - -GLenum kGLPolygonModes[] = { - GL_POINT, - GL_LINE, - GL_FILL, -}; -COMPILE_ASSERT(o3d::kNumPolygonMode == arraysize(kGLPolygonModes), - kGLPolygonModes_does_not_match_command_buffer_PolygonMode); - -GLenum kGLComparison[] = { - GL_NEVER, - GL_LESS, - GL_EQUAL, - GL_LEQUAL, - GL_GREATER, - GL_NOTEQUAL, - GL_GEQUAL, - GL_ALWAYS, -}; -COMPILE_ASSERT(o3d::kNumComparison == arraysize(kGLComparison), - kGLComparison_does_not_match_command_buffer_Comparison); - -GLenum kGLBlendFunc[] = { - GL_ZERO, - GL_ONE, - GL_SRC_COLOR, - GL_ONE_MINUS_SRC_COLOR, - GL_SRC_ALPHA, - GL_ONE_MINUS_SRC_ALPHA, - GL_DST_ALPHA, - GL_ONE_MINUS_DST_ALPHA, - GL_DST_COLOR, - GL_ONE_MINUS_DST_COLOR, - GL_SRC_ALPHA_SATURATE, - GL_CONSTANT_COLOR, - GL_ONE_MINUS_CONSTANT_COLOR, -}; -COMPILE_ASSERT(o3d::kNumBlendFunc == arraysize(kGLBlendFunc), - kGLBlendFunc_does_not_match_command_buffer_BlendFunc); - -GLenum kGLBlendEq[] = { - GL_FUNC_ADD, - GL_FUNC_SUBTRACT, - GL_FUNC_REVERSE_SUBTRACT, - GL_MIN, - GL_MAX, -}; -COMPILE_ASSERT(o3d::kNumBlendEq == arraysize(kGLBlendEq), - kGLBlendEq_does_not_match_command_buffer_BlendEq); - -GLenum kGLStencilOp[] = { - GL_KEEP, - GL_ZERO, - GL_REPLACE, - GL_INCR, - GL_DECR, - GL_INVERT, - GL_INCR_WRAP, - GL_DECR_WRAP, -}; -COMPILE_ASSERT(o3d::kNumStencilOp == arraysize(kGLStencilOp), - kGLStencilOp_does_not_match_command_buffer_StencilOp); - -// Check that the definition of the counter-clockwise func/ops match the -// clockwise ones, just shifted by 16 bits, so that we can use -// DecodeStencilFuncOps on both of them. -#define CHECK_CCW_MATCHES_CW(FIELD) \ - COMPILE_ASSERT(o3d::SetStencilTest::CW ## FIELD::kLength == \ - o3d::SetStencilTest::CCW ## FIELD::kLength, \ - CCW ## FIELD ## _length_does_not_match_ ## CW ## FIELD); \ - COMPILE_ASSERT(o3d::SetStencilTest::CW ## FIELD::kShift + 16 == \ - o3d::SetStencilTest::CCW ## FIELD::kShift, \ - CCW ## FIELD ## _shift_does_not_match_ ## CW ## FIELD) - -CHECK_CCW_MATCHES_CW(Func); -CHECK_CCW_MATCHES_CW(PassOp); -CHECK_CCW_MATCHES_CW(FailOp); -CHECK_CCW_MATCHES_CW(ZFailOp); - -#undef CHECK_CCW_MATCHES_CW - -// Decodes stencil test function and operations from the bitfield. -void DecodeStencilFuncOps(Uint32 params, - GLenum *func, - GLenum *pass, - GLenum *fail, - GLenum *zfail) { - // Sanity check. The value has already been tested in - // GAPIDecoder::DecodeSetStencilTest in gapi_decoder.cc. - DCHECK_EQ(o3d::SetStencilTest::Unused1::Get(params), 0); - // Check that the bitmask get cannot generate values outside of the allowed - // range. - COMPILE_ASSERT(o3d::SetStencilTest::CWFunc::kMask < - o3d::kNumComparison, - set_stencil_test_CWFunc_may_produce_invalid_values); - *func = kGLComparison[o3d::SetStencilTest::CWFunc::Get(params)]; - - COMPILE_ASSERT(o3d::SetStencilTest::CWPassOp::kMask < - o3d::kNumStencilOp, - set_stencil_test_CWPassOp_may_produce_invalid_values); - *pass = kGLStencilOp[o3d::SetStencilTest::CWPassOp::Get(params)]; - - COMPILE_ASSERT(o3d::SetStencilTest::CWFailOp::kMask < - o3d::kNumStencilOp, - set_stencil_test_CWFailOp_may_produce_invalid_values); - *fail = kGLStencilOp[o3d::SetStencilTest::CWFailOp::Get(params)]; - - COMPILE_ASSERT(o3d::SetStencilTest::CWZFailOp::kMask < - o3d::kNumStencilOp, - set_stencil_test_CWZFailOp_may_produce_invalid_values); - *zfail = kGLStencilOp[o3d::SetStencilTest::CWZFailOp::Get(params)]; -} - -} // anonymous namespace - -void GAPIGL::SetViewport(unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height, - float z_min, - float z_max) { - glViewport(x, y, width, height); - glDepthRange(z_min, z_max); - // Update the helper constant used for the D3D -> GL remapping. - // See effect_gl.cc for details. - glProgramEnvParameter4fARB(GL_VERTEX_PROGRAM_ARB, 0, - 1.f / width, 1.f / height, 2.f, 0.f); - CHECK_GL_ERROR(); -} - -void GAPIGL::SetScissor(bool enable, - unsigned int x, - unsigned int y, - unsigned int width, - unsigned int height) { - if (enable) { - glEnable(GL_SCISSOR_TEST); - glScissor(x, y, width, height); - } else { - glDisable(GL_SCISSOR_TEST); - } -} - -void GAPIGL::SetPointLineRaster(bool line_smooth, - bool point_sprite, - float point_size) { - if (line_smooth) { - glEnable(GL_LINE_SMOOTH); - } else { - glDisable(GL_LINE_SMOOTH); - } - if (point_sprite) { - glEnable(GL_POINT_SPRITE); - // TODO: check which TC gets affected by point sprites in D3D. - glActiveTextureARB(GL_TEXTURE0); - glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); - } else { - glActiveTextureARB(GL_TEXTURE0); - glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_FALSE); - glDisable(GL_POINT_SPRITE); - } - glPointSize(point_size); -} - -void GAPIGL::SetPolygonOffset(float slope_factor, float units) { - glPolygonOffset(slope_factor, units); -} - -void GAPIGL::SetPolygonRaster(o3d::PolygonMode fill_mode, - o3d::FaceCullMode cull_mode) { - DCHECK_LT(fill_mode, kNumPolygonMode); - glPolygonMode(GL_FRONT_AND_BACK, kGLPolygonModes[fill_mode]); - DCHECK_LT(cull_mode, kNumFaceCullMode); - switch (cull_mode) { - case kCullCW: - glEnable(GL_CULL_FACE); - glCullFace(GL_BACK); - break; - case kCullCCW: - glEnable(GL_CULL_FACE); - glCullFace(GL_FRONT); - break; - default: - glDisable(GL_CULL_FACE); - break; - } -} - -void GAPIGL::SetAlphaTest(bool enable, - float reference, - o3d::Comparison comp) { - DCHECK_LT(comp, kNumComparison); - if (enable) { - glEnable(GL_ALPHA_TEST); - glAlphaFunc(kGLComparison[comp], reference); - } else { - glDisable(GL_ALPHA_TEST); - } -} - -void GAPIGL::SetDepthTest(bool enable, - bool write_enable, - o3d::Comparison comp) { - DCHECK_LT(comp, kNumComparison); - if (enable) { - glEnable(GL_DEPTH_TEST); - glDepthFunc(kGLComparison[comp]); - } else { - glDisable(GL_DEPTH_TEST); - } - glDepthMask(write_enable); -} - -void GAPIGL::SetStencilTest(bool enable, - bool separate_ccw, - unsigned int write_mask, - unsigned int compare_mask, - unsigned int ref, - Uint32 func_ops) { - if (enable) { - glEnable(GL_STENCIL_TEST); - glStencilMask(write_mask); - - GLenum func; - GLenum pass; - GLenum fail; - GLenum zfail; - DecodeStencilFuncOps(func_ops, &func, &pass, &fail, &zfail); - if (separate_ccw) { - glStencilFuncSeparate(GL_FRONT, func, ref, compare_mask); - glStencilOpSeparate(GL_FRONT, pass, fail, zfail); - // Extract upper 16 bits. - Uint32 ccw_func_ops = BitField<16, 16>::Get(func_ops); - GLenum ccw_func; - GLenum ccw_pass; - GLenum ccw_fail; - GLenum ccw_zfail; - DecodeStencilFuncOps(ccw_func_ops, &ccw_func, &ccw_pass, &ccw_fail, - &ccw_zfail); - glStencilFuncSeparate(GL_BACK, ccw_func, ref, compare_mask); - glStencilOpSeparate(GL_BACK, ccw_pass, ccw_fail, ccw_zfail); - } else { - glStencilFunc(func, ref, compare_mask); - glStencilOp(pass, fail, zfail); - } - } else { - glDisable(GL_STENCIL_TEST); - } -} - -void GAPIGL::SetColorWrite(bool red, - bool green, - bool blue, - bool alpha, - bool dither) { - glColorMask(red, green, blue, alpha); - if (dither) { - glEnable(GL_DITHER); - } else { - glDisable(GL_DITHER); - } -} - -void GAPIGL::SetBlending(bool enable, - bool separate_alpha, - BlendEq color_eq, - BlendFunc color_src_func, - BlendFunc color_dst_func, - BlendEq alpha_eq, - BlendFunc alpha_src_func, - BlendFunc alpha_dst_func) { - DCHECK_LT(color_eq, kNumBlendEq); - DCHECK_LT(color_src_func, kNumBlendFunc); - DCHECK_LT(color_dst_func, kNumBlendFunc); - DCHECK_LT(alpha_eq, kNumBlendEq); - DCHECK_LT(alpha_src_func, kNumBlendFunc); - DCHECK_LT(alpha_dst_func, kNumBlendFunc); - if (enable) { - glEnable(GL_BLEND); - GLenum gl_color_eq = kGLBlendEq[color_eq]; - GLenum gl_color_src_func = kGLBlendFunc[color_src_func]; - GLenum gl_color_dst_func = kGLBlendFunc[color_dst_func]; - if (separate_alpha) { - GLenum gl_alpha_eq = kGLBlendEq[alpha_eq]; - GLenum gl_alpha_src_func = kGLBlendFunc[alpha_src_func]; - GLenum gl_alpha_dst_func = kGLBlendFunc[alpha_dst_func]; - glBlendFuncSeparate(gl_color_src_func, gl_color_dst_func, - gl_alpha_src_func, gl_alpha_dst_func); - glBlendEquationSeparate(gl_color_eq, gl_alpha_eq); - } else { - glBlendFunc(gl_color_src_func, gl_color_dst_func); - glBlendEquation(gl_color_eq); - } - } else { - glDisable(GL_BLEND); - } -} - -void GAPIGL::SetBlendingColor(const RGBA &color) { - glBlendColor(color.red, color.green, color.blue, color.alpha); -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/texture_d3d9.cc b/o3d/gpu/command_buffer/service/texture_d3d9.cc deleted file mode 100644 index 9f25ff0..0000000 --- a/o3d/gpu/command_buffer/service/texture_d3d9.cc +++ /dev/null @@ -1,731 +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 D3D9 versions of the texture resources, as well as -// the related GAPID3D9 function implementations. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_d3d9.h" -#include "gpu/command_buffer/service/texture_d3d9.h" - -namespace command_buffer { -namespace o3d { - -// Converts a texture format to a D3D texture format. -D3DFORMAT TextureD3D9::D3DFormat(texture::Format format) { - switch (format) { - case texture::kXRGB8: return D3DFMT_X8R8G8B8; - case texture::kARGB8: return D3DFMT_A8R8G8B8; - case texture::kABGR16F: return D3DFMT_A16B16G16R16F; - case texture::kR32F: return D3DFMT_R32F; - case texture::kABGR32F: return D3DFMT_A32B32G32R32F; - case texture::kDXT1: return D3DFMT_DXT1; - // TODO(petersont): Add DXT3/5 support. - default: return D3DFMT_UNKNOWN; - }; -} - -// Converts a cube map face to a D3D face. -D3DCUBEMAP_FACES TextureD3D9::D3DFace(texture::Face face) { - switch (face) { - case texture::kFacePositiveX: - return D3DCUBEMAP_FACE_POSITIVE_X; - case texture::kFaceNegativeX: - return D3DCUBEMAP_FACE_NEGATIVE_X; - case texture::kFacePositiveY: - return D3DCUBEMAP_FACE_POSITIVE_Y; - case texture::kFaceNegativeY: - return D3DCUBEMAP_FACE_NEGATIVE_Y; - case texture::kFacePositiveZ: - return D3DCUBEMAP_FACE_POSITIVE_Z; - case texture::kFaceNegativeZ: - return D3DCUBEMAP_FACE_NEGATIVE_Z; - } - LOG(FATAL) << "Not reached."; - return D3DCUBEMAP_FACE_POSITIVE_X; -} - -// Texture 2D functions - -// Destroys the 2D texture, releasing the D3D texture, and its shadow if any. -Texture2DD3D9::~Texture2DD3D9() { - DCHECK(d3d_texture_); - d3d_texture_ = NULL; - if (d3d_shadow_) { - d3d_shadow_->Release(); - d3d_shadow_ = NULL; - } -} - -// Creates a 2D texture. For dynamic textures, create it in the default pool, -// and a shadow version in the system memory pool (that we can lock). For -// regular texture, simply create one in the managed pool. -Texture2DD3D9 *Texture2DD3D9::Create(GAPID3D9 *gapi, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(width, 0U); - DCHECK_GT(height, 0U); - DCHECK_GT(levels, 0U); - D3DFORMAT d3d_format = D3DFormat(format); - IDirect3DDevice9 *device = gapi->d3d_device(); - if (enable_render_surfaces) { - CComPtr<IDirect3DTexture9> d3d_texture = NULL; - HRESULT result = device->CreateTexture(width, height, levels, - D3DUSAGE_RENDERTARGET, d3d_format, - D3DPOOL_DEFAULT, &d3d_texture, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture, - NULL, enable_render_surfaces); - } else if (flags & texture::kDynamic) { - CComPtr<IDirect3DTexture9> d3d_texture = NULL; - HRESULT result = device->CreateTexture(width, height, levels, - D3DUSAGE_DYNAMIC, d3d_format, - D3DPOOL_DEFAULT, &d3d_texture, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - CComPtr<IDirect3DTexture9> d3d_shadow = NULL; - result = device->CreateTexture(width, height, levels, D3DUSAGE_DYNAMIC, - d3d_format, D3DPOOL_SYSTEMMEM, &d3d_shadow, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture, - d3d_shadow, enable_render_surfaces); - } else { - CComPtr<IDirect3DTexture9> d3d_texture = NULL; - HRESULT result = device->CreateTexture(width, height, levels, 0, d3d_format, - D3DPOOL_MANAGED, &d3d_texture, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture2DD3D9(levels, format, flags, width, height, d3d_texture, - NULL, enable_render_surfaces); - } -} - -// Sets the data in the texture, using LockRect()/UnlockRect(). For dynamic -// textures, it copies the data to the shadow texture, then updates the actual -// texture. For regular texture, it directly modifies the actual texture. -bool Texture2DD3D9::SetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - DCHECK(d3d_texture_); - IDirect3DTexture9 *lock_texture = d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, 1, level); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < src_transfer_info.total_size) - return false; - - bool full_rect = IsFullVolume(mip_info, volume); - D3DLOCKED_RECT locked_rect; - RECT rect = {volume.x, volume.y, volume.x+volume.width, - volume.y+volume.height}; - DWORD lock_flags = - full_rect && (flags() & texture::kDynamic) ? D3DLOCK_DISCARD : 0; - HR(lock_texture->LockRect(level, &locked_rect, full_rect ? NULL : &rect, - lock_flags)); - - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, locked_rect.Pitch, - slice_pitch); - TransferVolume(volume, mip_info, dst_transfer_info, locked_rect.pBits, - src_transfer_info, data); - - HR(lock_texture->UnlockRect(level)); - if (d3d_shadow_) { - HR(gapi->d3d_device()->UpdateTexture(d3d_shadow_, d3d_texture_)); - } - return true; -} - -// Gets the data from the texture, using LockRect()/UnlockRect(). For dynamic -// textures, it gets the data from the shadow texture, For regular texture, it -// gets it directly from the actual texture. -bool Texture2DD3D9::GetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - DCHECK(d3d_texture_); - IDirect3DTexture9 *lock_texture = d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, 1, level); - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < dst_transfer_info.total_size) - return false; - - bool full_rect = IsFullVolume(mip_info, volume); - D3DLOCKED_RECT locked_rect; - RECT rect = {volume.x, volume.y, volume.x+volume.width, - volume.y+volume.height}; - DWORD lock_flags = D3DLOCK_READONLY; - HR(lock_texture->LockRect(level, &locked_rect, full_rect ? NULL : &rect, - lock_flags)); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, locked_rect.Pitch, - slice_pitch); - TransferVolume(volume, mip_info, dst_transfer_info, data, - src_transfer_info, locked_rect.pBits); - HR(lock_texture->UnlockRect(level)); - return true; -} - -bool Texture2DD3D9::CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface) { - IDirect3DTexture9* d3d_texture = - static_cast<IDirect3DTexture9*>(d3d_base_texture()); - D3DSURFACE_DESC surface_desc; - d3d_texture->GetLevelDesc(mip_level, &surface_desc); - if (width != surface_desc.Width || height != surface_desc.Height) { - return false; - } - HR(d3d_texture->GetSurfaceLevel(mip_level, direct3d_surface)); - return true; -} - -// Texture 3D functions - -// Destroys the 3D texture. -Texture3DD3D9::~Texture3DD3D9() { - DCHECK(d3d_texture_); - d3d_texture_ = NULL; - if (d3d_shadow_) { - d3d_shadow_->Release(); - d3d_shadow_ = NULL; - } -} - -// Creates a 3D texture. For dynamic textures, create it in the default pool, -// and a shadow version in the system memory pool (that we can lock). For -// regular texture, simply create one in the managed pool. -Texture3DD3D9 *Texture3DD3D9::Create(GAPID3D9 *gapi, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(width, 0U); - DCHECK_GT(height, 0U); - DCHECK_GT(depth, 0U); - DCHECK_GT(levels, 0U); - D3DFORMAT d3d_format = D3DFormat(format); - IDirect3DDevice9 *device = gapi->d3d_device(); - if (enable_render_surfaces) { - CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateVolumeTexture(width, height, depth, levels, - D3DUSAGE_RENDERTARGET, - d3d_format, D3DPOOL_DEFAULT, - &d3d_texture, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture3DD3D9(levels, format, flags, width, height, depth, - d3d_texture, NULL, enable_render_surfaces); - } else if (flags & texture::kDynamic) { - CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateVolumeTexture(width, height, depth, levels, - D3DUSAGE_DYNAMIC, d3d_format, - D3DPOOL_DEFAULT, &d3d_texture, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - CComPtr<IDirect3DVolumeTexture9> d3d_shadow = NULL; - result = device->CreateVolumeTexture(width, height, depth, levels, - D3DUSAGE_DYNAMIC, d3d_format, - D3DPOOL_SYSTEMMEM, &d3d_shadow, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture3DD3D9(levels, format, flags, width, height, depth, - d3d_texture, d3d_shadow, enable_render_surfaces); - } else { - CComPtr<IDirect3DVolumeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateVolumeTexture(width, height, depth, levels, - D3DUSAGE_DYNAMIC, d3d_format, - D3DPOOL_MANAGED, &d3d_texture, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new Texture3DD3D9(levels, format, flags, width, height, depth, - d3d_texture, NULL, enable_render_surfaces); - } -} - -// Sets the data in the texture, using LockBox()/UnlockBox(). For dynamic -// textures, it copies the data to the shadow texture, then updates the actual -// texture. For regular texture, it directly modifies the actual texture. -bool Texture3DD3D9::SetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - DCHECK(d3d_texture_); - IDirect3DVolumeTexture9 *lock_texture = - d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, depth_, level); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < src_transfer_info.total_size) - return false; - - bool full_box = IsFullVolume(mip_info, volume); - D3DLOCKED_BOX locked_box; - D3DBOX box = {volume.x, volume.y, volume.z, volume.x+volume.width, - volume.y+volume.height, volume.z+volume.depth}; - DWORD lock_flags = - full_box && (flags() & texture::kDynamic) ? D3DLOCK_DISCARD : 0; - HR(lock_texture->LockBox(level, &locked_box, full_box ? NULL : &box, - lock_flags)); - - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, locked_box.RowPitch, - locked_box.SlicePitch); - TransferVolume(volume, mip_info, dst_transfer_info, locked_box.pBits, - src_transfer_info, data); - - HR(lock_texture->UnlockBox(level)); - if (d3d_shadow_) { - HR(gapi->d3d_device()->UpdateTexture(d3d_shadow_, d3d_texture_)); - } - return true; -} - -// Gets the data from the texture, using LockBox()/UnlockBox(). For dynamic -// textures, it gets the data from the shadow texture, For regular texture, it -// gets it directly from the actual texture. -bool Texture3DD3D9::GetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - DCHECK(d3d_texture_); - IDirect3DVolumeTexture9 *lock_texture = - d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, depth_, level); - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < dst_transfer_info.total_size) - return false; - - bool full_box = IsFullVolume(mip_info, volume); - D3DLOCKED_BOX locked_box; - D3DBOX box = {volume.x, volume.y, volume.z, volume.x+volume.width, - volume.y+volume.height, volume.z+volume.depth}; - DWORD lock_flags = D3DLOCK_READONLY; - HR(lock_texture->LockBox(level, &locked_box, full_box ? NULL : &box, - lock_flags)); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, locked_box.RowPitch, - locked_box.SlicePitch); - TransferVolume(volume, mip_info, dst_transfer_info, data, - src_transfer_info, locked_box.pBits); - HR(lock_texture->UnlockBox(level)); - return true; -} - -bool Texture3DD3D9::CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface) { - // TODO(rlp): Currently unsupported. - DCHECK(false); - return false; -} - -// Texture Cube functions. - -// Destroys the cube map texture, releasing the D3D texture, and its shadow if -// any. -TextureCubeD3D9::~TextureCubeD3D9() { - DCHECK(d3d_texture_); - d3d_texture_ = NULL; - if (d3d_shadow_) { - d3d_shadow_->Release(); - d3d_shadow_ = NULL; - } -} - -// Creates a cube map texture. For dynamic textures, create it in the default -// pool, and a shadow version in the system memory pool (that we can lock). For -// regular texture, simply create one in the managed pool. -TextureCubeD3D9 *TextureCubeD3D9::Create(GAPID3D9 *gapi, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(side, 0U); - DCHECK_GT(levels, 0U); - D3DFORMAT d3d_format = D3DFormat(format); - IDirect3DDevice9 *device = gapi->d3d_device(); - if (enable_render_surfaces) { - CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateCubeTexture(side, levels, - D3DUSAGE_RENDERTARGET, - d3d_format, D3DPOOL_DEFAULT, - &d3d_texture, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, NULL, - enable_render_surfaces); - } else if (flags & texture::kDynamic) { - CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateCubeTexture(side, levels, D3DUSAGE_DYNAMIC, - d3d_format, D3DPOOL_DEFAULT, - &d3d_texture, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - CComPtr<IDirect3DCubeTexture9> d3d_shadow = NULL; - result = device->CreateCubeTexture(side, levels, D3DUSAGE_DYNAMIC, - d3d_format, D3DPOOL_SYSTEMMEM, - &d3d_shadow, NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, - d3d_shadow, enable_render_surfaces); - } else { - CComPtr<IDirect3DCubeTexture9> d3d_texture = NULL; - HRESULT result = device->CreateCubeTexture(side, levels, 0, d3d_format, - D3DPOOL_MANAGED, &d3d_texture, - NULL); - if (result != D3D_OK) { - LOG(ERROR) << "DirectX error when calling CreateTexture: " - << DXGetErrorStringA(result); - return NULL; - } - return new TextureCubeD3D9(levels, format, flags, side, d3d_texture, NULL, - enable_render_surfaces); - } -} - -// Sets the data in the texture, using LockRect()/UnlockRect(). For dynamic -// textures, it copies the data to the shadow texture, then updates the actual -// texture. For regular texture, it directly modifies the actual texture. -bool TextureCubeD3D9::SetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - DCHECK(d3d_texture_); - IDirect3DCubeTexture9 *lock_texture = - d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), side_, side_, 1, level); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < src_transfer_info.total_size) - return false; - - D3DCUBEMAP_FACES d3d_face = D3DFace(face); - bool full_rect = IsFullVolume(mip_info, volume); - D3DLOCKED_RECT locked_rect; - RECT rect = {volume.x, volume.y, volume.x+volume.width, - volume.y+volume.height}; - DWORD lock_flags = - full_rect && (flags() & texture::kDynamic) ? D3DLOCK_DISCARD : 0; - HR(lock_texture->LockRect(d3d_face, level, &locked_rect, - full_rect ? NULL : &rect, lock_flags)); - - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, locked_rect.Pitch, - slice_pitch); - TransferVolume(volume, mip_info, dst_transfer_info, locked_rect.pBits, - src_transfer_info, data); - - HR(lock_texture->UnlockRect(d3d_face, level)); - if (d3d_shadow_) { - HR(gapi->d3d_device()->UpdateTexture(d3d_shadow_, d3d_texture_)); - } - return true; -} - -// Gets the data from the texture, using LockRect()/UnlockRect(). For dynamic -// textures, it gets the data from the shadow texture, For regular texture, it -// gets it directly from the actual texture. -bool TextureCubeD3D9::GetData(GAPID3D9 *gapi, - const Volume &volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - DCHECK(d3d_texture_); - IDirect3DCubeTexture9 *lock_texture = - d3d_shadow_ ? d3d_shadow_ : d3d_texture_; - - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), side_, side_, 1, level); - TransferInfo dst_transfer_info; - MakeTransferInfo(&dst_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || level >= levels() || - size < dst_transfer_info.total_size) - return false; - - D3DCUBEMAP_FACES d3d_face = D3DFace(face); - bool full_rect = IsFullVolume(mip_info, volume); - D3DLOCKED_RECT locked_rect; - RECT rect = {volume.x, volume.y, volume.x+volume.width, - volume.y+volume.height}; - DWORD lock_flags = D3DLOCK_READONLY; - HR(lock_texture->LockRect(d3d_face, level, &locked_rect, - full_rect ? NULL : &rect, lock_flags)); - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, locked_rect.Pitch, - slice_pitch); - TransferVolume(volume, mip_info, dst_transfer_info, data, - src_transfer_info, locked_rect.pBits); - HR(lock_texture->UnlockRect(d3d_face, level)); - return true; -} - -bool TextureCubeD3D9::CreateRenderSurface( - int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface) { - IDirect3DCubeTexture9* d3d_cube_texture = - static_cast<IDirect3DCubeTexture9*>(d3d_base_texture()); - D3DSURFACE_DESC surface_desc; - d3d_cube_texture->GetLevelDesc(mip_level, &surface_desc); - if (width != surface_desc.Width || height != surface_desc.Height || - side < 0 || side > 5) { - return false; - } - HR(d3d_cube_texture->GetCubeMapSurface( - D3DFace(static_cast<texture::Face>(side)), - mip_level, - direct3d_surface)); - return true; -} - -// GAPID3D9 functions. - -// Destroys a texture resource. -parse_error::ParseError GAPID3D9::DestroyTexture(ResourceId id) { - // Dirty effect, because this texture id may be used - DirtyEffect(); - return textures_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Creates a 2D texture resource. -parse_error::ParseError GAPID3D9::CreateTexture2D( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - Texture2DD3D9 *texture = Texture2DD3D9::Create(this, width, height, levels, - format, flags, - enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Creates a 3D texture resource. -parse_error::ParseError GAPID3D9::CreateTexture3D( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - Texture3DD3D9 *texture = Texture3DD3D9::Create(this, width, height, depth, - levels, format, flags, - enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Creates a cube map texture resource. -parse_error::ParseError GAPID3D9::CreateTextureCube( - ResourceId id, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - TextureCubeD3D9 *texture = TextureCubeD3D9::Create(this, side, levels, - format, flags, - enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Copies the data into a texture resource. -parse_error::ParseError GAPID3D9::SetTextureData( - ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - TextureD3D9 *texture = textures_.Get(id); - if (!texture) - return parse_error::kParseInvalidArguments; - Volume volume = {x, y, z, width, height, depth}; - return texture->SetData(this, volume, level, face, row_pitch, slice_pitch, - size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data from a texture resource. -parse_error::ParseError GAPID3D9::GetTextureData( - ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - TextureD3D9 *texture = textures_.Get(id); - if (!texture) - return parse_error::kParseInvalidArguments; - Volume volume = {x, y, z, width, height, depth}; - return texture->GetData(this, volume, level, face, row_pitch, slice_pitch, - size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/texture_d3d9.h b/o3d/gpu/command_buffer/service/texture_d3d9.h deleted file mode 100644 index de913a8..0000000 --- a/o3d/gpu/command_buffer/service/texture_d3d9.h +++ /dev/null @@ -1,282 +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 GPU_COMMAND_BUFFER_SERVICE_TEXTURE_D3D9_H_ -#define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_D3D9_H_ - -// This file contains the definition of the D3D9 versions of texture-related -// resource classes. -#include <atlbase.h> - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/d3d9_utils.h" -#include "gpu/command_buffer/service/resource.h" -#include "gpu/command_buffer/service/texture_utils.h" - -namespace command_buffer { -namespace o3d { - -class GAPID3D9; - -// The base class for a D3D texture resource, providing access to the base D3D -// texture that can be assigned to an effect parameter or a sampler unit. -class TextureD3D9 : public Texture { - public: - TextureD3D9(texture::Type type, - unsigned int levels, - texture::Format format, - bool enable_render_surfaces, - unsigned int flags) - : Texture(type, levels, format, enable_render_surfaces, flags) {} - // Gets the D3D base texture. - virtual IDirect3DBaseTexture9 *d3d_base_texture() const = 0; - // Sets data into a texture resource. - virtual bool SetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) = 0; - // Gets data from a texture resource. - virtual bool GetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) = 0; - // Creates the render surface, returning false if unable to. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface) = 0; - static D3DFORMAT D3DFormat(texture::Format format); - static D3DCUBEMAP_FACES D3DFace(texture::Face face); - private: - DISALLOW_COPY_AND_ASSIGN(TextureD3D9); -}; - -// A 2D texture resource for D3D. -class Texture2DD3D9 : public TextureD3D9 { - public: - Texture2DD3D9(unsigned int levels, - texture::Format format, - unsigned int flags, - unsigned int width, - unsigned int height, - IDirect3DTexture9 *texture, - IDirect3DTexture9 *shadow, - bool enable_render_surfaces) - : TextureD3D9(texture::kTexture2d, levels, format, - enable_render_surfaces, flags), - width_(width), - height_(height), - d3d_texture_(texture), - d3d_shadow_(shadow) {} - virtual ~Texture2DD3D9(); - - // Creates a 2D texture resource. - static Texture2DD3D9 *Create(GAPID3D9 *gapi, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - // Sets data into a 2D texture resource. - virtual bool SetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - // Gets data from a 2D texture resource. - virtual bool GetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface); - // Gets the D3D base texture. - virtual IDirect3DBaseTexture9 *d3d_base_texture() const { - return d3d_texture_; - } - private: - unsigned int width_; - unsigned int height_; - CComPtr<IDirect3DTexture9> d3d_texture_; - IDirect3DTexture9 *d3d_shadow_; - DISALLOW_COPY_AND_ASSIGN(Texture2DD3D9); -}; - -// A 3D texture resource for D3D. -class Texture3DD3D9 : public TextureD3D9 { - public: - Texture3DD3D9(unsigned int levels, - texture::Format format, - unsigned int flags, - unsigned int width, - unsigned int height, - unsigned int depth, - IDirect3DVolumeTexture9 *texture, - IDirect3DVolumeTexture9 *shadow, - bool enable_render_surfaces) - : TextureD3D9(texture::kTexture3d, levels, format, - enable_render_surfaces, flags), - width_(width), - height_(height), - depth_(depth), - d3d_texture_(texture), - d3d_shadow_(shadow) {} - virtual ~Texture3DD3D9(); - // Creates a 3D texture resource. - static Texture3DD3D9 *Create(GAPID3D9 *gapi, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - // Sets data into a 3D texture resource. - virtual bool SetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - // Gets data from a 3D texture resource. - virtual bool GetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface); - // Gets the D3D base texture. - virtual IDirect3DBaseTexture9 *d3d_base_texture() const { - return d3d_texture_; - } - private: - unsigned int width_; - unsigned int height_; - unsigned int depth_; - CComPtr<IDirect3DVolumeTexture9> d3d_texture_; - IDirect3DVolumeTexture9 *d3d_shadow_; - DISALLOW_COPY_AND_ASSIGN(Texture3DD3D9); -}; - -// A cube map texture resource for D3D. -class TextureCubeD3D9 : public TextureD3D9 { - public: - TextureCubeD3D9(unsigned int levels, - texture::Format format, - unsigned int flags, - unsigned int side, - IDirect3DCubeTexture9 *texture, - IDirect3DCubeTexture9 *shadow, - bool enable_render_surfaces) - : TextureD3D9(texture::kTextureCube, levels, format, - enable_render_surfaces, flags), - side_(side), - d3d_texture_(texture), - d3d_shadow_(shadow) {} - virtual ~TextureCubeD3D9(); - // Creates a cube map texture resource. - static TextureCubeD3D9 *Create(GAPID3D9 *gapi, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - // Sets data into a cube map texture resource. - virtual bool SetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - // Gets data from a cube map texture resource. - virtual bool GetData(GAPID3D9 *gapi, - const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side, - IDirect3DSurface9** direct3d_surface); - // Gets the D3D base texture. - virtual IDirect3DBaseTexture9 *d3d_base_texture() const { - return d3d_texture_; - } - private: - unsigned int side_; - CComPtr<IDirect3DCubeTexture9> d3d_texture_; - IDirect3DCubeTexture9 *d3d_shadow_; - DISALLOW_COPY_AND_ASSIGN(TextureCubeD3D9); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_D3D9_H_ diff --git a/o3d/gpu/command_buffer/service/texture_gl.cc b/o3d/gpu/command_buffer/service/texture_gl.cc deleted file mode 100644 index 386c5ec..0000000 --- a/o3d/gpu/command_buffer/service/texture_gl.cc +++ /dev/null @@ -1,767 +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 texture-related GAPI functions on GL. - -#include "gpu/command_buffer/service/precompile.h" -#include "gpu/command_buffer/service/gapi_gl.h" -#include "gpu/command_buffer/service/texture_gl.h" - -namespace command_buffer { -namespace o3d { - -namespace { - -// Gets the GL internal format, format and type corresponding to a command -// buffer texture format. -bool GetGLFormatType(texture::Format format, - GLenum *internal_format, - GLenum *gl_format, - GLenum *gl_type) { - switch (format) { - case texture::kXRGB8: { - *internal_format = GL_RGB; - *gl_format = GL_BGRA; - *gl_type = GL_UNSIGNED_BYTE; - break; - } - case texture::kARGB8: { - *internal_format = GL_RGBA; - *gl_format = GL_BGRA; - *gl_type = GL_UNSIGNED_BYTE; - break; - } - case texture::kABGR16F: { - *internal_format = GL_RGBA16F_ARB; - *gl_format = GL_RGBA; - *gl_type = GL_HALF_FLOAT_ARB; - break; - } - case texture::kR32F: { - *internal_format = GL_LUMINANCE32F_ARB; - *gl_format = GL_LUMINANCE; - *gl_type = GL_FLOAT; - break; - } - case texture::kABGR32F: { - *internal_format = GL_RGBA32F_ARB; - *gl_format = GL_BGRA; - *gl_type = GL_FLOAT; - break; - } - case texture::kDXT1: { - *internal_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - *gl_format = 0; - *gl_type = 0; - break; - } - // TODO(petersont): Add DXT3/5 support. - default: - return false; - } - - return true; -} - -// Helper class used to prepare image data to match the layout that -// glTexImage* and glCompressedTexImage* expect. -class SetImageHelper { - public: - SetImageHelper() - : buffer_(NULL), - image_data_(NULL), - image_size_(0) { - } - - // Initializes the helper with the input data, re-using the input buffer if - // possible, or copying it into a temporary one. - bool Initialize(const MipLevelInfo &mip_info, - const Volume& volume, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int src_size, - const void *data) { - TransferInfo src_transfer_info; - MakeTransferInfo(&src_transfer_info, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || - src_size < src_transfer_info.total_size) - return false; - if (!src_transfer_info.packed) { - TransferInfo dst_transfer_info; - MakePackedTransferInfo(&dst_transfer_info, mip_info, volume); - buffer_.reset(new unsigned char[dst_transfer_info.total_size]); - TransferVolume(volume, mip_info, dst_transfer_info, buffer_.get(), - src_transfer_info, data); - image_data_ = buffer_.get(); - image_size_ = dst_transfer_info.total_size; - } else { - image_data_ = data; - image_size_ = src_transfer_info.total_size; - } - return true; - } - - // Gets the buffer that contains the data in the GL format. - const void *image_data() { return image_data_; } - // Gets the size of the buffer as GL expects it. - unsigned int image_size() { return image_size_; } - - private: - scoped_array<unsigned char> buffer_; - const void *image_data_; - unsigned int image_size_; - DISALLOW_COPY_AND_ASSIGN(SetImageHelper); -}; - -// Helper class used to retrieve image data to match the layout that -// glGetTexImage and glGetCompressedTexImage expect. -class GetImageHelper { - public: - GetImageHelper() - : dst_data_(NULL), - buffer_(NULL), - image_data_(NULL) { - memset(&mip_info_, 0, sizeof(mip_info_)); - memset(&volume_, 0, sizeof(volume_)); - memset(&dst_transfer_info_, 0, sizeof(dst_transfer_info_)); - memset(&src_transfer_info_, 0, sizeof(src_transfer_info_)); - } - - // Initialize the helper to make available a buffer to get the data from GL. - // It will re-use the passed in buffer if the layout matches GL, or allocate - // a temporary one. - bool Initialize(const MipLevelInfo &mip_info, - const Volume& volume, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int dst_size, - void *dst_data) { - mip_info_ = mip_info; - volume_ = volume; - dst_data_ = dst_data; - MakeTransferInfo(&dst_transfer_info_, mip_info, volume, row_pitch, - slice_pitch); - if (!CheckVolume(mip_info, volume) || - dst_size < dst_transfer_info_.total_size) - return false; - - if (!IsFullVolume(mip_info, volume) || !dst_transfer_info_.packed) { - // We can only retrieve the full image from GL. - Volume full_volume = { - 0, 0, 0, - mip_info.width, mip_info.height, mip_info.depth - }; - MakePackedTransferInfo(&src_transfer_info_, mip_info, full_volume); - buffer_.reset(new unsigned char[src_transfer_info_.total_size]); - image_data_ = buffer_.get(); - } else { - image_data_ = dst_data; - } - return true; - } - - // Finalize the helper, copying the data into the final buffer if needed. - void Finalize() { - if (!buffer_.get()) return; - unsigned int offset = - volume_.x / mip_info_.block_size_x * mip_info_.block_bpp + - volume_.y / mip_info_.block_size_y * src_transfer_info_.row_pitch + - volume_.z * src_transfer_info_.slice_pitch; - src_transfer_info_.row_size = dst_transfer_info_.row_size; - TransferVolume(volume_, mip_info_, dst_transfer_info_, dst_data_, - src_transfer_info_, buffer_.get() + offset); - } - - // Gets the buffer that can receive the data from GL. - void *image_data() { return image_data_; } - - private: - MipLevelInfo mip_info_; - Volume volume_; - TransferInfo dst_transfer_info_; - TransferInfo src_transfer_info_; - void *dst_data_; - scoped_array<unsigned char> buffer_; - void *image_data_; - DISALLOW_COPY_AND_ASSIGN(GetImageHelper); -}; - -} // anonymous namespace - -TextureGL::~TextureGL() { - glDeleteTextures(1, &gl_texture_); - CHECK_GL_ERROR(); -} - -Texture2DGL *Texture2DGL::Create(unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(width, 0U); - DCHECK_GT(height, 0U); - DCHECK_GT(levels, 0U); - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format, &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); // Was checked in the decoder. - GLuint gl_texture = 0; - glGenTextures(1, &gl_texture); - glBindTexture(GL_TEXTURE_2D, gl_texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1); - // glCompressedTexImage2D does't accept NULL as a parameter, so we need - // to pass in some data. - scoped_array<unsigned char> buffer; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, width, height, 1, 0); - unsigned int size = GetMipLevelSize(mip_info); - buffer.reset(new unsigned char[size]); - memset(buffer.get(), 0, size); - - unsigned int mip_width = width; - unsigned int mip_height = height; - - for (unsigned int i = 0; i < levels; ++i) { - if (gl_format) { - glTexImage2D(GL_TEXTURE_2D, i, gl_internal_format, mip_width, mip_height, - 0, gl_format, gl_type, buffer.get()); - } else { - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, width, height, 1, i); - unsigned int size = GetMipLevelSize(mip_info); - glCompressedTexImage2D(GL_TEXTURE_2D, i, gl_internal_format, mip_width, - mip_height, 0, size, buffer.get()); - } - mip_width = std::max(1U, mip_width >> 1); - mip_height = std::max(1U, mip_height >> 1); - } - return new Texture2DGL( - levels, format, enable_render_surfaces, flags, width, height, gl_texture); -} - -// Sets data into a 2D texture resource. -bool Texture2DGL::SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, 1, level); - SetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_2D, gl_texture_); - if (gl_format) { - glTexSubImage2D(GL_TEXTURE_2D, level, volume.x, volume.y, volume.width, - volume.height, gl_format, gl_type, helper.image_data()); - } else { - glCompressedTexSubImage2D(GL_TEXTURE_2D, level, volume.x, volume.y, - volume.width, volume.height, gl_internal_format, - helper.image_size(), helper.image_data()); - } - return true; -} - -bool Texture2DGL::GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, 1, level); - GetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_2D, gl_texture_); - if (gl_format) { - glGetTexImage(GL_TEXTURE_2D, level, gl_format, gl_type, - helper.image_data()); - } else { - glGetCompressedTexImage(GL_TEXTURE_2D, level, helper.image_data()); - } - - helper.Finalize(); - return true; -} - -bool Texture2DGL::CreateRenderSurface(int width, - int height, - int mip_level, - int side) { - return false; -} - -bool Texture2DGL::InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface) { - ::glFramebufferTexture2DEXT( - GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - GL_TEXTURE_2D, - gl_texture_, - gl_surface->mip_level()); - - GLenum framebuffer_status = ::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (GL_FRAMEBUFFER_COMPLETE_EXT != framebuffer_status) { - return false; - } - - return true; -} - -Texture3DGL *Texture3DGL::Create(unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(width, 0U); - DCHECK_GT(height, 0U); - DCHECK_GT(depth, 0U); - DCHECK_GT(levels, 0U); - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format, &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); // Was checked in the decoder. - GLuint gl_texture = 0; - glGenTextures(1, &gl_texture); - glBindTexture(GL_TEXTURE_3D, gl_texture); - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, levels - 1); - // glCompressedTexImage3D does't accept NULL as a parameter, so we need - // to pass in some data. - scoped_array<unsigned char> buffer; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, width, height, depth, 0); - unsigned int size = GetMipLevelSize(mip_info); - buffer.reset(new unsigned char[size]); - memset(buffer.get(), 0, size); - - unsigned int mip_width = width; - unsigned int mip_height = height; - unsigned int mip_depth = depth; - for (unsigned int i = 0; i < levels; ++i) { - if (gl_format) { - glTexImage3D(GL_TEXTURE_3D, i, gl_internal_format, mip_width, mip_height, - mip_depth, 0, gl_format, gl_type, buffer.get()); - } else { - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, width, height, depth, i); - unsigned int size = GetMipLevelSize(mip_info); - glCompressedTexImage3D(GL_TEXTURE_3D, i, gl_internal_format, mip_width, - mip_height, mip_depth, 0, size, buffer.get()); - } - mip_width = std::max(1U, mip_width >> 1); - mip_height = std::max(1U, mip_height >> 1); - mip_depth = std::max(1U, mip_depth >> 1); - } - return new Texture3DGL(levels, format, enable_render_surfaces, flags, width, - height, depth, gl_texture); -} - -bool Texture3DGL::SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, depth_, level); - SetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_3D, gl_texture_); - if (gl_format) { - glTexSubImage3D(GL_TEXTURE_3D, level, volume.x, volume.y, volume.z, - volume.width, volume.height, volume.depth, - gl_format, gl_type, helper.image_data()); - } else { - glCompressedTexSubImage3D(GL_TEXTURE_3D, level, volume.x, volume.y, - volume.z, volume.width, volume.height, - volume.depth, gl_internal_format, - helper.image_size(), helper.image_data()); - } - return true; -} - -bool Texture3DGL::GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), width_, height_, depth_, level); - GetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_3D, gl_texture_); - if (gl_format) { - glGetTexImage(GL_TEXTURE_3D, level, gl_format, gl_type, - helper.image_data()); - } else { - glGetCompressedTexImage(GL_TEXTURE_3D, level, helper.image_data()); - } - - helper.Finalize(); - return true; -} - -bool Texture3DGL::CreateRenderSurface(int width, - int height, - int mip_level, - int side) { - return false; -} - -bool Texture3DGL::InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface) { - return false; -} - -TextureCubeGL *TextureCubeGL::Create(unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - DCHECK_GT(side, 0U); - DCHECK_GT(levels, 0U); - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format, &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); // Was checked in the decoder. - GLuint gl_texture = 0; - glGenTextures(1, &gl_texture); - glBindTexture(GL_TEXTURE_CUBE_MAP, gl_texture); - glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, - levels-1); - // glCompressedTexImage2D does't accept NULL as a parameter, so we need - // to pass in some data. - scoped_array<unsigned char> buffer; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, side, side, 1, 0); - unsigned int size = GetMipLevelSize(mip_info); - buffer.reset(new unsigned char[size]); - memset(buffer.get(), 0, size); - - unsigned int mip_side = side; - for (unsigned int i = 0; i < levels; ++i) { - if (gl_format) { - for (unsigned int face = 0; face < 6; ++face) { - glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, i, - gl_internal_format, mip_side, mip_side, - 0, gl_format, gl_type, buffer.get()); - } - } else { - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format, side, side, 1, i); - unsigned int size = GetMipLevelSize(mip_info); - for (unsigned int face = 0; face < 6; ++face) { - glCompressedTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, i, - gl_internal_format, mip_side, mip_side, 0, size, - buffer.get()); - } - } - mip_side = std::max(1U, mip_side >> 1); - } - return new TextureCubeGL( - levels, format, enable_render_surfaces, flags, side, gl_texture); -} - -// Check that GL_TEXTURE_CUBE_MAP_POSITIVE_X + face yields the correct GLenum. -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveX == - GL_TEXTURE_CUBE_MAP_POSITIVE_X, POSITIVE_X_ENUMS_DO_NOT_MATCH); -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeX == - GL_TEXTURE_CUBE_MAP_NEGATIVE_X, NEGATIVE_X_ENUMS_DO_NOT_MATCH); -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveY == - GL_TEXTURE_CUBE_MAP_POSITIVE_Y, POSITIVE_Y_ENUMS_DO_NOT_MATCH); -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeY == - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, NEGATIVE_Y_ENUMS_DO_NOT_MATCH); -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFacePositiveZ == - GL_TEXTURE_CUBE_MAP_POSITIVE_Z, POSITIVE_Z_ENUMS_DO_NOT_MATCH); -COMPILE_ASSERT(GL_TEXTURE_CUBE_MAP_POSITIVE_X + texture::kFaceNegativeZ == - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, NEGATIVE_Z_ENUMS_DO_NOT_MATCH); - -bool TextureCubeGL::SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), side_, side_, 1, level); - SetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_CUBE_MAP, gl_texture_); - GLenum face_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face; - if (gl_format) { - glTexSubImage2D(face_target, level, volume.x, volume.y, volume.width, - volume.height, gl_format, gl_type, helper.image_data()); - } else { - glCompressedTexSubImage2D(face_target, level, volume.x, volume.y, - volume.width, volume.height, gl_internal_format, - helper.image_size(), helper.image_data()); - } - return true; -} - -bool TextureCubeGL::GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - if (level >= levels()) - return false; - MipLevelInfo mip_info; - MakeMipLevelInfo(&mip_info, format(), side_, side_, 1, level); - GetImageHelper helper; - if (!helper.Initialize(mip_info, volume, row_pitch, slice_pitch, size, data)) - return false; - - GLenum gl_internal_format = 0; - GLenum gl_format = 0; - GLenum gl_type = 0; - bool r = GetGLFormatType(format(), &gl_internal_format, &gl_format, &gl_type); - DCHECK(r); - glBindTexture(GL_TEXTURE_CUBE_MAP, gl_texture_); - GLenum face_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face; - if (gl_format) { - glGetTexImage(face_target, level, gl_format, gl_type, - helper.image_data()); - } else { - glGetCompressedTexImage(face_target, level, helper.image_data()); - } - - helper.Finalize(); - return true; -} - -bool TextureCubeGL::CreateRenderSurface(int width, - int height, - int mip_level, - int side) { - return false; -} - -bool TextureCubeGL::InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface) { - ::glFramebufferTexture2DEXT( - GL_FRAMEBUFFER_EXT, - GL_COLOR_ATTACHMENT0_EXT, - gl_surface->side(), - gl_texture_, - gl_surface->mip_level()); - - GLenum framebuffer_status = ::glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (GL_FRAMEBUFFER_COMPLETE_EXT != framebuffer_status) { - return false; - } - - return true; -} - - -// Destroys a texture resource. -parse_error::ParseError GAPIGL::DestroyTexture(ResourceId id) { - // Dirty effect, because this texture id may be used. - DirtyEffect(); - return textures_.Destroy(id) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Creates a 2D texture resource. -parse_error::ParseError GAPIGL::CreateTexture2D( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - Texture2DGL *texture = Texture2DGL::Create( - width, height, levels, format, flags, enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used. - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Creates a 3D texture resource. -parse_error::ParseError GAPIGL::CreateTexture3D( - ResourceId id, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - Texture3DGL *texture = Texture3DGL::Create( - width, height, depth, levels, format, flags, enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used. - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Creates a cube map texture resource. -parse_error::ParseError GAPIGL::CreateTextureCube( - ResourceId id, - unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces) { - TextureCubeGL *texture = TextureCubeGL::Create( - side, levels, format, flags, enable_render_surfaces); - if (!texture) return parse_error::kParseInvalidArguments; - // Dirty effect, because this texture id may be used. - DirtyEffect(); - textures_.Assign(id, texture); - return parse_error::kParseNoError; -} - -// Copies the data into a texture resource. -parse_error::ParseError GAPIGL::SetTextureData( - ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) { - TextureGL *texture = textures_.Get(id); - if (!texture) - return parse_error::kParseInvalidArguments; - Volume volume = {x, y, z, width, height, depth}; - // Dirty effect: SetData may need to call glBindTexture which will mess up the - // sampler parameters. - DirtyEffect(); - return texture->SetData(volume, level, face, row_pitch, slice_pitch, - size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -// Copies the data from a texture resource. -parse_error::ParseError GAPIGL::GetTextureData( - ResourceId id, - unsigned int x, - unsigned int y, - unsigned int z, - unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) { - TextureGL *texture = textures_.Get(id); - if (!texture) - return parse_error::kParseInvalidArguments; - Volume volume = {x, y, z, width, height, depth}; - // Dirty effect: GetData may need to call glBindTexture which will mess up the - // sampler parameters. - DirtyEffect(); - return texture->GetData(volume, level, face, row_pitch, slice_pitch, - size, data) ? - parse_error::kParseNoError : - parse_error::kParseInvalidArguments; -} - -} // namespace o3d -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/texture_gl.h b/o3d/gpu/command_buffer/service/texture_gl.h deleted file mode 100644 index d3e774c..0000000 --- a/o3d/gpu/command_buffer/service/texture_gl.h +++ /dev/null @@ -1,284 +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 declares the TextureGL, Texture2DGL, Texture3DGL and TextureCubeGL -// classes. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_TEXTURE_GL_H_ -#define GPU_COMMAND_BUFFER_SERVICE_TEXTURE_GL_H_ - -#include "gpu/command_buffer/common/gapi_interface.h" -#include "gpu/command_buffer/service/gl_utils.h" -#include "gpu/command_buffer/service/resource.h" -#include "gpu/command_buffer/service/texture_utils.h" - -namespace command_buffer { -namespace o3d { - -class RenderDepthStencilSurfaceGL; -class RenderSurfaceGL; - -// The base class for a GL texture resource, providing access to the base GL -// texture that can be assigned to an effect parameter or a sampler unit. -class TextureGL : public Texture { - public: - TextureGL(texture::Type type, - unsigned int levels, - texture::Format format, - bool enable_render_surfaces, - unsigned int flags, - GLuint gl_texture) - : Texture(type, levels, format, enable_render_surfaces, flags), - gl_texture_(gl_texture) {} - virtual ~TextureGL(); - - // Gets the GL texture object. - GLuint gl_texture() const { return gl_texture_; } - - // Sets data into a texture resource. - virtual bool SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data) = 0; - - // Gets data from a texture resource. - virtual bool GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data) = 0; - - // Creates the render surface, returning false if unable to. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side) = 0; - - virtual bool InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface) = 0; - - protected: - const GLuint gl_texture_; - - private: - DISALLOW_COPY_AND_ASSIGN(TextureGL); -}; - -// A 2D texture resource for GL. -class Texture2DGL : public TextureGL { - public: - Texture2DGL(unsigned int levels, - texture::Format format, - bool enable_render_surfaces, - unsigned int flags, - unsigned int width, - unsigned int height, - GLuint gl_texture) - : TextureGL(texture::kTexture2d, - levels, - format, - enable_render_surfaces, - flags, - gl_texture), - width_(width), - height_(height) {} - - // Creates a 2D texture resource. - static Texture2DGL *Create(unsigned int width, - unsigned int height, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Sets data into a 2D texture resource. - virtual bool SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - - // Gets data from a 2D texture resource. - virtual bool GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side); - - virtual bool InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface); - - private: - unsigned int width_; - unsigned int height_; - DISALLOW_COPY_AND_ASSIGN(Texture2DGL); -}; - -// A 3D texture resource for GL. -class Texture3DGL : public TextureGL { - public: - Texture3DGL(unsigned int levels, - texture::Format format, - bool enable_render_surfaces, - unsigned int flags, - unsigned int width, - unsigned int height, - unsigned int depth, - GLuint gl_texture) - : TextureGL(texture::kTexture3d, - levels, - format, - enable_render_surfaces, - flags, - gl_texture), - width_(width), - height_(height), - depth_(depth) {} - - // Creates a 3D texture resource. - static Texture3DGL *Create(unsigned int width, - unsigned int height, - unsigned int depth, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Sets data into a 3D texture resource. - virtual bool SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - - // Gets data from a 3D texture resource. - virtual bool GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side); - - virtual bool InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface); - - private: - unsigned int width_; - unsigned int height_; - unsigned int depth_; - DISALLOW_COPY_AND_ASSIGN(Texture3DGL); -}; - -// A cube map texture resource for GL. -class TextureCubeGL : public TextureGL { - public: - TextureCubeGL(unsigned int levels, - texture::Format format, - bool render_surface_enabled, - unsigned int flags, - unsigned int side, - GLuint gl_texture) - : TextureGL(texture::kTextureCube, - levels, - format, - render_surface_enabled, - flags, - gl_texture), - side_(side) {} - - // Creates a cube map texture resource. - static TextureCubeGL *Create(unsigned int side, - unsigned int levels, - texture::Format format, - unsigned int flags, - bool enable_render_surfaces); - - // Sets data into a cube map texture resource. - virtual bool SetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - const void *data); - - // Gets data from a cube map texture resource. - virtual bool GetData(const Volume& volume, - unsigned int level, - texture::Face face, - unsigned int row_pitch, - unsigned int slice_pitch, - unsigned int size, - void *data); - - // Create a render surface which matches this texture type. - virtual bool CreateRenderSurface(int width, - int height, - int mip_level, - int side); - - virtual bool InstallFrameBufferObjects( - RenderSurfaceGL *gl_surface); - - private: - unsigned int side_; - DISALLOW_COPY_AND_ASSIGN(TextureCubeGL); -}; - -} // namespace o3d -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_TEXTURE_GL_H_ diff --git a/o3d/gpu/command_buffer/service/texture_utils.cc b/o3d/gpu/command_buffer/service/texture_utils.cc deleted file mode 100644 index 4aac8fa..0000000 --- a/o3d/gpu/command_buffer/service/texture_utils.cc +++ /dev/null @@ -1,105 +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 some utilities for textures. - -#include "gpu/command_buffer/service/precompile.h" - -#include <stdlib.h> - -#include "gpu/command_buffer/service/texture_utils.h" - -namespace command_buffer { - -void MakeTransferInfo(TransferInfo *transfer_info, - const MipLevelInfo &mip_level, - const Volume &volume, - unsigned int row_pitch, - unsigned int slice_pitch) { - transfer_info->row_pitch = row_pitch; - transfer_info->slice_pitch = slice_pitch; - transfer_info->row_size = - volume.width / mip_level.block_size_x * mip_level.block_bpp; - transfer_info->slice_size = transfer_info->row_size + - (volume.height / mip_level.block_size_y - 1) * row_pitch; - transfer_info->total_size = transfer_info->slice_size + - (volume.depth - 1) * slice_pitch; - transfer_info->packed = (transfer_info->row_size == row_pitch) && - (volume.depth == 1 || transfer_info->slice_size == slice_pitch); -} - -void MakePackedTransferInfo(TransferInfo *transfer_info, - const MipLevelInfo &mip_level, - const Volume &volume) { - transfer_info->row_size = - volume.width / mip_level.block_size_x * mip_level.block_bpp; - transfer_info->row_pitch = transfer_info->row_size; - transfer_info->slice_size = - volume.height / mip_level.block_size_y * transfer_info->row_pitch; - transfer_info->slice_pitch = transfer_info->slice_size; - transfer_info->total_size = volume.depth * transfer_info->slice_pitch; - transfer_info->packed = true; -} - -// Transfers a volume of texels. -void TransferVolume(const Volume &volume, - const MipLevelInfo &mip_level, - const TransferInfo &dst_transfer_info, - void *dst_data, - const TransferInfo &src_transfer_info, - const void *src_data) { - DCHECK_EQ(src_transfer_info.row_size, dst_transfer_info.row_size); - if (src_transfer_info.packed && dst_transfer_info.packed) { - // fast path - DCHECK_EQ(src_transfer_info.total_size, dst_transfer_info.total_size); - DCHECK_EQ(src_transfer_info.row_pitch, dst_transfer_info.row_pitch); - DCHECK_EQ(src_transfer_info.slice_pitch, dst_transfer_info.slice_pitch); - memcpy(dst_data, src_data, src_transfer_info.total_size); - } else { - const char *src = static_cast<const char *>(src_data); - char *dst = static_cast<char *>(dst_data); - for (unsigned int slice = 0; slice < volume.depth; ++slice) { - const char *row_src = src; - char *row_dst = dst; - for (unsigned int row = 0; row < volume.height; - row += mip_level.block_size_y) { - memcpy(row_dst, row_src, src_transfer_info.row_size); - row_src += src_transfer_info.row_pitch; - row_dst += dst_transfer_info.row_pitch; - } - src += src_transfer_info.slice_pitch; - dst += dst_transfer_info.slice_pitch; - } - } -} - -} // namespace command_buffer diff --git a/o3d/gpu/command_buffer/service/texture_utils.h b/o3d/gpu/command_buffer/service/texture_utils.h deleted file mode 100644 index 0ace181..0000000 --- a/o3d/gpu/command_buffer/service/texture_utils.h +++ /dev/null @@ -1,156 +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 declares some utilities for textures, in particular to deal with -// in-memory texture data and layout. - -#ifndef GPU_COMMAND_BUFFER_SERVICE_CROSS_TEXTURE_UTILS_H_ -#define GPU_COMMAND_BUFFER_SERVICE_CROSS_TEXTURE_UTILS_H_ - -#include "gpu/command_buffer/common/logging.h" -#include "gpu/command_buffer/common/resource.h" - -namespace command_buffer { - -// Structure describing a volume of pixels. -struct Volume { - unsigned int x; - unsigned int y; - unsigned int z; - unsigned int width; - unsigned int height; - unsigned int depth; -}; - -// Structure describing the dimensions and structure of a mip level. -struct MipLevelInfo { - unsigned int block_bpp; - unsigned int block_size_x; - unsigned int block_size_y; - unsigned int width; - unsigned int height; - unsigned int depth; -}; - -// Structure describing a memory layout for transfers. -struct TransferInfo { - unsigned int row_size; // size in bytes of a row of blocks. - unsigned int row_pitch; // number of bytes between 2 successive rows. - unsigned int slice_size; // size in bytes of a slice of data. - unsigned int slice_pitch; // number of bytes between 2 successive slices. - unsigned int total_size; // total size of the data. - bool packed; // indicates whether the data is tightly packed. -}; - -// Round a value up, so that it is divisible by the block size. -static inline unsigned int RoundToBlockSize(unsigned int base, - unsigned int block) { - DCHECK_GT(base, 0U); - DCHECK_GT(block, 0U); - return block + base - 1 - (base - 1) % block; -} - -// Fills a MipLevelInfo structure from the base texture dimensions. -static inline void MakeMipLevelInfo(MipLevelInfo *mip_info, - texture::Format format, - unsigned int base_width, - unsigned int base_height, - unsigned int base_depth, - unsigned int level) { - mip_info->block_bpp = texture::GetBytesPerBlock(format); - mip_info->block_size_x = texture::GetBlockSizeX(format); - mip_info->block_size_y = texture::GetBlockSizeY(format); - mip_info->width = RoundToBlockSize( - texture::GetMipMapDimension(base_width, level), mip_info->block_size_x); - mip_info->height = RoundToBlockSize( - texture::GetMipMapDimension(base_height, level), mip_info->block_size_y); - mip_info->depth = texture::GetMipMapDimension(base_depth, level); -} - -// Gets the size in bytes of a mip level. -static inline unsigned int GetMipLevelSize(const MipLevelInfo &mip_info) { - return mip_info.block_bpp * mip_info.width / mip_info.block_size_x * - mip_info.height / mip_info.block_size_y * mip_info.depth; -} - -// Checks that [x .. x+width] is contained in [0 .. mip_width], and that both x -// and width are divisible by block_size, and that width is positive. -static inline bool CheckDimension(unsigned int x, - unsigned int width, - unsigned int mip_width, - unsigned int block_size) { - return x < mip_width && x+width <= mip_width && x % block_size == 0 && - width % block_size == 0 && width > 0; -} - -// Checks that given volume fits into a mip level. -static inline bool CheckVolume(const MipLevelInfo &mip_info, - const Volume &volume) { - return CheckDimension(volume.x, volume.width, mip_info.width, - mip_info.block_size_x) && - CheckDimension(volume.y, volume.height, mip_info.height, - mip_info.block_size_y) && - CheckDimension(volume.z, volume.depth, mip_info.depth, 1); -} - -// Checks whether a volume fully maps a mip level. -static inline bool IsFullVolume(const MipLevelInfo &mip_info, - const Volume &volume) { - return (volume.x == 0) && (volume.y == 0) && (volume.z == 0) && - (volume.width == mip_info.width) && - (volume.height == mip_info.height) && - (volume.depth == mip_info.depth); -} - -// Makes a transfer info from a mip level, a volume and row/slice pitches. -void MakeTransferInfo(TransferInfo *transfer_info, - const MipLevelInfo &mip_level, - const Volume &volume, - unsigned int row_pitch, - unsigned int slice_pitch); - -// Makes a transfer info from a mip level and a volume, considering packed data. -void MakePackedTransferInfo(TransferInfo *transfer_info, - const MipLevelInfo &mip_level, - const Volume &volume); - -// Transfers a volume of texels. -void TransferVolume(const Volume &volume, - const MipLevelInfo &mip_level, - const TransferInfo &dst_transfer_info, - void *dst_data, - const TransferInfo &src_transfer_info, - const void *src_data); - -} // namespace command_buffer - -#endif // GPU_COMMAND_BUFFER_SERVICE_CROSS_TEXTURE_UTILS_H_ diff --git a/o3d/gpu/gpu.gyp b/o3d/gpu/gpu.gyp index 9d81e66..a7a7c88 100644 --- a/o3d/gpu/gpu.gyp +++ b/o3d/gpu/gpu.gyp @@ -38,9 +38,6 @@ 'command_buffer/common/gles2_cmd_format.h', 'command_buffer/common/gles2_cmd_utils.cc', 'command_buffer/common/gles2_cmd_utils.h', - 'command_buffer/common/o3d_cmd_format.h', - 'command_buffer/common/o3d_cmd_format.cc', - 'command_buffer/common/gapi_interface.h', 'command_buffer/common/logging.h', 'command_buffer/common/mocks.h', 'command_buffer/common/resource.cc', @@ -133,14 +130,10 @@ 'sources': [ 'command_buffer/client/cmd_buffer_helper.cc', 'command_buffer/client/cmd_buffer_helper.h', - 'command_buffer/client/effect_helper.cc', - 'command_buffer/client/effect_helper.h', 'command_buffer/client/fenced_allocator.cc', 'command_buffer/client/fenced_allocator.h', 'command_buffer/client/id_allocator.cc', 'command_buffer/client/id_allocator.h', - 'command_buffer/client/o3d_cmd_helper.cc', - 'command_buffer/client/o3d_cmd_helper.h', ], }, { @@ -166,23 +159,10 @@ '..', '../..', ], - 'conditions': [ - ['OS == "win" and (renderer == "gl" or cb_service == "gl")', - { - 'include_dirs': [ - '../../<(glewdir)/include', - '../../<(cgdir)/include', - ], - }, - ], - ], }, # 'all_dependent_settings' 'dependencies': [ 'command_buffer_common', - - # TODO(apatrick): Remove this dependency when the synchronous messages - # are via IPC. - 'np_utils', + '../build/libs.gyp:gl_libs', ], 'sources': [ 'command_buffer/service/common_decoder.cc', @@ -192,10 +172,11 @@ 'command_buffer/service/command_buffer_service.h', 'command_buffer/service/cmd_parser.cc', 'command_buffer/service/cmd_parser.h', - 'command_buffer/service/effect_utils.cc', - 'command_buffer/service/effect_utils.h', - 'command_buffer/service/gapi_decoder.cc', - 'command_buffer/service/gapi_decoder.h', + 'command_buffer/service/gles2_cmd_decoder.h', + 'command_buffer/service/gles2_cmd_decoder_validate.h', + 'command_buffer/service/gles2_cmd_decoder_autogen.h', + 'command_buffer/service/gles2_cmd_decoder.cc', + 'command_buffer/service/gl_utils.h', 'command_buffer/service/gpu_processor.h', 'command_buffer/service/gpu_processor.cc', 'command_buffer/service/gpu_processor_mock.h', @@ -204,71 +185,8 @@ 'command_buffer/service/precompile.h', 'command_buffer/service/resource.cc', 'command_buffer/service/resource.h', - 'command_buffer/service/texture_utils.cc', - 'command_buffer/service/texture_utils.h', ], 'conditions': [ - ['cb_service == "d3d9"', - { - 'include_dirs': [ - '$(DXSDK_DIR)/Include', - ], - 'all_dependent_settings': { - 'include_dirs': [ - '$(DXSDK_DIR)/Include', - ], - 'link_settings': { - 'libraries': [ - '"$(DXSDK_DIR)/Lib/x86/DxErr.lib"', - ], - }, - }, # 'all_dependent_settings' - 'sources': [ - 'command_buffer/service/d3d9_utils.h', - 'command_buffer/service/effect_d3d9.cc', - 'command_buffer/service/effect_d3d9.h', - 'command_buffer/service/gapi_d3d9.cc', - 'command_buffer/service/gapi_d3d9.h', - 'command_buffer/service/geometry_d3d9.cc', - 'command_buffer/service/geometry_d3d9.h', - 'command_buffer/service/render_surface_d3d9.cc', - 'command_buffer/service/render_surface_d3d9.h', - 'command_buffer/service/sampler_d3d9.cc', - 'command_buffer/service/sampler_d3d9.h', - 'command_buffer/service/states_d3d9.cc', - 'command_buffer/service/texture_d3d9.cc', - 'command_buffer/service/texture_d3d9.h', - ], # 'sources' - }, - ], - ['cb_service == "gl"', - { - 'dependencies': [ - '../build/libs.gyp:gl_libs', - '../build/libs.gyp:cg_libs', - ], - 'sources': [ - 'command_buffer/service/effect_gl.cc', - 'command_buffer/service/effect_gl.h', - 'command_buffer/service/gapi_gl.cc', - 'command_buffer/service/gapi_gl.h', - 'command_buffer/service/geometry_gl.cc', - 'command_buffer/service/geometry_gl.h', - 'command_buffer/service/gles2_cmd_decoder.h', - 'command_buffer/service/gles2_cmd_decoder_validate.h', - 'command_buffer/service/gles2_cmd_decoder_autogen.h', - 'command_buffer/service/gles2_cmd_decoder.cc', - 'command_buffer/service/gl_utils.h', - 'command_buffer/service/render_surface_gl.cc', - 'command_buffer/service/render_surface_gl.h', - 'command_buffer/service/sampler_gl.cc', - 'command_buffer/service/sampler_gl.h', - 'command_buffer/service/states_gl.cc', - 'command_buffer/service/texture_gl.cc', - 'command_buffer/service/texture_gl.h', - ], # 'sources' - }, - ], ['OS == "linux"', { 'sources': [ @@ -284,7 +202,7 @@ ], }, ], - ], # 'conditions' + ], }, { 'target_name': 'command_buffer_service_unittests', @@ -343,9 +261,6 @@ 'np_utils/webkit_browser.h', ], }, - - # This is a standalone executable until O3D is fully moved over to using - # gyp. At that point these can become part of the regular O3D unit tests. { 'target_name': 'np_utils_unittests', 'type': 'none', diff --git a/o3d/plugin/plugin.gyp b/o3d/plugin/plugin.gyp index 9ea6e00..d320b61 100644 --- a/o3d/plugin/plugin.gyp +++ b/o3d/plugin/plugin.gyp @@ -50,7 +50,6 @@ '../../v8/tools/gyp/v8.gyp:v8', '../core/core.gyp:o3dCore', '../core/core.gyp:o3dCorePlatform', - '../gpu/gpu.gyp:np_utils', '../import/archive.gyp:o3dArchive', '../utils/utils.gyp:o3dUtils', '../../native_client/src/shared/imc/imc.gyp:google_nacl_imc', @@ -95,7 +94,7 @@ ], }, ], - ['renderer == "gl" or cb_service == "gl"', + ['renderer == "gl"', { 'dependencies': [ '../build/libs.gyp:gl_libs', @@ -124,6 +123,7 @@ 'mac/plugin_mac.h', 'mac/plugin_mac.mm', 'mac/graphics_utils_mac.mm', + 'mac/main_mac.mm', ], 'mac_framework_dirs': [ '../../<(cgdir)', @@ -188,18 +188,12 @@ ], }, ], - ['OS == "mac" and cb_service != "remote"', - { - 'sources': [ - 'mac/main_mac.mm', - ], - }, - ], ['OS == "linux"', { 'sources': [ 'linux/config.cc', 'linux/envvars.cc', + 'linux/main_linux.cc', ], 'ldflags': [ '-z', @@ -215,10 +209,9 @@ ], }, ], - ['OS == "linux" and cb_service != "remote"', + ['OS == "linux"', { 'sources': [ - 'linux/main_linux.cc', ], }, ], @@ -230,6 +223,7 @@ 'sources': [ 'win/config.cc', 'win/logger_main.cc', + 'win/main_win.cc', 'win/o3dPlugin.def', 'win/o3dPlugin.rc', 'win/plugin_logging-win32.cc', @@ -244,39 +238,17 @@ }, }, ], - ['OS == "win" and cb_service != "remote"', - { - 'sources': [ - 'win/main_win.cc', - ], - }, - ], ['OS == "win" and renderer == "d3d9"', { 'link_settings': { 'libraries': [ '"$(DXSDK_DIR)/Lib/x86/d3dx9.lib"', '-ld3d9.lib', - ], - }, - }, - ], - ['OS == "win" and (renderer == "d3d9" or cb_service == "d3d9" or cb_service == "remote")', - { - 'link_settings': { - 'libraries': [ '"$(DXSDK_DIR)/Lib/x86/DxErr.lib"', ], }, }, ], - ['cb_service == "remote"', - { - 'sources': [ - 'cross/main_remote_cb.cc', - ], - }, - ], ], }, ], @@ -424,7 +396,7 @@ }, }, ], - ['OS == "win" and (renderer == "d3d9" or cb_service == "d3d9")', + ['OS == "win" and renderer == "d3d9"', { 'link_settings': { 'libraries': [ diff --git a/o3d/plugin/win/main_win.cc b/o3d/plugin/win/main_win.cc index da4a1c2..6e8743f 100644 --- a/o3d/plugin/win/main_win.cc +++ b/o3d/plugin/win/main_win.cc @@ -51,31 +51,14 @@ #include "v8/include/v8.h" #include "breakpad/win/bluescreen_detector.h" -#if defined(RENDERER_CB) -#include "core/cross/command_buffer/renderer_cb.h" -#include "core/cross/command_buffer/display_window_cb.h" -#include "gpu/command_buffer/common/command_buffer.h" -#endif - using glue::_o3d::PluginObject; using glue::StreamManager; using o3d::DisplayWindowWindows; using o3d::Event; -#if defined(RENDERER_CB) -using command_buffer::CommandBuffer; -#endif - namespace { // The instance handle of the O3D DLL. HINSTANCE g_module_instance; - -// TODO(apatrick): We can have an NPBrowser in the other configurations when we -// move over to gyp. This is just to avoid having to write scons files for -// np_utils. -#if defined(RENDERER_CB) -np_utils::NPBrowser* g_browser; -#endif } // namespace anonymous #if !defined(O3D_INTERNAL_PLUGIN) @@ -736,10 +719,6 @@ extern "C" { NPError OSCALL NP_Initialize(NPNetscapeFuncs *browserFuncs) { HANDLE_CRASHES; -#if defined(RENDERER_CB) - g_browser = new np_utils::NPBrowser(browserFuncs); -#endif - NPError retval = InitializeNPNApi(browserFuncs); if (retval != NPERR_NO_ERROR) return retval; return InitializePlugin(); @@ -778,11 +757,6 @@ NPError OSCALL NP_Shutdown(void) { g_bluescreen_detector = NULL; } -#if defined(RENDERER_CB) - delete g_browser; - g_browser = NULL; -#endif - #endif // O3D_INTERNAL_PLUGIN return NPERR_NO_ERROR; @@ -915,27 +889,10 @@ NPError NPP_SetWindow(NPP instance, NPWindow *window) { ::ShowWindow(content_window, SW_SHOW); // create and assign the graphics context -#if defined(RENDERER_CB) - const unsigned int kDefaultCommandBufferSize = 256 << 10; - - // RendererCB takes ownership of CommandBuffer. - CommandBuffer* command_buffer = - RendererCBLocal::CreateCommandBuffer(instance, - obj->GetHWnd(), - kDefaultCommandBufferSize); - - DisplayWindowCB default_display; - default_display.set_command_buffer(command_buffer); - - obj->CreateRenderer(default_display); - obj->renderer()->Resize(window->width, window->height); - obj->client()->Init(); -#else DisplayWindowWindows default_display; default_display.set_hwnd(obj->GetHWnd()); obj->CreateRenderer(default_display); obj->client()->Init(); -#endif // we set the timer to 10ms or 100fps. At the time of this comment // the renderer does a vsync the max fps it will run will be the refresh diff --git a/o3d/tests/common/win/testing_common.cc b/o3d/tests/common/win/testing_common.cc index 7e8937d..7ab0bb2 100644 --- a/o3d/tests/common/win/testing_common.cc +++ b/o3d/tests/common/win/testing_common.cc @@ -50,21 +50,8 @@ #include "core/cross/types.h" #include "core/win/display_window_win.h" -#if defined(RENDERER_CB) -#include "core/cross/command_buffer/renderer_cb.h" -#include "core/cross/command_buffer/display_window_cb.h" -#include "gpu/np_utils/np_browser_stub.h" -#endif - using o3d::DisplayWindowWindows; -#if defined(RENDERER_CB) -using o3d::DisplayWindowCB; -using np_utils::NPObjectPointer; -using np_utils::StubNPBrowser; -using o3d::RendererCBLocal; -#endif - const int kWindowWidth = 16; const int kWindowHeight = 16; @@ -171,13 +158,6 @@ int WINAPI WinMain(HINSTANCE instance, o3d::Profiler profiler(g_service_locator); o3d::Features features(g_service_locator); - // TODO(apatrick): We can have an NPBrowser in the other configurations when - // we move over to gyp. This is just to avoid having to write scons files - // for np_utils. -#if defined(RENDERER_CB) - StubNPBrowser browser; -#endif - // create a renderer device based on the current platform g_renderer = o3d::Renderer::CreateDefaultRenderer(g_service_locator); @@ -185,21 +165,8 @@ int WINAPI WinMain(HINSTANCE instance, // is in the environment. bool success; -#if defined(RENDERER_CB) - const unsigned int kDefaultCommandBufferSize = 256 << 10; - - // RendererCB takes ownership of CommandBuffer. - DisplayWindowCB* display_window = new o3d::DisplayWindowCB; - display_window->set_command_buffer(RendererCBLocal::CreateCommandBuffer( - NULL, - g_window_handle, - kDefaultCommandBufferSize)); - display_window->set_width(kWindowWidth); - display_window->set_height(kWindowHeight); -#else DisplayWindowWindows* display_window = new o3d::DisplayWindowWindows; display_window->set_hwnd(g_window_handle); -#endif g_display_window = display_window; bool offscreen = (::GetEnvironmentVariableW(kOffScreenRenderer, diff --git a/o3d/tests/tests.gyp b/o3d/tests/tests.gyp index 5a5177a..129f2d7 100644 --- a/o3d/tests/tests.gyp +++ b/o3d/tests/tests.gyp @@ -102,13 +102,6 @@ ], }, ], - ['renderer == "cb"', - { - 'dependencies': [ - '../gpu/gpu.gyp:np_utils', - ] - }, - ], ['OS == "mac"', { 'dependencies': [ @@ -198,27 +191,19 @@ 'sources': [ 'common/win/dxcapture.cc', ], - 'link_settings': { - 'libraries': [ - '"$(DXSDK_DIR)/Lib/x86/d3dx9.lib"', - 'd3d9.lib', - ], - }, - }, - ], - ['OS == "win" and (renderer == "d3d9" or cb_service == "d3d9")', - { 'include_dirs': [ '"$(DXSDK_DIR)/Include"', ], 'link_settings': { 'libraries': [ + '"$(DXSDK_DIR)/Lib/x86/d3dx9.lib"', + 'd3d9.lib', '"$(DXSDK_DIR)/Lib/x86/DxErr.lib"', ], }, }, ], - ['OS == "win" and (renderer == "gl" or cb_service == "gl")', + ['OS == "win" and renderer == "gl"', { 'dependencies': [ '../build/libs.gyp:gl_libs', |