diff options
author | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 23:33:17 +0000 |
---|---|---|
committer | gspencer@google.com <gspencer@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-21 23:33:17 +0000 |
commit | 1b2bfdd574d9c4e21251ec2214e41d8905da4541 (patch) | |
tree | 125a1781c38b840effa24926a16f9599c0631281 /o3d/core/cross | |
parent | c7cc3f559ecc96849168432c7d3abcca4eeebb4f (diff) | |
download | chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.zip chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.tar.gz chromium_src-1b2bfdd574d9c4e21251ec2214e41d8905da4541.tar.bz2 |
This fixes a number of things that are warnings in the Mac compiler.
It fixes at least two real bugs, one in the tar generator, and one
in stream_bank.h.
Review URL: http://codereview.chromium.org/159168
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/core/cross')
25 files changed, 532 insertions, 519 deletions
diff --git a/o3d/core/cross/bitmap.cc b/o3d/core/cross/bitmap.cc index 320d3e1..98863cf 100644 --- a/o3d/core/cross/bitmap.cc +++ b/o3d/core/cross/bitmap.cc @@ -615,7 +615,7 @@ static void FilterTexel(unsigned int x, } for (unsigned int c = 0; c < components; ++c) { uint64 value = accum[c] / (src_height * src_width); - DCHECK_LE(value, 255); + DCHECK_LE(value, 255u); dst_data[(y * dst_width + x) * components + c] = static_cast<unsigned char>(value); } diff --git a/o3d/core/cross/bitmap.h b/o3d/core/cross/bitmap.h index 60ebb4a..8100b86 100644 --- a/o3d/core/cross/bitmap.h +++ b/o3d/core/cross/bitmap.h @@ -1,439 +1,439 @@ -/*
- * Copyright 2009, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-// This file contains the declaration of Bitmap helper class that can load
-// raw 24- and 32-bit bitmaps from popular image formats. The Bitmap class
-// also interprets the file format to record the correct OpenGL buffer format.
-//
-// Trying to keep this class independent from the OpenGL API in case they
-// need retargeting later on.
-
-#ifndef O3D_CORE_CROSS_BITMAP_H_
-#define O3D_CORE_CROSS_BITMAP_H_
-
-#include <stdlib.h>
-
-#include "base/cross/bits.h"
-#include "core/cross/types.h"
-#include "core/cross/texture.h"
-
-class FilePath;
-
-namespace o3d {
-
-class MemoryReadStream;
-class RawData;
-class Pack;
-
-// Bitmap provides an API for basic image operations on bitmap images,
-// including scale and crop. The contents of bitmap can be created from
-// a RawData object via LoadFromRawData(), and also can be transfered
-// to mip of a Texure2D or a specific face of TextureCUBE via methods
-// in Texture.
-
-class Bitmap : public ParamObject {
- public:
- typedef SmartPointer<Bitmap> Ref;
-
- explicit Bitmap(ServiceLocator* service_locator);
- virtual ~Bitmap() {}
-
- // We will fail to load images that are bigger than 4kx4k to avoid security
- // risks. GPUs don't usually support bigger sizes anyway.
- // The biggest bitmap buffer size with these dimensions is:
- // 4k x 4k x 4xsizeof(float) x6 x4/3 (x6 for cube maps, x4/3 for mipmaps)
- // That makes 2GB, representable in an unsigned int, so we will avoid wraps.
- static const unsigned int kMaxImageDimension = 4096;
- enum ImageFileType {
- UNKNOWN,
- TGA,
- JPEG,
- PNG,
- DDS,
- };
-
- static bool CheckImageDimensions(unsigned int width, unsigned int height) {
- return width > 0 && height > 0 &&
- width <= kMaxImageDimension && height < kMaxImageDimension;
- }
-
- // Creates a copy of a bitmap, copying the pixels as well.
- // Parameters:
- // source: the source bitmap.
- void CopyDeepFrom(const Bitmap &source) {
- Allocate(source.format_, source.width_, source.height_,
- source.num_mipmaps_, source.is_cubemap_);
- memcpy(image_data(), source.image_data(), GetTotalSize());
- }
-
- // Sets the bitmap parameters from another bitmap, stealing the pixel buffer
- // from the source bitmap.
- // Parameters:
- // source: the source bitmap.
- void SetFrom(Bitmap *source) {
- image_data_.reset();
- format_ = source->format_;
- width_ = source->width_;
- height_ = source->height_;
- num_mipmaps_ = source->num_mipmaps_;
- is_cubemap_ = source->is_cubemap_;
- image_data_.swap(source->image_data_);
- }
-
- // Allocates an uninitialized bitmap with specified parameters.
- // Parameters:
- // format: the format of the pixels.
- // width: the width of the base image.
- // height: the height of the base image.
- // num_mipmaps: the number of mip-maps.
- // cube_map: true if creating a cube map.
- void Allocate(Texture::Format format,
- unsigned int width,
- unsigned int height,
- unsigned int num_mipmaps,
- bool cube_map);
-
- // Allocates a bitmap with initialized parameters.
- // data is zero-initialized
- void AllocateData() {
- image_data_.reset(new unsigned char[GetTotalSize()]);
- memset(image_data_.get(), 0, GetTotalSize());
- }
-
- // Frees the data owned by the bitmap.
- void FreeData() {
- image_data_.reset(NULL);
- }
-
- // Gets the total size of the bitmap data, counting all faces and mip levels.
- unsigned int GetTotalSize() {
- return (is_cubemap_ ? 6 : 1) *
- GetMipChainSize(width_, height_, format_, num_mipmaps_);
- }
-
- // Computes the number of bytes of a texture pixel buffer.
- static unsigned int GetBufferSize(unsigned int width,
- unsigned int height,
- Texture::Format format);
-
- // Gets the image data for a given mip-map level and cube map face.
- // Parameters:
- // level: mip level to get.
- // face: face of cube to get. This parameter is ignored if
- // this bitmap is not a cube map.
- unsigned char *GetMipData(unsigned int level,
- TextureCUBE::CubeFace face) const;
-
- unsigned char *image_data() const { return image_data_.get(); }
- Texture::Format format() const { return format_; }
- unsigned int width() const { return width_; }
- unsigned int height() const { return height_; }
- unsigned int num_mipmaps() const { return num_mipmaps_; }
- bool is_cubemap() const { return is_cubemap_; }
-
- // Returns whether or not the dimensions of the bitmap are power-of-two.
- bool IsPOT() const {
- return ((width_ & (width_ - 1)) == 0) && ((height_ & (height_ - 1)) == 0);
- }
-
- void set_format(Texture::Format format) { format_ = format; }
- void set_width(unsigned int n) { width_ = n; }
- void set_height(unsigned int n) { height_ = n; }
- void set_num_mipmaps(unsigned int n) { num_mipmaps_ = n; }
- void set_is_cubemap(bool is_cubemap) { is_cubemap_ = is_cubemap; }
-
- // Loads a bitmap from a file.
- // Parameters:
- // filename: the name of the file to load.
- // file_type: the type of file to load. If UNKNOWN, the file type will be
- // determined from the filename extension, and if it is not a
- // known extension, all the loaders will be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromFile(const FilePath &filepath,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- // Loads a bitmap from a RawData object.
- // Parameters:
- // raw_data: contains the bitmap data in one of the known formats
- // file_type: the format of the bitmap data. If UNKNOWN, the file type
- // will be determined from the extension from raw_data's uri
- // and if it is not a known extension, all the loaders will
- // be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromRawData(RawData *raw_data,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- // Loads a bitmap from a MemoryReadStream.
- // Parameters:
- // stream: a stream for the bitmap data in one of the known formats
- // filename: a filename (or uri) of the original bitmap data
- // (may be an empty string)
- // file_type: the format of the bitmap data. If UNKNOWN, the file type
- // will be determined from the extension of |filename|
- // and if it is not a known extension, all the loaders
- // will be tried.
- // generate_mipmaps: whether or not to generate all the mip-map levels.
- bool LoadFromStream(MemoryReadStream *stream,
- const String &filename,
- ImageFileType file_type,
- bool generate_mipmaps);
-
- bool LoadFromPNGStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromTGAStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromDDSStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- bool LoadFromJPEGStream(MemoryReadStream *stream,
- const String &filename,
- bool generate_mipmaps);
-
- // Saves to a PNG file. The image must be of the ARGB8 format, be a 2D image
- // with no mip-maps (only the base level).
- // Parameters:
- // filename: the name of the file to into.
- // Returns:
- // true if successful.
- bool SaveToPNGFile(const char* filename);
-
- // Checks that the alpha channel for the entire bitmap is 1.0
- bool CheckAlphaIsOne() const;
-
- // Copy pixels from source bitmap. Scales if the width and height of source
- // and dest do not match.
- // Parameters:
- // source_img: source bitmap which would be drawn.
- // source_x: x-coordinate of the starting pixel in the source image.
- // source_x: y-coordinate of the starting pixel in the source image.
- // source_width: width of the source image to draw.
- // source_height: Height of the source image to draw.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the dest image to draw.
- // dest_height: height of the dest image to draw.
- void DrawImage(Bitmap* source_img, int source_x, int source_y,
- int source_width, int source_height,
- int dest_x, int dest_y,
- int dest_width, int dest_height);
-
- // Crop part of an image from src, scale it to an arbitrary size
- // and paste in dest image. Utility function for all DrawImage
- // function in bitmap and textures. Scale operation is based on
- // bilinear interpolation.
- // Note: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // src: source image which would be copied from.
- // src_x: x-coordinate of the starting pixel in the src image.
- // src_y: y-coordinate of the starting pixel in the src image.
- // src_width: width of the part in src image to be croped.
- // src_height: height of the part in src image to be croped.
- // src_img_width: width of the src image.
- // src_img_height: height of the src image.
- // dest: dest image which would be copied to.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the part in dest image to be pasted to.
- // dest_height: height of the part in dest image to be pasted to.
- // dest_img_width: width of the dest image.
- // dest_img_height: height of the src image.
- // component: size of each pixel in terms of array element.
- // Returns:
- // true if crop and scale succeeds.
- static void BilinearInterpolateScale(const uint8* src,
- int src_x, int src_y,
- int src_width, int src_height,
- int src_img_width, int src_img_height,
- uint8* dest,
- int dest_x, int dest_y,
- int dest_width, int dest_height,
- int dest_img_width, int dest_img_height,
- int component);
-
- // Detects the type of image file based on the filename.
- static ImageFileType GetFileTypeFromFilename(const char *filename);
- // Detects the type of image file based on the mime-type.
- static ImageFileType GetFileTypeFromMimeType(const char *mime_type);
-
- // Adds filler alpha byte (0xff) after every pixel. Assumes buffer was
- // allocated with enough storage)
- // can convert RGB -> RGBA, BGR -> BGRA, etc.
- static void XYZToXYZA(unsigned char *image_data, int pixel_count);
-
- // Swaps Red and Blue components in the image.
- static void RGBAToBGRA(unsigned char *image_data, int pixel_count);
-
- // Gets the number of mip-maps required for a full chain starting at
- // width x height.
- static unsigned int GetMipMapCount(unsigned int width, unsigned int height) {
- return 1 + base::bits::Log2Floor(std::max(width, height));
- }
-
- // Gets the smallest power-of-two value that is at least as high as
- // dimension. This is the POT dimension used in ScaleUpToPOT.
- static unsigned int GetPOTSize(unsigned int dimension) {
- return 1 << base::bits::Log2Ceiling(dimension);
- }
-
- // Gets the size of the buffer containing a mip-map chain, given its base
- // width, height, format and number of mip-map levels.
- static unsigned int GetMipChainSize(unsigned int base_width,
- unsigned int base_height,
- Texture::Format format,
- unsigned int num_mipmaps);
-
- // Generates mip-map levels for a single image, using the data from the base
- // level.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // base_width: the width of the base image.
- // base_height: the height of the base image.
- // format: the format of the data.
- // num_mipmaps: the number of mipmaps to generate.
- // data: the data containing the base image, and enough space for the
- // mip-maps.
- static bool GenerateMipmaps(unsigned int base_width,
- unsigned int base_height,
- Texture::Format format,
- unsigned int num_mipmaps,
- unsigned char *data);
-
- // Scales an image up to power-of-two textures, using point filtering.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // width: the non-power-of-two width of the original image.
- // height: the non-power-of-two height of the original image.
- // format: the format of the data.
- // src: the data containing the source data of the original image.
- // dst: a buffer with enough space for the power-of-two version. Pixels are
- // written from the end to the beginning so dst can be the same buffer as
- // src.
- static bool ScaleUpToPOT(unsigned int width,
- unsigned int height,
- Texture::Format format,
- const unsigned char *src,
- unsigned char *dst);
-
- // Scales an image to an arbitrary size, using point filtering.
- // NOTE: this doesn't work for DXTC, or floating-point images.
- //
- // Parameters:
- // src_width: the width of the original image.
- // src_height: the height of the original image.
- // format: the format of the data.
- // src: the data containing the source data of the original image.
- // dst_width: the width of the target image.
- // dst_height: the height of the target image.
- // dst: a buffer with enough space for the target version. Pixels are
- // written from the end to the beginning so dst can be the same buffer as
- // src if the transformation is an upscaling.
- static bool Scale(unsigned int src_width,
- unsigned int src_height,
- Texture::Format format,
- const unsigned char *src,
- unsigned int dst_width,
- unsigned int dst_height,
- unsigned char *dst);
-
- // adjust start points and boundaries when using DrawImage data
- // in bitmap and textures.
- // Parameters:
- // src_x: x-coordinate of the starting pixel in the source image.
- // src_y: y-coordinate of the starting pixel in the source image.
- // src_width: width of the source image to draw.
- // src_height: height of the source image to draw.
- // src_bmp_width: original width of source bitmap.
- // src_bmp_height: original height of source bitmap.
- // dest_x: x-coordinate of the starting pixel in the dest image.
- // dest_y: y-coordinate of the starting pixel in the dest image.
- // dest_width: width of the dest image to draw.
- // dest_height: height of the dest image to draw.
- // dest_bmp_width: original width of dest bitmap.
- // dest_bmp_height: original height of dest bitmap.
- // Returns:
- // false if src or dest rectangle is out of boundaries.
- static bool AdjustDrawImageBoundary(int* src_x, int* src_y,
- int* src_width, int* src_height,
- int src_bmp_width, int src_bmp_height,
- int* dest_x, int* dest_y,
- int* dest_width, int* dest_height,
- int dest_bmp_width, int dest_bmp_height);
-
- private:
- friend class IClassManager;
- static ObjectBase::Ref Create(ServiceLocator* service_locator);
-
- // pointer to the raw bitmap data
- scoped_array<uint8> image_data_;
- // format of the texture this is meant to represent.
- Texture::Format format_;
- // width of the bitmap in pixels.
- unsigned int width_;
- // height of the bitmap in pixels.
- unsigned int height_;
- // number of mipmap levels in this texture.
- unsigned int num_mipmaps_;
- // is this cube-map data
- bool is_cubemap_;
-
- // utility function used in AdjustDrawImageBoundary.
- // It adjusts start point and related measures
- // for a specific dimension.
- // Parameter:
- // src_a: the coordinate which is negative.
- // dest_a: same coordinate in the other image.
- // src_length: length measure of source image to draw.
- // dest_length: length measure of dest image to draw.
- // src_bmp_length: length measure of src image.
- // Returns:
- // true if adjust is successful.
- static bool AdjustDrawImageBoundHelper(int* src_a, int* dest_a,
- int* src_length, int* dest_length,
- int src_bmp_length);
-
- O3D_DECL_CLASS(Bitmap, ParamObject);
- DISALLOW_COPY_AND_ASSIGN(Bitmap);
-};
-
-} // namespace o3d
-
-#endif // O3D_CORE_CROSS_BITMAP_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. + */ + + +// This file contains the declaration of Bitmap helper class that can load +// raw 24- and 32-bit bitmaps from popular image formats. The Bitmap class +// also interprets the file format to record the correct OpenGL buffer format. +// +// Trying to keep this class independent from the OpenGL API in case they +// need retargeting later on. + +#ifndef O3D_CORE_CROSS_BITMAP_H_ +#define O3D_CORE_CROSS_BITMAP_H_ + +#include <stdlib.h> + +#include "base/cross/bits.h" +#include "core/cross/types.h" +#include "core/cross/texture.h" + +class FilePath; + +namespace o3d { + +class MemoryReadStream; +class RawData; +class Pack; + +// Bitmap provides an API for basic image operations on bitmap images, +// including scale and crop. The contents of bitmap can be created from +// a RawData object via LoadFromRawData(), and also can be transfered +// to mip of a Texure2D or a specific face of TextureCUBE via methods +// in Texture. + +class Bitmap : public ParamObject { + public: + typedef SmartPointer<Bitmap> Ref; + + explicit Bitmap(ServiceLocator* service_locator); + virtual ~Bitmap() {} + + // We will fail to load images that are bigger than 4kx4k to avoid security + // risks. GPUs don't usually support bigger sizes anyway. + // The biggest bitmap buffer size with these dimensions is: + // 4k x 4k x 4xsizeof(float) x6 x4/3 (x6 for cube maps, x4/3 for mipmaps) + // That makes 2GB, representable in an unsigned int, so we will avoid wraps. + static const unsigned int kMaxImageDimension = 4096; + enum ImageFileType { + UNKNOWN, + TGA, + JPEG, + PNG, + DDS, + }; + + static bool CheckImageDimensions(unsigned int width, unsigned int height) { + return width > 0 && height > 0 && + width <= kMaxImageDimension && height < kMaxImageDimension; + } + + // Creates a copy of a bitmap, copying the pixels as well. + // Parameters: + // source: the source bitmap. + void CopyDeepFrom(const Bitmap &source) { + Allocate(source.format_, source.width_, source.height_, + source.num_mipmaps_, source.is_cubemap_); + memcpy(image_data(), source.image_data(), GetTotalSize()); + } + + // Sets the bitmap parameters from another bitmap, stealing the pixel buffer + // from the source bitmap. + // Parameters: + // source: the source bitmap. + void SetFrom(Bitmap *source) { + image_data_.reset(); + format_ = source->format_; + width_ = source->width_; + height_ = source->height_; + num_mipmaps_ = source->num_mipmaps_; + is_cubemap_ = source->is_cubemap_; + image_data_.swap(source->image_data_); + } + + // Allocates an uninitialized bitmap with specified parameters. + // Parameters: + // format: the format of the pixels. + // width: the width of the base image. + // height: the height of the base image. + // num_mipmaps: the number of mip-maps. + // cube_map: true if creating a cube map. + void Allocate(Texture::Format format, + unsigned int width, + unsigned int height, + unsigned int num_mipmaps, + bool cube_map); + + // Allocates a bitmap with initialized parameters. + // data is zero-initialized + void AllocateData() { + image_data_.reset(new unsigned char[GetTotalSize()]); + memset(image_data_.get(), 0, GetTotalSize()); + } + + // Frees the data owned by the bitmap. + void FreeData() { + image_data_.reset(NULL); + } + + // Gets the total size of the bitmap data, counting all faces and mip levels. + unsigned int GetTotalSize() { + return (is_cubemap_ ? 6 : 1) * + GetMipChainSize(width_, height_, format_, num_mipmaps_); + } + + // Computes the number of bytes of a texture pixel buffer. + static unsigned int GetBufferSize(unsigned int width, + unsigned int height, + Texture::Format format); + + // Gets the image data for a given mip-map level and cube map face. + // Parameters: + // level: mip level to get. + // face: face of cube to get. This parameter is ignored if + // this bitmap is not a cube map. + unsigned char *GetMipData(unsigned int level, + TextureCUBE::CubeFace face) const; + + unsigned char *image_data() const { return image_data_.get(); } + Texture::Format format() const { return format_; } + unsigned int width() const { return width_; } + unsigned int height() const { return height_; } + unsigned int num_mipmaps() const { return num_mipmaps_; } + bool is_cubemap() const { return is_cubemap_; } + + // Returns whether or not the dimensions of the bitmap are power-of-two. + bool IsPOT() const { + return ((width_ & (width_ - 1)) == 0) && ((height_ & (height_ - 1)) == 0); + } + + void set_format(Texture::Format format) { format_ = format; } + void set_width(unsigned int n) { width_ = n; } + void set_height(unsigned int n) { height_ = n; } + void set_num_mipmaps(unsigned int n) { num_mipmaps_ = n; } + void set_is_cubemap(bool is_cubemap) { is_cubemap_ = is_cubemap; } + + // Loads a bitmap from a file. + // Parameters: + // filename: the name of the file to load. + // file_type: the type of file to load. If UNKNOWN, the file type will be + // determined from the filename extension, and if it is not a + // known extension, all the loaders will be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromFile(const FilePath &filepath, + ImageFileType file_type, + bool generate_mipmaps); + + // Loads a bitmap from a RawData object. + // Parameters: + // raw_data: contains the bitmap data in one of the known formats + // file_type: the format of the bitmap data. If UNKNOWN, the file type + // will be determined from the extension from raw_data's uri + // and if it is not a known extension, all the loaders will + // be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromRawData(RawData *raw_data, + ImageFileType file_type, + bool generate_mipmaps); + + // Loads a bitmap from a MemoryReadStream. + // Parameters: + // stream: a stream for the bitmap data in one of the known formats + // filename: a filename (or uri) of the original bitmap data + // (may be an empty string) + // file_type: the format of the bitmap data. If UNKNOWN, the file type + // will be determined from the extension of |filename| + // and if it is not a known extension, all the loaders + // will be tried. + // generate_mipmaps: whether or not to generate all the mip-map levels. + bool LoadFromStream(MemoryReadStream *stream, + const String &filename, + ImageFileType file_type, + bool generate_mipmaps); + + bool LoadFromPNGStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromTGAStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromDDSStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + bool LoadFromJPEGStream(MemoryReadStream *stream, + const String &filename, + bool generate_mipmaps); + + // Saves to a PNG file. The image must be of the ARGB8 format, be a 2D image + // with no mip-maps (only the base level). + // Parameters: + // filename: the name of the file to into. + // Returns: + // true if successful. + bool SaveToPNGFile(const char* filename); + + // Checks that the alpha channel for the entire bitmap is 1.0 + bool CheckAlphaIsOne() const; + + // Copy pixels from source bitmap. Scales if the width and height of source + // and dest do not match. + // Parameters: + // source_img: source bitmap which would be drawn. + // source_x: x-coordinate of the starting pixel in the source image. + // source_x: y-coordinate of the starting pixel in the source image. + // source_width: width of the source image to draw. + // source_height: Height of the source image to draw. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the dest image to draw. + // dest_height: height of the dest image to draw. + void DrawImage(Bitmap* source_img, int source_x, int source_y, + int source_width, int source_height, + int dest_x, int dest_y, + int dest_width, int dest_height); + + // Crop part of an image from src, scale it to an arbitrary size + // and paste in dest image. Utility function for all DrawImage + // function in bitmap and textures. Scale operation is based on + // bilinear interpolation. + // Note: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // src: source image which would be copied from. + // src_x: x-coordinate of the starting pixel in the src image. + // src_y: y-coordinate of the starting pixel in the src image. + // src_width: width of the part in src image to be croped. + // src_height: height of the part in src image to be croped. + // src_img_width: width of the src image. + // src_img_height: height of the src image. + // dest: dest image which would be copied to. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the part in dest image to be pasted to. + // dest_height: height of the part in dest image to be pasted to. + // dest_img_width: width of the dest image. + // dest_img_height: height of the src image. + // component: size of each pixel in terms of array element. + // Returns: + // true if crop and scale succeeds. + static void BilinearInterpolateScale(const uint8* src, + int src_x, int src_y, + int src_width, int src_height, + int src_img_width, int src_img_height, + uint8* dest, + int dest_x, int dest_y, + int dest_width, int dest_height, + int dest_img_width, int dest_img_height, + int component); + + // Detects the type of image file based on the filename. + static ImageFileType GetFileTypeFromFilename(const char *filename); + // Detects the type of image file based on the mime-type. + static ImageFileType GetFileTypeFromMimeType(const char *mime_type); + + // Adds filler alpha byte (0xff) after every pixel. Assumes buffer was + // allocated with enough storage) + // can convert RGB -> RGBA, BGR -> BGRA, etc. + static void XYZToXYZA(unsigned char *image_data, int pixel_count); + + // Swaps Red and Blue components in the image. + static void RGBAToBGRA(unsigned char *image_data, int pixel_count); + + // Gets the number of mip-maps required for a full chain starting at + // width x height. + static unsigned int GetMipMapCount(unsigned int width, unsigned int height) { + return 1 + base::bits::Log2Floor(std::max(width, height)); + } + + // Gets the smallest power-of-two value that is at least as high as + // dimension. This is the POT dimension used in ScaleUpToPOT. + static unsigned int GetPOTSize(unsigned int dimension) { + return 1 << base::bits::Log2Ceiling(dimension); + } + + // Gets the size of the buffer containing a mip-map chain, given its base + // width, height, format and number of mip-map levels. + static unsigned int GetMipChainSize(unsigned int base_width, + unsigned int base_height, + Texture::Format format, + unsigned int num_mipmaps); + + // Generates mip-map levels for a single image, using the data from the base + // level. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // base_width: the width of the base image. + // base_height: the height of the base image. + // format: the format of the data. + // num_mipmaps: the number of mipmaps to generate. + // data: the data containing the base image, and enough space for the + // mip-maps. + static bool GenerateMipmaps(unsigned int base_width, + unsigned int base_height, + Texture::Format format, + unsigned int num_mipmaps, + unsigned char *data); + + // Scales an image up to power-of-two textures, using point filtering. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // width: the non-power-of-two width of the original image. + // height: the non-power-of-two height of the original image. + // format: the format of the data. + // src: the data containing the source data of the original image. + // dst: a buffer with enough space for the power-of-two version. Pixels are + // written from the end to the beginning so dst can be the same buffer as + // src. + static bool ScaleUpToPOT(unsigned int width, + unsigned int height, + Texture::Format format, + const unsigned char *src, + unsigned char *dst); + + // Scales an image to an arbitrary size, using point filtering. + // NOTE: this doesn't work for DXTC, or floating-point images. + // + // Parameters: + // src_width: the width of the original image. + // src_height: the height of the original image. + // format: the format of the data. + // src: the data containing the source data of the original image. + // dst_width: the width of the target image. + // dst_height: the height of the target image. + // dst: a buffer with enough space for the target version. Pixels are + // written from the end to the beginning so dst can be the same buffer as + // src if the transformation is an upscaling. + static bool Scale(unsigned int src_width, + unsigned int src_height, + Texture::Format format, + const unsigned char *src, + unsigned int dst_width, + unsigned int dst_height, + unsigned char *dst); + + // adjust start points and boundaries when using DrawImage data + // in bitmap and textures. + // Parameters: + // src_x: x-coordinate of the starting pixel in the source image. + // src_y: y-coordinate of the starting pixel in the source image. + // src_width: width of the source image to draw. + // src_height: height of the source image to draw. + // src_bmp_width: original width of source bitmap. + // src_bmp_height: original height of source bitmap. + // dest_x: x-coordinate of the starting pixel in the dest image. + // dest_y: y-coordinate of the starting pixel in the dest image. + // dest_width: width of the dest image to draw. + // dest_height: height of the dest image to draw. + // dest_bmp_width: original width of dest bitmap. + // dest_bmp_height: original height of dest bitmap. + // Returns: + // false if src or dest rectangle is out of boundaries. + static bool AdjustDrawImageBoundary(int* src_x, int* src_y, + int* src_width, int* src_height, + int src_bmp_width, int src_bmp_height, + int* dest_x, int* dest_y, + int* dest_width, int* dest_height, + int dest_bmp_width, int dest_bmp_height); + + private: + friend class IClassManager; + static ObjectBase::Ref Create(ServiceLocator* service_locator); + + // pointer to the raw bitmap data + scoped_array<uint8> image_data_; + // format of the texture this is meant to represent. + Texture::Format format_; + // width of the bitmap in pixels. + int width_; + // height of the bitmap in pixels. + int height_; + // number of mipmap levels in this texture. + unsigned int num_mipmaps_; + // is this cube-map data + bool is_cubemap_; + + // utility function used in AdjustDrawImageBoundary. + // It adjusts start point and related measures + // for a specific dimension. + // Parameter: + // src_a: the coordinate which is negative. + // dest_a: same coordinate in the other image. + // src_length: length measure of source image to draw. + // dest_length: length measure of dest image to draw. + // src_bmp_length: length measure of src image. + // Returns: + // true if adjust is successful. + static bool AdjustDrawImageBoundHelper(int* src_a, int* dest_a, + int* src_length, int* dest_length, + int src_bmp_length); + + O3D_DECL_CLASS(Bitmap, ParamObject); + DISALLOW_COPY_AND_ASSIGN(Bitmap); +}; + +} // namespace o3d + +#endif // O3D_CORE_CROSS_BITMAP_H_ diff --git a/o3d/core/cross/bitmap_dds.cc b/o3d/core/cross/bitmap_dds.cc index eea1934..a4f9491 100644 --- a/o3d/core/cross/bitmap_dds.cc +++ b/o3d/core/cross/bitmap_dds.cc @@ -176,7 +176,7 @@ static void FlipDXTCImage(unsigned int width, unsigned char *data) { DCHECK(Bitmap::CheckImageDimensions(width, height)); // Height must be a power-of-two. - DCHECK_EQ(height & (height - 1), 0); + DCHECK_EQ(height & (height - 1), 0u); FlipBlockFunction full_block_function = NULL; FlipBlockFunction half_block_function = NULL; unsigned int block_bytes = 0; @@ -341,7 +341,7 @@ bool Bitmap::LoadFromDDSStream(MemoryReadStream *stream, // The size of the buffer needed to hold four-component per pixel // image data, including MIPMaps - int components_per_pixel = 0; + unsigned int components_per_pixel = 0; bool add_filler_alpha = false; bool rgb_to_bgr = false; @@ -478,10 +478,10 @@ bool Bitmap::LoadFromDDSStream(MemoryReadStream *stream, unsigned char *data = image_data.get() + face_size * face; // convert to four components per pixel if necessary if (add_filler_alpha) { - DCHECK_EQ(components_per_pixel, 3); + DCHECK_EQ(components_per_pixel, 3u); XYZToXYZA(data, pixel_count); } else { - DCHECK_EQ(components_per_pixel, 4); + DCHECK_EQ(components_per_pixel, 4u); } if (rgb_to_bgr) RGBAToBGRA(data, pixel_count); diff --git a/o3d/core/cross/bitmap_png.cc b/o3d/core/cross/bitmap_png.cc index ea8a9ac..38f5afe 100644 --- a/o3d/core/cross/bitmap_png.cc +++ b/o3d/core/cross/bitmap_png.cc @@ -199,7 +199,7 @@ bool Bitmap::LoadFromPNGStream(MemoryReadStream *stream, // Turn on interlace handling. REQURIED if you are not using // png_read_image(). To see how to handle interlacing passes, // see the png_read_row() method below: - int png_number_passes = png_set_interlace_handling(png_ptr); + png_set_interlace_handling(png_ptr); // Execute any setup steps for each Transform, i.e. to gamma correct and // add the background to the palette and update info structure. REQUIRED @@ -299,7 +299,7 @@ bool Bitmap::SaveToPNGFile(const char* filename) { } scoped_array<png_bytep> row_pointers(new png_bytep[height_]); - for (unsigned int i = 0; i < height_; ++i) { + for (int i = 0; i < height_; ++i) { row_pointers[height_-1-i] = image_data_.get() + i * width_ * 4; } diff --git a/o3d/core/cross/bounding_box.h b/o3d/core/cross/bounding_box.h index 8ce0c28..d83feb7 100644 --- a/o3d/core/cross/bounding_box.h +++ b/o3d/core/cross/bounding_box.h @@ -50,7 +50,7 @@ class RayIntersectionInfo; class BoundingBox { public: // Constructs an uninitialized BoundingBox marking it as non valid. - BoundingBox() : min_extent_(0, 0, 0), max_extent_(0, 0, 0), valid_(false) { } + BoundingBox() : valid_(false), min_extent_(0, 0, 0), max_extent_(0, 0, 0) { } // Constructs a BoundingBox. // Parameters: diff --git a/o3d/core/cross/buffer.cc b/o3d/core/cross/buffer.cc index 7d4ced1..ba2eb0a 100644 --- a/o3d/core/cross/buffer.cc +++ b/o3d/core/cross/buffer.cc @@ -100,11 +100,11 @@ static FieldCreator g_creators[] = { Buffer::Buffer(ServiceLocator* service_locator) : NamedObject(service_locator), features_(service_locator->GetService<Features>()), - access_mode_(NONE), field_change_count_(0), total_components_(0), stride_(0), num_elements_(0), + access_mode_(NONE), lock_count_(0) { } @@ -474,7 +474,7 @@ bool Buffer::Set(o3d::RawData *raw_data, // Lock before reading in all the fields to avoid locking/unlocking // for each field which would be slower o3d::BufferLockHelper helper(this); - void *buffer_data = helper.GetData(o3d::Buffer::WRITE_ONLY); + helper.GetData(o3d::Buffer::WRITE_ONLY); // Read each field for (int32 ff = 0; ff < num_fields; ++ff) { diff --git a/o3d/core/cross/canvas_paint.cc b/o3d/core/cross/canvas_paint.cc index 3e37877..e5ad327 100644 --- a/o3d/core/cross/canvas_paint.cc +++ b/o3d/core/cross/canvas_paint.cc @@ -95,7 +95,7 @@ class StrokeDrawLooper : public SkDrawLooper { }; StrokeDrawLooper::StrokeDrawLooper(SkScalar radius, SkColor color) - : fColor(color), fRadius(radius) { + : fRadius(radius), fColor(color) { } void StrokeDrawLooper::init(SkCanvas* canvas, SkPaint* paint) { @@ -175,17 +175,17 @@ CanvasPaint::CanvasPaint(ServiceLocator* service_locator) : ParamObject(service_locator), shader_(NULL), needs_update_(true), - color_(Float4(0, 0, 0, 1)), text_align_(LEFT), + color_(Float4(0, 0, 0, 1)), text_size_(10), + text_typeface_(""), + text_style_(NORMAL), + outline_radius_(0), + outline_color_(Float4(0, 0, 0, 1)), shadow_radius_(0), - shadow_color_(Float4(0, 0, 0, 1)), shadow_offset_x_(0), shadow_offset_y_(0), - outline_radius_(0), - outline_color_(Float4(0, 0, 0, 1)), - text_style_(NORMAL), - text_typeface_("") { + shadow_color_(Float4(0, 0, 0, 1)) { sk_paint_.setAntiAlias(true); } diff --git a/o3d/core/cross/client.cc b/o3d/core/cross/client.cc index e0fec9e..b6b103c 100644 --- a/o3d/core/cross/client.cc +++ b/o3d/core/cross/client.cc @@ -70,20 +70,20 @@ namespace o3d { Client::Client(ServiceLocator* service_locator) : service_locator_(service_locator), object_manager_(service_locator), - profiler_(service_locator), error_status_(service_locator), draw_list_manager_(service_locator), counter_manager_(service_locator), transformation_context_(service_locator), semantic_manager_(service_locator), - rendering_(false), - render_tree_called_(false), + profiler_(service_locator), renderer_(service_locator), evaluation_counter_(service_locator), - event_manager_(), - root_(NULL), + rendering_(false), + render_tree_called_(false), render_mode_(RENDERMODE_CONTINUOUS), + event_manager_(), last_tick_time_(0), + root_(NULL), #ifdef OS_WIN calls_(0), #endif diff --git a/o3d/core/cross/display_mode.h b/o3d/core/cross/display_mode.h index 722463a..e663803 100644 --- a/o3d/core/cross/display_mode.h +++ b/o3d/core/cross/display_mode.h @@ -46,11 +46,11 @@ namespace o3d { class DisplayMode { public: DisplayMode() - : valid_(false), - width_(0), + : width_(0), height_(0), refresh_rate_(0), - id_(-1) { // Since this is platform-specific, -1 may well be valid. + id_(-1), // Since this is platform-specific, -1 may well be valid. + valid_(false) { } void Set(int w, int h, int r, int i) { width_ = w; diff --git a/o3d/core/cross/gl/buffer_gl.cc b/o3d/core/cross/gl/buffer_gl.cc index fd65306..916fd245 100644 --- a/o3d/core/cross/gl/buffer_gl.cc +++ b/o3d/core/cross/gl/buffer_gl.cc @@ -57,6 +57,8 @@ GLenum BufferAccessModeToGLenum(Buffer::AccessMode access_mode) { return GL_WRITE_ONLY_ARB; case Buffer::READ_WRITE: return GL_READ_WRITE_ARB; + case Buffer::NONE: + break; } DCHECK(false); return GL_READ_WRITE_ARB; diff --git a/o3d/core/cross/gl/param_cache_gl.cc b/o3d/core/cross/gl/param_cache_gl.cc index c950f3f..28941a5 100644 --- a/o3d/core/cross/gl/param_cache_gl.cc +++ b/o3d/core/cross/gl/param_cache_gl.cc @@ -326,7 +326,6 @@ class EffectParamArraySamplerHandlerGL : public EffectParamHandlerGL { for (int i = 0; i < size; ++i) { Param* untyped_element = param->GetUntypedParam(i); if (untyped_element->IsA(ParamSampler::GetApparentClass())) { - CGparameter cg_element = cgGetArrayParameter(cg_param, i); ParamSampler* element = down_cast<ParamSampler*>(untyped_element); SamplerGL* sampler_gl = down_cast<SamplerGL*>(element->value()); if (!sampler_gl) { @@ -458,6 +457,8 @@ static EffectParamHandlerGL::Ref GetHandlerFromParamAndCgType( handler = EffectParamHandlerGL::Ref( new EffectParamArraySamplerHandlerGL(param_param_array)); break; + default: + break; } } else if (param->IsA(ParamMatrix4::GetApparentClass())) { if (cg_type == CG_FLOAT4x4) { diff --git a/o3d/core/cross/gl/primitive_gl.cc b/o3d/core/cross/gl/primitive_gl.cc index 99d637f..8207792 100644 --- a/o3d/core/cross/gl/primitive_gl.cc +++ b/o3d/core/cross/gl/primitive_gl.cc @@ -250,7 +250,7 @@ void PrimitiveGL::Render(Renderer* renderer, } } if (draw) { - DCHECK_NE(gl_primitive_type, GL_NONE); + DCHECK_NE(gl_primitive_type, static_cast<unsigned int>(GL_NONE)); renderer->AddPrimitivesRendered(number_primitives_); if (indexed()) glDrawElements(gl_primitive_type, diff --git a/o3d/core/cross/gl/renderer_gl.cc b/o3d/core/cross/gl/renderer_gl.cc index dbd34fd..b7197b5 100644 --- a/o3d/core/cross/gl/renderer_gl.cc +++ b/o3d/core/cross/gl/renderer_gl.cc @@ -528,19 +528,19 @@ RendererGL* RendererGL::CreateDefault(ServiceLocator* service_locator) { RendererGL::RendererGL(ServiceLocator* service_locator) : Renderer(service_locator), semantic_manager_(service_locator), -#ifdef OS_MACOSX - mac_agl_context_(0), - mac_cgl_context_(0), -#endif #ifdef OS_WIN gl_context_(NULL), #endif + fullscreen_(0), #ifdef OS_LINUX display_(NULL), window_(0), context_(0), #endif - fullscreen_(0), +#ifdef OS_MACOSX + mac_agl_context_(0), + mac_cgl_context_(0), +#endif render_surface_framebuffer_(0), cg_context_(NULL), alpha_function_ref_changed_(true), diff --git a/o3d/core/cross/gl/sampler_gl.cc b/o3d/core/cross/gl/sampler_gl.cc index 389602f..c64569c 100644 --- a/o3d/core/cross/gl/sampler_gl.cc +++ b/o3d/core/cross/gl/sampler_gl.cc @@ -96,6 +96,8 @@ unsigned int GLMinFilter(Sampler::FilterType o3d_filter, else if (mip_filter == Sampler::LINEAR) return GL_LINEAR_MIPMAP_LINEAR; } + DCHECK(false); + return GL_NONE; } unsigned int GLMagFilter(Sampler::FilterType o3d_filter) { diff --git a/o3d/core/cross/gl/texture_gl.cc b/o3d/core/cross/gl/texture_gl.cc index d4b767f..3238208 100644 --- a/o3d/core/cross/gl/texture_gl.cc +++ b/o3d/core/cross/gl/texture_gl.cc @@ -135,6 +135,8 @@ static GLenum GLFormatFromO3DFormat(Texture::Format format, return 0; } } + case Texture::UNKNOWN_FORMAT: + break; } // failed to find a matching format LOG(ERROR) << "Unrecognized Texture format type."; @@ -269,8 +271,8 @@ Texture2DGL::Texture2DGL(ServiceLocator* service_locator, renderer_(static_cast<RendererGL*>( service_locator->GetService<Renderer>())), gl_texture_(texture), - has_levels_(0), - backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))) { + backing_bitmap_(Bitmap::Ref(new Bitmap(service_locator))), + has_levels_(0) { DLOG(INFO) << "Texture2DGL Construct from GLint"; DCHECK_NE(format(), Texture::UNKNOWN_FORMAT); } @@ -355,10 +357,10 @@ Texture2DGL* Texture2DGL::Create(ServiceLocator* service_locator, } void Texture2DGL::UpdateBackedMipLevel(unsigned int level) { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap_->image_data()); - DCHECK_EQ(backing_bitmap_->width(), width()); - DCHECK_EQ(backing_bitmap_->height(), height()); + DCHECK_EQ(backing_bitmap_->width(), static_cast<unsigned int>(width())); + DCHECK_EQ(backing_bitmap_->height(), static_cast<unsigned int>(height())); DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level)); glBindTexture(GL_TEXTURE_2D, gl_texture_); @@ -394,7 +396,7 @@ bool Texture2DGL::Lock(int level, void** data) { return false; } if (!backing_bitmap_->image_data()) { - DCHECK_EQ(has_levels_, 0); + DCHECK_EQ(has_levels_, 0u); backing_bitmap_->Allocate(format(), width(), height(), levels(), false); } *data = backing_bitmap_->GetMipData(level, TextureCUBE::FACE_POSITIVE_X); @@ -605,11 +607,12 @@ TextureCUBEGL* TextureCUBEGL::Create(ServiceLocator* service_locator, void TextureCUBEGL::UpdateBackedMipLevel(unsigned int level, TextureCUBE::CubeFace face) { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); DCHECK(backing_bitmap_->image_data()); DCHECK(backing_bitmap_->is_cubemap()); - DCHECK_EQ(backing_bitmap_->width(), edge_length()); - DCHECK_EQ(backing_bitmap_->height(), edge_length()); + DCHECK_EQ(backing_bitmap_->width(), static_cast<unsigned int>(edge_length())); + DCHECK_EQ(backing_bitmap_->height(), + static_cast<unsigned int>(edge_length())); DCHECK_EQ(backing_bitmap_->format(), format()); DCHECK(HasLevel(level, face)); glBindTexture(GL_TEXTURE_2D, gl_texture_); @@ -672,7 +675,7 @@ bool TextureCUBEGL::Lock(CubeFace face, int level, void** data) { } if (!backing_bitmap_->image_data()) { for (unsigned int i = 0; i < 6; ++i) { - DCHECK_EQ(has_levels_[i], 0); + DCHECK_EQ(has_levels_[i], 0u); } backing_bitmap_->Allocate(format(), edge_length(), edge_length(), levels(), true); diff --git a/o3d/core/cross/gl/texture_gl.h b/o3d/core/cross/gl/texture_gl.h index cb76660..a647d47 100644 --- a/o3d/core/cross/gl/texture_gl.h +++ b/o3d/core/cross/gl/texture_gl.h @@ -119,7 +119,7 @@ class Texture2DGL : public Texture2D { // Returns true if the backing bitmap has the data for the level. bool HasLevel(unsigned int level) const { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); return (has_levels_ & (1 << level)) != 0; } @@ -196,7 +196,7 @@ class TextureCUBEGL : public TextureCUBE { // Returns true if the backing bitmap has the data for the level. bool HasLevel(unsigned int level, CubeFace face) const { - DCHECK_LT(level, levels()); + DCHECK_LT(static_cast<int>(level), levels()); return (has_levels_[face] & (1 << level)) != 0; } diff --git a/o3d/core/cross/gl/utils_gl.cc b/o3d/core/cross/gl/utils_gl.cc index f37a8c8..46b5a71c 100644 --- a/o3d/core/cross/gl/utils_gl.cc +++ b/o3d/core/cross/gl/utils_gl.cc @@ -194,7 +194,7 @@ Stream::Semantic GLVertexAttributeToStream(const unsigned int attr, // // TODO: make this a runtime provided value discovered during // Renderer creation. - const int kMaxAttrIndex = 15; + const unsigned int kMaxAttrIndex = 15u; if (attr > kMaxAttrIndex) { //TODO: Figure out how to get errors out of here to the client. DLOG(ERROR) << "Invalid vertex attribute index."; diff --git a/o3d/core/cross/message_queue.cc b/o3d/core/cross/message_queue.cc index b36d1e9..17e981d 100644 --- a/o3d/core/cross/message_queue.cc +++ b/o3d/core/cross/message_queue.cc @@ -296,7 +296,7 @@ bool MessageQueue::ReceiveMessageFromSocket(nacl::Handle socket, #endif // Valid messages must always contain at least the ID of the message - if (message_length >= sizeof(*message_id)) { + if (message_length >= static_cast<int>(sizeof(*message_id))) { // Check if the incoming message requires more space than we have // currently allocated. if (header->flags & nacl::kMessageTruncated) { diff --git a/o3d/core/cross/pack.cc b/o3d/core/cross/pack.cc index 87c64be8..dee5b87 100644 --- a/o3d/core/cross/pack.cc +++ b/o3d/core/cross/pack.cc @@ -168,8 +168,8 @@ Texture* Pack::CreateTextureFromBitmap(Bitmap *bitmap, const String& uri) { return NULL; } - if (bitmap->width() > Texture::MAX_DIMENSION || - bitmap->height() > Texture::MAX_DIMENSION) { + if (bitmap->width() > static_cast<unsigned int>(Texture::MAX_DIMENSION) || + bitmap->height() > static_cast<unsigned int>(Texture::MAX_DIMENSION)) { O3D_ERROR(service_locator()) << "Texture (uri='" << uri << "', size=" << bitmap->width() << "x" << bitmap->height() @@ -281,8 +281,8 @@ Texture2D* Pack::CreateTexture2D(int width, } if (enable_render_surfaces) { - if (Bitmap::GetPOTSize(width) != width || - Bitmap::GetPOTSize(height) != height) { + if (Bitmap::GetPOTSize(width) != static_cast<unsigned int>(width) || + Bitmap::GetPOTSize(height) != static_cast<unsigned int>(height)) { O3D_ERROR(service_locator()) << "Textures with RenderSurfaces enabled must have power-of-two " "dimensions."; @@ -322,7 +322,8 @@ TextureCUBE* Pack::CreateTextureCUBE(int edge_length, if (enable_render_surfaces) { - if (Bitmap::GetPOTSize(edge_length) != edge_length) { + if (Bitmap::GetPOTSize(edge_length) != + static_cast<unsigned int>(edge_length)) { O3D_ERROR(service_locator()) << "Textures with RenderSurfaces enabled must have power-of-two " "dimensions."; @@ -358,8 +359,8 @@ RenderDepthStencilSurface* Pack::CreateDepthStencilSurface(int width, return NULL; } - if (Bitmap::GetPOTSize(width) != width || - Bitmap::GetPOTSize(height) != height) { + if (Bitmap::GetPOTSize(width) != static_cast<unsigned int>(width) || + Bitmap::GetPOTSize(height) != static_cast<unsigned int>(height)) { O3D_ERROR(service_locator()) << "Depth-stencil RenderSurfaces must have power-of-two dimensions."; return NULL; diff --git a/o3d/core/cross/renderer.cc b/o3d/core/cross/renderer.cc index 86407e6..fe80a1a 100644 --- a/o3d/core/cross/renderer.cc +++ b/o3d/core/cross/renderer.cc @@ -93,10 +93,7 @@ bool IsSupportedTextureFormat(Texture::Format format, } // anonymous namespace Renderer::Renderer(ServiceLocator* service_locator) - : service_locator_(service_locator), - service_(service_locator, this), - features_(service_locator), - supports_npot_(false), + : supports_npot_(false), clear_client_(true), need_to_render_(true), current_render_surface_(NULL), @@ -108,12 +105,15 @@ Renderer::Renderer(ServiceLocator* service_locator) draw_elements_culled_(0), draw_elements_rendered_(0), primitives_rendered_(0), + viewport_(0.0f, 0.0f, 1.0f, 1.0f), + depth_range_(0.0f, 1.0f), + service_locator_(service_locator), + service_(service_locator, this), + features_(service_locator), width_(0), height_(0), render_width_(0), render_height_(0), - viewport_(0.0f, 0.0f, 1.0f, 1.0f), - depth_range_(0.0f, 1.0f), dest_x_offset_(0), dest_y_offset_(0) { } @@ -391,7 +391,7 @@ void Renderer::SetInitialStates() { it != state_handler_map_.end(); ++it) { StateHandler *state_handler = it->second; ParamVector& param_stack = state_param_stacks_[state_handler->index()]; - DCHECK_EQ(param_stack.size(), 1); + DCHECK_EQ(param_stack.size(), 1u); state_handler->SetState(this, param_stack[0]); } } @@ -539,7 +539,7 @@ void Renderer::AddDefaultStates() { } void Renderer::RemoveDefaultStates() { - DCHECK_EQ(state_stack_.size(), 1); + DCHECK_EQ(state_stack_.size(), 1u); DCHECK(state_stack_[0] == default_state_); state_stack_.clear(); const NamedParamRefMap& param_map = default_state_->params(); @@ -551,7 +551,7 @@ void Renderer::RemoveDefaultStates() { const StateHandler* state_handler = GetStateHandler(param); DCHECK(state_handler); ParamVector& param_stack = state_param_stacks_[state_handler->index()]; - DCHECK_EQ(param_stack.size(), 1); + DCHECK_EQ(param_stack.size(), 1u); DCHECK(param_stack[0] == param); param_stack.clear(); } diff --git a/o3d/core/cross/shape.cc b/o3d/core/cross/shape.cc index 0d3711d..d4822e4 100644 --- a/o3d/core/cross/shape.cc +++ b/o3d/core/cross/shape.cc @@ -78,7 +78,7 @@ ElementArray Shape::GetElements() const { void Shape::SetElements(const ElementArray& elements) { elements_.resize(elements.size()); - for (int i = 0; i != elements.size(); ++i) { + for (unsigned int i = 0; i != elements.size(); ++i) { elements_[i] = Element::Ref(elements[i]); } } diff --git a/o3d/core/cross/skin.cc b/o3d/core/cross/skin.cc index 7a29109..507ae09 100644 --- a/o3d/core/cross/skin.cc +++ b/o3d/core/cross/skin.cc @@ -48,10 +48,10 @@ const char *Skin::kSerializationID = "SKIN"; Skin::Skin(ServiceLocator* service_locator) : NamedObject(service_locator), - weak_pointer_manager_(this), highest_matrix_index_(0), highest_influences_(0), - info_valid_(false) { + info_valid_(false), + weak_pointer_manager_(this) { } const Skin::Influences* Skin::GetVertexInfluences(unsigned vertex_index) const { @@ -114,12 +114,12 @@ ObjectBase::Ref Skin::Create(ServiceLocator* service_locator) { } SkinEval::StreamInfo::StreamInfo() - : data_(NULL), - buffer_(NULL), - values_(NULL), - stride_(0), - compute_function_(NULL), - copy_function_(NULL) { + : compute_function_(NULL), + copy_function_(NULL), + data_(NULL), + buffer_(NULL), + values_(NULL), + stride_(0) { } namespace { diff --git a/o3d/core/cross/stream_bank.h b/o3d/core/cross/stream_bank.h index 8e1df1a..4d9af76 100644 --- a/o3d/core/cross/stream_bank.h +++ b/o3d/core/cross/stream_bank.h @@ -143,7 +143,7 @@ class StreamBank : public NamedObject { } virtual void OnAfterUnbindInput(Param* old_source) { - master_->number_binds_; + --master_->number_binds_; } private: diff --git a/o3d/core/cross/texture.cc b/o3d/core/cross/texture.cc index 88897c3..0cc784f 100644 --- a/o3d/core/cross/texture.cc +++ b/o3d/core/cross/texture.cc @@ -96,8 +96,8 @@ void Texture2D::DrawImage(Bitmap* src_img, int dst_width, int dst_height, int dest_mip) { DCHECK(src_img->image_data()); - int mip_width = std::max(1, width() >> dest_mip); - int mip_height = std::max(1, height() >> dest_mip); + unsigned int mip_width = std::max(1, width() >> dest_mip); + unsigned int mip_height = std::max(1, height() >> dest_mip); // Clip source and destination rectangles to // source and destination bitmaps. @@ -123,8 +123,10 @@ void Texture2D::DrawImage(Bitmap* src_img, // the entire bitmap on dest image, just perform memcpy. if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && src_img->width() == mip_width && src_img->height() == mip_height && - src_width == src_img->width() && src_height == src_img->height() && - dst_width == mip_width && dst_height == mip_height) { + static_cast<unsigned int>(src_width) == src_img->width() && + static_cast<unsigned int>(src_height) == src_img->height() && + static_cast<unsigned int>(dst_width) == mip_width && + static_cast<unsigned int>(dst_height) == mip_height) { void* data = NULL; if (!Lock(dest_mip, &data)) return; @@ -248,7 +250,7 @@ void TextureCUBE::DrawImage(Bitmap* src_img, CubeFace dest_face, int dest_mip) { DCHECK(src_img->image_data()); - int mip_length = std::max(1, edge_length() >> dest_mip); + unsigned int mip_length = std::max(1, edge_length() >> dest_mip); // Clip source and destination rectangles to // source and destination bitmaps. @@ -274,8 +276,10 @@ void TextureCUBE::DrawImage(Bitmap* src_img, // the entire bitmap on dest image, just perform memcpy. if (src_x == 0 && src_y == 0 && dst_x == 0 && dst_y == 0 && src_img->width() == mip_length && src_img->height() == mip_length && - src_width == src_img->width() && src_height == src_img->height() && - dst_width == mip_length && dst_height == mip_length) { + static_cast<unsigned int>(src_width) == src_img->width() && + static_cast<unsigned int>(src_height) == src_img->height() && + static_cast<unsigned int>(dst_width) == mip_length && + static_cast<unsigned int>(dst_height) == mip_length) { // get mip data by lock method. void* data = NULL; if (!Lock(dest_face, dest_mip, &data)) diff --git a/o3d/core/cross/transform.cc b/o3d/core/cross/transform.cc index 31fb5f0..2157a26 100644 --- a/o3d/core/cross/transform.cc +++ b/o3d/core/cross/transform.cc @@ -320,7 +320,7 @@ ShapeArray Transform::GetShapes() const { void Transform::SetShapes(const ShapeArray& shapes) { shape_array_.resize(shapes.size()); - for (int i = 0; i != shapes.size(); ++i) { + for (unsigned int i = 0; i != shapes.size(); ++i) { shape_array_[i] = Shape::Ref(shapes[i]); } } |