| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return NULL; | 128 return NULL; |
| 129 } | 129 } |
| 130 | 130 |
| 131 String filename = FilePathToUTF8(filepath); | 131 String filename = FilePathToUTF8(filepath); |
| 132 | 132 |
| 133 DLOG(INFO) << "CreateTextureFromFile(uri='" << uri | 133 DLOG(INFO) << "CreateTextureFromFile(uri='" << uri |
| 134 << "', filename='" << filename << "')"; | 134 << "', filename='" << filename << "')"; |
| 135 | 135 |
| 136 // TODO: Add support for volume texture when we have code to load | 136 // TODO: Add support for volume texture when we have code to load |
| 137 // them | 137 // them |
| 138 Bitmap bitmap; | 138 Bitmap::Ref bitmap(new Bitmap(service_locator())); |
| 139 if (!bitmap.LoadFromFile(filepath, file_type, generate_mipmaps)) { | 139 if (!bitmap->LoadFromFile(filepath, file_type, generate_mipmaps)) { |
| 140 O3D_ERROR(service_locator()) | 140 O3D_ERROR(service_locator()) |
| 141 << "Failed to load bitmap file \"" << uri << "\""; | 141 << "Failed to load bitmap file \"" << uri << "\""; |
| 142 return NULL; | 142 return NULL; |
| 143 } | 143 } |
| 144 | 144 |
| 145 return CreateTextureFromBitmap(&bitmap, uri); | 145 return CreateTextureFromBitmap(bitmap, uri); |
| 146 } | 146 } |
| 147 | 147 |
| 148 // Creates a Texture object from a file in the current render context format. | 148 // Creates a Texture object from a file in the current render context format. |
| 149 // This version takes a String |filename| argument instead of the preferred | 149 // This version takes a String |filename| argument instead of the preferred |
| 150 // FilePath argument. The use of this method should be phased out | 150 // FilePath argument. The use of this method should be phased out |
| 151 Texture* Pack::CreateTextureFromFile(const String& uri, | 151 Texture* Pack::CreateTextureFromFile(const String& uri, |
| 152 const String& filename, | 152 const String& filename, |
| 153 Bitmap::ImageFileType file_type, | 153 Bitmap::ImageFileType file_type, |
| 154 bool generate_mipmaps) { | 154 bool generate_mipmaps) { |
| 155 FilePath filepath = UTF8ToFilePath(filename); | 155 FilePath filepath = UTF8ToFilePath(filename); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } else { | 191 } else { |
| 192 O3D_ERROR(service_locator()) | 192 O3D_ERROR(service_locator()) |
| 193 << "Unable to create texture (uri='" << uri | 193 << "Unable to create texture (uri='" << uri |
| 194 << "', size=" << bitmap->width() << "x" << bitmap->height() | 194 << "', size=" << bitmap->width() << "x" << bitmap->height() |
| 195 << ", mips=" << bitmap->num_mipmaps()<< ")"; | 195 << ", mips=" << bitmap->num_mipmaps()<< ")"; |
| 196 } | 196 } |
| 197 | 197 |
| 198 return texture.Get(); | 198 return texture.Get(); |
| 199 } | 199 } |
| 200 | 200 |
| 201 | |
| 202 // Creates a Texture object from RawData and allocates | 201 // Creates a Texture object from RawData and allocates |
| 203 // the necessary resources for it. | 202 // the necessary resources for it. |
| 204 Texture* Pack::CreateTextureFromRawData(RawData *raw_data, | 203 Texture* Pack::CreateTextureFromRawData(RawData *raw_data, |
| 205 bool generate_mips) { | 204 bool generate_mips) { |
| 206 if (!renderer_) { | 205 if (!renderer_) { |
| 207 O3D_ERROR(service_locator()) << "No Render Device Available"; | 206 O3D_ERROR(service_locator()) << "No Render Device Available"; |
| 208 return NULL; | 207 return NULL; |
| 209 } | 208 } |
| 210 | 209 |
| 211 const String uri = raw_data->uri(); | 210 const String uri = raw_data->uri(); |
| 212 | 211 |
| 213 DLOG(INFO) << "CreateTextureFromRawData(uri='" << uri << "')"; | 212 DLOG(INFO) << "CreateTextureFromRawData(uri='" << uri << "')"; |
| 214 | 213 |
| 215 | 214 |
| 216 Bitmap bitmap; | 215 Bitmap::Ref bitmap(new Bitmap(service_locator())); |
| 217 if (!bitmap.LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) { | 216 if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN, generate_mips)) { |
| 218 O3D_ERROR(service_locator()) | 217 O3D_ERROR(service_locator()) |
| 219 << "Failed to load bitmap from raw data \"" << uri << "\""; | 218 << "Failed to load bitmap from raw data \"" << uri << "\""; |
| 220 return NULL; | 219 return NULL; |
| 221 } | 220 } |
| 222 | 221 |
| 223 return CreateTextureFromBitmap(&bitmap, uri); | 222 return CreateTextureFromBitmap(bitmap, uri); |
| 223 } |
| 224 |
| 225 // Create a bitmap object. |
| 226 Bitmap* Pack::CreateBitmap(int width, int height, |
| 227 Texture::Format format) { |
| 228 DCHECK(Bitmap::CheckImageDimensions(width, height)); |
| 229 |
| 230 Bitmap::Ref bitmap(new Bitmap(service_locator())); |
| 231 if (bitmap.IsNull()) { |
| 232 O3D_ERROR(service_locator()) |
| 233 << "Failed to create bitmap object."; |
| 234 return NULL; |
| 235 } |
| 236 bitmap->Allocate(format, width, height, 1, false); |
| 237 if (!bitmap->image_data()) { |
| 238 O3D_ERROR(service_locator()) |
| 239 << "Failed to allocate memory for bitmap."; |
| 240 return NULL; |
| 241 } |
| 242 RegisterObject(bitmap); |
| 243 return bitmap.Get(); |
| 244 } |
| 245 |
| 246 // Create a new bitmap object from rawdata. |
| 247 Bitmap* Pack::CreateBitmapFromRawData(RawData* raw_data) { |
| 248 Bitmap::Ref bitmap(new Bitmap(service_locator())); |
| 249 if (bitmap.IsNull()) { |
| 250 O3D_ERROR(service_locator()) |
| 251 << "Failed to create bitmap object."; |
| 252 return NULL; |
| 253 } |
| 254 if (!bitmap->LoadFromRawData(raw_data, Bitmap::UNKNOWN, |
| 255 false)) { |
| 256 O3D_ERROR(service_locator()) |
| 257 << "Failed to load bitmap from raw data."; |
| 258 return NULL; |
| 259 } |
| 260 RegisterObject(bitmap); |
| 261 return bitmap.Get(); |
| 224 } | 262 } |
| 225 | 263 |
| 226 // Creates a Texture2D object and allocates the necessary resources for it. | 264 // Creates a Texture2D object and allocates the necessary resources for it. |
| 227 Texture2D* Pack::CreateTexture2D(int width, | 265 Texture2D* Pack::CreateTexture2D(int width, |
| 228 int height, | 266 int height, |
| 229 Texture::Format format, | 267 Texture::Format format, |
| 230 int levels, | 268 int levels, |
| 231 bool enable_render_surfaces) { | 269 bool enable_render_surfaces) { |
| 232 if (!renderer_) { | 270 if (!renderer_) { |
| 233 O3D_ERROR(service_locator()) << "No Render Device Available"; | 271 O3D_ERROR(service_locator()) << "No Render Device Available"; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 426 |
| 389 bool Pack::UnregisterObject(ObjectBase *object) { | 427 bool Pack::UnregisterObject(ObjectBase *object) { |
| 390 ObjectSet::iterator find(owned_objects_.find(ObjectBase::Ref(object))); | 428 ObjectSet::iterator find(owned_objects_.find(ObjectBase::Ref(object))); |
| 391 if (find == owned_objects_.end()) | 429 if (find == owned_objects_.end()) |
| 392 return false; | 430 return false; |
| 393 | 431 |
| 394 owned_objects_.erase(find); | 432 owned_objects_.erase(find); |
| 395 return true; | 433 return true; |
| 396 } | 434 } |
| 397 } // namespace o3d | 435 } // namespace o3d |
| OLD | NEW |