diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 22:57:44 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-22 22:57:44 +0000 |
commit | 2c1639589b5932b565c9d420cb79b56a4212a706 (patch) | |
tree | d74cd853d4753f9c19e5d50ad58d156a33417806 | |
parent | 2e29d9243d84374d861a86252a2923cba9e49941 (diff) | |
download | chromium_src-2c1639589b5932b565c9d420cb79b56a4212a706.zip chromium_src-2c1639589b5932b565c9d420cb79b56a4212a706.tar.gz chromium_src-2c1639589b5932b565c9d420cb79b56a4212a706.tar.bz2 |
Fixes to get renderer=cb cb_service=gl to compile
again.
I was working on spliting some of the command buffer
code in preparation for GL command buffers so those
changes are in there as well. I didn't realize the
gl command buffers were broken.
I'm planning on sharing some of the command buffer
code and commands so I thought about making the
command buffers into 2 parts. The first N (256?)
commands are common commands. Noop, SetToken, Jump
Gosub. Those will be handled by common code.
After that come the O3D or GL command buffer
commands. I'm not sure that's a good idea but
there is a significant amount of code in managing
tokens and parsing etc and it seems like it would
be nice to share it until/if we delete the O3D
command buffers.
Note: You'll see that SetToken is hardcoded to 1.
I plan to fix that in the next CL when I split
the command into shared vs specific.
Review URL: http://codereview.chromium.org/307043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29831 0039d316-1c4b-4281-b951-d872f2087c98
48 files changed, 1168 insertions, 881 deletions
diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper.cc b/o3d/command_buffer/client/cross/cmd_buffer_helper.cc index 108f78e..a67eecb 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper.cc +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper.cc @@ -121,7 +121,8 @@ int32 CommandBufferHelper::InsertToken() { token_ = (token_ + 1) & 0x7FFFFFFF; CommandBufferEntry args; args.value_uint32 = token_; - AddCommand(command_buffer::kSetToken, 1, &args); + const uint32 kSetToken = 1; // TODO(gman): add a common set of commands. + AddCommand(kSetToken, 1, &args); if (token_ == 0) { // we wrapped Finish(); diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper.h b/o3d/command_buffer/client/cross/cmd_buffer_helper.h index b42c5e0..e69e020 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper.h +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper.h @@ -37,7 +37,7 @@ #include "command_buffer/common/cross/logging.h" #include "command_buffer/common/cross/constants.h" -#include "command_buffer/common/cross/cmd_buffer_format.h" +#include "command_buffer/common/cross/cmd_buffer_common.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" namespace o3d { @@ -60,10 +60,10 @@ namespace command_buffer { // // commands have been executed. class CommandBufferHelper { public: - explicit CommandBufferHelper( + CommandBufferHelper( NPP npp, const gpu_plugin::NPObjectPointer<NPObject>& command_buffer); - ~CommandBufferHelper(); + virtual ~CommandBufferHelper(); bool Initialize(); @@ -170,592 +170,6 @@ class CommandBufferHelper { parse_error::ParseError GetParseError(); - // ------------------ Individual commands ---------------------- - - void Noop(uint32 skip_count) { - cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( - skip_count * sizeof(CommandBufferEntry)); - cmd.Init(skip_count); - } - - - void SetToken(uint32 token) { - cmd::SetToken& cmd = GetCmdSpace<cmd::SetToken>(); - cmd.Init(token); - } - - - void BeginFrame() { - cmd::BeginFrame& cmd = GetCmdSpace<cmd::BeginFrame>(); - cmd.Init(); - } - - - void EndFrame() { - cmd::EndFrame& cmd = GetCmdSpace<cmd::EndFrame>(); - cmd.Init(); - } - - void Clear( - uint32 buffers, - float red, float green, float blue, float alpha, - float depth, uint32 stencil) { - cmd::Clear& cmd = GetCmdSpace<cmd::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) { - cmd::SetViewport& cmd = GetCmdSpace<cmd::SetViewport>(); - cmd.Init(left, top, width, height, z_min, z_max); - } - - void CreateVertexBuffer( - ResourceId vertex_buffer_id, uint32 size, vertex_buffer::Flags flags) { - cmd::CreateVertexBuffer& cmd = GetCmdSpace<cmd::CreateVertexBuffer>(); - cmd.Init(vertex_buffer_id, size, flags); - } - - void DestroyVertexBuffer(ResourceId vertex_buffer_id) { - cmd::DestroyVertexBuffer& cmd = GetCmdSpace<cmd::DestroyVertexBuffer>(); - cmd.Init(vertex_buffer_id); - } - - void SetVertexBufferDataImmediate( - ResourceId vertex_buffer_id, uint32 offset, - const void* data, uint32 size) { - cmd::SetVertexBufferDataImmediate& cmd = - GetImmediateCmdSpace<cmd::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) { - cmd::SetVertexBufferData& cmd = - GetCmdSpace<cmd::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) { - cmd::GetVertexBufferData& cmd = - GetCmdSpace<cmd::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) { - cmd::CreateIndexBuffer& cmd = - GetCmdSpace<cmd::CreateIndexBuffer>(); - cmd.Init(index_buffer_id, size, flags); - } - - void DestroyIndexBuffer(ResourceId index_buffer_id) { - cmd::DestroyIndexBuffer& cmd = GetCmdSpace<cmd::DestroyIndexBuffer>(); - cmd.Init(index_buffer_id); - } - - void SetIndexBufferDataImmediate( - ResourceId index_buffer_id, uint32 offset, - const void* data, uint32 size) { - cmd::SetIndexBufferDataImmediate& cmd = - GetImmediateCmdSpace<cmd::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) { - cmd::SetIndexBufferData& cmd = GetCmdSpace<cmd::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) { - cmd::GetIndexBufferData& cmd = GetCmdSpace<cmd::GetIndexBufferData>(); - cmd.Init(index_buffer_id, offset, size, - shared_memory_id, shared_memory_offset); - } - - void CreateVertexStruct(ResourceId vertex_struct_id, uint32 input_count) { - cmd::CreateVertexStruct& cmd = GetCmdSpace<cmd::CreateVertexStruct>(); - cmd.Init(vertex_struct_id, input_count); - } - - void DestroyVertexStruct(ResourceId vertex_struct_id) { - cmd::DestroyVertexStruct& cmd = GetCmdSpace<cmd::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) { - cmd::SetVertexInput& cmd = GetCmdSpace<cmd::SetVertexInput>(); - cmd.Init( - vertex_struct_id, - input_index, - vertex_buffer_id, - offset, - semantic, - semantic_index, - type, - stride); - } - - void SetVertexStruct(ResourceId vertex_struct_id) { - cmd::SetVertexStruct& cmd = GetCmdSpace<cmd::SetVertexStruct>(); - cmd.Init(vertex_struct_id); - } - - void Draw(PrimitiveType primitive_type, uint32 first, uint32 count) { - cmd::Draw& cmd = GetCmdSpace<cmd::Draw>(); - cmd.Init(primitive_type, first, count); - } - - void DrawIndexed( - PrimitiveType primitive_type, - ResourceId index_buffer_id, - uint32 first, - uint32 count, - uint32 min_index, - uint32 max_index) { - cmd::DrawIndexed& cmd = GetCmdSpace<cmd::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) { - cmd::CreateEffect& cmd = GetCmdSpace<cmd::CreateEffect>(); - cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); - } - - void CreateEffectImmediate( - ResourceId effect_id, uint32 size, const void* data) { - cmd::CreateEffectImmediate& cmd = - GetImmediateCmdSpace<cmd::CreateEffectImmediate>(size); - cmd.Init(effect_id, size, data); - } - - void DestroyEffect(ResourceId effect_id) { - cmd::DestroyEffect& cmd = GetCmdSpace<cmd::DestroyEffect>(); - cmd.Init(effect_id); - } - - void SetEffect(ResourceId effect_id) { - cmd::SetEffect& cmd = GetCmdSpace<cmd::SetEffect>(); - cmd.Init(effect_id); - } - - void GetParamCount( - ResourceId effect_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - cmd::GetParamCount& cmd = GetCmdSpace<cmd::GetParamCount>(); - cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); - } - - void CreateParam(ResourceId param_id, ResourceId effect_id, uint32 index) { - cmd::CreateParam& cmd = GetCmdSpace<cmd::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) { - cmd::CreateParamByName& cmd = GetCmdSpace<cmd::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) { - cmd::CreateParamByNameImmediate& cmd = - GetImmediateCmdSpace<cmd::CreateParamByNameImmediate>(size); - cmd.Init(param_id, effect_id, size, data); - } - - void DestroyParam(ResourceId param_id) { - cmd::DestroyParam& cmd = GetCmdSpace<cmd::DestroyParam>(); - cmd.Init(param_id); - } - - void SetParamData( - ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - cmd::SetParamData& cmd = GetCmdSpace<cmd::SetParamData>(); - cmd.Init(param_id, size, shared_memory_id, shared_memory_offset); - } - - void SetParamDataImmediate( - ResourceId param_id, uint32 size, const void* data) { - cmd::SetParamDataImmediate& cmd = - GetImmediateCmdSpace<cmd::SetParamDataImmediate>(size); - cmd.Init(param_id, size, data); - } - - void GetParamDesc( - ResourceId param_id, uint32 size, - uint32 shared_memory_id, uint32 shared_memory_offset) { - cmd::GetParamDesc& cmd = GetCmdSpace<cmd::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) { - cmd::GetStreamCount& cmd = GetCmdSpace<cmd::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) { - cmd::GetStreamDesc& cmd = GetCmdSpace<cmd::GetStreamDesc>(); - cmd.Init(effect_id, index, size, shared_memory_id, shared_memory_offset); - } - - void DestroyTexture(ResourceId texture_id) { - cmd::DestroyTexture& cmd = GetCmdSpace<cmd::DestroyTexture>(); - cmd.Init(texture_id); - } - - void CreateTexture2d( - ResourceId texture_id, - uint32 width, uint32 height, - uint32 levels, texture::Format format, - bool enable_render_surfaces) { - cmd::CreateTexture2d& cmd = GetCmdSpace<cmd::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) { - cmd::CreateTexture3d& cmd = GetCmdSpace<cmd::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) { - cmd::CreateTextureCube& cmd = GetCmdSpace<cmd::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) { - cmd::SetTextureData& cmd = GetCmdSpace<cmd::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) { - cmd::SetTextureDataImmediate& cmd = - GetImmediateCmdSpace<cmd::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) { - cmd::GetTextureData& cmd = GetCmdSpace<cmd::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) { - cmd::CreateSampler& cmd = GetCmdSpace<cmd::CreateSampler>(); - cmd.Init(sampler_id); - } - - void DestroySampler(ResourceId sampler_id) { - cmd::DestroySampler& cmd = GetCmdSpace<cmd::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) { - cmd::SetSamplerStates& cmd = GetCmdSpace<cmd::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) { - cmd::SetSamplerBorderColor& cmd = - GetCmdSpace<cmd::SetSamplerBorderColor>(); - cmd.Init(sampler_id, red, green, blue, alpha); - } - - void SetSamplerTexture(ResourceId sampler_id, ResourceId texture_id) { - cmd::SetSamplerTexture& cmd = GetCmdSpace<cmd::SetSamplerTexture>(); - cmd.Init(sampler_id, texture_id); - } - - void SetScissor( - uint32 x, - uint32 y, - uint32 width, - uint32 height, - bool enable) { - cmd::SetScissor& cmd = GetCmdSpace<cmd::SetScissor>(); - cmd.Init( - x, - y, - width, - height, - enable); - } - - void SetPolygonOffset(float slope_factor, float units) { - cmd::SetPolygonOffset& cmd = GetCmdSpace<cmd::SetPolygonOffset>(); - cmd.Init(slope_factor, units); - } - - void SetPointLineRaster( - bool line_smooth_enable, bool point_sprite_enable, float point_size) { - cmd::SetPointLineRaster& cmd = GetCmdSpace<cmd::SetPointLineRaster>(); - cmd.Init(line_smooth_enable, point_sprite_enable, point_size); - } - - void SetPolygonRaster(PolygonMode fill_mode, FaceCullMode cull_mode) { - cmd::SetPolygonRaster& cmd = GetCmdSpace<cmd::SetPolygonRaster>(); - cmd.Init(fill_mode, cull_mode); - } - - void SetAlphaTest(Comparison func, bool enable, float value) { - cmd::SetAlphaTest& cmd = GetCmdSpace<cmd::SetAlphaTest>(); - cmd.Init(func, enable, value); - } - - void SetDepthTest(Comparison func, bool write_enable, bool enable) { - cmd::SetDepthTest& cmd = GetCmdSpace<cmd::SetDepthTest>(); - cmd.Init(func, write_enable, enable); - } - - void SetStencilTest( - 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) { - cmd::SetStencilTest& cmd = GetCmdSpace<cmd::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) { - cmd::SetColorWrite& cmd = GetCmdSpace<cmd::SetColorWrite>(); - cmd.Init(mask, dither_enable); - } - - void SetBlending( - 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) { - cmd::SetBlending& cmd = GetCmdSpace<cmd::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) { - cmd::SetBlendingColor& cmd = GetCmdSpace<cmd::SetBlendingColor>(); - cmd.Init(red, green, blue, alpha); - } - - void CreateRenderSurface( - ResourceId render_surface_id, ResourceId texture_id, - uint32 width, uint32 height, - uint32 level, uint32 side) { - cmd::CreateRenderSurface& cmd = GetCmdSpace<cmd::CreateRenderSurface>(); - cmd.Init(render_surface_id, texture_id, width, height, level, side); - } - - void DestroyRenderSurface(ResourceId render_surface_id) { - cmd::DestroyRenderSurface& cmd = - GetCmdSpace<cmd::DestroyRenderSurface>(); - cmd.Init(render_surface_id); - } - - void CreateDepthSurface( - ResourceId depth_surface_id, uint32 width, uint32 height) { - cmd::CreateDepthSurface& cmd = GetCmdSpace<cmd::CreateDepthSurface>(); - cmd.Init(depth_surface_id, width, height); - } - - void DestroyDepthSurface(ResourceId depth_surface_id) { - cmd::DestroyDepthSurface& cmd = GetCmdSpace<cmd::DestroyDepthSurface>(); - cmd.Init(depth_surface_id); - } - - void SetRenderSurface( - ResourceId render_surface_id, ResourceId depth_surface_id) { - cmd::SetRenderSurface& cmd = GetCmdSpace<cmd::SetRenderSurface>(); - cmd.Init(render_surface_id, depth_surface_id); - } - - void SetBackSurfaces() { - cmd::SetBackSurfaces& cmd = GetCmdSpace<cmd::SetBackSurfaces>(); - cmd.Init(); - } - private: // Waits until get changes, updating the value of get_. void WaitForGetChange(); @@ -776,6 +190,7 @@ class CommandBufferHelper { int32 put_; friend class CommandBufferHelperTest; + DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); }; } // namespace command_buffer diff --git a/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc b/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc index 95d31d5..959660ed 100644 --- a/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc +++ b/o3d/command_buffer/client/cross/cmd_buffer_helper_test.cc @@ -48,7 +48,6 @@ using gpu_plugin::CommandBuffer; using gpu_plugin::GPUProcessor; using gpu_plugin::NPCreateObject; using gpu_plugin::NPObjectPointer; -using gpu_plugin::SharedMemory; using testing::Return; using testing::Mock; using testing::Truly; @@ -72,8 +71,8 @@ class CommandBufferHelperTest : public testing::Test { EXPECT_CALL(*api_mock_, DoCommand(0, 0, _)) .WillRepeatedly(Return(parse_error::kParseNoError)); - NPObjectPointer<SharedMemory> ring_buffer = - NPCreateObject<SharedMemory>(NULL); + NPObjectPointer<gpu_plugin::SharedMemory> ring_buffer = + NPCreateObject<gpu_plugin::SharedMemory>(NULL); ring_buffer->Initialize(kCommandBufferSizeBytes); size_t size_bytes; diff --git a/o3d/command_buffer/client/cross/effect_helper.h b/o3d/command_buffer/client/cross/effect_helper.h index cc6b3bb..0fa41c7 100644 --- a/o3d/command_buffer/client/cross/effect_helper.h +++ b/o3d/command_buffer/client/cross/effect_helper.h @@ -37,6 +37,7 @@ #include <vector> #include "command_buffer/common/cross/resource.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" namespace o3d { namespace command_buffer { @@ -66,7 +67,7 @@ class EffectHelper { unsigned int semantic_index; }; - EffectHelper(CommandBufferHelper *helper, + EffectHelper(O3DCmdHelper *helper, FencedAllocatorWrapper *shm_allocator, unsigned int shm_id, IdAllocator *param_id_allocator) @@ -143,7 +144,7 @@ class EffectHelper { std::vector<EffectStreamDesc> *descs); private: - CommandBufferHelper *helper_; + O3DCmdHelper *helper_; FencedAllocatorWrapper *shm_allocator_; unsigned int shm_id_; IdAllocator *param_id_allocator_; diff --git a/o3d/command_buffer/client/cross/fenced_allocator_test.cc b/o3d/command_buffer/client/cross/fenced_allocator_test.cc index 8c6ef1e..1ba510d 100644 --- a/o3d/command_buffer/client/cross/fenced_allocator_test.cc +++ b/o3d/command_buffer/client/cross/fenced_allocator_test.cc @@ -50,7 +50,6 @@ using gpu_plugin::CommandBuffer; using gpu_plugin::GPUProcessor; using gpu_plugin::NPCreateObject; using gpu_plugin::NPObjectPointer; -using gpu_plugin::SharedMemory; using testing::Return; using testing::Mock; using testing::Truly; @@ -74,8 +73,8 @@ class BaseFencedAllocatorTest : public testing::Test { .WillRepeatedly(DoAll(Invoke(api_mock_.get(), &AsyncAPIMock::SetToken), Return(parse_error::kParseNoError))); - NPObjectPointer<SharedMemory> ring_buffer = - NPCreateObject<SharedMemory>(NULL); + NPObjectPointer<gpu_plugin::SharedMemory> ring_buffer = + NPCreateObject<gpu_plugin::SharedMemory>(NULL); ring_buffer->Initialize(1024); size_t size_bytes; diff --git a/o3d/command_buffer/client/cross/o3d_cmd_helper.cc b/o3d/command_buffer/client/cross/o3d_cmd_helper.cc new file mode 100644 index 0000000..9cf9f44 --- /dev/null +++ b/o3d/command_buffer/client/cross/o3d_cmd_helper.cc @@ -0,0 +1,44 @@ +/* + * 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 "command_buffer/client/cross/o3d_cmd_helper.h" + +namespace o3d { +namespace command_buffer { + +// Currently this is a place holder. + +} // namespace command_buffer +} // namespace o3d + diff --git a/o3d/command_buffer/client/cross/o3d_cmd_helper.h b/o3d/command_buffer/client/cross/o3d_cmd_helper.h new file mode 100644 index 0000000..9aa7644 --- /dev/null +++ b/o3d/command_buffer/client/cross/o3d_cmd_helper.h @@ -0,0 +1,647 @@ +/* + * 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 O3D_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ +#define O3D_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ + +#include "command_buffer/common/cross/logging.h" +#include "command_buffer/common/cross/constants.h" +#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/common/cross/cmd_buffer_format.h" +#include "o3d/gpu_plugin/np_utils/np_object_pointer.h" + +namespace o3d { +namespace command_buffer { + +// A helper for O3D command buffers. +class O3DCmdHelper : public CommandBufferHelper { + public: + O3DCmdHelper( + NPP npp, + const gpu_plugin::NPObjectPointer<NPObject>& command_buffer) + : CommandBufferHelper(npp, command_buffer) { + } + virtual ~O3DCmdHelper() { + } + + // ------------------ Individual commands ---------------------- + + void Noop(uint32 skip_count) { + cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( + skip_count * sizeof(CommandBufferEntry)); + cmd.Init(skip_count); + } + + void SetToken(uint32 token) { + cmd::SetToken& cmd = GetCmdSpace<cmd::SetToken>(); + cmd.Init(token); + } + + void BeginFrame() { + cmd::BeginFrame& cmd = GetCmdSpace<cmd::BeginFrame>(); + cmd.Init(); + } + + + void EndFrame() { + cmd::EndFrame& cmd = GetCmdSpace<cmd::EndFrame>(); + cmd.Init(); + } + + void Clear( + uint32 buffers, + float red, float green, float blue, float alpha, + float depth, uint32 stencil) { + cmd::Clear& cmd = GetCmdSpace<cmd::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) { + cmd::SetViewport& cmd = GetCmdSpace<cmd::SetViewport>(); + cmd.Init(left, top, width, height, z_min, z_max); + } + + void CreateVertexBuffer( + ResourceId vertex_buffer_id, uint32 size, vertex_buffer::Flags flags) { + cmd::CreateVertexBuffer& cmd = GetCmdSpace<cmd::CreateVertexBuffer>(); + cmd.Init(vertex_buffer_id, size, flags); + } + + void DestroyVertexBuffer(ResourceId vertex_buffer_id) { + cmd::DestroyVertexBuffer& cmd = GetCmdSpace<cmd::DestroyVertexBuffer>(); + cmd.Init(vertex_buffer_id); + } + + void SetVertexBufferDataImmediate( + ResourceId vertex_buffer_id, uint32 offset, + const void* data, uint32 size) { + cmd::SetVertexBufferDataImmediate& cmd = + GetImmediateCmdSpace<cmd::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) { + cmd::SetVertexBufferData& cmd = + GetCmdSpace<cmd::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) { + cmd::GetVertexBufferData& cmd = + GetCmdSpace<cmd::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) { + cmd::CreateIndexBuffer& cmd = + GetCmdSpace<cmd::CreateIndexBuffer>(); + cmd.Init(index_buffer_id, size, flags); + } + + void DestroyIndexBuffer(ResourceId index_buffer_id) { + cmd::DestroyIndexBuffer& cmd = GetCmdSpace<cmd::DestroyIndexBuffer>(); + cmd.Init(index_buffer_id); + } + + void SetIndexBufferDataImmediate( + ResourceId index_buffer_id, uint32 offset, + const void* data, uint32 size) { + cmd::SetIndexBufferDataImmediate& cmd = + GetImmediateCmdSpace<cmd::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) { + cmd::SetIndexBufferData& cmd = GetCmdSpace<cmd::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) { + cmd::GetIndexBufferData& cmd = GetCmdSpace<cmd::GetIndexBufferData>(); + cmd.Init(index_buffer_id, offset, size, + shared_memory_id, shared_memory_offset); + } + + void CreateVertexStruct(ResourceId vertex_struct_id, uint32 input_count) { + cmd::CreateVertexStruct& cmd = GetCmdSpace<cmd::CreateVertexStruct>(); + cmd.Init(vertex_struct_id, input_count); + } + + void DestroyVertexStruct(ResourceId vertex_struct_id) { + cmd::DestroyVertexStruct& cmd = GetCmdSpace<cmd::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) { + cmd::SetVertexInput& cmd = GetCmdSpace<cmd::SetVertexInput>(); + cmd.Init( + vertex_struct_id, + input_index, + vertex_buffer_id, + offset, + semantic, + semantic_index, + type, + stride); + } + + void SetVertexStruct(ResourceId vertex_struct_id) { + cmd::SetVertexStruct& cmd = GetCmdSpace<cmd::SetVertexStruct>(); + cmd.Init(vertex_struct_id); + } + + void Draw(PrimitiveType primitive_type, uint32 first, uint32 count) { + cmd::Draw& cmd = GetCmdSpace<cmd::Draw>(); + cmd.Init(primitive_type, first, count); + } + + void DrawIndexed( + PrimitiveType primitive_type, + ResourceId index_buffer_id, + uint32 first, + uint32 count, + uint32 min_index, + uint32 max_index) { + cmd::DrawIndexed& cmd = GetCmdSpace<cmd::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) { + cmd::CreateEffect& cmd = GetCmdSpace<cmd::CreateEffect>(); + cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); + } + + void CreateEffectImmediate( + ResourceId effect_id, uint32 size, const void* data) { + cmd::CreateEffectImmediate& cmd = + GetImmediateCmdSpace<cmd::CreateEffectImmediate>(size); + cmd.Init(effect_id, size, data); + } + + void DestroyEffect(ResourceId effect_id) { + cmd::DestroyEffect& cmd = GetCmdSpace<cmd::DestroyEffect>(); + cmd.Init(effect_id); + } + + void SetEffect(ResourceId effect_id) { + cmd::SetEffect& cmd = GetCmdSpace<cmd::SetEffect>(); + cmd.Init(effect_id); + } + + void GetParamCount( + ResourceId effect_id, uint32 size, + uint32 shared_memory_id, uint32 shared_memory_offset) { + cmd::GetParamCount& cmd = GetCmdSpace<cmd::GetParamCount>(); + cmd.Init(effect_id, size, shared_memory_id, shared_memory_offset); + } + + void CreateParam(ResourceId param_id, ResourceId effect_id, uint32 index) { + cmd::CreateParam& cmd = GetCmdSpace<cmd::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) { + cmd::CreateParamByName& cmd = GetCmdSpace<cmd::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) { + cmd::CreateParamByNameImmediate& cmd = + GetImmediateCmdSpace<cmd::CreateParamByNameImmediate>(size); + cmd.Init(param_id, effect_id, size, data); + } + + void DestroyParam(ResourceId param_id) { + cmd::DestroyParam& cmd = GetCmdSpace<cmd::DestroyParam>(); + cmd.Init(param_id); + } + + void SetParamData( + ResourceId param_id, uint32 size, + uint32 shared_memory_id, uint32 shared_memory_offset) { + cmd::SetParamData& cmd = GetCmdSpace<cmd::SetParamData>(); + cmd.Init(param_id, size, shared_memory_id, shared_memory_offset); + } + + void SetParamDataImmediate( + ResourceId param_id, uint32 size, const void* data) { + cmd::SetParamDataImmediate& cmd = + GetImmediateCmdSpace<cmd::SetParamDataImmediate>(size); + cmd.Init(param_id, size, data); + } + + void GetParamDesc( + ResourceId param_id, uint32 size, + uint32 shared_memory_id, uint32 shared_memory_offset) { + cmd::GetParamDesc& cmd = GetCmdSpace<cmd::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) { + cmd::GetStreamCount& cmd = GetCmdSpace<cmd::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) { + cmd::GetStreamDesc& cmd = GetCmdSpace<cmd::GetStreamDesc>(); + cmd.Init(effect_id, index, size, shared_memory_id, shared_memory_offset); + } + + void DestroyTexture(ResourceId texture_id) { + cmd::DestroyTexture& cmd = GetCmdSpace<cmd::DestroyTexture>(); + cmd.Init(texture_id); + } + + void CreateTexture2d( + ResourceId texture_id, + uint32 width, uint32 height, + uint32 levels, texture::Format format, + bool enable_render_surfaces) { + cmd::CreateTexture2d& cmd = GetCmdSpace<cmd::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) { + cmd::CreateTexture3d& cmd = GetCmdSpace<cmd::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) { + cmd::CreateTextureCube& cmd = GetCmdSpace<cmd::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) { + cmd::SetTextureData& cmd = GetCmdSpace<cmd::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) { + cmd::SetTextureDataImmediate& cmd = + GetImmediateCmdSpace<cmd::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) { + cmd::GetTextureData& cmd = GetCmdSpace<cmd::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) { + cmd::CreateSampler& cmd = GetCmdSpace<cmd::CreateSampler>(); + cmd.Init(sampler_id); + } + + void DestroySampler(ResourceId sampler_id) { + cmd::DestroySampler& cmd = GetCmdSpace<cmd::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) { + cmd::SetSamplerStates& cmd = GetCmdSpace<cmd::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) { + cmd::SetSamplerBorderColor& cmd = + GetCmdSpace<cmd::SetSamplerBorderColor>(); + cmd.Init(sampler_id, red, green, blue, alpha); + } + + void SetSamplerTexture(ResourceId sampler_id, ResourceId texture_id) { + cmd::SetSamplerTexture& cmd = GetCmdSpace<cmd::SetSamplerTexture>(); + cmd.Init(sampler_id, texture_id); + } + + void SetScissor( + uint32 x, + uint32 y, + uint32 width, + uint32 height, + bool enable) { + cmd::SetScissor& cmd = GetCmdSpace<cmd::SetScissor>(); + cmd.Init( + x, + y, + width, + height, + enable); + } + + void SetPolygonOffset(float slope_factor, float units) { + cmd::SetPolygonOffset& cmd = GetCmdSpace<cmd::SetPolygonOffset>(); + cmd.Init(slope_factor, units); + } + + void SetPointLineRaster( + bool line_smooth_enable, bool point_sprite_enable, float point_size) { + cmd::SetPointLineRaster& cmd = GetCmdSpace<cmd::SetPointLineRaster>(); + cmd.Init(line_smooth_enable, point_sprite_enable, point_size); + } + + void SetPolygonRaster(PolygonMode fill_mode, FaceCullMode cull_mode) { + cmd::SetPolygonRaster& cmd = GetCmdSpace<cmd::SetPolygonRaster>(); + cmd.Init(fill_mode, cull_mode); + } + + void SetAlphaTest(Comparison func, bool enable, float value) { + cmd::SetAlphaTest& cmd = GetCmdSpace<cmd::SetAlphaTest>(); + cmd.Init(func, enable, value); + } + + void SetDepthTest(Comparison func, bool write_enable, bool enable) { + cmd::SetDepthTest& cmd = GetCmdSpace<cmd::SetDepthTest>(); + cmd.Init(func, write_enable, enable); + } + + void SetStencilTest( + 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) { + cmd::SetStencilTest& cmd = GetCmdSpace<cmd::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) { + cmd::SetColorWrite& cmd = GetCmdSpace<cmd::SetColorWrite>(); + cmd.Init(mask, dither_enable); + } + + void SetBlending( + 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) { + cmd::SetBlending& cmd = GetCmdSpace<cmd::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) { + cmd::SetBlendingColor& cmd = GetCmdSpace<cmd::SetBlendingColor>(); + cmd.Init(red, green, blue, alpha); + } + + void CreateRenderSurface( + ResourceId render_surface_id, ResourceId texture_id, + uint32 width, uint32 height, + uint32 level, uint32 side) { + cmd::CreateRenderSurface& cmd = GetCmdSpace<cmd::CreateRenderSurface>(); + cmd.Init(render_surface_id, texture_id, width, height, level, side); + } + + void DestroyRenderSurface(ResourceId render_surface_id) { + cmd::DestroyRenderSurface& cmd = + GetCmdSpace<cmd::DestroyRenderSurface>(); + cmd.Init(render_surface_id); + } + + void CreateDepthSurface( + ResourceId depth_surface_id, uint32 width, uint32 height) { + cmd::CreateDepthSurface& cmd = GetCmdSpace<cmd::CreateDepthSurface>(); + cmd.Init(depth_surface_id, width, height); + } + + void DestroyDepthSurface(ResourceId depth_surface_id) { + cmd::DestroyDepthSurface& cmd = GetCmdSpace<cmd::DestroyDepthSurface>(); + cmd.Init(depth_surface_id); + } + + void SetRenderSurface( + ResourceId render_surface_id, ResourceId depth_surface_id) { + cmd::SetRenderSurface& cmd = GetCmdSpace<cmd::SetRenderSurface>(); + cmd.Init(render_surface_id, depth_surface_id); + } + + void SetBackSurfaces() { + cmd::SetBackSurfaces& cmd = GetCmdSpace<cmd::SetBackSurfaces>(); + cmd.Init(); + } +}; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_CLIENT_CROSS_O3D_CMD_HELPER_H_ + diff --git a/o3d/command_buffer/command_buffer.gyp b/o3d/command_buffer/command_buffer.gyp index 9d63cd1..c54e8253 100644 --- a/o3d/command_buffer/command_buffer.gyp +++ b/o3d/command_buffer/command_buffer.gyp @@ -39,6 +39,7 @@ }, # 'all_dependent_settings' 'sources': [ 'common/cross/bitfield_helpers.h', + 'common/cross/cmd_buffer_common.h', 'common/cross/cmd_buffer_format.h', 'common/cross/cmd_buffer_format.cc', 'common/cross/gapi_interface.h', @@ -74,6 +75,8 @@ 'client/cross/fenced_allocator.h', 'client/cross/id_allocator.cc', 'client/cross/id_allocator.h', + 'client/cross/o3d_cmd_helper.cc', + 'client/cross/o3d_cmd_helper.h', ], }, { @@ -94,6 +97,16 @@ 'include_dirs': [ '..', ], + 'conditions': [ + ['OS == "win" and (renderer == "gl" or cb_service == "gl")', + { + 'include_dirs': [ + '../../<(glewdir)/include', + '../../<(cgdir)/include', + ], + }, + ], + ], }, # 'all_dependent_settings' 'dependencies': [ 'command_buffer_common', @@ -182,6 +195,8 @@ 'service/cross/gl/geometry_gl.cc', 'service/cross/gl/geometry_gl.h', 'service/cross/gl/gl_utils.h', + 'service/cross/gl/render_surface_gl.cc', + 'service/cross/gl/render_surface_gl.h', 'service/cross/gl/sampler_gl.cc', 'service/cross/gl/sampler_gl.h', 'service/cross/gl/states_gl.cc', diff --git a/o3d/command_buffer/common/cross/cmd_buffer_common.h b/o3d/command_buffer/common/cross/cmd_buffer_common.h new file mode 100644 index 0000000..87776d0 --- /dev/null +++ b/o3d/command_buffer/common/cross/cmd_buffer_common.h @@ -0,0 +1,195 @@ +/* + * 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 common parts of command buffer formats. + +#ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_COMMON_H_ +#define O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_COMMON_H_ + +#include "base/basictypes.h" +#include "command_buffer/common/cross/types.h" +#include "command_buffer/common/cross/bitfield_helpers.h" +#include "command_buffer/common/cross/logging.h" +#include "core/cross/packing.h" + +namespace o3d { +namespace command_buffer { + +namespace cmd { + enum ArgFlags { + kFixed = 0x0, + kAtLeastN = 0x1, + }; +} // namespace cmd + +// Computes the number of command buffer entries needed for a certain size. In +// other words it rounds up to a multiple of entries. +inline uint32 ComputeNumEntries(size_t size_in_bytes) { + return static_cast<uint32>( + (size_in_bytes + sizeof(uint32) - 1) / sizeof(uint32)); // NOLINT +} + +// Rounds up to a multiple of entries in bytes. +inline size_t RoundSizeToMultipleOfEntries(size_t size_in_bytes) { + return ComputeNumEntries(size_in_bytes) * sizeof(uint32); // NOLINT +} + +// Struct that defines the command header in the command buffer. +struct CommandHeader { + Uint32 size:8; + Uint32 command:24; + + void Init(uint32 _command, uint32 _size) { + DCHECK_LT(_size, 256u); + command = _command; + size = _size; + } + + // Sets the header based on the passed in command. Can not be used for + // variable sized commands like immediate commands or Noop. + template <typename T> + void SetCmd() { + COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); + Init(T::kCmdId, ComputeNumEntries(sizeof(T))); // NOLINT + } + + // Sets the header by a size in bytes. + template <typename T> + void SetCmdBySize(uint32 size_in_bytes) { + COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); + Init(T::kCmdId, ComputeNumEntries(sizeof(T) + size_in_bytes)); // NOLINT + } +}; + +COMPILE_ASSERT(sizeof(CommandHeader) == 4, Sizeof_CommandHeader_is_not_4); + +// Union that defines possible command buffer entries. +union CommandBufferEntry { + CommandHeader value_header; + Uint32 value_uint32; + Int32 value_int32; + float value_float; +}; + +COMPILE_ASSERT(sizeof(CommandBufferEntry) == 4, + Sizeof_CommandBufferEntry_is_not_4); + + +// Make sure the compiler does not add extra padding to any of the command +// structures. +O3D_PUSH_STRUCTURE_PACKING_1; + +// Gets the address of memory just after a structure in a typesafe way. This is +// used for IMMEDIATE commands to get the address of the place to put the data. +// Immediate command put their data direclty in the command buffer. +// Parameters: +// cmd: Address of command. +template <typename T> +void* ImmediateDataAddress(T* cmd) { + COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); + return reinterpret_cast<char*>(cmd) + sizeof(*cmd); +} + +// Gets the address of the place to put the next command in a typesafe way. +// This can only be used for fixed sized commands. +template <typename T> +// Parameters: +// cmd: Address of command. +void* NextCmdAddress(void* cmd) { + COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); + return reinterpret_cast<char*>(cmd) + sizeof(T); +} + +// Gets the address of the place to put the next command in a typesafe way. +// This can only be used for variable sized command like IMMEDIATE commands. +// Parameters: +// cmd: Address of command. +// size_of_data_in_bytes: Size of the data for the command. +template <typename T> +void* NextImmediateCmdAddress(void* cmd, uint32 size_of_data_in_bytes) { + COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); + return reinterpret_cast<char*>(cmd) + sizeof(T) + // NOLINT + RoundSizeToMultipleOfEntries(size_of_data_in_bytes); +} + +struct SharedMemory { + void Init(uint32 _id, uint32 _offset) { + id = _id; + offset = _offset; + } + + uint32 id; + uint32 offset; +}; + +COMPILE_ASSERT(offsetof(SharedMemory, id) == 0, + Offsetof_SharedMemory_id_not_0); +COMPILE_ASSERT(offsetof(SharedMemory, offset) == 4, + Offsetof_SharedMemory_offset_not_4); + + +namespace cmd { + +// 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 COMMON_COMMAND_BUFFER_CMDS(OP) \ + OP(Noop) /* 0 */ \ + OP(SetToken) /* 1 */ \ + +// Common commands. +enum CommonCommandId { + #define COMMON_COMMAND_BUFFER_CMD_OP(name) k ## name, + + COMMON_COMMAND_BUFFER_CMDS(COMMON_COMMAND_BUFFER_CMD_OP) + + #undef COMMON_COMMAND_BUFFER_CMD_OP + + kNumCommands, + kLastCommonId = 1023, // reserver 1024 spaces for common commands +}; + +COMPILE_ASSERT(kNumCommands - 1 <= kLastCommonId, Too_many_common_commands); + +} // namespace cmd + +O3D_POP_STRUCTURE_PACKING; + +} // namespace command_buffer +} // namespace o3d + +#endif // O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_COMMON_H_ + diff --git a/o3d/command_buffer/common/cross/cmd_buffer_format.cc b/o3d/command_buffer/common/cross/cmd_buffer_format.cc index 0cefbc6c..b7b9590 100644 --- a/o3d/command_buffer/common/cross/cmd_buffer_format.cc +++ b/o3d/command_buffer/common/cross/cmd_buffer_format.cc @@ -37,6 +37,7 @@ namespace o3d { namespace command_buffer { +namespace cmd { const char* GetCommandName(CommandId id) { static const char* const names[] = { @@ -53,6 +54,7 @@ const char* GetCommandName(CommandId id) { names[id] : "*unknown-command*"; } +} // namespace cmd } // namespace command_buffer } // namespace o3d diff --git a/o3d/command_buffer/common/cross/cmd_buffer_format.h b/o3d/command_buffer/common/cross/cmd_buffer_format.h index 3c5e567..e546f83 100644 --- a/o3d/command_buffer/common/cross/cmd_buffer_format.h +++ b/o3d/command_buffer/common/cross/cmd_buffer_format.h @@ -59,12 +59,8 @@ #ifndef O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ #define O3D_COMMAND_BUFFER_COMMON_CROSS_CMD_BUFFER_FORMAT_H_ -#include "base/basictypes.h" -#include "command_buffer/common/cross/types.h" -#include "command_buffer/common/cross/logging.h" +#include "command_buffer/common/cross/cmd_buffer_common.h" #include "command_buffer/common/cross/resource.h" -#include "command_buffer/common/cross/bitfield_helpers.h" -#include "core/cross/packing.h" namespace o3d { namespace command_buffer { @@ -77,74 +73,75 @@ namespace command_buffer { // // NOTE: THE ORDER OF THESE MUST NOT CHANGE (their id is derived by order) #define O3D_COMMAND_BUFFER_CMDS(OP) \ - OP(Noop) /* 0 */ \ - OP(SetToken) /* 1 */ \ - OP(BeginFrame) /* 2 */ \ - OP(EndFrame) /* 3 */ \ - OP(Clear) /* 4 */ \ - OP(CreateVertexBuffer) /* 5 */ \ - OP(DestroyVertexBuffer) /* 6 */ \ - OP(SetVertexBufferData) /* 7 */ \ - OP(SetVertexBufferDataImmediate) /* 8 */ \ - OP(GetVertexBufferData) /* 9 */ \ - OP(CreateIndexBuffer) /* 10 */ \ - OP(DestroyIndexBuffer) /* 11 */ \ - OP(SetIndexBufferData) /* 12 */ \ - OP(SetIndexBufferDataImmediate) /* 13 */ \ - OP(GetIndexBufferData) /* 14 */ \ - OP(CreateVertexStruct) /* 15 */ \ - OP(DestroyVertexStruct) /* 16 */ \ - OP(SetVertexInput) /* 17 */ \ - OP(SetVertexStruct) /* 18 */ \ - OP(Draw) /* 19 */ \ - OP(DrawIndexed) /* 20 */ \ - OP(CreateEffect) /* 21 */ \ - OP(CreateEffectImmediate) /* 22 */ \ - OP(DestroyEffect) /* 23 */ \ - OP(SetEffect) /* 24 */ \ - OP(GetParamCount) /* 25 */ \ - OP(CreateParam) /* 26 */ \ - OP(CreateParamByName) /* 27 */ \ - OP(CreateParamByNameImmediate) /* 28 */ \ - OP(DestroyParam) /* 29 */ \ - OP(SetParamData) /* 30 */ \ - OP(SetParamDataImmediate) /* 31 */ \ - OP(GetParamDesc) /* 32 */ \ - OP(GetStreamCount) /* 33 */ \ - OP(GetStreamDesc) /* 34 */ \ - OP(DestroyTexture) /* 35 */ \ - OP(CreateTexture2d) /* 36 */ \ - OP(CreateTexture3d) /* 37 */ \ - OP(CreateTextureCube) /* 38 */ \ - OP(SetTextureData) /* 39 */ \ - OP(SetTextureDataImmediate) /* 40 */ \ - OP(GetTextureData) /* 41 */ \ - OP(CreateSampler) /* 42 */ \ - OP(DestroySampler) /* 43 */ \ - OP(SetSamplerStates) /* 44 */ \ - OP(SetSamplerBorderColor) /* 45 */ \ - OP(SetSamplerTexture) /* 46 */ \ - OP(SetViewport) /* 47 */ \ - OP(SetScissor) /* 48 */ \ - OP(SetPointLineRaster) /* 49 */ \ - OP(SetPolygonRaster) /* 50 */ \ - OP(SetPolygonOffset) /* 51 */ \ - OP(SetAlphaTest) /* 52 */ \ - OP(SetDepthTest) /* 53 */ \ - OP(SetStencilTest) /* 54 */ \ - OP(SetBlending) /* 55 */ \ - OP(SetBlendingColor) /* 56 */ \ - OP(SetColorWrite) /* 57 */ \ - OP(CreateRenderSurface) /* 58 */ \ - OP(DestroyRenderSurface) /* 59 */ \ - OP(CreateDepthSurface) /* 60 */ \ - OP(DestroyDepthSurface) /* 61 */ \ - OP(SetRenderSurface) /* 62 */ \ - OP(SetBackSurfaces) /* 63 */ \ + OP(Noop) /* 1024 */ \ + OP(SetToken) /* 1025 */ \ + OP(BeginFrame) /* 1026 */ \ + OP(EndFrame) /* 1027 */ \ + OP(Clear) /* 1028 */ \ + OP(CreateVertexBuffer) /* 1029 */ \ + OP(DestroyVertexBuffer) /* 1030 */ \ + OP(SetVertexBufferData) /* 1031 */ \ + OP(SetVertexBufferDataImmediate) /* 1032 */ \ + OP(GetVertexBufferData) /* 1033 */ \ + OP(CreateIndexBuffer) /* 1034 */ \ + OP(DestroyIndexBuffer) /* 1035 */ \ + OP(SetIndexBufferData) /* 1036 */ \ + OP(SetIndexBufferDataImmediate) /* 1037 */ \ + OP(GetIndexBufferData) /* 1038 */ \ + OP(CreateVertexStruct) /* 1039 */ \ + OP(DestroyVertexStruct) /* 1040 */ \ + OP(SetVertexInput) /* 1041 */ \ + OP(SetVertexStruct) /* 1042 */ \ + OP(Draw) /* 1043 */ \ + OP(DrawIndexed) /* 1044 */ \ + OP(CreateEffect) /* 1045 */ \ + OP(CreateEffectImmediate) /* 1046 */ \ + OP(DestroyEffect) /* 1047 */ \ + OP(SetEffect) /* 1048 */ \ + OP(GetParamCount) /* 1049 */ \ + OP(CreateParam) /* 1050 */ \ + OP(CreateParamByName) /* 1051 */ \ + OP(CreateParamByNameImmediate) /* 1052 */ \ + OP(DestroyParam) /* 1053 */ \ + OP(SetParamData) /* 1054 */ \ + OP(SetParamDataImmediate) /* 1055 */ \ + OP(GetParamDesc) /* 1056 */ \ + OP(GetStreamCount) /* 1057 */ \ + OP(GetStreamDesc) /* 1058 */ \ + OP(DestroyTexture) /* 1059 */ \ + OP(CreateTexture2d) /* 1060 */ \ + OP(CreateTexture3d) /* 1061 */ \ + OP(CreateTextureCube) /* 1062 */ \ + OP(SetTextureData) /* 1063 */ \ + OP(SetTextureDataImmediate) /* 1064 */ \ + OP(GetTextureData) /* 1065 */ \ + OP(CreateSampler) /* 1066 */ \ + OP(DestroySampler) /* 1067 */ \ + OP(SetSamplerStates) /* 1068 */ \ + OP(SetSamplerBorderColor) /* 1069 */ \ + OP(SetSamplerTexture) /* 1070 */ \ + OP(SetViewport) /* 1071 */ \ + OP(SetScissor) /* 1072 */ \ + OP(SetPointLineRaster) /* 1073 */ \ + OP(SetPolygonRaster) /* 1074 */ \ + OP(SetPolygonOffset) /* 1075 */ \ + OP(SetAlphaTest) /* 1076 */ \ + OP(SetDepthTest) /* 1077 */ \ + OP(SetStencilTest) /* 1078 */ \ + OP(SetBlending) /* 1079 */ \ + OP(SetBlendingColor) /* 1080 */ \ + OP(SetColorWrite) /* 1081 */ \ + OP(CreateRenderSurface) /* 1082 */ \ + OP(DestroyRenderSurface) /* 1083 */ \ + OP(CreateDepthSurface) /* 1084 */ \ + OP(DestroyDepthSurface) /* 1085 */ \ + OP(SetRenderSurface) /* 1086 */ \ + OP(SetBackSurfaces) /* 1087 */ \ // GAPI commands. enum CommandId { + kStartPoint = cmd::kLastCommonId, // All O3D commands start after this. #define O3D_COMMAND_BUFFER_CMD_OP(name) k ## name, O3D_COMMAND_BUFFER_CMDS(O3D_COMMAND_BUFFER_CMD_OP) @@ -154,68 +151,6 @@ enum CommandId { kNumCommands, }; -const char* GetCommandName(CommandId id); - -namespace cmd { - enum ArgFlags { - kFixed = 0x0, - kAtLeastN = 0x1, - }; -} // namespace cmd - -// Computes the number of command buffer entries needed for a certain size. In -// other words it rounds up to a multiple of entries. -inline uint32 ComputeNumEntries(size_t size_in_bytes) { - return static_cast<uint32>( - (size_in_bytes + sizeof(uint32) - 1) / sizeof(uint32)); // NOLINT -} - -// Rounds up to a multiple of entries in bytes. -inline size_t RoundSizeToMultipleOfEntries(size_t size_in_bytes) { - return ComputeNumEntries(size_in_bytes) * sizeof(uint32); // NOLINT -} - -// Struct that defines the command header in the command buffer. -struct CommandHeader { - Uint32 size:8; - Uint32 command:24; - - void Init(uint32 _command, uint32 _size) { - DCHECK_LT(_size, 256u); - DCHECK_LT(_command, static_cast<unsigned int>(kNumCommands)); - command = _command; - size = _size; - } - - // Sets the header based on the passed in command. Can not be used for - // variable sized commands like immediate commands or Noop. - template <typename T> - void SetCmd() { - COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); - Init(T::kCmdId, ComputeNumEntries(sizeof(T))); // NOLINT - } - - // Sets the header by a size in bytes. - template <typename T> - void SetCmdBySize(uint32 size_in_bytes) { - COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); - Init(T::kCmdId, ComputeNumEntries(sizeof(T) + size_in_bytes)); // NOLINT - } -}; - -COMPILE_ASSERT(sizeof(CommandHeader) == 4, Sizeof_CommandHeader_is_not_4); - -// Union that defines possible command buffer entries. -union CommandBufferEntry { - CommandHeader value_header; - Uint32 value_uint32; - Int32 value_int32; - float value_float; -}; - -COMPILE_ASSERT(sizeof(CommandBufferEntry) == 4, - Sizeof_CommandBufferEntry_is_not_4); - // Bit definitions for buffers to clear. enum ClearBuffer { kColor = 0x1, @@ -307,58 +242,12 @@ enum BlendFunc { namespace cmd { +const char* GetCommandName(CommandId id); + // Make sure the compiler does not add extra padding to any of the command // structures. O3D_PUSH_STRUCTURE_PACKING_1; -// Gets the address of memory just after a structure in a typesafe way. This is -// used for IMMEDIATE commands to get the address of the place to put the data. -// Immediate command put their data direclty in the command buffer. -// Parameters: -// cmd: Address of command. -template <typename T> -void* ImmediateDataAddress(T* cmd) { - COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); - return reinterpret_cast<char*>(cmd) + sizeof(*cmd); -} - -// Gets the address of the place to put the next command in a typesafe way. -// This can only be used for fixed sized commands. -template <typename T> -// Parameters: -// cmd: Address of command. -void* NextCmdAddress(void* cmd) { - COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); - return reinterpret_cast<char*>(cmd) + sizeof(T); -} - -// Gets the address of the place to put the next command in a typesafe way. -// This can only be used for variable sized command like IMMEDIATE commands. -// Parameters: -// cmd: Address of command. -// size_of_data_in_bytes: Size of the data for the command. -template <typename T> -void* NextImmediateCmdAddress(void* cmd, uint32 size_of_data_in_bytes) { - COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); - return reinterpret_cast<char*>(cmd) + sizeof(T) + // NOLINT - RoundSizeToMultipleOfEntries(size_of_data_in_bytes); -} - -struct SharedMemory { - void Init(uint32 _id, uint32 _offset) { - id = _id; - offset = _offset; - } - - uint32 id; - uint32 offset; -}; - -COMPILE_ASSERT(offsetof(SharedMemory, id) == 0, - Offsetof_SharedMemory_id_not_0); -COMPILE_ASSERT(offsetof(SharedMemory, offset) == 4, - Offsetof_SharedMemory_offset_not_4); - struct Noop { typedef Noop ValueType; static const CommandId kCmdId = command_buffer::kNoop; @@ -3317,8 +3206,7 @@ COMPILE_ASSERT(offsetof(SetBackSurfaces, header) == 0, O3D_POP_STRUCTURE_PACKING; -} // namespace cmd - +} // namespace o3d } // namespace command_buffer } // namespace o3d diff --git a/o3d/command_buffer/service/cross/cmd_parser.cc b/o3d/command_buffer/service/cross/cmd_parser.cc index d17ab99..6f72aed 100644 --- a/o3d/command_buffer/service/cross/cmd_parser.cc +++ b/o3d/command_buffer/service/cross/cmd_parser.cc @@ -33,6 +33,8 @@ // This file contains the implementation of the command parser. #include "command_buffer/service/cross/cmd_parser.h" +// TODO(gman): remove this so we can use this code for different formats. +#include "command_buffer/common/cross/cmd_buffer_format.h" namespace o3d { namespace command_buffer { @@ -86,7 +88,7 @@ parse_error::ParseError CommandParser::ProcessCommand() { // get these errors. if (result != parse_error::kParseNoError) { DLOG(INFO) << "Error: " << result << " for Command " - << GetCommandName(static_cast<CommandId>(header.command)); + << cmd::GetCommandName(static_cast<CommandId>(header.command)); } get_ = (get + header.size) % entry_count_; return result; diff --git a/o3d/command_buffer/service/cross/cmd_parser.h b/o3d/command_buffer/service/cross/cmd_parser.h index 89b8269..ea003d2 100644 --- a/o3d/command_buffer/service/cross/cmd_parser.h +++ b/o3d/command_buffer/service/cross/cmd_parser.h @@ -37,7 +37,7 @@ #include "core/cross/types.h" #include "command_buffer/common/cross/constants.h" -#include "command_buffer/common/cross/cmd_buffer_format.h" +#include "command_buffer/common/cross/cmd_buffer_common.h" namespace o3d { namespace command_buffer { diff --git a/o3d/command_buffer/service/cross/cmd_parser_test.cc b/o3d/command_buffer/service/cross/cmd_parser_test.cc index d85eb67..02ee3948 100644 --- a/o3d/command_buffer/service/cross/cmd_parser_test.cc +++ b/o3d/command_buffer/service/cross/cmd_parser_test.cc @@ -35,6 +35,7 @@ #include "tests/common/win/testing_common.h" #include "command_buffer/service/cross/cmd_parser.h" #include "command_buffer/service/cross/mocks.h" +#include "base/scoped_ptr.h" namespace o3d { namespace command_buffer { diff --git a/o3d/command_buffer/service/cross/gapi_decoder.h b/o3d/command_buffer/service/cross/gapi_decoder.h index 08555eb..9c6cd32 100644 --- a/o3d/command_buffer/service/cross/gapi_decoder.h +++ b/o3d/command_buffer/service/cross/gapi_decoder.h @@ -37,6 +37,7 @@ #include "core/cross/types.h" #include "command_buffer/service/cross/cmd_parser.h" +#include "command_buffer/common/cross/cmd_buffer_format.h" namespace o3d { namespace command_buffer { diff --git a/o3d/command_buffer/service/cross/gl/gapi_gl.h b/o3d/command_buffer/service/cross/gl/gapi_gl.h index 324638b..3c07ba0 100644 --- a/o3d/command_buffer/service/cross/gl/gapi_gl.h +++ b/o3d/command_buffer/service/cross/gl/gapi_gl.h @@ -37,6 +37,9 @@ #define O3D_COMMAND_BUFFER_SERVICE_CROSS_GL_GAPI_GL_H_ #include <build/build_config.h> +#include <GL/glew.h> +#include <Cg/cg.h> +#include <Cg/cgGL.h> #include "command_buffer/common/cross/gapi_interface.h" #include "command_buffer/service/cross/gl/gl_utils.h" #include "command_buffer/service/cross/gl/effect_gl.h" @@ -61,6 +64,10 @@ class GAPIGL : public GAPIInterface { 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. diff --git a/o3d/command_buffer/service/cross/gl/gl_utils.h b/o3d/command_buffer/service/cross/gl/gl_utils.h index 36dfbf6..7500af6 100644 --- a/o3d/command_buffer/service/cross/gl/gl_utils.h +++ b/o3d/command_buffer/service/cross/gl/gl_utils.h @@ -36,6 +36,10 @@ #ifndef O3D_COMMAND_BUFFER_SERVICE_CROSS_GL_GL_UTILS_H_ #define O3D_COMMAND_BUFFER_SERVICE_CROSS_GL_GL_UTILS_H_ +#include <GL/glew.h> +#if defined(OS_WIN) +#include <GL/wglew.h> +#endif #include <Cg/cg.h> #include <Cg/cgGL.h> #include <build/build_config.h> diff --git a/o3d/command_buffer/service/cross/precompile.h b/o3d/command_buffer/service/cross/precompile.h index 8a178e9..56de3de 100644 --- a/o3d/command_buffer/service/cross/precompile.h +++ b/o3d/command_buffer/service/cross/precompile.h @@ -42,18 +42,6 @@ #include <windows.h> #endif -#if defined(CB_SERVICE_D3D9) -#include <d3d9.h> -#include <d3dx9.h> -#endif // defined(CB_SERVICE_D3D9) - -#if defined(CB_SERVICE_GL) -#include <GL/glew.h> -#include <GL/wglew.h> -#include <Cg/cg.h> -#include <Cg/cgGL.h> -#endif // defined(CB_SERVICE_GL) - #include <assert.h> #include <algorithm> #include <map> diff --git a/o3d/core/cross/command_buffer/buffer_cb.cc b/o3d/core/cross/command_buffer/buffer_cb.cc index 2809d7f..2d8d890 100644 --- a/o3d/core/cross/command_buffer/buffer_cb.cc +++ b/o3d/core/cross/command_buffer/buffer_cb.cc @@ -34,12 +34,12 @@ #include "core/cross/precompile.h" #include "core/cross/command_buffer/buffer_cb.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" #include "command_buffer/client/cross/fenced_allocator.h" namespace o3d { using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::FencedAllocator; VertexBufferCB::VertexBufferCB(ServiceLocator* service_locator, @@ -59,7 +59,7 @@ VertexBufferCB::~VertexBufferCB() { // Sends the DestroyVertexBuffer command, and frees the ID from the allocator. void VertexBufferCB::ConcreteFree() { if (resource_id_ != command_buffer::kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyVertexBuffer(resource_id_); renderer_->vertex_buffer_ids().FreeID(resource_id_); resource_id_ = command_buffer::kInvalidResource; @@ -71,7 +71,7 @@ bool VertexBufferCB::ConcreteAllocate(size_t size_in_bytes) { ConcreteFree(); if (size_in_bytes > 0) { resource_id_ = renderer_->vertex_buffer_ids().AllocateID(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateVertexBuffer(resource_id_, size_in_bytes, command_buffer::vertex_buffer::kNone); has_data_ = false; @@ -89,7 +89,7 @@ bool VertexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes()); if (!lock_pointer_) return false; if (has_data_) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->GetVertexBufferData( resource_id_, 0, GetSizeInBytes(), renderer_->transfer_shm_id(), @@ -105,7 +105,7 @@ bool VertexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { bool VertexBufferCB::ConcreteUnlock() { if (GetSizeInBytes() == 0 || !lock_pointer_) return false; - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->SetVertexBufferData( resource_id_, 0, GetSizeInBytes(), renderer_->transfer_shm_id(), @@ -135,7 +135,7 @@ IndexBufferCB::~IndexBufferCB() { // Sends the DestroyIndexBuffer command, and frees the ID from the allocator. void IndexBufferCB::ConcreteFree() { if (resource_id_ != command_buffer::kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyIndexBuffer(resource_id_); renderer_->index_buffer_ids().FreeID(resource_id_); resource_id_ = command_buffer::kInvalidResource; @@ -147,7 +147,7 @@ bool IndexBufferCB::ConcreteAllocate(size_t size_in_bytes) { ConcreteFree(); if (size_in_bytes > 0) { resource_id_ = renderer_->index_buffer_ids().AllocateID(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateIndexBuffer( resource_id_, size_in_bytes, command_buffer::index_buffer::kIndex32Bit); @@ -166,7 +166,7 @@ bool IndexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { lock_pointer_ = renderer_->allocator()->Alloc(GetSizeInBytes()); if (!lock_pointer_) return false; if (has_data_) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->GetIndexBufferData( resource_id_, 0, GetSizeInBytes(), renderer_->transfer_shm_id(), @@ -182,7 +182,7 @@ bool IndexBufferCB::ConcreteLock(AccessMode access_mode, void **buffer_data) { bool IndexBufferCB::ConcreteUnlock() { if (GetSizeInBytes() == 0 || !lock_pointer_) return false; - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->SetIndexBufferData( resource_id_, 0, GetSizeInBytes(), renderer_->transfer_shm_id(), diff --git a/o3d/core/cross/command_buffer/effect_cb.cc b/o3d/core/cross/command_buffer/effect_cb.cc index 172d717..a3b0260 100644 --- a/o3d/core/cross/command_buffer/effect_cb.cc +++ b/o3d/core/cross/command_buffer/effect_cb.cc @@ -40,12 +40,12 @@ #include "command_buffer/common/cross/constants.h" #include "command_buffer/common/cross/cmd_buffer_format.h" #include "command_buffer/client/cross/fenced_allocator.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" namespace o3d { using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::ResourceId; namespace effect_param = command_buffer::effect_param; namespace parse_error = command_buffer::parse_error; @@ -91,7 +91,7 @@ bool EffectCB::LoadFromFXString(const String& source) { ResourceId resource_id = renderer_->effect_ids().AllocateID(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateEffect( resource_id, source_size, renderer_->transfer_shm_id(), @@ -136,7 +136,7 @@ void EffectCB::Destroy() { set_source(""); ++generation_; if (resource_id_ != command_buffer::kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyEffect(resource_id_); renderer_->effect_ids().FreeID(resource_id_); resource_id_ = command_buffer::kInvalidResource; diff --git a/o3d/core/cross/command_buffer/param_cache_cb.cc b/o3d/core/cross/command_buffer/param_cache_cb.cc index 297be90..db3d0d7 100644 --- a/o3d/core/cross/command_buffer/param_cache_cb.cc +++ b/o3d/core/cross/command_buffer/param_cache_cb.cc @@ -40,12 +40,12 @@ #include "core/cross/command_buffer/param_cache_cb.h" #include "core/cross/command_buffer/sampler_cb.h" #include "command_buffer/common/cross/cmd_buffer_format.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" namespace o3d { using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::EffectHelper; using command_buffer::ResourceId; namespace effect_param = command_buffer::effect_param; @@ -54,7 +54,7 @@ namespace effect_param = command_buffer::effect_param; class ParamHandlerCB { public: virtual ~ParamHandlerCB() {} - virtual void SetValue(CommandBufferHelper *helper) = 0; + virtual void SetValue(O3DCmdHelper* helper) = 0; }; // Template implementation of ParamHandlerCB. @@ -69,7 +69,7 @@ class TypedParamHandlerCB : public ParamHandlerCB { // Sends the param value to the service. // This template definition only works for value types (floatn, matrix, int, // ..., but not textures or samplers). - virtual void SetValue(CommandBufferHelper *helper) { + virtual void SetValue(O3DCmdHelper* helper) { typename T::DataType value = param_->value(); helper->SetParamDataImmediate(id_, sizeof(value), &value); } @@ -91,7 +91,7 @@ class MatrixParamHandlerColumnsCB : public ParamHandlerCB { } // Sends the param value to the service. - virtual void SetValue(CommandBufferHelper *helper) { + virtual void SetValue(O3DCmdHelper* helper) { Matrix4 value = transpose(param_->value()); helper->SetParamDataImmediate(id_, sizeof(value), &value); } @@ -108,7 +108,7 @@ class SamplerParamHandlerCB : public ParamHandlerCB { } // Sends the param value to the service. - virtual void SetValue(CommandBufferHelper *helper) { + virtual void SetValue(O3DCmdHelper* helper) { SamplerCB *sampler = down_cast<SamplerCB *>(param_->value()); uint32 value; if (!sampler) { @@ -277,7 +277,7 @@ void ParamCacheCB::ClearHandlers() { handlers_.clear(); } -void ParamCacheCB::RunHandlers(CommandBufferHelper *helper) { +void ParamCacheCB::RunHandlers(O3DCmdHelper* helper) { for (unsigned int i = 0; i < handlers_.size(); ++i) { handlers_[i]->SetValue(helper); } diff --git a/o3d/core/cross/command_buffer/param_cache_cb.h b/o3d/core/cross/command_buffer/param_cache_cb.h index b8fd536..b96430c 100644 --- a/o3d/core/cross/command_buffer/param_cache_cb.h +++ b/o3d/core/cross/command_buffer/param_cache_cb.h @@ -59,7 +59,7 @@ class ParamCacheCB : public ParamCache { ParamObject* override); // Runs all the cached handlers. - void RunHandlers(command_buffer::CommandBufferHelper *helper); + void RunHandlers(command_buffer::O3DCmdHelper* helper); protected: // Validates platform specific information about the effect. diff --git a/o3d/core/cross/command_buffer/primitive_cb.cc b/o3d/core/cross/command_buffer/primitive_cb.cc index a451662..a5418d4 100644 --- a/o3d/core/cross/command_buffer/primitive_cb.cc +++ b/o3d/core/cross/command_buffer/primitive_cb.cc @@ -41,14 +41,14 @@ #include "core/cross/command_buffer/stream_bank_cb.h" #include "core/cross/error.h" #include "command_buffer/common/cross/gapi_interface.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" // TODO: add unit tests. namespace o3d { using command_buffer::ResourceId; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::CommandBufferEntry; using command_buffer::GAPIInterface; using command_buffer::kInvalidResource; @@ -128,7 +128,7 @@ void PrimitiveCB::PlatformSpecificRender(Renderer* renderer, stream_bank_cb->BindStreamsForRendering(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); // Sets current effect. // TODO: cache current effect ? diff --git a/o3d/core/cross/command_buffer/render_surface_cb.cc b/o3d/core/cross/command_buffer/render_surface_cb.cc index df90b49..2b66d98 100644 --- a/o3d/core/cross/command_buffer/render_surface_cb.cc +++ b/o3d/core/cross/command_buffer/render_surface_cb.cc @@ -31,13 +31,13 @@ #include "core/cross/command_buffer/render_surface_cb.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" namespace o3d { using command_buffer::ResourceId; using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator, int width, @@ -57,7 +57,7 @@ RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator, ResourceId id = renderer_->render_surface_ids().AllocateID(); resource_id_ = id; - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateRenderSurface( id, reinterpret_cast<uint32>(texture->GetTextureHandle()), @@ -71,7 +71,7 @@ RenderSurfaceCB::~RenderSurfaceCB() { void RenderSurfaceCB::Destroy() { // This should never be called during rendering. if (resource_id_ != command_buffer::kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyRenderSurface(resource_id_); renderer_->render_surface_ids().FreeID(resource_id_); resource_id_ = command_buffer::kInvalidResource; @@ -91,13 +91,13 @@ RenderDepthStencilSurfaceCB::RenderDepthStencilSurfaceCB( DCHECK(renderer); ResourceId id = renderer_->depth_surface_ids().AllocateID(); resource_id_ = id; - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateDepthSurface(id, width, height); } void RenderDepthStencilSurfaceCB::Destroy() { if (resource_id_ != command_buffer::kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyDepthSurface(resource_id_); renderer_->depth_surface_ids().FreeID(resource_id_); resource_id_ = command_buffer::kInvalidResource; diff --git a/o3d/core/cross/command_buffer/renderer_cb.cc b/o3d/core/cross/command_buffer/renderer_cb.cc index 4db474f..985bc74 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.cc +++ b/o3d/core/cross/command_buffer/renderer_cb.cc @@ -34,7 +34,7 @@ #include "core/cross/precompile.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" #include "command_buffer/client/cross/fenced_allocator.h" #include "command_buffer/common/cross/gapi_interface.h" #include "core/cross/command_buffer/buffer_cb.h" @@ -57,7 +57,7 @@ namespace o3d { using command_buffer::GAPIInterface; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using gpu_plugin::CommandBuffer; using gpu_plugin::GPUProcessor; using gpu_plugin::NPBrowser; @@ -291,8 +291,8 @@ Renderer::InitStatus RendererCB::InitPlatformSpecific( command_buffer_ = display_platform.command_buffer(); DCHECK(command_buffer_.Get()); - // Create and initialize a CommandBufferHelper. - helper_ = new CommandBufferHelper(npp_, command_buffer_); + // Create and initialize a O3DCmdHelper. + helper_ = new O3DCmdHelper(npp_, command_buffer_); if (!helper_->Initialize()) { Destroy(); return INITIALIZATION_ERROR; diff --git a/o3d/core/cross/command_buffer/renderer_cb.h b/o3d/core/cross/command_buffer/renderer_cb.h index 5668c21..76aad8b 100644 --- a/o3d/core/cross/command_buffer/renderer_cb.h +++ b/o3d/core/cross/command_buffer/renderer_cb.h @@ -46,7 +46,7 @@ namespace o3d { namespace command_buffer { -class CommandBufferHelper; +class O3DCmdHelper; class BufferSyncInterface; class FencedAllocatorWrapper; } // namespace command_buffer @@ -162,7 +162,7 @@ class RendererCB : public Renderer { IdAllocator &depth_surface_ids() { return depth_surface_ids_; } // Gets the command buffer helper. - command_buffer::CommandBufferHelper *helper() const { return helper_; } + command_buffer::O3DCmdHelper *helper() const { return helper_; } // Gets the registered ID of the transfer shared memory. int32 transfer_shm_id() const { return transfer_shm_id_; } @@ -260,7 +260,7 @@ class RendererCB : public Renderer { void *transfer_shm_address_; NPP npp_; gpu_plugin::NPObjectPointer<NPObject> command_buffer_; - command_buffer::CommandBufferHelper *helper_; + command_buffer::O3DCmdHelper *helper_; FencedAllocatorWrapper *allocator_; IdAllocator vertex_buffer_ids_; diff --git a/o3d/core/cross/command_buffer/sampler_cb.cc b/o3d/core/cross/command_buffer/sampler_cb.cc index a327595..25c945b 100644 --- a/o3d/core/cross/command_buffer/sampler_cb.cc +++ b/o3d/core/cross/command_buffer/sampler_cb.cc @@ -37,12 +37,12 @@ #include "core/cross/command_buffer/sampler_cb.h" #include "core/cross/command_buffer/renderer_cb.h" #include "command_buffer/common/cross/cmd_buffer_format.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" namespace o3d { using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::ResourceId; namespace sampler = command_buffer::sampler; @@ -94,7 +94,7 @@ SamplerCB::~SamplerCB() { } void SamplerCB::SetTextureAndStates() { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); sampler::AddressingMode address_mode_u_cb = AddressModeToCB(address_mode_u()); sampler::AddressingMode address_mode_v_cb = AddressModeToCB(address_mode_v()); sampler::AddressingMode address_mode_w_cb = AddressModeToCB(address_mode_w()); diff --git a/o3d/core/cross/command_buffer/stream_bank_cb.cc b/o3d/core/cross/command_buffer/stream_bank_cb.cc index ade0c4a..86997da 100644 --- a/o3d/core/cross/command_buffer/stream_bank_cb.cc +++ b/o3d/core/cross/command_buffer/stream_bank_cb.cc @@ -40,14 +40,14 @@ #include "core/cross/command_buffer/effect_cb.h" #include "core/cross/command_buffer/stream_bank_cb.h" #include "command_buffer/common/cross/gapi_interface.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" // TODO: add unit tests. namespace o3d { using command_buffer::ResourceId; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::CommandBufferEntry; using command_buffer::GAPIInterface; using command_buffer::kInvalidResource; @@ -146,7 +146,7 @@ void StreamBankCB::OnUpdateStreams() { void StreamBankCB::CreateVertexStruct() { DCHECK_EQ(kInvalidResource, vertex_struct_id_); vertex_struct_id_ = renderer_->vertex_structs_ids().AllocateID(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->CreateVertexStruct(vertex_struct_id_, vertex_stream_params_.size()); for (unsigned int i = 0; i < vertex_stream_params_.size(); ++i) { const Stream &stream = vertex_stream_params_[i]->stream(); @@ -181,7 +181,7 @@ void StreamBankCB::CreateVertexStruct() { // Destroys the vertex struct resource on the service side. void StreamBankCB::DestroyVertexStruct() { if (vertex_struct_id_ != kInvalidResource) { - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->DestroyVertexStruct(vertex_struct_id_); renderer_->vertex_structs_ids().FreeID(vertex_struct_id_); vertex_struct_id_ = kInvalidResource; @@ -191,7 +191,7 @@ void StreamBankCB::DestroyVertexStruct() { void StreamBankCB::BindStreamsForRendering() { if (vertex_struct_id_ == kInvalidResource) CreateVertexStruct(); - CommandBufferHelper *helper = renderer_->helper(); + O3DCmdHelper* helper = renderer_->helper(); helper->SetVertexStruct(vertex_struct_id_); } diff --git a/o3d/core/cross/command_buffer/texture_cb.cc b/o3d/core/cross/command_buffer/texture_cb.cc index 3b6b32d..0ef1ee4 100644 --- a/o3d/core/cross/command_buffer/texture_cb.cc +++ b/o3d/core/cross/command_buffer/texture_cb.cc @@ -40,13 +40,13 @@ #include "command_buffer/common/cross/cmd_buffer_format.h" #include "command_buffer/common/cross/resource.h" -#include "command_buffer/client/cross/cmd_buffer_helper.h" +#include "command_buffer/client/cross/o3d_cmd_helper.h" #include "command_buffer/client/cross/fenced_allocator.h" namespace o3d { using command_buffer::CommandBufferEntry; -using command_buffer::CommandBufferHelper; +using command_buffer::O3DCmdHelper; using command_buffer::FencedAllocatorWrapper; using command_buffer::ResourceId; namespace texture = command_buffer::texture; @@ -135,7 +135,7 @@ void SetTextureData(RendererCB *renderer, size_t mip_size, unsigned char* mip_data) { FencedAllocatorWrapper *allocator = renderer->allocator(); - CommandBufferHelper *helper = renderer->helper(); + O3DCmdHelper* helper = renderer->helper(); helper->SetTextureData( texture_id, x, y, z, @@ -157,7 +157,7 @@ void UpdateResourceFromBitmap(RendererCB *renderer, const Bitmap &bitmap) { DCHECK(bitmap.image_data()); FencedAllocatorWrapper *allocator = renderer->allocator(); - CommandBufferHelper *helper = renderer->helper(); + O3DCmdHelper* helper = renderer->helper(); unsigned int mip_width = std::max(1U, bitmap.width() >> level); unsigned int mip_height = std::max(1U, bitmap.height() >> level); unsigned char *mip_data = bitmap.GetMipData(level); @@ -192,7 +192,7 @@ void CopyBackResourceToBitmap(RendererCB *renderer, const Bitmap &bitmap) { DCHECK(bitmap.image_data()); FencedAllocatorWrapper *allocator = renderer->allocator(); - CommandBufferHelper *helper = renderer->helper(); + O3DCmdHelper* helper = renderer->helper(); unsigned int mip_width = std::max(1U, bitmap.width() >> level); unsigned int mip_height = std::max(1U, bitmap.height() >> level); size_t mip_size = diff --git a/o3d/core/cross/gl/buffer_gl.h b/o3d/core/cross/gl/buffer_gl.h index e2f287c..69d34a1 100644 --- a/o3d/core/cross/gl/buffer_gl.h +++ b/o3d/core/cross/gl/buffer_gl.h @@ -37,6 +37,7 @@ #define O3D_CORE_CROSS_GL_BUFFER_GL_H_ #include "core/cross/buffer.h" +#include "core/cross/gl/gl_headers.h" namespace o3d { diff --git a/o3d/core/cross/gl/effect_gl.cc b/o3d/core/cross/gl/effect_gl.cc index a161d3e..4a61e37 100644 --- a/o3d/core/cross/gl/effect_gl.cc +++ b/o3d/core/cross/gl/effect_gl.cc @@ -41,7 +41,6 @@ #pragma warning(disable : 4311) #endif -#include "Cg/cgGL.h" #include <sstream> #include "base/cross/std_functional.h" #include "core/cross/semantic_manager.h" diff --git a/o3d/core/cross/gl/effect_gl.h b/o3d/core/cross/gl/effect_gl.h index 3273055..1d9b81f 100644 --- a/o3d/core/cross/gl/effect_gl.h +++ b/o3d/core/cross/gl/effect_gl.h @@ -45,6 +45,7 @@ #include <utility> #include <vector> #include <map> +#include "core/cross/gl/gl_headers.h" #include "core/cross/effect.h" #include "core/cross/gl/utils_gl.h" diff --git a/o3d/core/cross/gl/gl_headers.h b/o3d/core/cross/gl/gl_headers.h new file mode 100644 index 0000000..e800997 --- /dev/null +++ b/o3d/core/cross/gl/gl_headers.h @@ -0,0 +1,43 @@ +/*
+ * Copyright 2009, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef O3D_CORE_CROSS_GL_GL_HEADERS_H_
+#define O3D_CORE_CROSS_GL_GL_HEADERS_H_
+
+#include <GL/glew.h>
+#if defined(OS_WIN)
+#include <GL/wglew.h>
+#endif
+#include <Cg/cg.h>
+#include <Cg/cgGL.h>
+
+#endif // O3D_CORE_CROSS_GL_GL_HEADERS_H_
+
diff --git a/o3d/core/cross/gl/param_cache_gl.h b/o3d/core/cross/gl/param_cache_gl.h index bfd9aea..52731cd 100644 --- a/o3d/core/cross/gl/param_cache_gl.h +++ b/o3d/core/cross/gl/param_cache_gl.h @@ -36,6 +36,7 @@ #define O3D_CORE_CROSS_GL_PARAM_CACHE_GL_H_ #include <map> +#include "core/cross/gl/gl_headers.h" #include "core/cross/param_cache.h" #include "core/cross/gl/effect_gl.h" diff --git a/o3d/core/cross/gl/render_surface_gl.h b/o3d/core/cross/gl/render_surface_gl.h index 56f9544..593b7994 100644 --- a/o3d/core/cross/gl/render_surface_gl.h +++ b/o3d/core/cross/gl/render_surface_gl.h @@ -36,6 +36,7 @@ #ifndef O3D_CORE_CROSS_GL_RENDER_SURFACE_GL_H_ #define O3D_CORE_CROSS_GL_RENDER_SURFACE_GL_H_ +#include "core/cross/gl/gl_headers.h" #include "core/cross/render_surface.h" #include "core/cross/texture.h" diff --git a/o3d/core/cross/gl/renderer_gl.h b/o3d/core/cross/gl/renderer_gl.h index de2a8cb..25e0290 100644 --- a/o3d/core/cross/gl/renderer_gl.h +++ b/o3d/core/cross/gl/renderer_gl.h @@ -37,7 +37,7 @@ #ifndef O3D_CORE_CROSS_GL_RENDERER_GL_H_ #define O3D_CORE_CROSS_GL_RENDERER_GL_H_ -#include <Cg/cg.h> +#include "core/cross/gl/gl_headers.h" #include <build/build_config.h> #include "core/cross/renderer.h" #include "core/cross/renderer_platform.h" diff --git a/o3d/core/cross/gl/sampler_gl.cc b/o3d/core/cross/gl/sampler_gl.cc index 9e432ba2..ab95b05 100644 --- a/o3d/core/cross/gl/sampler_gl.cc +++ b/o3d/core/cross/gl/sampler_gl.cc @@ -32,7 +32,7 @@ // This file contains the implementation for SamplerGL. -// Precompiled header comes before everything else. +#include "core/cross/gl/gl_headers.h" #include "core/cross/error.h" #include "core/cross/gl/renderer_gl.h" #include "core/cross/gl/sampler_gl.h" diff --git a/o3d/core/cross/gl/texture_gl.cc b/o3d/core/cross/gl/texture_gl.cc index 9b4ea7fe4..c168f41 100644 --- a/o3d/core/cross/gl/texture_gl.cc +++ b/o3d/core/cross/gl/texture_gl.cc @@ -33,6 +33,7 @@ // Implementations of the abstract Texture2D and TextureCUBE classes using // the OpenGL graphics API. +#include "core/cross/gl/gl_headers.h" #include "core/cross/error.h" #include "core/cross/types.h" #include "core/cross/pointer_utils.h" diff --git a/o3d/core/cross/gl/texture_gl.h b/o3d/core/cross/gl/texture_gl.h index 3a74b85..579dc07 100644 --- a/o3d/core/cross/gl/texture_gl.h +++ b/o3d/core/cross/gl/texture_gl.h @@ -44,12 +44,6 @@ #pragma warning(disable : 4311) #endif -//#ifdef OS_MACOSX -//#include <OpenGL/gl.h> -//#else -//#include <GL/gl.h> -//#endif - #include "core/cross/bitmap.h" #include "core/cross/texture.h" #include "core/cross/types.h" diff --git a/o3d/core/cross/gl/utils_gl.cc b/o3d/core/cross/gl/utils_gl.cc index 2dd938b..f75abc6 100644 --- a/o3d/core/cross/gl/utils_gl.cc +++ b/o3d/core/cross/gl/utils_gl.cc @@ -33,6 +33,7 @@ #include "core/cross/stream.h" #include "core/cross/types.h" #include "core/cross/gl/utils_gl.h" +#include "core/cross/gl/gl_headers.h" // Required OpenGL extensions: // GL_ARB_vertex_buffer_object diff --git a/o3d/core/cross/precompile.h b/o3d/core/cross/precompile.h index 3e11e99..8a99389 100644 --- a/o3d/core/cross/precompile.h +++ b/o3d/core/cross/precompile.h @@ -40,24 +40,8 @@ #if defined(OS_WIN) #include <windows.h> - -#if defined(RENDERER_D3D9) -#include <d3d9.h> -#include <d3dx9.h> -#endif - #endif // defined(OS_WIN) -#if defined(RENDERER_GL) -#include <GL/glew.h> -#if defined(OS_WIN) -#include <GL/wglew.h> -#endif - -#include <Cg/cg.h> -#include <Cg/cgGL.h> -#endif // defined(RENDERER_GL) - #include <assert.h> #include <algorithm> #include <map> diff --git a/o3d/core/cross/renderer_platform.h b/o3d/core/cross/renderer_platform.h index df54972..f512d9a 100644 --- a/o3d/core/cross/renderer_platform.h +++ b/o3d/core/cross/renderer_platform.h @@ -39,11 +39,14 @@ #include <build/build_config.h> #if defined(OS_MACOSX) +#include "core/cross/gl/gl_headers.h" #include <OpenGL/OpenGL.h> #include <AGL/agl.h> #elif defined(OS_LINUX) +#include "core/cross/gl/gl_headers.h" #include <GL/glx.h> #elif defined(OS_WIN) && defined(RENDERER_GL) +#include "core/cross/gl/gl_headers.h" #include <gl/GL.h> #endif diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp index 87d83f5..8fcd89b 100644 --- a/o3d/gpu_plugin/gpu_plugin.gyp +++ b/o3d/gpu_plugin/gpu_plugin.gyp @@ -94,13 +94,46 @@ '../command_buffer/command_buffer.gyp:command_buffer_service', 'np_utils', ], - 'include_dirs': [ - '../..', + 'conditions': [ + ['cb_service == "d3d9"', + { + 'include_dirs': [ + '../..', + '$(DXSDK_DIR)/Include', + ], + } + ], + ['cb_service == "gl"', + { + 'include_dirs': [ + '../../<(glewdir)/include', + '../../<(cgdir)/include', + ], + } + ], ], 'all_dependent_settings': { 'include_dirs': [ '../..', ], + 'conditions': [ + ['cb_service == "d3d9"', + { + 'include_dirs': [ + '../..', + '$(DXSDK_DIR)/Include', + ], + } + ], + ['cb_service == "gl"', + { + 'include_dirs': [ + '../../<(glewdir)/include', + '../../<(cgdir)/include', + ], + } + ], + ], }, # 'all_dependent_settings' 'sources': [ 'command_buffer.cc', diff --git a/o3d/gpu_plugin/gpu_processor.h b/o3d/gpu_plugin/gpu_processor.h index 05865ce..31dc055 100644 --- a/o3d/gpu_plugin/gpu_processor.h +++ b/o3d/gpu_plugin/gpu_processor.h @@ -14,8 +14,12 @@ #include "o3d/gpu_plugin/command_buffer.h" #include "o3d/gpu_plugin/np_utils/np_object_pointer.h" -#if defined(OS_WIN) +#if defined(CB_SERVICE_D3D9) #include "o3d/command_buffer/service/win/d3d9/gapi_d3d9.h" +#elif defined(CB_SERVICE_GL) +#include "o3d/command_buffer/service/cross/gl/gapi_gl.h" +#else +#error command buffer service not defined #endif namespace o3d { @@ -26,20 +30,26 @@ namespace gpu_plugin { class GPUProcessor : public ::base::RefCounted<GPUProcessor>, public command_buffer::CommandBufferEngine { public: +#if defined(CB_SERVICE_D3D9) + typedef command_buffer::GAPID3D9 GPUGAPIInterface; +#elif defined(CB_SERVICE_GL) + typedef command_buffer::GAPIGL GPUGAPIInterface; +#else +#error command buffer service not defined +#endif + GPUProcessor(NPP npp, CommandBuffer* command_buffer); -#if defined(OS_WIN) // This constructor is for unit tests. GPUProcessor(NPP npp, CommandBuffer* command_buffer, - command_buffer::GAPID3D9* gapi, + GPUGAPIInterface* gapi, command_buffer::GAPIDecoder* decoder, command_buffer::CommandParser* parser, int commands_per_update); virtual bool Initialize(HWND hwnd); -#endif // OS_WIN virtual ~GPUProcessor(); @@ -77,11 +87,9 @@ class GPUProcessor : public ::base::RefCounted<GPUProcessor>, scoped_ptr< ::base::SharedMemory> mapped_ring_buffer_; int commands_per_update_; -#if defined(OS_WIN) - scoped_ptr<command_buffer::GAPID3D9> gapi_; + scoped_ptr<GPUGAPIInterface> gapi_; scoped_ptr<command_buffer::GAPIDecoder> decoder_; scoped_ptr<command_buffer::CommandParser> parser_; -#endif }; } // namespace gpu_plugin diff --git a/o3d/gpu_plugin/gpu_processor_win.cc b/o3d/gpu_plugin/gpu_processor_win.cc index 53d9afc..a765ff94 100644 --- a/o3d/gpu_plugin/gpu_processor_win.cc +++ b/o3d/gpu_plugin/gpu_processor_win.cc @@ -15,14 +15,14 @@ GPUProcessor::GPUProcessor(NPP npp, command_buffer_(command_buffer), commands_per_update_(100) { DCHECK(command_buffer); - gapi_.reset(new command_buffer::GAPID3D9); + gapi_.reset(new GPUGAPIInterface); decoder_.reset(new command_buffer::GAPIDecoder(gapi_.get())); decoder_->set_engine(this); } GPUProcessor::GPUProcessor(NPP npp, CommandBuffer* command_buffer, - command_buffer::GAPID3D9* gapi, + GPUGAPIInterface* gapi, command_buffer::GAPIDecoder* decoder, command_buffer::CommandParser* parser, int commands_per_update) diff --git a/o3d/plugin/plugin.gyp b/o3d/plugin/plugin.gyp index 819f2dd..78b29c3 100644 --- a/o3d/plugin/plugin.gyp +++ b/o3d/plugin/plugin.gyp @@ -95,7 +95,7 @@ ], }, ], - ['renderer == "gl"', + ['renderer == "gl" or cb_service == "gl"', { 'dependencies': [ '../build/libs.gyp:gl_libs', diff --git a/o3d/tests/common/mac/testing_common.mm b/o3d/tests/common/mac/testing_common.mm index c00ef34..0d2a2e0 100644 --- a/o3d/tests/common/mac/testing_common.mm +++ b/o3d/tests/common/mac/testing_common.mm @@ -33,6 +33,7 @@ // Contains macintosh-specific code for setting up the Client object // used in the unit tests. +#include <GL/glew.h> #include <OpenGL/OpenGL.h> #include <OpenGL/gl.h> #include <OpenGL/glu.h> diff --git a/o3d/tests/tests.gyp b/o3d/tests/tests.gyp index 1aef0cc..8942228 100644 --- a/o3d/tests/tests.gyp +++ b/o3d/tests/tests.gyp @@ -221,6 +221,13 @@ }, }, ], + ['OS == "win" and (renderer == "gl" or cb_service == "gl")', + { + 'dependencies': [ + '../build/libs.gyp:gl_libs', + ], + }, + ], ['OS == "linux"', { 'sources': [ |