diff options
author | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 13:21:07 +0000 |
---|---|---|
committer | maruel@chromium.org <maruel@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-17 13:21:07 +0000 |
commit | a0abcf44533e242c524ed2955838880d00feadc9 (patch) | |
tree | a2e15f339acf72930b63122040e6fdaace0f1e70 /o3d | |
parent | 1f01d47474d6b06a2d1351416eeed320f892dde2 (diff) | |
download | chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.zip chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.gz chromium_src-a0abcf44533e242c524ed2955838880d00feadc9.tar.bz2 |
Add missing gclient dependencies to .gitignore.
Fix the format of many directories so they don't show up in git status anymore.
Run dos2unix on *.cc, caught many inconsistent and CRLF files.
TBR=evan
TEST=still build, git status shows nothing
BUG=none
Review URL: http://codereview.chromium.org/211010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26441 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
21 files changed, 3008 insertions, 3008 deletions
diff --git a/o3d/command_buffer/service/cross/gl/effect_gl.cc b/o3d/command_buffer/service/cross/gl/effect_gl.cc index 4e9da56..c2c49e3 100644 --- a/o3d/command_buffer/service/cross/gl/effect_gl.cc +++ b/o3d/command_buffer/service/cross/gl/effect_gl.cc @@ -445,7 +445,7 @@ void EffectGL::AddLowLevelParams(CGprogram prog, CGenum name_space, bool vp) { int num_elements; if (cg_type == CG_ARRAY) { num_elements = cgGetArraySize(cg_param, 0); - // Substitute the first element's type for our type.
+ // Substitute the first element's type for our type. cg_type = cgGetParameterType(cgGetArrayParameter(cg_param, 0)); } else { num_elements = 0; diff --git a/o3d/command_buffer/service/cross/precompile.cc b/o3d/command_buffer/service/cross/precompile.cc index 97064b4..d95a72b 100644 --- a/o3d/command_buffer/service/cross/precompile.cc +++ b/o3d/command_buffer/service/cross/precompile.cc @@ -1,33 +1,33 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "command_buffer/service/cross/precompile.h"
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "command_buffer/service/cross/precompile.h" diff --git a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc index 987eceb..2883baf 100644 --- a/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc +++ b/o3d/command_buffer/service/win/d3d9/render_surface_d3d9.cc @@ -1,230 +1,230 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file implements the D3D9 versions of the render surface resources,
-// as well as the related GAPID3D9 function implementations.
-
-#include "command_buffer/service/win/d3d9/render_surface_d3d9.h"
-#include "command_buffer/service/win/d3d9/gapi_d3d9.h"
-#include "command_buffer/service/win/d3d9/texture_d3d9.h"
-
-
-namespace o3d {
-namespace command_buffer {
-
-RenderSurfaceD3D9::RenderSurfaceD3D9(int width,
- int height,
- int mip_level,
- int side,
- TextureD3D9 *texture,
- IDirect3DSurface9 *direct3d_surface)
- : width_(width),
- height_(height),
- mip_level_(mip_level),
- texture_(texture),
- direct3d_surface_(direct3d_surface) {
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
- DCHECK_GT(mip_level, -1);
- DCHECK(texture);
-}
-
-RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi,
- int width,
- int height,
- int mip_level,
- int side,
- TextureD3D9 *texture) {
- DCHECK(gapi);
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
- DCHECK_GT(mip_level, -1);
- DCHECK(texture);
- CComPtr<IDirect3DSurface9> direct3d_surface_handle;
- bool success =
- texture->CreateRenderSurface(width, height, mip_level, side,
- &direct3d_surface_handle);
- if (!success || direct3d_surface_handle == NULL) {
- // If the surface was not created properly, delete and return nothing.
- return NULL;
- }
- RenderSurfaceD3D9 *render_surface =
- new RenderSurfaceD3D9(width,
- height,
- mip_level,
- side,
- texture,
- direct3d_surface_handle);
- return render_surface;
-}
-
-RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9(
- int width,
- int height,
- IDirect3DSurface9 *direct3d_surface)
- : width_(width),
- height_(height),
- direct3d_surface_(direct3d_surface) {
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
-}
-
-RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create(
- GAPID3D9 *gapi,
- int width,
- int height) {
- DCHECK(gapi);
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
-
- CComPtr<IDirect3DSurface9> direct3d_surface;
- gapi->d3d_device()->CreateDepthStencilSurface(
- width,
- height,
- D3DFMT_D24S8, // d3d format
- D3DMULTISAMPLE_NONE, // multisampling type
- 0, // multisample quality level
- FALSE, // z-buffer discarding disabled
- &direct3d_surface,
- NULL); // This parameter is required to be NULL.
- if (direct3d_surface == NULL) {
- return NULL;
- }
- RenderDepthStencilSurfaceD3D9 *depth_stencil =
- new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface);
- return depth_stencil;
-}
-
-// GAPI Interface functions ---------------------------------------------------
-
-// Copies the data from a texture resource.
-BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface(
- ResourceID id,
- unsigned int width,
- unsigned int height,
- unsigned int mip_level,
- unsigned int side,
- ResourceID texture_id) {
- if (id == current_surface_id_) {
- // This will delete the current surface which would be bad.
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- TextureD3D9 *texture = textures_.Get(texture_id);
- if (!texture->render_surfaces_enabled()) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- } else {
- RenderSurfaceD3D9 *render_surface = RenderSurfaceD3D9::Create(this,
- width,
- height,
- mip_level,
- side,
- texture);
- if (render_surface == NULL) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- render_surfaces_.Assign(id, render_surface);
- }
- return BufferSyncInterface::PARSE_NO_ERROR;
-}
-
-BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) {
- if (id == current_surface_id_) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- return render_surfaces_.Destroy(id) ?
- BufferSyncInterface::PARSE_NO_ERROR :
- BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
-}
-
-BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface(
- ResourceID id,
- unsigned int width,
- unsigned int height) {
- if (id == current_depth_surface_id_) {
- // This will delete the current surface which would be bad.
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- RenderDepthStencilSurfaceD3D9 *depth_surface =
- RenderDepthStencilSurfaceD3D9::Create(this, width, height);
- if (depth_surface == NULL) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- depth_surfaces_.Assign(id, depth_surface);
- return BufferSyncInterface::PARSE_NO_ERROR;
-}
-
-BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) {
- if (id == current_depth_surface_id_) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
- return depth_surfaces_.Destroy(id) ?
- BufferSyncInterface::PARSE_NO_ERROR :
- BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
-}
-
-BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface(
- ResourceID render_surface_id,
- ResourceID depth_stencil_id) {
- RenderSurfaceD3D9 *d3d_render_surface =
- render_surfaces_.Get(render_surface_id);
- RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface =
- depth_surfaces_.Get(depth_stencil_id);
-
- if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) {
- return BufferSyncInterface::PARSE_INVALID_ARGUMENTS;
- }
-
- IDirect3DSurface9 *d3d_surface =
- d3d_render_surface ? d3d_render_surface->direct3d_surface() : NULL;
- IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ?
- d3d_render_depth_surface->direct3d_surface() : NULL;
-
- // Get the device and set the render target and the depth stencil surface.
- IDirect3DDevice9 *device = this->d3d_device();
-
- HR(device->SetRenderTarget(0, d3d_surface));
- HR(device->SetDepthStencilSurface(d3d_depth_surface));
- current_surface_id_ = render_surface_id;
- current_depth_surface_id_ = depth_stencil_id;
- return BufferSyncInterface::PARSE_NO_ERROR;
-}
-
-void GAPID3D9::SetBackSurfaces() {
- // Get the device and set the render target and the depth stencil surface.
- IDirect3DDevice9 *device = this->d3d_device();
- HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_));
- HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_));
-}
-
-} // namespace command_buffer
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file implements the D3D9 versions of the render surface resources, +// as well as the related GAPID3D9 function implementations. + +#include "command_buffer/service/win/d3d9/render_surface_d3d9.h" +#include "command_buffer/service/win/d3d9/gapi_d3d9.h" +#include "command_buffer/service/win/d3d9/texture_d3d9.h" + + +namespace o3d { +namespace command_buffer { + +RenderSurfaceD3D9::RenderSurfaceD3D9(int width, + int height, + int mip_level, + int side, + TextureD3D9 *texture, + IDirect3DSurface9 *direct3d_surface) + : width_(width), + height_(height), + mip_level_(mip_level), + texture_(texture), + direct3d_surface_(direct3d_surface) { + DCHECK_GT(width, 0); + DCHECK_GT(height, 0); + DCHECK_GT(mip_level, -1); + DCHECK(texture); +} + +RenderSurfaceD3D9* RenderSurfaceD3D9::Create(GAPID3D9 *gapi, + int width, + int height, + int mip_level, + int side, + TextureD3D9 *texture) { + DCHECK(gapi); + DCHECK_GT(width, 0); + DCHECK_GT(height, 0); + DCHECK_GT(mip_level, -1); + DCHECK(texture); + CComPtr<IDirect3DSurface9> direct3d_surface_handle; + bool success = + texture->CreateRenderSurface(width, height, mip_level, side, + &direct3d_surface_handle); + if (!success || direct3d_surface_handle == NULL) { + // If the surface was not created properly, delete and return nothing. + return NULL; + } + RenderSurfaceD3D9 *render_surface = + new RenderSurfaceD3D9(width, + height, + mip_level, + side, + texture, + direct3d_surface_handle); + return render_surface; +} + +RenderDepthStencilSurfaceD3D9::RenderDepthStencilSurfaceD3D9( + int width, + int height, + IDirect3DSurface9 *direct3d_surface) + : width_(width), + height_(height), + direct3d_surface_(direct3d_surface) { + DCHECK_GT(width, 0); + DCHECK_GT(height, 0); +} + +RenderDepthStencilSurfaceD3D9* RenderDepthStencilSurfaceD3D9::Create( + GAPID3D9 *gapi, + int width, + int height) { + DCHECK(gapi); + DCHECK_GT(width, 0); + DCHECK_GT(height, 0); + + CComPtr<IDirect3DSurface9> direct3d_surface; + gapi->d3d_device()->CreateDepthStencilSurface( + width, + height, + D3DFMT_D24S8, // d3d format + D3DMULTISAMPLE_NONE, // multisampling type + 0, // multisample quality level + FALSE, // z-buffer discarding disabled + &direct3d_surface, + NULL); // This parameter is required to be NULL. + if (direct3d_surface == NULL) { + return NULL; + } + RenderDepthStencilSurfaceD3D9 *depth_stencil = + new RenderDepthStencilSurfaceD3D9(width, height, direct3d_surface); + return depth_stencil; +} + +// GAPI Interface functions --------------------------------------------------- + +// Copies the data from a texture resource. +BufferSyncInterface::ParseError GAPID3D9::CreateRenderSurface( + ResourceID id, + unsigned int width, + unsigned int height, + unsigned int mip_level, + unsigned int side, + ResourceID texture_id) { + if (id == current_surface_id_) { + // This will delete the current surface which would be bad. + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + TextureD3D9 *texture = textures_.Get(texture_id); + if (!texture->render_surfaces_enabled()) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } else { + RenderSurfaceD3D9 *render_surface = RenderSurfaceD3D9::Create(this, + width, + height, + mip_level, + side, + texture); + if (render_surface == NULL) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + render_surfaces_.Assign(id, render_surface); + } + return BufferSyncInterface::PARSE_NO_ERROR; +} + +BufferSyncInterface::ParseError GAPID3D9::DestroyRenderSurface(ResourceID id) { + if (id == current_surface_id_) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + return render_surfaces_.Destroy(id) ? + BufferSyncInterface::PARSE_NO_ERROR : + BufferSyncInterface::PARSE_INVALID_ARGUMENTS; +} + +BufferSyncInterface::ParseError GAPID3D9::CreateDepthSurface( + ResourceID id, + unsigned int width, + unsigned int height) { + if (id == current_depth_surface_id_) { + // This will delete the current surface which would be bad. + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + RenderDepthStencilSurfaceD3D9 *depth_surface = + RenderDepthStencilSurfaceD3D9::Create(this, width, height); + if (depth_surface == NULL) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + depth_surfaces_.Assign(id, depth_surface); + return BufferSyncInterface::PARSE_NO_ERROR; +} + +BufferSyncInterface::ParseError GAPID3D9::DestroyDepthSurface(ResourceID id) { + if (id == current_depth_surface_id_) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + return depth_surfaces_.Destroy(id) ? + BufferSyncInterface::PARSE_NO_ERROR : + BufferSyncInterface::PARSE_INVALID_ARGUMENTS; +} + +BufferSyncInterface::ParseError GAPID3D9::SetRenderSurface( + ResourceID render_surface_id, + ResourceID depth_stencil_id) { + RenderSurfaceD3D9 *d3d_render_surface = + render_surfaces_.Get(render_surface_id); + RenderDepthStencilSurfaceD3D9 *d3d_render_depth_surface = + depth_surfaces_.Get(depth_stencil_id); + + if (d3d_render_surface == NULL && d3d_render_depth_surface == NULL) { + return BufferSyncInterface::PARSE_INVALID_ARGUMENTS; + } + + IDirect3DSurface9 *d3d_surface = + d3d_render_surface ? d3d_render_surface->direct3d_surface() : NULL; + IDirect3DSurface9 *d3d_depth_surface = d3d_render_depth_surface ? + d3d_render_depth_surface->direct3d_surface() : NULL; + + // Get the device and set the render target and the depth stencil surface. + IDirect3DDevice9 *device = this->d3d_device(); + + HR(device->SetRenderTarget(0, d3d_surface)); + HR(device->SetDepthStencilSurface(d3d_depth_surface)); + current_surface_id_ = render_surface_id; + current_depth_surface_id_ = depth_stencil_id; + return BufferSyncInterface::PARSE_NO_ERROR; +} + +void GAPID3D9::SetBackSurfaces() { + // Get the device and set the render target and the depth stencil surface. + IDirect3DDevice9 *device = this->d3d_device(); + HR(d3d_device()->SetRenderTarget(0, back_buffer_surface_)); + HR(d3d_device()->SetDepthStencilSurface(back_buffer_depth_surface_)); +} + +} // namespace command_buffer +} // namespace o3d + diff --git a/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc b/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc index d570fda..b11121fa 100644 --- a/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc +++ b/o3d/command_buffer/service/win/d3d9/texture_d3d9.cc @@ -230,18 +230,18 @@ bool Texture2DD3D9::GetData(GAPID3D9 *gapi, return true; } -bool Texture2DD3D9::CreateRenderSurface(int width,
- int height,
- int mip_level,
- int side,
- IDirect3DSurface9** direct3d_surface) {
- IDirect3DTexture9* d3d_texture =
- static_cast<IDirect3DTexture9*>(d3d_base_texture());
- D3DSURFACE_DESC surface_desc;
- d3d_texture->GetLevelDesc(mip_level, &surface_desc);
- if (width != surface_desc.Width || height != surface_desc.Height) {
- return false;
- }
+bool Texture2DD3D9::CreateRenderSurface(int width, + int height, + int mip_level, + int side, + IDirect3DSurface9** direct3d_surface) { + IDirect3DTexture9* d3d_texture = + static_cast<IDirect3DTexture9*>(d3d_base_texture()); + D3DSURFACE_DESC surface_desc; + d3d_texture->GetLevelDesc(mip_level, &surface_desc); + if (width != surface_desc.Width || height != surface_desc.Height) { + return false; + } HR(d3d_texture->GetSurfaceLevel(mip_level, direct3d_surface)); return true; } @@ -591,12 +591,12 @@ bool TextureCubeD3D9::CreateRenderSurface( int side, IDirect3DSurface9** direct3d_surface) { IDirect3DCubeTexture9* d3d_cube_texture = - static_cast<IDirect3DCubeTexture9*>(d3d_base_texture());
- D3DSURFACE_DESC surface_desc;
- d3d_cube_texture->GetLevelDesc(mip_level, &surface_desc);
- if (width != surface_desc.Width || height != surface_desc.Height ||
- side < 0 || side > 5) {
- return false;
+ static_cast<IDirect3DCubeTexture9*>(d3d_base_texture()); + D3DSURFACE_DESC surface_desc; + d3d_cube_texture->GetLevelDesc(mip_level, &surface_desc); + if (width != surface_desc.Width || height != surface_desc.Height || + side < 0 || side > 5) { + return false; } HR(d3d_cube_texture->GetCubeMapSurface( D3DFace(static_cast<texture::Face>(side)), diff --git a/o3d/core/cross/command_buffer/render_surface_cb.cc b/o3d/core/cross/command_buffer/render_surface_cb.cc index f65ce3d..bb967d2 100644 --- a/o3d/core/cross/command_buffer/render_surface_cb.cc +++ b/o3d/core/cross/command_buffer/render_surface_cb.cc @@ -49,9 +49,9 @@ RenderSurfaceCB::RenderSurfaceCB(ServiceLocator *service_locator, RendererCB *renderer) : RenderSurface(service_locator, width, height, texture), resource_id_(command_buffer::kInvalidResource), - renderer_(renderer) {
- DCHECK_GT(width, 0);
- DCHECK_GT(height, 0);
+ renderer_(renderer) { + DCHECK_GT(width, 0); + DCHECK_GT(height, 0); DCHECK_GT(mip_level, -1); DCHECK(texture); DCHECK(renderer); @@ -95,8 +95,8 @@ RenderDepthStencilSurfaceCB::RenderDepthStencilSurfaceCB( RendererCB *renderer) : RenderDepthStencilSurface(service_locator, width, height), resource_id_(command_buffer::kInvalidResource), - renderer_(renderer) {
- DCHECK_GT(width, 0);
+ renderer_(renderer) { + DCHECK_GT(width, 0); DCHECK_GT(height, 0); DCHECK(renderer); ResourceID id = renderer_->depth_surface_ids().AllocateID(); diff --git a/o3d/core/cross/command_buffer/texture_cb.cc b/o3d/core/cross/command_buffer/texture_cb.cc index 73f53fc..12e3d98 100644 --- a/o3d/core/cross/command_buffer/texture_cb.cc +++ b/o3d/core/cross/command_buffer/texture_cb.cc @@ -359,7 +359,7 @@ void Texture2DCB::SetRect(int level, << "SetRect must be full rectangle for compressed textures"; return; } - unsigned int dst_pitch = image::ComputePitch(format(), src_width);
+ unsigned int dst_pitch = image::ComputePitch(format(), src_width); size_t size = dst_pitch * src_height; FencedAllocatorWrapper *allocator = renderer_->allocator(); @@ -588,7 +588,7 @@ void TextureCUBECB::SetRect(TextureCUBE::CubeFace face, return; } - unsigned int dst_pitch = image::ComputePitch(format(), src_width);
+ unsigned int dst_pitch = image::ComputePitch(format(), src_width); size_t size = dst_pitch * src_height; FencedAllocatorWrapper *allocator = renderer_->allocator(); diff --git a/o3d/core/cross/message_commands.cc b/o3d/core/cross/message_commands.cc index 9744612..f7c0f7e 100644 --- a/o3d/core/cross/message_commands.cc +++ b/o3d/core/cross/message_commands.cc @@ -1,49 +1,49 @@ -/*
- * 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 string descriptions of various IMC messages for O3D.
-
-#include "core/cross/message_commands.h"
-
-namespace o3d {
-namespace imc {
-const char* GetMessageDescription(MessageId id) {
- static const char* const message_descriptions[] = {
- #define O3D_IMC_MESSAGE_OP(id, class_name) #id,
- O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP)
- #undef O3D_IMC_MESSAGE_OP
- };
- return message_descriptions[id];
-}
-} // namespace imc
-} // namespace o3d
-
-
+/* + * 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 string descriptions of various IMC messages for O3D. + +#include "core/cross/message_commands.h" + +namespace o3d { +namespace imc { +const char* GetMessageDescription(MessageId id) { + static const char* const message_descriptions[] = { + #define O3D_IMC_MESSAGE_OP(id, class_name) #id, + O3D_IMC_MESSAGE_LIST(O3D_IMC_MESSAGE_OP) + #undef O3D_IMC_MESSAGE_OP + }; + return message_descriptions[id]; +} +} // namespace imc +} // namespace o3d + + diff --git a/o3d/core/cross/render_surface_test.cc b/o3d/core/cross/render_surface_test.cc index 5aafbfe..5e51e62 100644 --- a/o3d/core/cross/render_surface_test.cc +++ b/o3d/core/cross/render_surface_test.cc @@ -1,273 +1,273 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#include "core/cross/precompile.h"
-#include "tests/common/win/testing_common.h"
-#include "core/cross/client.h"
-#include "core/cross/pack.h"
-#include "core/cross/renderer.h"
-#include "core/cross/bitmap.h"
-#include "core/cross/features.h"
-#include "core/cross/texture.h"
-#include "core/cross/render_surface.h"
-#include "core/cross/render_surface_set.h"
-#include "core/cross/renderer_platform.h"
-#include "core/cross/error_status.h"
-
-// Defined in testing_common.cc, for each platform.
-extern o3d::DisplayWindow *g_display_window;
-
-namespace o3d {
-
-// A mock render which pushes commands to the renderer so that
-// actual rendering calls that maintain state can be handled by a
-// variable rather than actually rendering.
-class MockRenderer {
- public:
- // Creates a forwarding render class that pushes functionality to be tested
- // to the desired renderer and handles other functionality on its own.
- explicit MockRenderer(Renderer *renderer) : renderer_(renderer) {}
-
- virtual ~MockRenderer() {}
-
- // Rather than actually rendering, this just sets the state in the renderer.
- void StartRendering() {
- renderer_->set_rendering(true);
- }
-
- // This resets the state in the renderer.
- void FinishRendering() {
- renderer_->set_rendering(false);
- }
-
- // Pushes SetRenderSurfaces to the renderer.
- void SetRenderSurfaces(const RenderSurface *surface,
- const RenderDepthStencilSurface *depth_surface,
- bool is_back_buffer) {
- renderer_->SetRenderSurfaces(surface, depth_surface, is_back_buffer);
- }
-
- // Pushes GetRenderSurfaces to the renderer.
- void GetRenderSurfaces(const RenderSurface **surface,
- const RenderDepthStencilSurface **depth_surface,
- bool *is_back_buffer) {
- renderer_->GetRenderSurfaces(surface, depth_surface, is_back_buffer);
- }
- private:
- Renderer *renderer_;
-};
-
-// Class for testing render surfaces and associated functionality.
-class RenderSurfaceTest : public testing::Test {
- public:
- RenderSurfaceTest()
- : object_manager_(g_service_locator),
- error_status_(g_service_locator) {}
-
- protected:
- virtual void SetUp() {
- service_locator_ = new ServiceLocator;
- features_ = new Features(service_locator_);
- pack_ = object_manager_->CreatePack();
- renderer_ = new MockRenderer(g_renderer);
- renderer_->StartRendering();
- }
-
- virtual void TearDown() {
- renderer_->FinishRendering();
- pack_->Destroy();
- error_status_.ClearLastError();
- delete features_;
- delete service_locator_;
- delete renderer_;
- }
-
- ServiceLocator* service_locator() const {
- return service_locator_;
- }
-
- MockRenderer* renderer() const {
- return renderer_;
- }
-
- Pack* pack() const {
- return pack_;
- }
-
- ServiceDependency<ObjectManager> object_manager_;
- ErrorStatus error_status_;
- ServiceLocator *service_locator_;
- Features *features_;
- Pack *pack_;
- MockRenderer *renderer_;
-};
-
-// Tests that non PoT textures can't make render surfaces.
-TEST_F(RenderSurfaceTest, NonPowerOfTwoRenderSurfaceEnabled) {
- Texture2D *texture = pack()->CreateTexture2D(20, 32, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL == texture);
-}
-
-// Tests that a render surface can be created from a texture 2d.
-TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTexture2D) {
- Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL != texture);
-
- RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
- ASSERT_TRUE(NULL != render_surface);
- ASSERT_TRUE(NULL != render_surface->texture());
- ASSERT_EQ(render_surface->width(), 16);
- ASSERT_EQ(render_surface->height(), 32);
-}
-
-// Tests that a render surface can be created from a cube texture.
-TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTextureCUBE) {
- TextureCUBE *texture = pack()->CreateTextureCUBE(16, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL != texture);
-
- RenderSurface::Ref render_surface = texture->GetRenderSurface(
- TextureCUBE::FACE_POSITIVE_X, 0);
- ASSERT_TRUE(NULL != render_surface);
- ASSERT_TRUE(NULL != render_surface->texture());
- ASSERT_EQ(render_surface->width(), 16);
- ASSERT_EQ(render_surface->height(), 16);
-}
-
-// Tests the renderer's functionality to swap render surfaces and that
-// the correct render surfaces are set.
-TEST_F(RenderSurfaceTest, SwapRenderSurfaces) {
- Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL != texture);
-
- RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
- ASSERT_TRUE(NULL != render_surface);
- ASSERT_TRUE(texture == render_surface->texture());
-
- RenderDepthStencilSurface *depth_surface =
- pack()->CreateDepthStencilSurface(16, 32);
-
- // Now swap surfaces.
- renderer()->SetRenderSurfaces(render_surface, depth_surface, false);
- const RenderSurface *test_render_surface = NULL;
- const RenderDepthStencilSurface *test_depth_surface = NULL;
- bool test_is_back_buffer;
- renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface,
- &test_is_back_buffer);
- ASSERT_TRUE(test_render_surface == render_surface);
- ASSERT_TRUE(test_depth_surface == depth_surface);
- ASSERT_FALSE(test_is_back_buffer);
-}
-
-// Tests the renderer's functionality to swap render surfaces and return
-// the old one to the main rendering surface.
-TEST_F(RenderSurfaceTest, SetBackSurfaces) {
- Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL != texture);
-
- RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
- ASSERT_TRUE(NULL != render_surface);
- ASSERT_TRUE(texture == render_surface->texture());
-
- RenderDepthStencilSurface *depth_surface =
- pack()->CreateDepthStencilSurface(16, 32);
-
- // Save the original surfaces for comparison.
- const RenderSurface *original_render_surface = NULL;
- const RenderDepthStencilSurface *original_depth_surface = NULL;
- bool original_is_back_buffer;
- renderer()->GetRenderSurfaces(&original_render_surface,
- &original_depth_surface,
- &original_is_back_buffer);
- // Now swap surfaces.
- renderer()->SetRenderSurfaces(render_surface, depth_surface, false);
- // Return the back buffers
- renderer()->SetRenderSurfaces(NULL, NULL, true);
- // Get the original surfaces again for comparison.
- const RenderSurface *restored_render_surface = NULL;
- const RenderDepthStencilSurface *restored_depth_surface = NULL;
- bool restored_is_back_buffer;
- renderer()->GetRenderSurfaces(&original_render_surface,
- &original_depth_surface,
- &restored_is_back_buffer);
- ASSERT_TRUE(original_render_surface == restored_render_surface);
- ASSERT_TRUE(original_depth_surface == restored_depth_surface);
- ASSERT_TRUE(restored_is_back_buffer);
-}
-
-// Tests the render surfaces interaction as part of a render surface set
-// which is how they are commonly used in practice.
-TEST_F(RenderSurfaceTest, RenderSurfaceSetTest) {
- Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true);
- ASSERT_TRUE(NULL != texture);
-
- RenderSurface::Ref render_surface = texture->GetRenderSurface(0);
- ASSERT_TRUE(NULL != render_surface);
- ASSERT_TRUE(texture == render_surface->texture());
-
- RenderDepthStencilSurface *depth_surface =
- pack()->CreateDepthStencilSurface(16, 32);
- ASSERT_TRUE(depth_surface != NULL);
-
- RenderSurfaceSet *render_surface_set = pack()->Create<RenderSurfaceSet>();
- ASSERT_TRUE(render_surface_set != NULL);
- render_surface_set->set_render_surface(render_surface);
- render_surface_set->set_render_depth_stencil_surface(depth_surface);
- ASSERT_TRUE(render_surface_set->ValidateBoundSurfaces());
-
- RenderContext render_context(g_renderer);
-
- const RenderSurface *old_render_surface = NULL;
- const RenderDepthStencilSurface *old_depth_surface = NULL;
- bool old_is_back_buffer = false;
- renderer()->GetRenderSurfaces(&old_render_surface, &old_depth_surface,
- &old_is_back_buffer);
-
- render_surface_set->Render(&render_context);
- const RenderSurface *test_render_surface = NULL;
- const RenderDepthStencilSurface *test_depth_surface = NULL;
- bool test_is_back_buffer = false;
- renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface,
- &test_is_back_buffer);
- ASSERT_TRUE(test_render_surface == render_surface);
- ASSERT_TRUE(test_depth_surface == depth_surface);
- ASSERT_FALSE(test_is_back_buffer);
-
- render_surface_set->PostRender(&render_context);
- renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface,
- &test_is_back_buffer);
- ASSERT_TRUE(test_render_surface == old_render_surface);
- ASSERT_TRUE(test_depth_surface == old_depth_surface);
- ASSERT_TRUE(test_is_back_buffer == old_is_back_buffer);
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "core/cross/precompile.h" +#include "tests/common/win/testing_common.h" +#include "core/cross/client.h" +#include "core/cross/pack.h" +#include "core/cross/renderer.h" +#include "core/cross/bitmap.h" +#include "core/cross/features.h" +#include "core/cross/texture.h" +#include "core/cross/render_surface.h" +#include "core/cross/render_surface_set.h" +#include "core/cross/renderer_platform.h" +#include "core/cross/error_status.h" + +// Defined in testing_common.cc, for each platform. +extern o3d::DisplayWindow *g_display_window; + +namespace o3d { + +// A mock render which pushes commands to the renderer so that +// actual rendering calls that maintain state can be handled by a +// variable rather than actually rendering. +class MockRenderer { + public: + // Creates a forwarding render class that pushes functionality to be tested + // to the desired renderer and handles other functionality on its own. + explicit MockRenderer(Renderer *renderer) : renderer_(renderer) {} + + virtual ~MockRenderer() {} + + // Rather than actually rendering, this just sets the state in the renderer. + void StartRendering() { + renderer_->set_rendering(true); + } + + // This resets the state in the renderer. + void FinishRendering() { + renderer_->set_rendering(false); + } + + // Pushes SetRenderSurfaces to the renderer. + void SetRenderSurfaces(const RenderSurface *surface, + const RenderDepthStencilSurface *depth_surface, + bool is_back_buffer) { + renderer_->SetRenderSurfaces(surface, depth_surface, is_back_buffer); + } + + // Pushes GetRenderSurfaces to the renderer. + void GetRenderSurfaces(const RenderSurface **surface, + const RenderDepthStencilSurface **depth_surface, + bool *is_back_buffer) { + renderer_->GetRenderSurfaces(surface, depth_surface, is_back_buffer); + } + private: + Renderer *renderer_; +}; + +// Class for testing render surfaces and associated functionality. +class RenderSurfaceTest : public testing::Test { + public: + RenderSurfaceTest() + : object_manager_(g_service_locator), + error_status_(g_service_locator) {} + + protected: + virtual void SetUp() { + service_locator_ = new ServiceLocator; + features_ = new Features(service_locator_); + pack_ = object_manager_->CreatePack(); + renderer_ = new MockRenderer(g_renderer); + renderer_->StartRendering(); + } + + virtual void TearDown() { + renderer_->FinishRendering(); + pack_->Destroy(); + error_status_.ClearLastError(); + delete features_; + delete service_locator_; + delete renderer_; + } + + ServiceLocator* service_locator() const { + return service_locator_; + } + + MockRenderer* renderer() const { + return renderer_; + } + + Pack* pack() const { + return pack_; + } + + ServiceDependency<ObjectManager> object_manager_; + ErrorStatus error_status_; + ServiceLocator *service_locator_; + Features *features_; + Pack *pack_; + MockRenderer *renderer_; +}; + +// Tests that non PoT textures can't make render surfaces. +TEST_F(RenderSurfaceTest, NonPowerOfTwoRenderSurfaceEnabled) { + Texture2D *texture = pack()->CreateTexture2D(20, 32, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL == texture); +} + +// Tests that a render surface can be created from a texture 2d. +TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTexture2D) { + Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL != texture); + + RenderSurface::Ref render_surface = texture->GetRenderSurface(0); + ASSERT_TRUE(NULL != render_surface); + ASSERT_TRUE(NULL != render_surface->texture()); + ASSERT_EQ(render_surface->width(), 16); + ASSERT_EQ(render_surface->height(), 32); +} + +// Tests that a render surface can be created from a cube texture. +TEST_F(RenderSurfaceTest, CreateRenderSurfaceFromTextureCUBE) { + TextureCUBE *texture = pack()->CreateTextureCUBE(16, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL != texture); + + RenderSurface::Ref render_surface = texture->GetRenderSurface( + TextureCUBE::FACE_POSITIVE_X, 0); + ASSERT_TRUE(NULL != render_surface); + ASSERT_TRUE(NULL != render_surface->texture()); + ASSERT_EQ(render_surface->width(), 16); + ASSERT_EQ(render_surface->height(), 16); +} + +// Tests the renderer's functionality to swap render surfaces and that +// the correct render surfaces are set. +TEST_F(RenderSurfaceTest, SwapRenderSurfaces) { + Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL != texture); + + RenderSurface::Ref render_surface = texture->GetRenderSurface(0); + ASSERT_TRUE(NULL != render_surface); + ASSERT_TRUE(texture == render_surface->texture()); + + RenderDepthStencilSurface *depth_surface = + pack()->CreateDepthStencilSurface(16, 32); + + // Now swap surfaces. + renderer()->SetRenderSurfaces(render_surface, depth_surface, false); + const RenderSurface *test_render_surface = NULL; + const RenderDepthStencilSurface *test_depth_surface = NULL; + bool test_is_back_buffer; + renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface, + &test_is_back_buffer); + ASSERT_TRUE(test_render_surface == render_surface); + ASSERT_TRUE(test_depth_surface == depth_surface); + ASSERT_FALSE(test_is_back_buffer); +} + +// Tests the renderer's functionality to swap render surfaces and return +// the old one to the main rendering surface. +TEST_F(RenderSurfaceTest, SetBackSurfaces) { + Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL != texture); + + RenderSurface::Ref render_surface = texture->GetRenderSurface(0); + ASSERT_TRUE(NULL != render_surface); + ASSERT_TRUE(texture == render_surface->texture()); + + RenderDepthStencilSurface *depth_surface = + pack()->CreateDepthStencilSurface(16, 32); + + // Save the original surfaces for comparison. + const RenderSurface *original_render_surface = NULL; + const RenderDepthStencilSurface *original_depth_surface = NULL; + bool original_is_back_buffer; + renderer()->GetRenderSurfaces(&original_render_surface, + &original_depth_surface, + &original_is_back_buffer); + // Now swap surfaces. + renderer()->SetRenderSurfaces(render_surface, depth_surface, false); + // Return the back buffers + renderer()->SetRenderSurfaces(NULL, NULL, true); + // Get the original surfaces again for comparison. + const RenderSurface *restored_render_surface = NULL; + const RenderDepthStencilSurface *restored_depth_surface = NULL; + bool restored_is_back_buffer; + renderer()->GetRenderSurfaces(&original_render_surface, + &original_depth_surface, + &restored_is_back_buffer); + ASSERT_TRUE(original_render_surface == restored_render_surface); + ASSERT_TRUE(original_depth_surface == restored_depth_surface); + ASSERT_TRUE(restored_is_back_buffer); +} + +// Tests the render surfaces interaction as part of a render surface set +// which is how they are commonly used in practice. +TEST_F(RenderSurfaceTest, RenderSurfaceSetTest) { + Texture2D *texture = pack()->CreateTexture2D(16, 32, Texture::ARGB8, 2, true); + ASSERT_TRUE(NULL != texture); + + RenderSurface::Ref render_surface = texture->GetRenderSurface(0); + ASSERT_TRUE(NULL != render_surface); + ASSERT_TRUE(texture == render_surface->texture()); + + RenderDepthStencilSurface *depth_surface = + pack()->CreateDepthStencilSurface(16, 32); + ASSERT_TRUE(depth_surface != NULL); + + RenderSurfaceSet *render_surface_set = pack()->Create<RenderSurfaceSet>(); + ASSERT_TRUE(render_surface_set != NULL); + render_surface_set->set_render_surface(render_surface); + render_surface_set->set_render_depth_stencil_surface(depth_surface); + ASSERT_TRUE(render_surface_set->ValidateBoundSurfaces()); + + RenderContext render_context(g_renderer); + + const RenderSurface *old_render_surface = NULL; + const RenderDepthStencilSurface *old_depth_surface = NULL; + bool old_is_back_buffer = false; + renderer()->GetRenderSurfaces(&old_render_surface, &old_depth_surface, + &old_is_back_buffer); + + render_surface_set->Render(&render_context); + const RenderSurface *test_render_surface = NULL; + const RenderDepthStencilSurface *test_depth_surface = NULL; + bool test_is_back_buffer = false; + renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface, + &test_is_back_buffer); + ASSERT_TRUE(test_render_surface == render_surface); + ASSERT_TRUE(test_depth_surface == depth_surface); + ASSERT_FALSE(test_is_back_buffer); + + render_surface_set->PostRender(&render_context); + renderer()->GetRenderSurfaces(&test_render_surface, &test_depth_surface, + &test_is_back_buffer); + ASSERT_TRUE(test_render_surface == old_render_surface); + ASSERT_TRUE(test_depth_surface == old_depth_surface); + ASSERT_TRUE(test_is_back_buffer == old_is_back_buffer); +} + +} // namespace o3d + diff --git a/o3d/core/cross/texture_base_test.cc b/o3d/core/cross/texture_base_test.cc index 5f11c8f..c52bfbc 100644 --- a/o3d/core/cross/texture_base_test.cc +++ b/o3d/core/cross/texture_base_test.cc @@ -1,101 +1,101 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file implements unit tests for class Texture.
-
-#include "tests/common/win/testing_common.h"
-#include "core/cross/texture_base.h"
-#include "core/cross/object_manager.h"
-
-namespace o3d {
-
-namespace {
-
-Texture::RGBASwizzleIndices swizzle;
-
-class MockTexture : public Texture {
- public:
- typedef SmartPointer<MockTexture> Ref;
-
- MockTexture(ServiceLocator* service_locator,
- Texture::Format format,
- int levels,
- bool enable_render_surfaces)
- : Texture(service_locator, format, levels, enable_render_surfaces) {
- }
-
- virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices() {
- return swizzle;
- }
-
- virtual void* GetTextureHandle() const {
- return NULL;
- }
-
- virtual void SetFromBitmap(const Bitmap& bitmap) {
- }
-
- virtual void GenerateMips(int source_level, int num_levels) {
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockTexture);
-};
-
-} // anonymous namespace
-
-class TextureTest : public testing::Test {
- protected:
-
- TextureTest()
- : object_manager_(g_service_locator) {
- }
-
- private:
- ServiceDependency<ObjectManager> object_manager_;
-};
-
-TEST_F(TextureTest, Basic) {
- MockTexture::Ref texture(new MockTexture(
- g_service_locator,
- Texture::XRGB8,
- 1,
- false));
- ASSERT_TRUE(texture != NULL);
- EXPECT_EQ(texture->format(), Texture::XRGB8);
- EXPECT_EQ(texture->levels(), 1);
- EXPECT_FALSE(texture->alpha_is_one());
- EXPECT_FALSE(texture->render_surfaces_enabled());
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file implements unit tests for class Texture. + +#include "tests/common/win/testing_common.h" +#include "core/cross/texture_base.h" +#include "core/cross/object_manager.h" + +namespace o3d { + +namespace { + +Texture::RGBASwizzleIndices swizzle; + +class MockTexture : public Texture { + public: + typedef SmartPointer<MockTexture> Ref; + + MockTexture(ServiceLocator* service_locator, + Texture::Format format, + int levels, + bool enable_render_surfaces) + : Texture(service_locator, format, levels, enable_render_surfaces) { + } + + virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices() { + return swizzle; + } + + virtual void* GetTextureHandle() const { + return NULL; + } + + virtual void SetFromBitmap(const Bitmap& bitmap) { + } + + virtual void GenerateMips(int source_level, int num_levels) { + } + + private: + DISALLOW_COPY_AND_ASSIGN(MockTexture); +}; + +} // anonymous namespace + +class TextureTest : public testing::Test { + protected: + + TextureTest() + : object_manager_(g_service_locator) { + } + + private: + ServiceDependency<ObjectManager> object_manager_; +}; + +TEST_F(TextureTest, Basic) { + MockTexture::Ref texture(new MockTexture( + g_service_locator, + Texture::XRGB8, + 1, + false)); + ASSERT_TRUE(texture != NULL); + EXPECT_EQ(texture->format(), Texture::XRGB8); + EXPECT_EQ(texture->levels(), 1); + EXPECT_FALSE(texture->alpha_is_one()); + EXPECT_FALSE(texture->render_surfaces_enabled()); +} + +} // namespace o3d + diff --git a/o3d/core/cross/texture_test.cc b/o3d/core/cross/texture_test.cc index ba6e93c..d8de84f 100644 --- a/o3d/core/cross/texture_test.cc +++ b/o3d/core/cross/texture_test.cc @@ -1,201 +1,201 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file implements unit tests for class Texture.
-
-#include "tests/common/win/testing_common.h"
-#include "core/cross/texture.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-
-namespace o3d {
-
-namespace {
-
-bool CompareTexture(Texture2D* texture, int level, const uint8* expected) {
- Texture2D::LockHelper helper(texture, level, Texture::kReadOnly);
- const uint8* data = helper.GetDataAs<const uint8>();
- unsigned mip_width = image::ComputeMipDimension(level, texture->width());
- unsigned mip_height = image::ComputeMipDimension(level, texture->height());
-
- int bytes_per_row = image::ComputePitch(texture->format(), mip_width);
- for (unsigned yy = 0; yy < mip_height; ++yy) {
- if (memcmp(data, expected, bytes_per_row) != 0) {
- return false;
- }
- expected += bytes_per_row;
- data += helper.pitch();
- }
- return true;
-}
-
-} // anonymous namespace.
-
-class Texture2DTest : public testing::Test {
- protected:
- Texture2DTest()
- : object_manager_(g_service_locator) {
- }
-
- virtual void SetUp() {
- pack_ = object_manager_->CreatePack();
- }
-
- virtual void TearDown() {
- pack_->Destroy();
- }
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ObjectManager> object_manager_;
- Pack* pack_;
-};
-
-TEST_F(Texture2DTest, Basic) {
- Texture2D* texture = pack()->CreateTexture2D(8, 8, Texture::ARGB8, 1, false);
- ASSERT_TRUE(texture != NULL);
- EXPECT_TRUE(texture->IsA(Texture2D::GetApparentClass()));
- EXPECT_TRUE(texture->IsA(Texture::GetApparentClass()));
- EXPECT_TRUE(texture->IsA(ParamObject::GetApparentClass()));
- EXPECT_EQ(texture->format(), Texture::ARGB8);
- EXPECT_EQ(texture->levels(), 1);
- EXPECT_FALSE(texture->render_surfaces_enabled());
- EXPECT_EQ(0, Texture::kMaxDimension >> Texture::kMaxLevels);
- EXPECT_EQ(1, Texture::kMaxDimension >> (Texture::kMaxLevels - 1));
-}
-
-TEST_F(Texture2DTest, SetRect) {
- const int kWidth = 8;
- const int kHeight = 8;
- const int kLevels = 2;
- const int kDestMip = 1;
- const unsigned kDestX = 1u;
- const unsigned kDestY = 1u;
- Texture2D* texture = pack()->CreateTexture2D(
- kWidth, kHeight, Texture::ARGB8, kLevels, false);
- ASSERT_TRUE(texture != NULL);
- static const uint8 kExpected1[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- EXPECT_TRUE(CompareTexture(texture, 1, kExpected1));
- const int kSrcWidth = 2;
- const int kSrcHeight = 2;
- static const uint8 kSourcePixels[] = {
- 0x01, 0x01, 0x01, 0x02, 0x03, 0x03, 0x03, 0x04,
- 0x05, 0x05, 0x05, 0x06, 0x07, 0x07, 0x07, 0x08,
- };
- const int kSourcePitch = sizeof(kSourcePixels[0]) * kSrcWidth * 4;
- // normal copy
- texture->SetRect(kDestMip, kDestX, kDestY,
- kSrcWidth, kSrcHeight, kSourcePixels, kSourcePitch);
- static const uint8 kExpected2[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02,
- 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06,
- 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- EXPECT_TRUE(CompareTexture(texture, 1, kExpected2));
- // flipped copy
- texture->SetRect(
- kDestMip, kDestX, kDestY,
- kSrcWidth, kSrcHeight,
- kSourcePixels + kSourcePitch,
- -kSourcePitch);
- static const uint8 kExpected3[] = {
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06,
- 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02,
- 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00,
-
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- };
- EXPECT_TRUE(CompareTexture(texture, 1, kExpected3));
-}
-
-class TextureCUBETest : public testing::Test {
- protected:
- TextureCUBETest()
- : object_manager_(g_service_locator) {
- }
-
- virtual void SetUp() {
- pack_ = object_manager_->CreatePack();
- }
-
- virtual void TearDown() {
- pack_->Destroy();
- }
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ObjectManager> object_manager_;
- Pack* pack_;
-};
-
-TEST_F(TextureCUBETest, Basic) {
- TextureCUBE* texture =
- pack()->CreateTextureCUBE(8, Texture::ARGB8, 1, false);
- ASSERT_TRUE(texture != NULL);
- EXPECT_TRUE(texture->IsA(TextureCUBE::GetApparentClass()));
- EXPECT_TRUE(texture->IsA(Texture::GetApparentClass()));
- EXPECT_TRUE(texture->IsA(ParamObject::GetApparentClass()));
- EXPECT_EQ(texture->format(), Texture::ARGB8);
- EXPECT_EQ(texture->levels(), 1);
- EXPECT_FALSE(texture->render_surfaces_enabled());
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// This file implements unit tests for class Texture. + +#include "tests/common/win/testing_common.h" +#include "core/cross/texture.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" + +namespace o3d { + +namespace { + +bool CompareTexture(Texture2D* texture, int level, const uint8* expected) { + Texture2D::LockHelper helper(texture, level, Texture::kReadOnly); + const uint8* data = helper.GetDataAs<const uint8>(); + unsigned mip_width = image::ComputeMipDimension(level, texture->width()); + unsigned mip_height = image::ComputeMipDimension(level, texture->height()); + + int bytes_per_row = image::ComputePitch(texture->format(), mip_width); + for (unsigned yy = 0; yy < mip_height; ++yy) { + if (memcmp(data, expected, bytes_per_row) != 0) { + return false; + } + expected += bytes_per_row; + data += helper.pitch(); + } + return true; +} + +} // anonymous namespace. + +class Texture2DTest : public testing::Test { + protected: + Texture2DTest() + : object_manager_(g_service_locator) { + } + + virtual void SetUp() { + pack_ = object_manager_->CreatePack(); + } + + virtual void TearDown() { + pack_->Destroy(); + } + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ObjectManager> object_manager_; + Pack* pack_; +}; + +TEST_F(Texture2DTest, Basic) { + Texture2D* texture = pack()->CreateTexture2D(8, 8, Texture::ARGB8, 1, false); + ASSERT_TRUE(texture != NULL); + EXPECT_TRUE(texture->IsA(Texture2D::GetApparentClass())); + EXPECT_TRUE(texture->IsA(Texture::GetApparentClass())); + EXPECT_TRUE(texture->IsA(ParamObject::GetApparentClass())); + EXPECT_EQ(texture->format(), Texture::ARGB8); + EXPECT_EQ(texture->levels(), 1); + EXPECT_FALSE(texture->render_surfaces_enabled()); + EXPECT_EQ(0, Texture::kMaxDimension >> Texture::kMaxLevels); + EXPECT_EQ(1, Texture::kMaxDimension >> (Texture::kMaxLevels - 1)); +} + +TEST_F(Texture2DTest, SetRect) { + const int kWidth = 8; + const int kHeight = 8; + const int kLevels = 2; + const int kDestMip = 1; + const unsigned kDestX = 1u; + const unsigned kDestY = 1u; + Texture2D* texture = pack()->CreateTexture2D( + kWidth, kHeight, Texture::ARGB8, kLevels, false); + ASSERT_TRUE(texture != NULL); + static const uint8 kExpected1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + EXPECT_TRUE(CompareTexture(texture, 1, kExpected1)); + const int kSrcWidth = 2; + const int kSrcHeight = 2; + static const uint8 kSourcePixels[] = { + 0x01, 0x01, 0x01, 0x02, 0x03, 0x03, 0x03, 0x04, + 0x05, 0x05, 0x05, 0x06, 0x07, 0x07, 0x07, 0x08, + }; + const int kSourcePitch = sizeof(kSourcePixels[0]) * kSrcWidth * 4; + // normal copy + texture->SetRect(kDestMip, kDestX, kDestY, + kSrcWidth, kSrcHeight, kSourcePixels, kSourcePitch); + static const uint8 kExpected2[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, + 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06, + 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + EXPECT_TRUE(CompareTexture(texture, 1, kExpected2)); + // flipped copy + texture->SetRect( + kDestMip, kDestX, kDestY, + kSrcWidth, kSrcHeight, + kSourcePixels + kSourcePitch, + -kSourcePitch); + static const uint8 kExpected3[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x06, + 0x07, 0x07, 0x07, 0x08, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, + 0x03, 0x03, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + EXPECT_TRUE(CompareTexture(texture, 1, kExpected3)); +} + +class TextureCUBETest : public testing::Test { + protected: + TextureCUBETest() + : object_manager_(g_service_locator) { + } + + virtual void SetUp() { + pack_ = object_manager_->CreatePack(); + } + + virtual void TearDown() { + pack_->Destroy(); + } + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ObjectManager> object_manager_; + Pack* pack_; +}; + +TEST_F(TextureCUBETest, Basic) { + TextureCUBE* texture = + pack()->CreateTextureCUBE(8, Texture::ARGB8, 1, false); + ASSERT_TRUE(texture != NULL); + EXPECT_TRUE(texture->IsA(TextureCUBE::GetApparentClass())); + EXPECT_TRUE(texture->IsA(Texture::GetApparentClass())); + EXPECT_TRUE(texture->IsA(ParamObject::GetApparentClass())); + EXPECT_EQ(texture->format(), Texture::ARGB8); + EXPECT_EQ(texture->levels(), 1); + EXPECT_FALSE(texture->render_surfaces_enabled()); +} + +} // namespace o3d + diff --git a/o3d/import/cross/camera_info.cc b/o3d/import/cross/camera_info.cc index 905c337..3f46e4c 100644 --- a/o3d/import/cross/camera_info.cc +++ b/o3d/import/cross/camera_info.cc @@ -1,98 +1,98 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "import/cross/camera_info.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.CameraInfo", CameraInfo, JSONObject);
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.PerspectiveCameraInfo", PerspectiveCameraInfo, CameraInfo);
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.OrthographicCameraInfo", OrthographicCameraInfo, CameraInfo);
-
-const char* CameraInfo::kAspectRatioParamName = "aspectRatio";
-const char* CameraInfo::kNearZParamName = "nearZ";
-const char* CameraInfo::kFarZParamName = "farZ";
-const char* CameraInfo::kTransformValueName = "transform";
-const char* CameraInfo::kEyeValueName = "eye";
-const char* CameraInfo::kTargetValueName = "target";
-const char* CameraInfo::kUpValueName = "up";
-
-CameraInfo::CameraInfo(ServiceLocator* service_locator)
- : JSONObject(service_locator) {
- RegisterParamRef(kAspectRatioParamName, &aspect_ratio_param_);
- RegisterParamRef(kNearZParamName, &near_z_param_);
- RegisterParamRef(kFarZParamName, &far_z_param_);
- RegisterJSONValue(kTransformValueName, &transform_value_);
- RegisterJSONValue(kEyeValueName, &eye_value_);
- RegisterJSONValue(kTargetValueName, &target_value_);
- RegisterJSONValue(kUpValueName, &up_value_);
-
- set_aspect_ratio(1.0f);
- set_near_z(0.01f);
- set_far_z(10000.0f);
-}
-
-const char* OrthographicCameraInfo::kMagXParamName = "magX";
-const char* OrthographicCameraInfo::kMagYParamName = "magY";
-
-OrthographicCameraInfo::OrthographicCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- RegisterParamRef(kMagXParamName, &mag_x_param_);
- RegisterParamRef(kMagYParamName, &mag_y_param_);
-
- set_mag_x(1.0f);
- set_mag_y(1.0f);
-}
-
-ObjectBase::Ref OrthographicCameraInfo::Create(
- ServiceLocator* service_locator) {
- return ObjectBase::Ref(new OrthographicCameraInfo(service_locator));
-}
-
-const char* PerspectiveCameraInfo::kFieldOfViewYParamName = "fieldOfViewY";
-
-PerspectiveCameraInfo::PerspectiveCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- RegisterParamRef(kFieldOfViewYParamName, &field_of_view_y_param_);
-
- set_field_of_view_y(30.0f * 3.14159f / 180.0f);
-}
-
-ObjectBase::Ref PerspectiveCameraInfo::Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new PerspectiveCameraInfo(service_locator));
-}
-
-} // namespace o3d
-
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "import/cross/camera_info.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.CameraInfo", CameraInfo, JSONObject); +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.PerspectiveCameraInfo", PerspectiveCameraInfo, CameraInfo); +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.OrthographicCameraInfo", OrthographicCameraInfo, CameraInfo); + +const char* CameraInfo::kAspectRatioParamName = "aspectRatio"; +const char* CameraInfo::kNearZParamName = "nearZ"; +const char* CameraInfo::kFarZParamName = "farZ"; +const char* CameraInfo::kTransformValueName = "transform"; +const char* CameraInfo::kEyeValueName = "eye"; +const char* CameraInfo::kTargetValueName = "target"; +const char* CameraInfo::kUpValueName = "up"; + +CameraInfo::CameraInfo(ServiceLocator* service_locator) + : JSONObject(service_locator) { + RegisterParamRef(kAspectRatioParamName, &aspect_ratio_param_); + RegisterParamRef(kNearZParamName, &near_z_param_); + RegisterParamRef(kFarZParamName, &far_z_param_); + RegisterJSONValue(kTransformValueName, &transform_value_); + RegisterJSONValue(kEyeValueName, &eye_value_); + RegisterJSONValue(kTargetValueName, &target_value_); + RegisterJSONValue(kUpValueName, &up_value_); + + set_aspect_ratio(1.0f); + set_near_z(0.01f); + set_far_z(10000.0f); +} + +const char* OrthographicCameraInfo::kMagXParamName = "magX"; +const char* OrthographicCameraInfo::kMagYParamName = "magY"; + +OrthographicCameraInfo::OrthographicCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + RegisterParamRef(kMagXParamName, &mag_x_param_); + RegisterParamRef(kMagYParamName, &mag_y_param_); + + set_mag_x(1.0f); + set_mag_y(1.0f); +} + +ObjectBase::Ref OrthographicCameraInfo::Create( + ServiceLocator* service_locator) { + return ObjectBase::Ref(new OrthographicCameraInfo(service_locator)); +} + +const char* PerspectiveCameraInfo::kFieldOfViewYParamName = "fieldOfViewY"; + +PerspectiveCameraInfo::PerspectiveCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + RegisterParamRef(kFieldOfViewYParamName, &field_of_view_y_param_); + + set_field_of_view_y(30.0f * 3.14159f / 180.0f); +} + +ObjectBase::Ref PerspectiveCameraInfo::Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new PerspectiveCameraInfo(service_locator)); +} + +} // namespace o3d + + diff --git a/o3d/import/cross/camera_info_test.cc b/o3d/import/cross/camera_info_test.cc index ce1b105..662b161 100644 --- a/o3d/import/cross/camera_info_test.cc +++ b/o3d/import/cross/camera_info_test.cc @@ -1,222 +1,222 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/camera_info.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-namespace {
-
-// A class to test CameraInfo.
-class TestCameraInfo : public CameraInfo {
- public:
- typedef SmartPointer<TestCameraInfo> Ref;
-
- static ObjectBase::Ref Create(ServiceLocator* service_locator);
-
- private:
- explicit TestCameraInfo(ServiceLocator* service_locator)
- : CameraInfo(service_locator) {
- }
-
- O3D_OBJECT_BASE_DECL_CLASS(TestCameraInfo, CameraInfo);
- DISALLOW_COPY_AND_ASSIGN(TestCameraInfo);
-};
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.TestCameraInfo", TestCameraInfo, CameraInfo);
-
-ObjectBase::Ref TestCameraInfo::Create(
- ServiceLocator* service_locator) {
- return ObjectBase::Ref(new TestCameraInfo(service_locator));
-}
-
-} // anonymous namespace
-
-class TestCameraInfoTest : public testing::Test {
- protected:
- TestCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<TestCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void TestCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void TestCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a TestCameraInfo, tests basic properties.
-TEST_F(TestCameraInfoTest, TestTestCameraInfo) {
- TestCameraInfo *camera_info = pack()->Create<TestCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(TestCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->aspect_ratio(), 1.0f);
- EXPECT_EQ(camera_info->near_z(), 0.01f);
- EXPECT_EQ(camera_info->far_z(), 10000.0f);
- EXPECT_TRUE(camera_info->transform() == NULL);
-
- Transform* transform = pack()->Create<Transform>();
- ASSERT_TRUE(transform != NULL);
-
- camera_info->set_aspect_ratio(2.0f);
- camera_info->set_near_z(0.02f);
- camera_info->set_far_z(20000.0f);
- camera_info->set_transform(transform);
- camera_info->set_eye(Float3(10.0f, 20.0f, 30.0f));
- camera_info->set_target(Float3(11.0f, 22.0f, 33.0f));
- camera_info->set_up(Float3(12.0f, 23.0f, 34.0f));
-
- EXPECT_EQ(camera_info->aspect_ratio(), 2.0f);
- EXPECT_EQ(camera_info->near_z(), 0.02f);
- EXPECT_EQ(camera_info->far_z(), 20000.0f);
- EXPECT_TRUE(camera_info->transform() == transform);
- EXPECT_EQ(camera_info->eye(), Float3(10.0f, 20.0f, 30.0f));
- EXPECT_EQ(camera_info->target(), Float3(11.0f, 22.0f, 33.0f));
- EXPECT_EQ(camera_info->up(), Float3(12.0f, 23.0f, 34.0f));
-}
-
-class PerspectiveCameraInfoTest : public testing::Test {
- protected:
- PerspectiveCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<PerspectiveCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void PerspectiveCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void PerspectiveCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a PerspectiveCameraInfo, tests basic properties.
-TEST_F(PerspectiveCameraInfoTest, TestPerspectiveCameraInfo) {
- PerspectiveCameraInfo *camera_info = pack()->Create<PerspectiveCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(PerspectiveCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->field_of_view_y(), 30.0f * 3.14159f / 180.0f);
-
- camera_info->set_field_of_view_y(60.0f * 3.14159f / 180.0f);
-
- EXPECT_EQ(camera_info->field_of_view_y(), 60.0f * 3.14159f / 180.0f);
-}
-
-class OrthographicCameraInfoTest : public testing::Test {
- protected:
- OrthographicCameraInfoTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<OrthographicCameraInfo> class_register_;
- Pack* pack_;
-};
-
-void OrthographicCameraInfoTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void OrthographicCameraInfoTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a OrthographicCameraInfo, tests basic properties.
-TEST_F(OrthographicCameraInfoTest, TestOrthographicCameraInfo) {
- OrthographicCameraInfo *camera_info =
- pack()->Create<OrthographicCameraInfo>();
- EXPECT_TRUE(camera_info->IsA(OrthographicCameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass()));
-
- EXPECT_EQ(camera_info->mag_x(), 1.0f);
- EXPECT_EQ(camera_info->mag_y(), 1.0f);
-
- camera_info->set_mag_x(2.0f);
- camera_info->set_mag_y(3.0f);
-
- EXPECT_EQ(camera_info->mag_x(), 2.0f);
- EXPECT_EQ(camera_info->mag_y(), 3.0f);
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/camera_info.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" +#include "utils/cross/math_gtest.h" + +namespace o3d { + +namespace { + +// A class to test CameraInfo. +class TestCameraInfo : public CameraInfo { + public: + typedef SmartPointer<TestCameraInfo> Ref; + + static ObjectBase::Ref Create(ServiceLocator* service_locator); + + private: + explicit TestCameraInfo(ServiceLocator* service_locator) + : CameraInfo(service_locator) { + } + + O3D_OBJECT_BASE_DECL_CLASS(TestCameraInfo, CameraInfo); + DISALLOW_COPY_AND_ASSIGN(TestCameraInfo); +}; + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.TestCameraInfo", TestCameraInfo, CameraInfo); + +ObjectBase::Ref TestCameraInfo::Create( + ServiceLocator* service_locator) { + return ObjectBase::Ref(new TestCameraInfo(service_locator)); +} + +} // anonymous namespace + +class TestCameraInfoTest : public testing::Test { + protected: + TestCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<TestCameraInfo> class_register_; + Pack* pack_; +}; + +void TestCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void TestCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a TestCameraInfo, tests basic properties. +TEST_F(TestCameraInfoTest, TestTestCameraInfo) { + TestCameraInfo *camera_info = pack()->Create<TestCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(TestCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->aspect_ratio(), 1.0f); + EXPECT_EQ(camera_info->near_z(), 0.01f); + EXPECT_EQ(camera_info->far_z(), 10000.0f); + EXPECT_TRUE(camera_info->transform() == NULL); + + Transform* transform = pack()->Create<Transform>(); + ASSERT_TRUE(transform != NULL); + + camera_info->set_aspect_ratio(2.0f); + camera_info->set_near_z(0.02f); + camera_info->set_far_z(20000.0f); + camera_info->set_transform(transform); + camera_info->set_eye(Float3(10.0f, 20.0f, 30.0f)); + camera_info->set_target(Float3(11.0f, 22.0f, 33.0f)); + camera_info->set_up(Float3(12.0f, 23.0f, 34.0f)); + + EXPECT_EQ(camera_info->aspect_ratio(), 2.0f); + EXPECT_EQ(camera_info->near_z(), 0.02f); + EXPECT_EQ(camera_info->far_z(), 20000.0f); + EXPECT_TRUE(camera_info->transform() == transform); + EXPECT_EQ(camera_info->eye(), Float3(10.0f, 20.0f, 30.0f)); + EXPECT_EQ(camera_info->target(), Float3(11.0f, 22.0f, 33.0f)); + EXPECT_EQ(camera_info->up(), Float3(12.0f, 23.0f, 34.0f)); +} + +class PerspectiveCameraInfoTest : public testing::Test { + protected: + PerspectiveCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<PerspectiveCameraInfo> class_register_; + Pack* pack_; +}; + +void PerspectiveCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void PerspectiveCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a PerspectiveCameraInfo, tests basic properties. +TEST_F(PerspectiveCameraInfoTest, TestPerspectiveCameraInfo) { + PerspectiveCameraInfo *camera_info = pack()->Create<PerspectiveCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(PerspectiveCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->field_of_view_y(), 30.0f * 3.14159f / 180.0f); + + camera_info->set_field_of_view_y(60.0f * 3.14159f / 180.0f); + + EXPECT_EQ(camera_info->field_of_view_y(), 60.0f * 3.14159f / 180.0f); +} + +class OrthographicCameraInfoTest : public testing::Test { + protected: + OrthographicCameraInfoTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<OrthographicCameraInfo> class_register_; + Pack* pack_; +}; + +void OrthographicCameraInfoTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void OrthographicCameraInfoTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a OrthographicCameraInfo, tests basic properties. +TEST_F(OrthographicCameraInfoTest, TestOrthographicCameraInfo) { + OrthographicCameraInfo *camera_info = + pack()->Create<OrthographicCameraInfo>(); + EXPECT_TRUE(camera_info->IsA(OrthographicCameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(CameraInfo::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(camera_info->IsA(ParamObject::GetApparentClass())); + + EXPECT_EQ(camera_info->mag_x(), 1.0f); + EXPECT_EQ(camera_info->mag_y(), 1.0f); + + camera_info->set_mag_x(2.0f); + camera_info->set_mag_y(3.0f); + + EXPECT_EQ(camera_info->mag_x(), 2.0f); + EXPECT_EQ(camera_info->mag_y(), 3.0f); +} + +} // namespace o3d + diff --git a/o3d/import/cross/destination_buffer.cc b/o3d/import/cross/destination_buffer.cc index 5aa3124..d52bda8 100644 --- a/o3d/import/cross/destination_buffer.cc +++ b/o3d/import/cross/destination_buffer.cc @@ -1,79 +1,79 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "import/cross/destination_buffer.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS(
- "o3djs.DestinationBuffer", DestinationBuffer, VertexBuffer);
-
-DestinationBuffer::DestinationBuffer(ServiceLocator* service_locator)
- : VertexBuffer(service_locator),
- buffer_() {
-}
-
-DestinationBuffer::~DestinationBuffer() {
- ConcreteFree();
-}
-
-void DestinationBuffer::ConcreteFree() {
- buffer_.reset();
-}
-
-bool DestinationBuffer::ConcreteAllocate(size_t size_in_bytes) {
- ConcreteFree();
-
- buffer_.reset(new char[size_in_bytes]);
-
- return true;
-}
-
-bool DestinationBuffer::ConcreteLock(AccessMode access_mode,
- void **buffer_data) {
- if (!buffer_.get()) {
- return false;
- }
-
- *buffer_data = reinterpret_cast<void*>(buffer_.get());
- return true;
-}
-
-bool DestinationBuffer::ConcreteUnlock() {
- return buffer_.get() != NULL;
-}
-
-ObjectBase::Ref DestinationBuffer::Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new DestinationBuffer(service_locator));
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "import/cross/destination_buffer.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS( + "o3djs.DestinationBuffer", DestinationBuffer, VertexBuffer); + +DestinationBuffer::DestinationBuffer(ServiceLocator* service_locator) + : VertexBuffer(service_locator), + buffer_() { +} + +DestinationBuffer::~DestinationBuffer() { + ConcreteFree(); +} + +void DestinationBuffer::ConcreteFree() { + buffer_.reset(); +} + +bool DestinationBuffer::ConcreteAllocate(size_t size_in_bytes) { + ConcreteFree(); + + buffer_.reset(new char[size_in_bytes]); + + return true; +} + +bool DestinationBuffer::ConcreteLock(AccessMode access_mode, + void **buffer_data) { + if (!buffer_.get()) { + return false; + } + + *buffer_data = reinterpret_cast<void*>(buffer_.get()); + return true; +} + +bool DestinationBuffer::ConcreteUnlock() { + return buffer_.get() != NULL; +} + +ObjectBase::Ref DestinationBuffer::Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new DestinationBuffer(service_locator)); +} + +} // namespace o3d + diff --git a/o3d/import/cross/destination_buffer_test.cc b/o3d/import/cross/destination_buffer_test.cc index c7f69d3..2ad2513 100644 --- a/o3d/import/cross/destination_buffer_test.cc +++ b/o3d/import/cross/destination_buffer_test.cc @@ -1,104 +1,104 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/destination_buffer.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-
-namespace o3d {
-
-class DestinationBufferTest : public testing::Test {
- protected:
- DestinationBufferTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator) {
- class_manager_->AddTypedClass<DestinationBuffer>();
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- Pack* pack_;
-};
-
-void DestinationBufferTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void DestinationBufferTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-
-// Creates a Destination buffer, tests basic properties, and checks that writing
-// then reading data works.
-TEST_F(DestinationBufferTest, TestDestinationBuffer) {
- Buffer *buffer = pack()->Create<DestinationBuffer>();
- EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass()));
- EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass()));
- EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass()));
-
- const size_t kSize = 100;
- Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1);
- ASSERT_TRUE(field != NULL);
- ASSERT_TRUE(buffer->AllocateElements(kSize));
- EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT
-
- // Put some data into the buffer.
- uint32 *data = NULL;
- ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data));
- ASSERT_TRUE(data != NULL);
- for (uint32 i = 0; i < kSize; ++i) {
- data[i] = i;
- }
- ASSERT_TRUE(buffer->Unlock());
-
- data = NULL;
- // Read the data from the buffer, checks that it's the expected values.
- ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data));
- ASSERT_TRUE(data != NULL);
- for (uint32 i = 0; i < kSize; ++i) {
- EXPECT_EQ(i, data[i]);
- }
- ASSERT_TRUE(buffer->Unlock());
-}
-
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/destination_buffer.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" + +namespace o3d { + +class DestinationBufferTest : public testing::Test { + protected: + DestinationBufferTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator) { + class_manager_->AddTypedClass<DestinationBuffer>(); + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + Pack* pack_; +}; + +void DestinationBufferTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void DestinationBufferTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + + +// Creates a Destination buffer, tests basic properties, and checks that writing +// then reading data works. +TEST_F(DestinationBufferTest, TestDestinationBuffer) { + Buffer *buffer = pack()->Create<DestinationBuffer>(); + EXPECT_TRUE(buffer->IsA(DestinationBuffer::GetApparentClass())); + EXPECT_TRUE(buffer->IsA(VertexBuffer::GetApparentClass())); + EXPECT_TRUE(buffer->IsA(Buffer::GetApparentClass())); + + const size_t kSize = 100; + Field* field = buffer->CreateField(UInt32Field::GetApparentClass(), 1); + ASSERT_TRUE(field != NULL); + ASSERT_TRUE(buffer->AllocateElements(kSize)); + EXPECT_EQ(kSize * sizeof(uint32), buffer->GetSizeInBytes()); // NOLINT + + // Put some data into the buffer. + uint32 *data = NULL; + ASSERT_TRUE(buffer->LockAs(Buffer::WRITE_ONLY, &data)); + ASSERT_TRUE(data != NULL); + for (uint32 i = 0; i < kSize; ++i) { + data[i] = i; + } + ASSERT_TRUE(buffer->Unlock()); + + data = NULL; + // Read the data from the buffer, checks that it's the expected values. + ASSERT_TRUE(buffer->LockAs(Buffer::READ_ONLY, &data)); + ASSERT_TRUE(data != NULL); + for (uint32 i = 0; i < kSize; ++i) { + EXPECT_EQ(i, data[i]); + } + ASSERT_TRUE(buffer->Unlock()); +} + + +} // namespace o3d + diff --git a/o3d/import/cross/json_object.cc b/o3d/import/cross/json_object.cc index a681a3a..906e730 100644 --- a/o3d/import/cross/json_object.cc +++ b/o3d/import/cross/json_object.cc @@ -1,66 +1,66 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file defines the JSON Object class.
-
-#include "import/cross/json_object.h"
-
-namespace o3d {
-
-O3D_OBJECT_BASE_DEFN_CLASS("o3djs.JSONObject", JSONObject, ParamObject);
-
-JSONObject::JSONObject(ServiceLocator* service_locator)
- : ParamObject(service_locator) {
-}
-
-void JSONObject::AddProperty(const String& name, JSONValue* value) {
- std::pair<NameValueMap::iterator, bool> result = properties_.insert(
- std::pair<String, JSONValue::Ref>(name, JSONValue::Ref(value)));
- DCHECK(result.second);
-}
-
-void JSONObject::Serialize(StructuredWriter* writer) const {
- writer->WritePropertyName("object");
- writer->OpenObject();
- for (NameValueMap::const_iterator it(properties_.begin());
- it != properties_.end();
- ++it) {
- if (it->second->exists()) {
- writer->WritePropertyName(it->first);
- it->second->Serialize(writer);
- }
- }
- writer->CloseObject();
-}
-
-} // namespace o3d
-
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file defines the JSON Object class. + +#include "import/cross/json_object.h" + +namespace o3d { + +O3D_OBJECT_BASE_DEFN_CLASS("o3djs.JSONObject", JSONObject, ParamObject); + +JSONObject::JSONObject(ServiceLocator* service_locator) + : ParamObject(service_locator) { +} + +void JSONObject::AddProperty(const String& name, JSONValue* value) { + std::pair<NameValueMap::iterator, bool> result = properties_.insert( + std::pair<String, JSONValue::Ref>(name, JSONValue::Ref(value))); + DCHECK(result.second); +} + +void JSONObject::Serialize(StructuredWriter* writer) const { + writer->WritePropertyName("object"); + writer->OpenObject(); + for (NameValueMap::const_iterator it(properties_.begin()); + it != properties_.end(); + ++it) { + if (it->second->exists()) { + writer->WritePropertyName(it->first); + it->second->Serialize(writer); + } + } + writer->CloseObject(); +} + +} // namespace o3d + + diff --git a/o3d/import/cross/json_object_test.cc b/o3d/import/cross/json_object_test.cc index 8935f8b..137de45 100644 --- a/o3d/import/cross/json_object_test.cc +++ b/o3d/import/cross/json_object_test.cc @@ -1,448 +1,448 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "import/cross/json_object.h"
-#include "core/cross/class_manager.h"
-#include "core/cross/object_manager.h"
-#include "core/cross/pack.h"
-#include "core/cross/service_dependency.h"
-#include "utils/cross/string_writer.h"
-#include "utils/cross/json_writer.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-namespace {
-
-// A class to test JSONObject
-class TestJSONObject : public JSONObject {
- public:
- typedef SmartPointer<TestJSONObject> Ref;
-
- static const char* kFloatValueName;
- static const char* kFloat2ValueName;
- static const char* kFloat3ValueName;
- static const char* kFloat4ValueName;
- static const char* kMatrix4ValueName;
- static const char* kIntegerValueName;
- static const char* kBooleanValueName;
- static const char* kStringValueName;
- static const char* kTransformValueName;
- static const char* kMaterialValueName;
- static const char* kOptionalFloatValueName;
- static const char* kOptionalFloat2ValueName;
- static const char* kOptionalFloat3ValueName;
- static const char* kOptionalFloat4ValueName;
- static const char* kOptionalMatrix4ValueName;
- static const char* kOptionalIntegerValueName;
- static const char* kOptionalBooleanValueName;
- static const char* kOptionalStringValueName;
-
- float float_value() const {
- return float_value_->value();
- }
-
- void set_float_value(float value) {
- float_value_->set_value(value);
- }
-
- Float2 float2_value() const {
- return float2_value_->value();
- }
-
- void set_float2_value(const Float2& value) {
- float2_value_->set_value(value);
- }
-
- Float3 float3_value() const {
- return float3_value_->value();
- }
-
- void set_float3_value(const Float3& value) {
- float3_value_->set_value(value);
- }
-
- Float4 float4_value() const {
- return float4_value_->value();
- }
-
- void set_float4_value(const Float4& value) {
- float4_value_->set_value(value);
- }
-
- Matrix4 matrix4_value() const {
- return matrix4_value_->value();
- }
-
- void set_matrix4_value(const Matrix4& value) {
- matrix4_value_->set_value(value);
- }
-
- int integer_value() const {
- return integer_value_->value();
- }
-
- void set_integer_value(int value) {
- integer_value_->set_value(value);
- }
-
- bool boolean_value() const {
- return boolean_value_->value();
- }
-
- void set_boolean_value(bool value) {
- boolean_value_->set_value(value);
- }
-
- String string_value() const {
- return string_value_->value();
- }
-
- void set_string_value(const String& value) {
- string_value_->set_value(value);
- }
-
- Transform* transform_value() const {
- return transform_value_->value();
- }
-
- void set_transform_value(Transform* value) {
- transform_value_->set_value(value);
- }
-
- Material* material_value() const {
- return material_value_->value();
- }
-
- void set_material_value(Material* value) {
- material_value_->set_value(value);
- }
-
- float optional_float_value() const {
- return optional_float_value_->value();
- }
-
- void set_optional_float_value(float value) {
- optional_float_value_->set_value(value);
- }
-
- Float2 optional_float2_value() const {
- return optional_float2_value_->value();
- }
-
- void set_optional_float2_value(const Float2& value) {
- optional_float2_value_->set_value(value);
- }
-
- Float3 optional_float3_value() const {
- return optional_float3_value_->value();
- }
-
- void set_optional_float3_value(const Float3& value) {
- optional_float3_value_->set_value(value);
- }
-
- Float4 optional_float4_value() const {
- return optional_float4_value_->value();
- }
-
- void set_optional_float4_value(const Float4& value) {
- optional_float4_value_->set_value(value);
- }
-
- Matrix4 optional_matrix4_value() const {
- return optional_matrix4_value_->value();
- }
-
- void set_optional_matrix4_value(const Matrix4& value) {
- optional_matrix4_value_->set_value(value);
- }
-
- int optional_integer_value() const {
- return optional_integer_value_->value();
- }
-
- void set_optional_integer_value(int value) {
- optional_integer_value_->set_value(value);
- }
-
- bool optional_boolean_value() const {
- return optional_boolean_value_->value();
- }
-
- void set_optional_boolean_value(bool value) {
- optional_boolean_value_->set_value(value);
- }
-
- String optional_string_value() const {
- return optional_string_value_->value();
- }
-
- void set_optional_string_value(const String& value) {
- optional_string_value_->set_value(value);
- }
-
- static ObjectBase::Ref Create(ServiceLocator* service_locator) {
- return ObjectBase::Ref(new TestJSONObject(service_locator));
- }
-
- private:
- explicit TestJSONObject(ServiceLocator* service_locator)
- : JSONObject(service_locator) {
- RegisterJSONValue(kFloatValueName, &float_value_);
- RegisterJSONValue(kFloat2ValueName, &float2_value_);
- RegisterJSONValue(kFloat3ValueName, &float3_value_);
- RegisterJSONValue(kFloat4ValueName, &float4_value_);
- RegisterJSONValue(kMatrix4ValueName, &matrix4_value_);
- RegisterJSONValue(kIntegerValueName, &integer_value_);
- RegisterJSONValue(kBooleanValueName, &boolean_value_);
- RegisterJSONValue(kStringValueName, &string_value_);
- RegisterJSONValue(kTransformValueName, &transform_value_);
- RegisterJSONValue(kMaterialValueName, &material_value_);
- RegisterJSONValue(kOptionalFloatValueName, &optional_float_value_);
- RegisterJSONValue(kOptionalFloat2ValueName, &optional_float2_value_);
- RegisterJSONValue(kOptionalFloat3ValueName, &optional_float3_value_);
- RegisterJSONValue(kOptionalFloat4ValueName, &optional_float4_value_);
- RegisterJSONValue(kOptionalMatrix4ValueName, &optional_matrix4_value_);
- RegisterJSONValue(kOptionalIntegerValueName, &optional_integer_value_);
- RegisterJSONValue(kOptionalBooleanValueName, &optional_boolean_value_);
- RegisterJSONValue(kOptionalStringValueName, &optional_string_value_);
- }
-
- // One of each type of JSONValue
- JSONFloat::Ref float_value_;
- JSONFloat2::Ref float2_value_;
- JSONFloat3::Ref float3_value_;
- JSONFloat4::Ref float4_value_;
- JSONMatrix4::Ref matrix4_value_;
- JSONInteger::Ref integer_value_;
- JSONBoolean::Ref boolean_value_;
- JSONString::Ref string_value_;
- JSONTransform::Ref transform_value_;
- JSONMaterial::Ref material_value_;
- JSONOptionalFloat::Ref optional_float_value_;
- JSONOptionalFloat2::Ref optional_float2_value_;
- JSONOptionalFloat3::Ref optional_float3_value_;
- JSONOptionalFloat4::Ref optional_float4_value_;
- JSONOptionalMatrix4::Ref optional_matrix4_value_;
- JSONOptionalInteger::Ref optional_integer_value_;
- JSONOptionalBoolean::Ref optional_boolean_value_;
- JSONOptionalString::Ref optional_string_value_;
-
- O3D_OBJECT_BASE_DECL_CLASS(TestJSONObject, JSONObject);
- DISALLOW_COPY_AND_ASSIGN(TestJSONObject);
-};
-
-O3D_OBJECT_BASE_DEFN_CLASS("TestJSONObject", TestJSONObject, JSONObject);
-
-const char* TestJSONObject::kFloatValueName = "floatValue";
-const char* TestJSONObject::kFloat2ValueName = "float2Value";
-const char* TestJSONObject::kFloat3ValueName = "float3Value";
-const char* TestJSONObject::kFloat4ValueName = "float4Value";
-const char* TestJSONObject::kMatrix4ValueName = "matrix4Value";
-const char* TestJSONObject::kIntegerValueName = "integerValue";
-const char* TestJSONObject::kBooleanValueName = "booleanValue";
-const char* TestJSONObject::kStringValueName = "stringValue";
-const char* TestJSONObject::kTransformValueName = "transformValue";
-const char* TestJSONObject::kMaterialValueName = "materialValue";
-const char* TestJSONObject::kOptionalFloatValueName = "optionalFloatValue";
-const char* TestJSONObject::kOptionalFloat2ValueName = "optionalFloat2Value";
-const char* TestJSONObject::kOptionalFloat3ValueName = "optionalFloat3Value";
-const char* TestJSONObject::kOptionalFloat4ValueName = "optionalFloat4Value";
-const char* TestJSONObject::kOptionalMatrix4ValueName = "optionalMatrix4Value";
-const char* TestJSONObject::kOptionalIntegerValueName = "optionalIntegerValue";
-const char* TestJSONObject::kOptionalStringValueName = "optionalStringValue";
-const char* TestJSONObject::kOptionalBooleanValueName = "optionalBooleanValue";
-
-} // anonymous namespace
-
-class JSONObjectTest : public testing::Test {
- protected:
- JSONObjectTest()
- : class_manager_(g_service_locator),
- object_manager_(g_service_locator),
- class_register_(g_service_locator) {
- }
-
- virtual void SetUp();
- virtual void TearDown();
-
- Pack* pack() { return pack_; }
-
- private:
- ServiceDependency<ClassManager> class_manager_;
- ServiceDependency<ObjectManager> object_manager_;
- ClassManager::Register<TestJSONObject> class_register_;
- Pack* pack_;
-};
-
-void JSONObjectTest::SetUp() {
- pack_ = object_manager_->CreatePack();
-}
-
-void JSONObjectTest::TearDown() {
- object_manager_->DestroyPack(pack_);
-}
-
-// Creates a JSONObject, tests basic properties.
-TEST_F(JSONObjectTest, BasicTest) {
- TestJSONObject* object = pack()->Create<TestJSONObject>();
- ASSERT_TRUE(object != NULL);
- EXPECT_TRUE(object->IsA(TestJSONObject::GetApparentClass()));
- EXPECT_TRUE(object->IsA(JSONObject::GetApparentClass()));
- EXPECT_TRUE(object->IsA(ParamObject::GetApparentClass()));
-
- // Test everything has its default value.
- EXPECT_EQ(object->float_value(), 0.0f);
- EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f));
- EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f));
- EXPECT_EQ(object->float3_value(), Float3(0.0f, 0.0f, 0.0f));
- EXPECT_EQ(object->float4_value(), Float4(0.0f, 0.0f, 0.0f, 0.0f));
- EXPECT_EQ(object->matrix4_value(), Matrix4::identity());
- EXPECT_EQ(object->integer_value(), 0);
- EXPECT_FALSE(object->boolean_value());
- EXPECT_EQ(object->string_value(), "");
- EXPECT_TRUE(object->transform_value() == NULL);
- EXPECT_TRUE(object->material_value() == NULL);
-
- // Test that all the values got created by serializing it.
- {
- StringWriter output(StringWriter::LF);
- JsonWriter json_writer(&output, 2);
- object->Serialize(&json_writer);
- json_writer.Close();
- // There is an assumption here that objects will be serialized in this
- // order.
- static const char *kExpected =
- "\"object\": {\n"
- " \"booleanValue\": false,\n"
- " \"float2Value\": [0,0],\n"
- " \"float3Value\": [0,0,0],\n"
- " \"float4Value\": [0,0,0,0],\n"
- " \"floatValue\": 0,\n"
- " \"integerValue\": 0,\n"
- " \"materialValue\": null,\n"
- " \"matrix4Value\": [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],\n"
- " \"stringValue\": \"\",\n"
- " \"transformValue\": null\n"
- "}\n";
- EXPECT_EQ(kExpected, output.ToString());
- }
-}
-
-TEST_F(JSONObjectTest, SetTest) {
- TestJSONObject* object = pack()->Create<TestJSONObject>();
- ASSERT_TRUE(object != NULL);
- // Test setting the values.
- Matrix4 test_matrix(Vector4(1.0f, 2.0f, 3.0f, 4.0f),
- Vector4(2.0f, 2.0f, 8.0f, 9.0f),
- Vector4(3.0f, 5.0f, 3.0f, 10.0f),
- Vector4(4.0f, 6.0f, 7.0f, 4.0f));
- Matrix4 test_matrix2(Vector4(11.0f, 12.0f, 13.0f, 14.0f),
- Vector4(12.0f, 12.0f, 18.0f, 19.0f),
- Vector4(13.0f, 15.0f, 13.0f, 110.0f),
- Vector4(14.0f, 16.0f, 17.0f, 14.0f));
-
- object->set_float_value(1.2f);
- object->set_float2_value(Float2(3.4f, 5.6f));
- object->set_float3_value(Float3(7.8f, 9.0f, 10.0f));
- object->set_float4_value(Float4(11.0f, 12.0f, 13.0f, 14.0f));
- object->set_matrix4_value(test_matrix);
- object->set_integer_value(123);
- object->set_boolean_value(true);
- object->set_string_value("test");
- object->set_optional_float_value(15.0f);
- object->set_optional_float2_value(Float2(14.0f, 15.0f));
- object->set_optional_float3_value(Float3(13.0f, 14.0f, 15.0f));
- object->set_optional_float4_value(Float4(12.0f, 13.0f, 14.0f, 15.0f));
- object->set_optional_matrix4_value(test_matrix2);
- object->set_optional_integer_value(456);
- object->set_optional_string_value("hello");
- object->set_optional_boolean_value(false);
-
- Transform* transform = pack()->Create<Transform>();
- Material* material = pack()->Create<Material>();
- ASSERT_TRUE(transform != NULL);
- ASSERT_TRUE(material != NULL);
-
- object->set_transform_value(transform);
- object->set_material_value(material);
-
- // Check the new values
- EXPECT_EQ(object->float_value(), 1.2f);
- EXPECT_EQ(object->float2_value(), Float2(3.4f, 5.6f));
- EXPECT_EQ(object->float3_value(), Float3(7.8f, 9.0f, 10.0f));
- EXPECT_EQ(object->float4_value(), Float4(11.0f, 12.0f, 13.0f, 14.0f));
- EXPECT_EQ(object->matrix4_value(), test_matrix);
- EXPECT_EQ(object->integer_value(), 123);
- EXPECT_TRUE(object->boolean_value());
- EXPECT_EQ(object->string_value(), "test");
- EXPECT_TRUE(object->transform_value() == transform);
- EXPECT_TRUE(object->material_value() == material);
-
- // See that they got set by serializing them.
- {
- StringWriter output(StringWriter::LF);
- JsonWriter json_writer(&output, 2);
- object->Serialize(&json_writer);
- json_writer.Close();
-
- char buffer[1000];
- static const char* kExpected =
- "\"object\": {\n"
- " \"booleanValue\": true,\n"
- " \"float2Value\": [3.4,5.6],\n"
- " \"float3Value\": [7.8,9,10],\n"
- " \"float4Value\": [11,12,13,14],\n"
- " \"floatValue\": 1.2,\n"
- " \"integerValue\": 123,\n"
- " \"materialValue\": {\"ref\":%d},\n"
- " \"matrix4Value\": [[1,2,3,4],[2,2,8,9],[3,5,3,10],[4,6,7,4]],\n"
- " \"optionalBooleanValue\": false,\n"
- " \"optionalFloat2Value\": [14,15],\n"
- " \"optionalFloat3Value\": [13,14,15],\n"
- " \"optionalFloat4Value\": [12,13,14,15],\n"
- " \"optionalFloatValue\": 15,\n"
- " \"optionalIntegerValue\": 456,\n"
- " \"optionalMatrix4Value\": "
- "[[11,12,13,14],[12,12,18,19],[13,15,13,110],[14,16,17,14]],\n"
- " \"optionalStringValue\": \"hello\",\n"
- " \"stringValue\": \"test\",\n"
- " \"transformValue\": {\"ref\":%d}\n"
- "}\n";
- sprintf(buffer, kExpected, material->id(), transform->id()); // NOLINT
- EXPECT_EQ(static_cast<const char*>(buffer), output.ToString());
- }
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "import/cross/json_object.h" +#include "core/cross/class_manager.h" +#include "core/cross/object_manager.h" +#include "core/cross/pack.h" +#include "core/cross/service_dependency.h" +#include "utils/cross/string_writer.h" +#include "utils/cross/json_writer.h" +#include "utils/cross/math_gtest.h" + +namespace o3d { + +namespace { + +// A class to test JSONObject +class TestJSONObject : public JSONObject { + public: + typedef SmartPointer<TestJSONObject> Ref; + + static const char* kFloatValueName; + static const char* kFloat2ValueName; + static const char* kFloat3ValueName; + static const char* kFloat4ValueName; + static const char* kMatrix4ValueName; + static const char* kIntegerValueName; + static const char* kBooleanValueName; + static const char* kStringValueName; + static const char* kTransformValueName; + static const char* kMaterialValueName; + static const char* kOptionalFloatValueName; + static const char* kOptionalFloat2ValueName; + static const char* kOptionalFloat3ValueName; + static const char* kOptionalFloat4ValueName; + static const char* kOptionalMatrix4ValueName; + static const char* kOptionalIntegerValueName; + static const char* kOptionalBooleanValueName; + static const char* kOptionalStringValueName; + + float float_value() const { + return float_value_->value(); + } + + void set_float_value(float value) { + float_value_->set_value(value); + } + + Float2 float2_value() const { + return float2_value_->value(); + } + + void set_float2_value(const Float2& value) { + float2_value_->set_value(value); + } + + Float3 float3_value() const { + return float3_value_->value(); + } + + void set_float3_value(const Float3& value) { + float3_value_->set_value(value); + } + + Float4 float4_value() const { + return float4_value_->value(); + } + + void set_float4_value(const Float4& value) { + float4_value_->set_value(value); + } + + Matrix4 matrix4_value() const { + return matrix4_value_->value(); + } + + void set_matrix4_value(const Matrix4& value) { + matrix4_value_->set_value(value); + } + + int integer_value() const { + return integer_value_->value(); + } + + void set_integer_value(int value) { + integer_value_->set_value(value); + } + + bool boolean_value() const { + return boolean_value_->value(); + } + + void set_boolean_value(bool value) { + boolean_value_->set_value(value); + } + + String string_value() const { + return string_value_->value(); + } + + void set_string_value(const String& value) { + string_value_->set_value(value); + } + + Transform* transform_value() const { + return transform_value_->value(); + } + + void set_transform_value(Transform* value) { + transform_value_->set_value(value); + } + + Material* material_value() const { + return material_value_->value(); + } + + void set_material_value(Material* value) { + material_value_->set_value(value); + } + + float optional_float_value() const { + return optional_float_value_->value(); + } + + void set_optional_float_value(float value) { + optional_float_value_->set_value(value); + } + + Float2 optional_float2_value() const { + return optional_float2_value_->value(); + } + + void set_optional_float2_value(const Float2& value) { + optional_float2_value_->set_value(value); + } + + Float3 optional_float3_value() const { + return optional_float3_value_->value(); + } + + void set_optional_float3_value(const Float3& value) { + optional_float3_value_->set_value(value); + } + + Float4 optional_float4_value() const { + return optional_float4_value_->value(); + } + + void set_optional_float4_value(const Float4& value) { + optional_float4_value_->set_value(value); + } + + Matrix4 optional_matrix4_value() const { + return optional_matrix4_value_->value(); + } + + void set_optional_matrix4_value(const Matrix4& value) { + optional_matrix4_value_->set_value(value); + } + + int optional_integer_value() const { + return optional_integer_value_->value(); + } + + void set_optional_integer_value(int value) { + optional_integer_value_->set_value(value); + } + + bool optional_boolean_value() const { + return optional_boolean_value_->value(); + } + + void set_optional_boolean_value(bool value) { + optional_boolean_value_->set_value(value); + } + + String optional_string_value() const { + return optional_string_value_->value(); + } + + void set_optional_string_value(const String& value) { + optional_string_value_->set_value(value); + } + + static ObjectBase::Ref Create(ServiceLocator* service_locator) { + return ObjectBase::Ref(new TestJSONObject(service_locator)); + } + + private: + explicit TestJSONObject(ServiceLocator* service_locator) + : JSONObject(service_locator) { + RegisterJSONValue(kFloatValueName, &float_value_); + RegisterJSONValue(kFloat2ValueName, &float2_value_); + RegisterJSONValue(kFloat3ValueName, &float3_value_); + RegisterJSONValue(kFloat4ValueName, &float4_value_); + RegisterJSONValue(kMatrix4ValueName, &matrix4_value_); + RegisterJSONValue(kIntegerValueName, &integer_value_); + RegisterJSONValue(kBooleanValueName, &boolean_value_); + RegisterJSONValue(kStringValueName, &string_value_); + RegisterJSONValue(kTransformValueName, &transform_value_); + RegisterJSONValue(kMaterialValueName, &material_value_); + RegisterJSONValue(kOptionalFloatValueName, &optional_float_value_); + RegisterJSONValue(kOptionalFloat2ValueName, &optional_float2_value_); + RegisterJSONValue(kOptionalFloat3ValueName, &optional_float3_value_); + RegisterJSONValue(kOptionalFloat4ValueName, &optional_float4_value_); + RegisterJSONValue(kOptionalMatrix4ValueName, &optional_matrix4_value_); + RegisterJSONValue(kOptionalIntegerValueName, &optional_integer_value_); + RegisterJSONValue(kOptionalBooleanValueName, &optional_boolean_value_); + RegisterJSONValue(kOptionalStringValueName, &optional_string_value_); + } + + // One of each type of JSONValue + JSONFloat::Ref float_value_; + JSONFloat2::Ref float2_value_; + JSONFloat3::Ref float3_value_; + JSONFloat4::Ref float4_value_; + JSONMatrix4::Ref matrix4_value_; + JSONInteger::Ref integer_value_; + JSONBoolean::Ref boolean_value_; + JSONString::Ref string_value_; + JSONTransform::Ref transform_value_; + JSONMaterial::Ref material_value_; + JSONOptionalFloat::Ref optional_float_value_; + JSONOptionalFloat2::Ref optional_float2_value_; + JSONOptionalFloat3::Ref optional_float3_value_; + JSONOptionalFloat4::Ref optional_float4_value_; + JSONOptionalMatrix4::Ref optional_matrix4_value_; + JSONOptionalInteger::Ref optional_integer_value_; + JSONOptionalBoolean::Ref optional_boolean_value_; + JSONOptionalString::Ref optional_string_value_; + + O3D_OBJECT_BASE_DECL_CLASS(TestJSONObject, JSONObject); + DISALLOW_COPY_AND_ASSIGN(TestJSONObject); +}; + +O3D_OBJECT_BASE_DEFN_CLASS("TestJSONObject", TestJSONObject, JSONObject); + +const char* TestJSONObject::kFloatValueName = "floatValue"; +const char* TestJSONObject::kFloat2ValueName = "float2Value"; +const char* TestJSONObject::kFloat3ValueName = "float3Value"; +const char* TestJSONObject::kFloat4ValueName = "float4Value"; +const char* TestJSONObject::kMatrix4ValueName = "matrix4Value"; +const char* TestJSONObject::kIntegerValueName = "integerValue"; +const char* TestJSONObject::kBooleanValueName = "booleanValue"; +const char* TestJSONObject::kStringValueName = "stringValue"; +const char* TestJSONObject::kTransformValueName = "transformValue"; +const char* TestJSONObject::kMaterialValueName = "materialValue"; +const char* TestJSONObject::kOptionalFloatValueName = "optionalFloatValue"; +const char* TestJSONObject::kOptionalFloat2ValueName = "optionalFloat2Value"; +const char* TestJSONObject::kOptionalFloat3ValueName = "optionalFloat3Value"; +const char* TestJSONObject::kOptionalFloat4ValueName = "optionalFloat4Value"; +const char* TestJSONObject::kOptionalMatrix4ValueName = "optionalMatrix4Value"; +const char* TestJSONObject::kOptionalIntegerValueName = "optionalIntegerValue"; +const char* TestJSONObject::kOptionalStringValueName = "optionalStringValue"; +const char* TestJSONObject::kOptionalBooleanValueName = "optionalBooleanValue"; + +} // anonymous namespace + +class JSONObjectTest : public testing::Test { + protected: + JSONObjectTest() + : class_manager_(g_service_locator), + object_manager_(g_service_locator), + class_register_(g_service_locator) { + } + + virtual void SetUp(); + virtual void TearDown(); + + Pack* pack() { return pack_; } + + private: + ServiceDependency<ClassManager> class_manager_; + ServiceDependency<ObjectManager> object_manager_; + ClassManager::Register<TestJSONObject> class_register_; + Pack* pack_; +}; + +void JSONObjectTest::SetUp() { + pack_ = object_manager_->CreatePack(); +} + +void JSONObjectTest::TearDown() { + object_manager_->DestroyPack(pack_); +} + +// Creates a JSONObject, tests basic properties. +TEST_F(JSONObjectTest, BasicTest) { + TestJSONObject* object = pack()->Create<TestJSONObject>(); + ASSERT_TRUE(object != NULL); + EXPECT_TRUE(object->IsA(TestJSONObject::GetApparentClass())); + EXPECT_TRUE(object->IsA(JSONObject::GetApparentClass())); + EXPECT_TRUE(object->IsA(ParamObject::GetApparentClass())); + + // Test everything has its default value. + EXPECT_EQ(object->float_value(), 0.0f); + EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f)); + EXPECT_EQ(object->float2_value(), Float2(0.0f, 0.0f)); + EXPECT_EQ(object->float3_value(), Float3(0.0f, 0.0f, 0.0f)); + EXPECT_EQ(object->float4_value(), Float4(0.0f, 0.0f, 0.0f, 0.0f)); + EXPECT_EQ(object->matrix4_value(), Matrix4::identity()); + EXPECT_EQ(object->integer_value(), 0); + EXPECT_FALSE(object->boolean_value()); + EXPECT_EQ(object->string_value(), ""); + EXPECT_TRUE(object->transform_value() == NULL); + EXPECT_TRUE(object->material_value() == NULL); + + // Test that all the values got created by serializing it. + { + StringWriter output(StringWriter::LF); + JsonWriter json_writer(&output, 2); + object->Serialize(&json_writer); + json_writer.Close(); + // There is an assumption here that objects will be serialized in this + // order. + static const char *kExpected = + "\"object\": {\n" + " \"booleanValue\": false,\n" + " \"float2Value\": [0,0],\n" + " \"float3Value\": [0,0,0],\n" + " \"float4Value\": [0,0,0,0],\n" + " \"floatValue\": 0,\n" + " \"integerValue\": 0,\n" + " \"materialValue\": null,\n" + " \"matrix4Value\": [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]],\n" + " \"stringValue\": \"\",\n" + " \"transformValue\": null\n" + "}\n"; + EXPECT_EQ(kExpected, output.ToString()); + } +} + +TEST_F(JSONObjectTest, SetTest) { + TestJSONObject* object = pack()->Create<TestJSONObject>(); + ASSERT_TRUE(object != NULL); + // Test setting the values. + Matrix4 test_matrix(Vector4(1.0f, 2.0f, 3.0f, 4.0f), + Vector4(2.0f, 2.0f, 8.0f, 9.0f), + Vector4(3.0f, 5.0f, 3.0f, 10.0f), + Vector4(4.0f, 6.0f, 7.0f, 4.0f)); + Matrix4 test_matrix2(Vector4(11.0f, 12.0f, 13.0f, 14.0f), + Vector4(12.0f, 12.0f, 18.0f, 19.0f), + Vector4(13.0f, 15.0f, 13.0f, 110.0f), + Vector4(14.0f, 16.0f, 17.0f, 14.0f)); + + object->set_float_value(1.2f); + object->set_float2_value(Float2(3.4f, 5.6f)); + object->set_float3_value(Float3(7.8f, 9.0f, 10.0f)); + object->set_float4_value(Float4(11.0f, 12.0f, 13.0f, 14.0f)); + object->set_matrix4_value(test_matrix); + object->set_integer_value(123); + object->set_boolean_value(true); + object->set_string_value("test"); + object->set_optional_float_value(15.0f); + object->set_optional_float2_value(Float2(14.0f, 15.0f)); + object->set_optional_float3_value(Float3(13.0f, 14.0f, 15.0f)); + object->set_optional_float4_value(Float4(12.0f, 13.0f, 14.0f, 15.0f)); + object->set_optional_matrix4_value(test_matrix2); + object->set_optional_integer_value(456); + object->set_optional_string_value("hello"); + object->set_optional_boolean_value(false); + + Transform* transform = pack()->Create<Transform>(); + Material* material = pack()->Create<Material>(); + ASSERT_TRUE(transform != NULL); + ASSERT_TRUE(material != NULL); + + object->set_transform_value(transform); + object->set_material_value(material); + + // Check the new values + EXPECT_EQ(object->float_value(), 1.2f); + EXPECT_EQ(object->float2_value(), Float2(3.4f, 5.6f)); + EXPECT_EQ(object->float3_value(), Float3(7.8f, 9.0f, 10.0f)); + EXPECT_EQ(object->float4_value(), Float4(11.0f, 12.0f, 13.0f, 14.0f)); + EXPECT_EQ(object->matrix4_value(), test_matrix); + EXPECT_EQ(object->integer_value(), 123); + EXPECT_TRUE(object->boolean_value()); + EXPECT_EQ(object->string_value(), "test"); + EXPECT_TRUE(object->transform_value() == transform); + EXPECT_TRUE(object->material_value() == material); + + // See that they got set by serializing them. + { + StringWriter output(StringWriter::LF); + JsonWriter json_writer(&output, 2); + object->Serialize(&json_writer); + json_writer.Close(); + + char buffer[1000]; + static const char* kExpected = + "\"object\": {\n" + " \"booleanValue\": true,\n" + " \"float2Value\": [3.4,5.6],\n" + " \"float3Value\": [7.8,9,10],\n" + " \"float4Value\": [11,12,13,14],\n" + " \"floatValue\": 1.2,\n" + " \"integerValue\": 123,\n" + " \"materialValue\": {\"ref\":%d},\n" + " \"matrix4Value\": [[1,2,3,4],[2,2,8,9],[3,5,3,10],[4,6,7,4]],\n" + " \"optionalBooleanValue\": false,\n" + " \"optionalFloat2Value\": [14,15],\n" + " \"optionalFloat3Value\": [13,14,15],\n" + " \"optionalFloat4Value\": [12,13,14,15],\n" + " \"optionalFloatValue\": 15,\n" + " \"optionalIntegerValue\": 456,\n" + " \"optionalMatrix4Value\": " + "[[11,12,13,14],[12,12,18,19],[13,15,13,110],[14,16,17,14]],\n" + " \"optionalStringValue\": \"hello\",\n" + " \"stringValue\": \"test\",\n" + " \"transformValue\": {\"ref\":%d}\n" + "}\n"; + sprintf(buffer, kExpected, material->id(), transform->id()); // NOLINT + EXPECT_EQ(static_cast<const char*>(buffer), output.ToString()); + } +} + +} // namespace o3d + diff --git a/o3d/plugin/cross/texture_static_glue.cc b/o3d/plugin/cross/texture_static_glue.cc index b5cf995..a3da6ef 100644 --- a/o3d/plugin/cross/texture_static_glue.cc +++ b/o3d/plugin/cross/texture_static_glue.cc @@ -1,606 +1,606 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <vector>
-#include "core/cross/pointer_utils.h"
-#include "core/cross/error.h"
-#include "core/cross/math_utilities.h"
-#include "core/cross/texture.h"
-#include "core/cross/image_utils.h"
-
-namespace {
-
-void SetRectCheck(o3d::Texture* self,
- void* data,
- int pitch,
- int destination_x,
- int destination_y,
- int texture_width,
- int texture_height,
- int source_width,
- int source_height,
- const std::vector<float>& values) {
- unsigned num_components;
- unsigned swizzle[4] = {2, 1, 0, 3};
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- swizzle[0] = 0;
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- const o3d::Texture::RGBASwizzleIndices& indices =
- self->GetABGR32FSwizzleIndices();
- for (int ii = 0; ii < 4; ++ii) {
- swizzle[ii] = indices[ii];
- }
- break;
- }
- default:
- DCHECK(false);
- return;
- }
-
- // clip
- int source_x = 0;
- int source_y = 0;
- int copy_width = source_width;
- int copy_height = source_height;
-
- if (destination_x < 0) {
- copy_width += destination_x;
- source_x -= destination_x;
- destination_x = 0;
- }
- if (destination_x + copy_width > static_cast<int>(texture_width)) {
- copy_width -= destination_x + copy_width - texture_width;
- }
-
- if (destination_y < 0) {
- copy_height += destination_y;
- source_y -= destination_y;
- destination_y = 0;
- }
- if (destination_y + copy_height > static_cast<int>(texture_height)) {
- copy_height -= destination_y + copy_height - texture_height;
- }
-
- if (copy_width <= 0 || copy_height <= 0) {
- return;
- }
-
- const float* source =
- &values[0] +
- (source_y * source_width + source_x) * num_components;
- unsigned source_stride = (source_width - copy_width) * num_components;
- switch (self->format()) {
- case o3d::Texture::ABGR16F: {
- uint16* dest_line =
- static_cast<uint16*>(data) +
- (destination_y * texture_width + destination_x) * num_components;
- for (; copy_height > 0; --copy_height) {
- uint16* destination = dest_line;
- for (int xx = 0; xx < copy_width; ++xx) {
- for (unsigned element = 0; element < num_components; ++element) {
- destination[element] = Vectormath::Aos::FloatToHalf(
- source[swizzle[element]]);
- }
- destination += num_components;
- source += num_components;
- }
- dest_line = o3d::AddPointerOffset<uint16*>(dest_line, pitch);
- source += source_stride;
- }
- break;
- }
- case o3d::Texture::R32F:
- case o3d::Texture::ABGR32F: {
- float* dest_line =
- static_cast<float*>(data) +
- (destination_y * texture_width + destination_x) * num_components;
- for (; copy_height > 0; --copy_height) {
- float* destination = dest_line;
- for (int xx = 0; xx < copy_width; ++xx) {
- for (unsigned element = 0; element < num_components; ++element) {
- destination[element] = source[swizzle[element]];
- }
- destination += num_components;
- source += num_components;
- }
- dest_line = o3d::AddPointerOffset<float*>(dest_line, pitch);
- source += source_stride;
- }
- break;
- }
- default: {
- uint8* dest_line =
- static_cast<uint8*>(data) +
- (destination_y * texture_width + destination_x) * 4;
- for (; copy_height > 0; --copy_height) {
- uint8* destination = dest_line;
- for (int xx = 0; xx < copy_width; ++xx) {
- destination[0] = static_cast<unsigned char>(
- source[swizzle[0]] * 255.0f);
- destination[1] = static_cast<unsigned char>(
- source[swizzle[1]] * 255.0f);
- destination[2] = static_cast<unsigned char>(
- source[swizzle[2]] * 255.0f);
- destination[3] = (num_components == 4) ?
- static_cast<unsigned char>(source[swizzle[3]] * 255.0f) : 255;
- destination += 4;
- source += num_components;
- }
- dest_line = o3d::AddPointerOffset<uint8*>(dest_line, pitch);
- source += source_stride;
- }
- break;
- }
- }
-}
-
-void SetRectCheck2D(o3d::Texture2D* self,
- int level,
- int destination_x,
- int destination_y,
- int source_width,
- const std::vector<float>& values,
- bool check_needed) {
- if (level < 0 || level >= self->levels()) {
- O3D_ERROR(self->service_locator())
- << "level (" << level << " out of range";
- return;
- }
- if (values.empty() || source_width <= 0) {
- return;
- }
- unsigned num_values = values.size();
- unsigned texture_width = std::max(self->width() >> level, 1);
- unsigned texture_height = std::max(self->height() >> level, 1);
- unsigned num_components;
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- break;
- }
- default:
- O3D_ERROR(self->service_locator())
- << "Texture::Set not supported for this type of texture";
- return;
- }
- if (num_values % num_components != 0) {
- O3D_ERROR(self->service_locator())
- << "The number of elements passed in must be a multiple of "
- << num_components;
- }
- unsigned num_elements = num_values / num_components;
- if (num_elements % source_width != 0) {
- O3D_ERROR(self->service_locator())
- << "The number of elements passed in must be a multiple of the "
- << "width";
- return;
- }
- unsigned source_height = num_elements / source_width;
- if (check_needed) {
- unsigned needed = num_components * texture_width * texture_height;
- if (num_values != needed) {
- O3D_ERROR(self->service_locator())
- << "needed " << needed << " values but " << num_values
- << " passed in.";
- return;
- }
- }
- o3d::Texture2D::LockHelper helper(self, level, o3d::Texture::kWriteOnly);
- void* data = helper.GetData();
- if (!data) {
- O3D_ERROR(self->service_locator()) << "could not lock texture";
- return;
- }
-
- SetRectCheck(self, data, helper.pitch(),
- destination_x, destination_y,
- texture_width, texture_height,
- source_width, source_height,
- values);
-}
-
-void SetRectCheckCUBE(o3d::TextureCUBE* self,
- o3d::TextureCUBE::CubeFace face,
- int level,
- int destination_x,
- int destination_y,
- int source_width,
- const std::vector<float>& values,
- bool check_needed) {
- if (level < 0 || level >= self->levels()) {
- O3D_ERROR(self->service_locator())
- << "level (" << level << " out of range";
- return;
- }
- if (values.empty() || source_width <= 0) {
- return;
- }
- unsigned num_values = values.size();
- unsigned texture_width = std::max(self->edge_length() >> level, 1);
- unsigned texture_height = texture_width;
- unsigned num_components;
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- break;
- }
- default:
- O3D_ERROR(self->service_locator())
- << "Texture::Set not supported for this type of texture";
- return;
- }
- if (num_values % num_components != 0) {
- O3D_ERROR(self->service_locator())
- << "The number of elements passed in must be a multiple of "
- << num_components;
- }
- unsigned num_elements = num_values / num_components;
- if (num_elements % source_width != 0) {
- O3D_ERROR(self->service_locator())
- << "The number of elements passed in must be a multiple of the "
- << "width";
- return;
- }
- unsigned source_height = num_elements / source_width;
- if (check_needed) {
- unsigned needed = num_components * texture_width * texture_height;
- if (num_values != needed) {
- O3D_ERROR(self->service_locator())
- << "needed " << needed << " values but " << num_values
- << " passed in.";
- return;
- }
- }
- o3d::TextureCUBE::LockHelper helper(
- self, face, level, o3d::Texture::kWriteOnly);
- void* data = helper.GetData();
- if (!data) {
- O3D_ERROR(self->service_locator()) << "could not lock texture";
- return;
- }
-
- SetRectCheck(self, data, helper.pitch(),
- destination_x, destination_y,
- texture_width, texture_height,
- source_width, source_height,
- values);
-}
-
-// Assumes dst points to width * height * num_components floats.
-void GetRect(o3d::Texture* self,
- const void* src_data,
- int src_pitch,
- int x,
- int y,
- int width,
- int height,
- float* dst) {
- unsigned num_components;
- unsigned swizzle[4] = {2, 1, 0, 3};
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- swizzle[0] = 0;
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- const o3d::Texture::RGBASwizzleIndices& indices =
- self->GetABGR32FSwizzleIndices();
- for (int ii = 0; ii < 4; ++ii) {
- swizzle[ii] = indices[ii];
- }
- break;
- }
- default:
- DCHECK(false);
- return;
- }
-
- switch (self->format()) {
- case o3d::Texture::ABGR16F: {
- uint16* src_line = o3d::PointerFromVoidPointer<uint16*>(
- src_data,
- (y * src_pitch)) + x * num_components;
- for (; height > 0; --height) {
- uint16* src = src_line;
- for (int xx = 0; xx < width; ++xx) {
- for (unsigned element = 0; element < num_components; ++element) {
- dst[swizzle[element]] = Vectormath::Aos::HalfToFloat(src[element]);
- }
- dst += num_components;
- src += num_components;
- }
- src_line = o3d::AddPointerOffset<uint16*>(src_line, src_pitch);
- }
- break;
- }
- case o3d::Texture::R32F:
- case o3d::Texture::ABGR32F: {
- float* src_line = o3d::PointerFromVoidPointer<float*>(
- src_data,
- (y * src_pitch)) + x * num_components;
- for (; height > 0; --height) {
- float* src = src_line;
- for (int xx = 0; xx < width; ++xx) {
- for (unsigned element = 0; element < num_components; ++element) {
- dst[swizzle[element]] = src[element];
- }
- dst += num_components;
- src += num_components;
- }
- src_line = o3d::AddPointerOffset<float*>(src_line, src_pitch);
- }
- break;
- }
- default: {
- uint8* src_line = o3d::PointerFromVoidPointer<uint8*>(
- src_data,
- (y * src_pitch)) + x * num_components;
- for (; height > 0; --height) {
- uint8* src = src_line;
- for (int xx = 0; xx < width; ++xx) {
- dst[swizzle[0]] = static_cast<float>(src[0]) / 255.0f;
- dst[swizzle[1]] = static_cast<float>(src[1]) / 255.0f;
- dst[swizzle[2]] = static_cast<float>(src[2]) / 255.0f;
- if (num_components == 4) {
- dst[swizzle[3]] = static_cast<float>(src[3]) / 255.0f;
- }
- dst += num_components;
- src += 4;
- }
- src_line = o3d::AddPointerOffset<uint8*>(src_line, src_pitch);
- }
- break;
- }
- }
-}
-
-} // anonymous namespace
-
-namespace glue {
-namespace namespace_o3d {
-namespace class_Texture2D {
-
-void userglue_method_SetRect(o3d::Texture2D* self,
- int level,
- int destination_x,
- int destination_y,
- int source_width,
- const std::vector<float>& values) {
- SetRectCheck2D(self,
- level,
- destination_x,
- destination_y,
- source_width,
- values,
- false);
-}
-void userglue_method_Set(o3d::Texture2D* self,
- int level,
- const std::vector<float>& values) {
- SetRectCheck2D(
- self, level, 0, 0,
- o3d::image::ComputeMipDimension(level, self->width()),
- values, true);
-}
-std::vector<float> userglue_method_GetRect(o3d::Texture2D* self,
- int level,
- int x,
- int y,
- int width,
- int height) {
- std::vector<float> empty;
- if (level < 0 || level >= self->levels()) {
- O3D_ERROR(self->service_locator())
- << "level (" << level << " out of range";
- return empty;
- }
- if (width <= 0 || height <= 0) {
- O3D_ERROR(self->service_locator())
- << "width and height must be positive";
- return empty;
- }
-
- int mip_width =
- static_cast<int>(o3d::image::ComputeMipDimension(level, self->width()));
- int mip_height =
- static_cast<int>(o3d::image::ComputeMipDimension(level, self->height()));
-
- if (x < 0 || x + width > mip_width || y < 0 || y + height > mip_height) {
- O3D_ERROR(self->service_locator()) << "area out of range";
- return empty;
- }
-
- unsigned num_components;
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- break;
- }
- default:
- O3D_ERROR(self->service_locator())
- << "Texture::Set not supported for this type of texture";
- return empty;
- }
- o3d::Texture2D::LockHelper helper(self, level, o3d::Texture::kReadOnly);
- void* data = helper.GetData();
- if (!data) {
- O3D_ERROR(self->service_locator()) << "could not lock texture";
- return empty;
- }
-
- std::vector<float> values(width * height * num_components, 0);
- GetRect(self, data, helper.pitch(), x, y, width, height, &values[0]);
- return values;
-}
-
-} // namespace class_Texture2D
-
-namespace class_TextureCUBE {
-
-void userglue_method_SetRect(o3d::TextureCUBE* self,
- o3d::TextureCUBE::CubeFace face,
- int level,
- int destination_x,
- int destination_y,
- int source_width,
- const std::vector<float>& values) {
- SetRectCheckCUBE(self,
- face,
- level,
- destination_x,
- destination_y,
- source_width,
- values,
- false);
-}
-void userglue_method_Set(o3d::TextureCUBE* self,
- o3d::TextureCUBE::CubeFace face,
- int level,
- const std::vector<float>& values) {
- SetRectCheckCUBE(self, face, level, 0, 0,
- o3d::image::ComputeMipDimension(level, self->edge_length()),
- values, true);
-}
-std::vector<float> userglue_method_GetRect(o3d::TextureCUBE* self,
- o3d::TextureCUBE::CubeFace face,
- int level,
- int x,
- int y,
- int width,
- int height) {
- std::vector<float> empty;
- if (level < 0 || level >= self->levels()) {
- O3D_ERROR(self->service_locator())
- << "level (" << level << " out of range";
- return empty;
- }
- if (width <= 0 || height <= 0) {
- O3D_ERROR(self->service_locator())
- << "width and height must be positive";
- return empty;
- }
-
- int mip_length = static_cast<int>(o3d::image::ComputeMipDimension(
- level, self->edge_length()));
-
- if (x < 0 || x + width > mip_length || y < 0 || y + height > mip_length) {
- O3D_ERROR(self->service_locator()) << "area out of range";
- return empty;
- }
-
- unsigned num_components;
- switch (self->format()) {
- case o3d::Texture::XRGB8:
- num_components = 3;
- break;
- case o3d::Texture::R32F:
- num_components = 1;
- break;
- case o3d::Texture::ARGB8:
- case o3d::Texture::ABGR16F:
- num_components = 4;
- break;
- case o3d::Texture::ABGR32F: {
- num_components = 4;
- break;
- }
- default:
- O3D_ERROR(self->service_locator())
- << "Texture::Set not supported for this type of texture";
- return empty;
- }
- o3d::TextureCUBE::LockHelper helper(
- self, face, level, o3d::Texture::kReadOnly);
- void* data = helper.GetData();
- if (!data) {
- O3D_ERROR(self->service_locator()) << "could not lock texture";
- return empty;
- }
-
- std::vector<float> values(width * height * num_components, 0);
- GetRect(self, data, helper.pitch(), x, y, width, height, &values[0]);
- return values;
-}
-
-} // namespace class_TextureCUBE
-
-} // namespace namespace_o3d
-} // namespace glue
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <vector> +#include "core/cross/pointer_utils.h" +#include "core/cross/error.h" +#include "core/cross/math_utilities.h" +#include "core/cross/texture.h" +#include "core/cross/image_utils.h" + +namespace { + +void SetRectCheck(o3d::Texture* self, + void* data, + int pitch, + int destination_x, + int destination_y, + int texture_width, + int texture_height, + int source_width, + int source_height, + const std::vector<float>& values) { + unsigned num_components; + unsigned swizzle[4] = {2, 1, 0, 3}; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + swizzle[0] = 0; + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + const o3d::Texture::RGBASwizzleIndices& indices = + self->GetABGR32FSwizzleIndices(); + for (int ii = 0; ii < 4; ++ii) { + swizzle[ii] = indices[ii]; + } + break; + } + default: + DCHECK(false); + return; + } + + // clip + int source_x = 0; + int source_y = 0; + int copy_width = source_width; + int copy_height = source_height; + + if (destination_x < 0) { + copy_width += destination_x; + source_x -= destination_x; + destination_x = 0; + } + if (destination_x + copy_width > static_cast<int>(texture_width)) { + copy_width -= destination_x + copy_width - texture_width; + } + + if (destination_y < 0) { + copy_height += destination_y; + source_y -= destination_y; + destination_y = 0; + } + if (destination_y + copy_height > static_cast<int>(texture_height)) { + copy_height -= destination_y + copy_height - texture_height; + } + + if (copy_width <= 0 || copy_height <= 0) { + return; + } + + const float* source = + &values[0] + + (source_y * source_width + source_x) * num_components; + unsigned source_stride = (source_width - copy_width) * num_components; + switch (self->format()) { + case o3d::Texture::ABGR16F: { + uint16* dest_line = + static_cast<uint16*>(data) + + (destination_y * texture_width + destination_x) * num_components; + for (; copy_height > 0; --copy_height) { + uint16* destination = dest_line; + for (int xx = 0; xx < copy_width; ++xx) { + for (unsigned element = 0; element < num_components; ++element) { + destination[element] = Vectormath::Aos::FloatToHalf( + source[swizzle[element]]); + } + destination += num_components; + source += num_components; + } + dest_line = o3d::AddPointerOffset<uint16*>(dest_line, pitch); + source += source_stride; + } + break; + } + case o3d::Texture::R32F: + case o3d::Texture::ABGR32F: { + float* dest_line = + static_cast<float*>(data) + + (destination_y * texture_width + destination_x) * num_components; + for (; copy_height > 0; --copy_height) { + float* destination = dest_line; + for (int xx = 0; xx < copy_width; ++xx) { + for (unsigned element = 0; element < num_components; ++element) { + destination[element] = source[swizzle[element]]; + } + destination += num_components; + source += num_components; + } + dest_line = o3d::AddPointerOffset<float*>(dest_line, pitch); + source += source_stride; + } + break; + } + default: { + uint8* dest_line = + static_cast<uint8*>(data) + + (destination_y * texture_width + destination_x) * 4; + for (; copy_height > 0; --copy_height) { + uint8* destination = dest_line; + for (int xx = 0; xx < copy_width; ++xx) { + destination[0] = static_cast<unsigned char>( + source[swizzle[0]] * 255.0f); + destination[1] = static_cast<unsigned char>( + source[swizzle[1]] * 255.0f); + destination[2] = static_cast<unsigned char>( + source[swizzle[2]] * 255.0f); + destination[3] = (num_components == 4) ? + static_cast<unsigned char>(source[swizzle[3]] * 255.0f) : 255; + destination += 4; + source += num_components; + } + dest_line = o3d::AddPointerOffset<uint8*>(dest_line, pitch); + source += source_stride; + } + break; + } + } +} + +void SetRectCheck2D(o3d::Texture2D* self, + int level, + int destination_x, + int destination_y, + int source_width, + const std::vector<float>& values, + bool check_needed) { + if (level < 0 || level >= self->levels()) { + O3D_ERROR(self->service_locator()) + << "level (" << level << " out of range"; + return; + } + if (values.empty() || source_width <= 0) { + return; + } + unsigned num_values = values.size(); + unsigned texture_width = std::max(self->width() >> level, 1); + unsigned texture_height = std::max(self->height() >> level, 1); + unsigned num_components; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + break; + } + default: + O3D_ERROR(self->service_locator()) + << "Texture::Set not supported for this type of texture"; + return; + } + if (num_values % num_components != 0) { + O3D_ERROR(self->service_locator()) + << "The number of elements passed in must be a multiple of " + << num_components; + } + unsigned num_elements = num_values / num_components; + if (num_elements % source_width != 0) { + O3D_ERROR(self->service_locator()) + << "The number of elements passed in must be a multiple of the " + << "width"; + return; + } + unsigned source_height = num_elements / source_width; + if (check_needed) { + unsigned needed = num_components * texture_width * texture_height; + if (num_values != needed) { + O3D_ERROR(self->service_locator()) + << "needed " << needed << " values but " << num_values + << " passed in."; + return; + } + } + o3d::Texture2D::LockHelper helper(self, level, o3d::Texture::kWriteOnly); + void* data = helper.GetData(); + if (!data) { + O3D_ERROR(self->service_locator()) << "could not lock texture"; + return; + } + + SetRectCheck(self, data, helper.pitch(), + destination_x, destination_y, + texture_width, texture_height, + source_width, source_height, + values); +} + +void SetRectCheckCUBE(o3d::TextureCUBE* self, + o3d::TextureCUBE::CubeFace face, + int level, + int destination_x, + int destination_y, + int source_width, + const std::vector<float>& values, + bool check_needed) { + if (level < 0 || level >= self->levels()) { + O3D_ERROR(self->service_locator()) + << "level (" << level << " out of range"; + return; + } + if (values.empty() || source_width <= 0) { + return; + } + unsigned num_values = values.size(); + unsigned texture_width = std::max(self->edge_length() >> level, 1); + unsigned texture_height = texture_width; + unsigned num_components; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + break; + } + default: + O3D_ERROR(self->service_locator()) + << "Texture::Set not supported for this type of texture"; + return; + } + if (num_values % num_components != 0) { + O3D_ERROR(self->service_locator()) + << "The number of elements passed in must be a multiple of " + << num_components; + } + unsigned num_elements = num_values / num_components; + if (num_elements % source_width != 0) { + O3D_ERROR(self->service_locator()) + << "The number of elements passed in must be a multiple of the " + << "width"; + return; + } + unsigned source_height = num_elements / source_width; + if (check_needed) { + unsigned needed = num_components * texture_width * texture_height; + if (num_values != needed) { + O3D_ERROR(self->service_locator()) + << "needed " << needed << " values but " << num_values + << " passed in."; + return; + } + } + o3d::TextureCUBE::LockHelper helper( + self, face, level, o3d::Texture::kWriteOnly); + void* data = helper.GetData(); + if (!data) { + O3D_ERROR(self->service_locator()) << "could not lock texture"; + return; + } + + SetRectCheck(self, data, helper.pitch(), + destination_x, destination_y, + texture_width, texture_height, + source_width, source_height, + values); +} + +// Assumes dst points to width * height * num_components floats. +void GetRect(o3d::Texture* self, + const void* src_data, + int src_pitch, + int x, + int y, + int width, + int height, + float* dst) { + unsigned num_components; + unsigned swizzle[4] = {2, 1, 0, 3}; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + swizzle[0] = 0; + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + const o3d::Texture::RGBASwizzleIndices& indices = + self->GetABGR32FSwizzleIndices(); + for (int ii = 0; ii < 4; ++ii) { + swizzle[ii] = indices[ii]; + } + break; + } + default: + DCHECK(false); + return; + } + + switch (self->format()) { + case o3d::Texture::ABGR16F: { + uint16* src_line = o3d::PointerFromVoidPointer<uint16*>( + src_data, + (y * src_pitch)) + x * num_components; + for (; height > 0; --height) { + uint16* src = src_line; + for (int xx = 0; xx < width; ++xx) { + for (unsigned element = 0; element < num_components; ++element) { + dst[swizzle[element]] = Vectormath::Aos::HalfToFloat(src[element]); + } + dst += num_components; + src += num_components; + } + src_line = o3d::AddPointerOffset<uint16*>(src_line, src_pitch); + } + break; + } + case o3d::Texture::R32F: + case o3d::Texture::ABGR32F: { + float* src_line = o3d::PointerFromVoidPointer<float*>( + src_data, + (y * src_pitch)) + x * num_components; + for (; height > 0; --height) { + float* src = src_line; + for (int xx = 0; xx < width; ++xx) { + for (unsigned element = 0; element < num_components; ++element) { + dst[swizzle[element]] = src[element]; + } + dst += num_components; + src += num_components; + } + src_line = o3d::AddPointerOffset<float*>(src_line, src_pitch); + } + break; + } + default: { + uint8* src_line = o3d::PointerFromVoidPointer<uint8*>( + src_data, + (y * src_pitch)) + x * num_components; + for (; height > 0; --height) { + uint8* src = src_line; + for (int xx = 0; xx < width; ++xx) { + dst[swizzle[0]] = static_cast<float>(src[0]) / 255.0f; + dst[swizzle[1]] = static_cast<float>(src[1]) / 255.0f; + dst[swizzle[2]] = static_cast<float>(src[2]) / 255.0f; + if (num_components == 4) { + dst[swizzle[3]] = static_cast<float>(src[3]) / 255.0f; + } + dst += num_components; + src += 4; + } + src_line = o3d::AddPointerOffset<uint8*>(src_line, src_pitch); + } + break; + } + } +} + +} // anonymous namespace + +namespace glue { +namespace namespace_o3d { +namespace class_Texture2D { + +void userglue_method_SetRect(o3d::Texture2D* self, + int level, + int destination_x, + int destination_y, + int source_width, + const std::vector<float>& values) { + SetRectCheck2D(self, + level, + destination_x, + destination_y, + source_width, + values, + false); +} +void userglue_method_Set(o3d::Texture2D* self, + int level, + const std::vector<float>& values) { + SetRectCheck2D( + self, level, 0, 0, + o3d::image::ComputeMipDimension(level, self->width()), + values, true); +} +std::vector<float> userglue_method_GetRect(o3d::Texture2D* self, + int level, + int x, + int y, + int width, + int height) { + std::vector<float> empty; + if (level < 0 || level >= self->levels()) { + O3D_ERROR(self->service_locator()) + << "level (" << level << " out of range"; + return empty; + } + if (width <= 0 || height <= 0) { + O3D_ERROR(self->service_locator()) + << "width and height must be positive"; + return empty; + } + + int mip_width = + static_cast<int>(o3d::image::ComputeMipDimension(level, self->width())); + int mip_height = + static_cast<int>(o3d::image::ComputeMipDimension(level, self->height())); + + if (x < 0 || x + width > mip_width || y < 0 || y + height > mip_height) { + O3D_ERROR(self->service_locator()) << "area out of range"; + return empty; + } + + unsigned num_components; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + break; + } + default: + O3D_ERROR(self->service_locator()) + << "Texture::Set not supported for this type of texture"; + return empty; + } + o3d::Texture2D::LockHelper helper(self, level, o3d::Texture::kReadOnly); + void* data = helper.GetData(); + if (!data) { + O3D_ERROR(self->service_locator()) << "could not lock texture"; + return empty; + } + + std::vector<float> values(width * height * num_components, 0); + GetRect(self, data, helper.pitch(), x, y, width, height, &values[0]); + return values; +} + +} // namespace class_Texture2D + +namespace class_TextureCUBE { + +void userglue_method_SetRect(o3d::TextureCUBE* self, + o3d::TextureCUBE::CubeFace face, + int level, + int destination_x, + int destination_y, + int source_width, + const std::vector<float>& values) { + SetRectCheckCUBE(self, + face, + level, + destination_x, + destination_y, + source_width, + values, + false); +} +void userglue_method_Set(o3d::TextureCUBE* self, + o3d::TextureCUBE::CubeFace face, + int level, + const std::vector<float>& values) { + SetRectCheckCUBE(self, face, level, 0, 0, + o3d::image::ComputeMipDimension(level, self->edge_length()), + values, true); +} +std::vector<float> userglue_method_GetRect(o3d::TextureCUBE* self, + o3d::TextureCUBE::CubeFace face, + int level, + int x, + int y, + int width, + int height) { + std::vector<float> empty; + if (level < 0 || level >= self->levels()) { + O3D_ERROR(self->service_locator()) + << "level (" << level << " out of range"; + return empty; + } + if (width <= 0 || height <= 0) { + O3D_ERROR(self->service_locator()) + << "width and height must be positive"; + return empty; + } + + int mip_length = static_cast<int>(o3d::image::ComputeMipDimension( + level, self->edge_length())); + + if (x < 0 || x + width > mip_length || y < 0 || y + height > mip_length) { + O3D_ERROR(self->service_locator()) << "area out of range"; + return empty; + } + + unsigned num_components; + switch (self->format()) { + case o3d::Texture::XRGB8: + num_components = 3; + break; + case o3d::Texture::R32F: + num_components = 1; + break; + case o3d::Texture::ARGB8: + case o3d::Texture::ABGR16F: + num_components = 4; + break; + case o3d::Texture::ABGR32F: { + num_components = 4; + break; + } + default: + O3D_ERROR(self->service_locator()) + << "Texture::Set not supported for this type of texture"; + return empty; + } + o3d::TextureCUBE::LockHelper helper( + self, face, level, o3d::Texture::kReadOnly); + void* data = helper.GetData(); + if (!data) { + O3D_ERROR(self->service_locator()) << "could not lock texture"; + return empty; + } + + std::vector<float> values(width * height * num_components, 0); + GetRect(self, data, helper.pitch(), x, y, width, height, &values[0]); + return values; +} + +} // namespace class_TextureCUBE + +} // namespace namespace_o3d +} // namespace glue + diff --git a/o3d/utils/cross/base64_test.cc b/o3d/utils/cross/base64_test.cc index 9eacd69..d291f14 100644 --- a/o3d/utils/cross/base64_test.cc +++ b/o3d/utils/cross/base64_test.cc @@ -1,170 +1,170 @@ -/*
- * 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 tests of base64 functions
-
-#include "tests/common/win/testing_common.h"
-#include "utils/cross/base64.h"
-
-namespace o3d {
-
-class Base64Test : public testing::Test {
-};
-
-TEST_F(Base64Test, GetEncodeLength) {
- EXPECT_EQ(0u, base64::GetEncodeLength(0));
- EXPECT_EQ(4u, base64::GetEncodeLength(1));
- EXPECT_EQ(4u, base64::GetEncodeLength(2));
- EXPECT_EQ(4u, base64::GetEncodeLength(3));
- EXPECT_EQ(8u, base64::GetEncodeLength(4));
-}
-
-TEST_F(Base64Test, Encode) {
- unsigned char buffer[100];
- memset(buffer, 0xFF, sizeof(buffer));
- base64::Encode("abc", 3, buffer);
- EXPECT_EQ(0, memcmp(buffer, "YWJj", 4));
- EXPECT_EQ(0xFF, buffer[4]);
- memset(buffer, 0xFF, sizeof(buffer));
- base64::Encode("ab\0c", 4, buffer);
- EXPECT_EQ(0, memcmp(buffer, "YWIAYw==", 8));
- EXPECT_EQ(0xFF, buffer[8]);
-}
-
-TEST_F(Base64Test, GetDecodeLength) {
- size_t length = 256u;
- base64::GetDecodeLength("", 0, &length);
- EXPECT_EQ(0u, length);
-
- length = 256u;
- base64::GetDecodeLength("YQ==", 4, &length);
- EXPECT_EQ(1u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWI=", 4, &length);
- EXPECT_EQ(2u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJj", 4, &length);
- EXPECT_EQ(3u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJjZA==", 8, &length);
- EXPECT_EQ(4u, length);
-
- length = 256u;
- base64::GetDecodeLength("YWJjZGU=", 8, &length);
- EXPECT_EQ(5u, length);
-}
-
-TEST_F(Base64Test, GetDecodeLengthInputError) {
- base64::DecodeStatus status = base64::kSuccess;
- size_t length = 256u;
- status = base64::GetDecodeLength("Y@==", 4, &length);
- EXPECT_EQ(base64::kBadCharError, status);
-
- status = base64::GetDecodeLength("Y Q==", 4, &length);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::GetDecodeLength("Y", 1, &length);
- EXPECT_EQ(base64::kPadError, status);
-}
-
-TEST_F(Base64Test, Decode) {
- unsigned char buffer[10];
- memset(buffer, 0xFF, sizeof(buffer));
- unsigned char result_buffer[10];
- memset(result_buffer, 0xFF, sizeof(result_buffer));
- base64::DecodeStatus status = base64::kSuccess;
-
- status = base64::Decode("", 0, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[0] = 'a';
- status = base64::Decode("YQ==", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[1] = 'b';
- status = base64::Decode("YWI=", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[2] = 'c';
- status = base64::Decode("YWJj", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[3] = 'd';
- status = base64::Decode("YWJjZA==", 8, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-
- result_buffer[4] = 'e';
- status = base64::Decode("YWJjZGU=", 8, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
- EXPECT_EQ(0, memcmp(buffer, result_buffer, 10));
-}
-
-TEST_F(Base64Test, DecodeInputError) {
- unsigned char buffer[10];
- base64::DecodeStatus status = base64::kSuccess;
- status = base64::Decode("Y@==", 4, buffer, 10);
- EXPECT_EQ(base64::kBadCharError, status);
-
- status = base64::Decode("Y Q==", 4, buffer, 10);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::Decode("Y", 1, buffer, 10);
- EXPECT_EQ(base64::kPadError, status);
-}
-
-TEST_F(Base64Test, DecodeOverflowError) {
- unsigned char buffer[10];
- base64::DecodeStatus status = base64::kSuccess;
- status = base64::Decode("YWJjZA==", 8, buffer, 3);
- EXPECT_EQ(base64::kOutputOverflowError, status);
-
- status = base64::Decode("YWJjZA==", 8, buffer, 4);
- EXPECT_EQ(base64::kSuccess, status);
-
- status = base64::Decode("YQ==", 8, buffer, 0);
- EXPECT_EQ(base64::kOutputOverflowError, status);
-
- status = base64::Decode("YQ==", 8, buffer, 1);
- EXPECT_EQ(base64::kSuccess, status);
-}
-
-} // namespace o3d
-
-
+/* + * 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 tests of base64 functions + +#include "tests/common/win/testing_common.h" +#include "utils/cross/base64.h" + +namespace o3d { + +class Base64Test : public testing::Test { +}; + +TEST_F(Base64Test, GetEncodeLength) { + EXPECT_EQ(0u, base64::GetEncodeLength(0)); + EXPECT_EQ(4u, base64::GetEncodeLength(1)); + EXPECT_EQ(4u, base64::GetEncodeLength(2)); + EXPECT_EQ(4u, base64::GetEncodeLength(3)); + EXPECT_EQ(8u, base64::GetEncodeLength(4)); +} + +TEST_F(Base64Test, Encode) { + unsigned char buffer[100]; + memset(buffer, 0xFF, sizeof(buffer)); + base64::Encode("abc", 3, buffer); + EXPECT_EQ(0, memcmp(buffer, "YWJj", 4)); + EXPECT_EQ(0xFF, buffer[4]); + memset(buffer, 0xFF, sizeof(buffer)); + base64::Encode("ab\0c", 4, buffer); + EXPECT_EQ(0, memcmp(buffer, "YWIAYw==", 8)); + EXPECT_EQ(0xFF, buffer[8]); +} + +TEST_F(Base64Test, GetDecodeLength) { + size_t length = 256u; + base64::GetDecodeLength("", 0, &length); + EXPECT_EQ(0u, length); + + length = 256u; + base64::GetDecodeLength("YQ==", 4, &length); + EXPECT_EQ(1u, length); + + length = 256u; + base64::GetDecodeLength("YWI=", 4, &length); + EXPECT_EQ(2u, length); + + length = 256u; + base64::GetDecodeLength("YWJj", 4, &length); + EXPECT_EQ(3u, length); + + length = 256u; + base64::GetDecodeLength("YWJjZA==", 8, &length); + EXPECT_EQ(4u, length); + + length = 256u; + base64::GetDecodeLength("YWJjZGU=", 8, &length); + EXPECT_EQ(5u, length); +} + +TEST_F(Base64Test, GetDecodeLengthInputError) { + base64::DecodeStatus status = base64::kSuccess; + size_t length = 256u; + status = base64::GetDecodeLength("Y@==", 4, &length); + EXPECT_EQ(base64::kBadCharError, status); + + status = base64::GetDecodeLength("Y Q==", 4, &length); + EXPECT_EQ(base64::kSuccess, status); + + status = base64::GetDecodeLength("Y", 1, &length); + EXPECT_EQ(base64::kPadError, status); +} + +TEST_F(Base64Test, Decode) { + unsigned char buffer[10]; + memset(buffer, 0xFF, sizeof(buffer)); + unsigned char result_buffer[10]; + memset(result_buffer, 0xFF, sizeof(result_buffer)); + base64::DecodeStatus status = base64::kSuccess; + + status = base64::Decode("", 0, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); + + result_buffer[0] = 'a'; + status = base64::Decode("YQ==", 4, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); + + result_buffer[1] = 'b'; + status = base64::Decode("YWI=", 4, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); + + result_buffer[2] = 'c'; + status = base64::Decode("YWJj", 4, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); + + result_buffer[3] = 'd'; + status = base64::Decode("YWJjZA==", 8, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); + + result_buffer[4] = 'e'; + status = base64::Decode("YWJjZGU=", 8, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + EXPECT_EQ(0, memcmp(buffer, result_buffer, 10)); +} + +TEST_F(Base64Test, DecodeInputError) { + unsigned char buffer[10]; + base64::DecodeStatus status = base64::kSuccess; + status = base64::Decode("Y@==", 4, buffer, 10); + EXPECT_EQ(base64::kBadCharError, status); + + status = base64::Decode("Y Q==", 4, buffer, 10); + EXPECT_EQ(base64::kSuccess, status); + + status = base64::Decode("Y", 1, buffer, 10); + EXPECT_EQ(base64::kPadError, status); +} + +TEST_F(Base64Test, DecodeOverflowError) { + unsigned char buffer[10]; + base64::DecodeStatus status = base64::kSuccess; + status = base64::Decode("YWJjZA==", 8, buffer, 3); + EXPECT_EQ(base64::kOutputOverflowError, status); + + status = base64::Decode("YWJjZA==", 8, buffer, 4); + EXPECT_EQ(base64::kSuccess, status); + + status = base64::Decode("YQ==", 8, buffer, 0); + EXPECT_EQ(base64::kOutputOverflowError, status); + + status = base64::Decode("YQ==", 8, buffer, 1); + EXPECT_EQ(base64::kSuccess, status); +} + +} // namespace o3d + + diff --git a/o3d/utils/cross/dataurl.cc b/o3d/utils/cross/dataurl.cc index f796719..328d174 100644 --- a/o3d/utils/cross/dataurl.cc +++ b/o3d/utils/cross/dataurl.cc @@ -1,113 +1,113 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file contains the definition of functions for dealing with data urls.
-
-#include "utils/cross/dataurl.h"
-#include "core/cross/types.h"
-#include "utils/cross/base64.h"
-
-namespace o3d {
-namespace dataurl {
-
-const char* const kEmptyDataURL = "data:,";
-
-String ToDataURL(const String& mime_type, const void* data, size_t length) {
- String header(String("data:") + mime_type + ";base64,");
- String result(header.size() + base64::GetEncodeLength(length), ' ');
- result.replace(0, header.size(), header);
- base64::Encode(data, length, &result[header.size()]);
- return result;
-}
-
-// Decodes the data URL and stores a pointer to the data in dst_buffer
-bool FromDataURL(const String& data_url,
- scoped_array<uint8>* dst_buffer,
- size_t* output_length,
- String* error_string) {
- // First parse the data_url
- const String kDataHeader("data:");
- const String kBase64Header(";base64,");
- // The string has to be long enough.
- if (data_url.size() <= kDataHeader.size() + kBase64Header.size()) {
- *error_string = "Invalid formatting: The data URL is not long enough.";
- return false;
- }
- // it must start with "data:"
- if (data_url.compare(0, kDataHeader.size(), kDataHeader) != 0) {
- *error_string
- = "Invalid formatting: The data URL must start with 'data:'";
- return false;
- }
- // we only support base64 data URL's
- String::size_type data_index = data_url.find(kBase64Header);
- if (data_index == String::npos) {
- *error_string
- = "Invalid formatting: The data URL have ';base64,' in the header.";
- return false;
- }
- // The start of the data.
- data_index += kBase64Header.size();
- if (data_index >= data_url.size()) {
- *error_string
- = "Invalid formatting: There must be data in the body of the data URL.";
- return false;
- }
-
- // Get the length of the decoded data
- size_t input_length = data_url.size() - data_index;
- base64::DecodeStatus return_code = base64::GetDecodeLength(
- &data_url[data_index],
- input_length,
- output_length);
- if (return_code != base64::kSuccess) {
- if (return_code == base64::kPadError) {
- *error_string
- = "Invalid formatting: Padding error in the data URL data.";
- } else {
- *error_string
- = "Invalid formatting: Bad character error in the data URL data.";
- }
- return false;
- }
-
- dst_buffer->reset(new uint8[*output_length]);
- base64::Decode(&data_url[data_index],
- input_length,
- dst_buffer->get(),
- (*output_length));
-
- return true;
-}
-
-} // namespace dataurl
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file contains the definition of functions for dealing with data urls. + +#include "utils/cross/dataurl.h" +#include "core/cross/types.h" +#include "utils/cross/base64.h" + +namespace o3d { +namespace dataurl { + +const char* const kEmptyDataURL = "data:,"; + +String ToDataURL(const String& mime_type, const void* data, size_t length) { + String header(String("data:") + mime_type + ";base64,"); + String result(header.size() + base64::GetEncodeLength(length), ' '); + result.replace(0, header.size(), header); + base64::Encode(data, length, &result[header.size()]); + return result; +} + +// Decodes the data URL and stores a pointer to the data in dst_buffer +bool FromDataURL(const String& data_url, + scoped_array<uint8>* dst_buffer, + size_t* output_length, + String* error_string) { + // First parse the data_url + const String kDataHeader("data:"); + const String kBase64Header(";base64,"); + // The string has to be long enough. + if (data_url.size() <= kDataHeader.size() + kBase64Header.size()) { + *error_string = "Invalid formatting: The data URL is not long enough."; + return false; + } + // it must start with "data:" + if (data_url.compare(0, kDataHeader.size(), kDataHeader) != 0) { + *error_string + = "Invalid formatting: The data URL must start with 'data:'"; + return false; + } + // we only support base64 data URL's + String::size_type data_index = data_url.find(kBase64Header); + if (data_index == String::npos) { + *error_string + = "Invalid formatting: The data URL have ';base64,' in the header."; + return false; + } + // The start of the data. + data_index += kBase64Header.size(); + if (data_index >= data_url.size()) { + *error_string + = "Invalid formatting: There must be data in the body of the data URL."; + return false; + } + + // Get the length of the decoded data + size_t input_length = data_url.size() - data_index; + base64::DecodeStatus return_code = base64::GetDecodeLength( + &data_url[data_index], + input_length, + output_length); + if (return_code != base64::kSuccess) { + if (return_code == base64::kPadError) { + *error_string + = "Invalid formatting: Padding error in the data URL data."; + } else { + *error_string + = "Invalid formatting: Bad character error in the data URL data."; + } + return false; + } + + dst_buffer->reset(new uint8[*output_length]); + base64::Decode(&data_url[data_index], + input_length, + dst_buffer->get(), + (*output_length)); + + return true; +} + +} // namespace dataurl +} // namespace o3d + diff --git a/o3d/utils/cross/math_gtest.cc b/o3d/utils/cross/math_gtest.cc index 0f7cc90d..1296817 100644 --- a/o3d/utils/cross/math_gtest.cc +++ b/o3d/utils/cross/math_gtest.cc @@ -1,119 +1,119 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-// This file defines the some helper for gtest for the math library used by O3D.
-
-#include "utils/cross/math_gtest.h"
-#include "core/cross/types.h"
-
-
-namespace Vectormath {
-namespace Aos {
-
-bool operator==(const Vector4& left, const Vector4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Vector4& left, const Vector4& right) {
- return !(left == right);
-}
-
-bool operator==(const Matrix4& left, const Matrix4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Matrix4& left, const Matrix4& right) {
- return !(left == right);
-}
-
-std::ostream& operator<<(std::ostream& stream, const Vector4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Matrix4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-} // namespace Aos
-} // namespace Vectormath
-
-namespace o3d {
-
-bool operator==(const Float2& left, const Float2& right) {
- return left[0] == right[0] && left[1] == right[1];
-}
-
-bool operator!=(const Float2& left, const Float2& right) {
- return !(left == right);
-}
-
-bool operator==(const Float3& left, const Float3& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2];
-}
-
-bool operator!=(const Float3& left, const Float3& right) {
- return !(left == right);
-}
-
-bool operator==(const Float4& left, const Float4& right) {
- return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] &&
- left[3] == right[3];
-}
-
-bool operator!=(const Float4& left, const Float4& right) {
- return !(left == right);
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float2& value) {
- stream << "{" << value[0] << ", " << value[1] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float3& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}";
- return stream;
-}
-
-std::ostream& operator<<(std::ostream& stream, const Float4& value) {
- stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", "
- << value[3] << "}";
- return stream;
-}
-
-} // namespace o3d
-
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file defines the some helper for gtest for the math library used by O3D. + +#include "utils/cross/math_gtest.h" +#include "core/cross/types.h" + + +namespace Vectormath { +namespace Aos { + +bool operator==(const Vector4& left, const Vector4& right) { + return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && + left[3] == right[3]; +} + +bool operator!=(const Vector4& left, const Vector4& right) { + return !(left == right); +} + +bool operator==(const Matrix4& left, const Matrix4& right) { + return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && + left[3] == right[3]; +} + +bool operator!=(const Matrix4& left, const Matrix4& right) { + return !(left == right); +} + +std::ostream& operator<<(std::ostream& stream, const Vector4& value) { + stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " + << value[3] << "}"; + return stream; +} + +std::ostream& operator<<(std::ostream& stream, const Matrix4& value) { + stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " + << value[3] << "}"; + return stream; +} + +} // namespace Aos +} // namespace Vectormath + +namespace o3d { + +bool operator==(const Float2& left, const Float2& right) { + return left[0] == right[0] && left[1] == right[1]; +} + +bool operator!=(const Float2& left, const Float2& right) { + return !(left == right); +} + +bool operator==(const Float3& left, const Float3& right) { + return left[0] == right[0] && left[1] == right[1] && left[2] == right[2]; +} + +bool operator!=(const Float3& left, const Float3& right) { + return !(left == right); +} + +bool operator==(const Float4& left, const Float4& right) { + return left[0] == right[0] && left[1] == right[1] && left[2] == right[2] && + left[3] == right[3]; +} + +bool operator!=(const Float4& left, const Float4& right) { + return !(left == right); +} + +std::ostream& operator<<(std::ostream& stream, const Float2& value) { + stream << "{" << value[0] << ", " << value[1] << "}"; + return stream; +} + +std::ostream& operator<<(std::ostream& stream, const Float3& value) { + stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << "}"; + return stream; +} + +std::ostream& operator<<(std::ostream& stream, const Float4& value) { + stream << "{" << value[0] << ", " << value[1] << ", " << value[2] << ", " + << value[3] << "}"; + return stream; +} + +} // namespace o3d + + diff --git a/o3d/utils/cross/math_gtest_test.cc b/o3d/utils/cross/math_gtest_test.cc index a0e4f00..ae6bc62 100644 --- a/o3d/utils/cross/math_gtest_test.cc +++ b/o3d/utils/cross/math_gtest_test.cc @@ -1,70 +1,70 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "tests/common/win/testing_common.h"
-#include "utils/cross/math_gtest.h"
-
-namespace o3d {
-
-class MathGTestTest : public testing::Test {
-};
-
-// Test the math gtest helper functions.
-TEST_F(MathGTestTest, TestMathGTest) {
- EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f));
- EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f));
- EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f));
- EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f));
- EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f));
- EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f));
- EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f));
- Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f),
- Vector4(1.2f, 2.3f, 3.4f, 4.5f),
- Vector4(1.3f, 2.4f, 3.5f, 4.6f),
- Vector4(1.4f, 2.5f, 3.6f, 4.7f));
- Matrix4 b(a);
- EXPECT_EQ(a, b);
- for (int ii = 0; ii < 4; ++ii) {
- for (int jj = 0; jj < 4; ++jj) {
- b = a;
- b.setElem(ii, jj, b.getElem(ii, jj) * 2);
- EXPECT_NE(a, b);
- }
- }
-}
-
-} // namespace o3d
-
+/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests/common/win/testing_common.h" +#include "utils/cross/math_gtest.h" + +namespace o3d { + +class MathGTestTest : public testing::Test { +}; + +// Test the math gtest helper functions. +TEST_F(MathGTestTest, TestMathGTest) { + EXPECT_EQ(Float2(1.2f, 2.3f), Float2(1.2f, 2.3f)); + EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.3f, 2.3f)); + EXPECT_NE(Float2(1.2f, 2.3f), Float2(1.2f, 2.4f)); + EXPECT_EQ(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.5f)); + EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.3f, 2.3f, 4.5f)); + EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.4f, 4.5f)); + EXPECT_NE(Float3(1.2f, 2.3f, 4.5f), Float3(1.2f, 2.3f, 4.6f)); + EXPECT_EQ(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.7f)); + EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.3f, 2.3f, 4.5f, 6.7f)); + EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.4f, 4.5f, 6.7f)); + EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.6f, 6.7f)); + EXPECT_NE(Float4(1.2f, 2.3f, 4.5f, 6.7f), Float4(1.2f, 2.3f, 4.5f, 6.8f)); + Matrix4 a(Vector4(1.1f, 2.2f, 3.3f, 4.4f), + Vector4(1.2f, 2.3f, 3.4f, 4.5f), + Vector4(1.3f, 2.4f, 3.5f, 4.6f), + Vector4(1.4f, 2.5f, 3.6f, 4.7f)); + Matrix4 b(a); + EXPECT_EQ(a, b); + for (int ii = 0; ii < 4; ++ii) { + for (int jj = 0; jj < 4; ++jj) { + b = a; + b.setElem(ii, jj, b.getElem(ii, jj) * 2); + EXPECT_NE(a, b); + } + } +} + +} // namespace o3d + |