void ByteOrder::Swap (size_t bytes, void* data) { vdGlobalAssertMsg(bytes == 2 || bytes == 4 || bytes == 8, "Size must be 2, 4, or 8\n"); int size = (int)bytes; char* raw = (char*) data; for (int i0 = 0, i1 = size - 1; i0 < size/2; ++i0, --i1) { char save = raw[i0]; raw[i0] = raw[i1]; raw[i1] = save; } }
Texture* Texture::Load2D( const Symbol& name, const vd::string& filename) { ImageFormat format; ImageBuffer8u pixels; ImageInput& input = ImageInput::GetInstance(); vd::status open = input.Open(filename, format); if(open != Status::Code::Success) { vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filename.c_str()); return false; } vd::status read = input.Read(pixels); if(read != Status::Code::Success) { vdLogGlobalWarning("Error: Failed to load texture from image file '%s'\n", filename.c_str()); return false; } input.Close(); GLenum internal = GL_RGBA; GLenum layout = GL_RGBA; switch(format.Channels.Count) { case 1: internal = layout = GL_LUMINANCE; break; case 2: internal = layout = GL_LUMINANCE_ALPHA; break; case 3: internal = layout = GL_RGB; break; case 4: internal = layout = GL_RGBA; break; default: vdLogGlobalWarning("Invalid channel layout for creating texture from image file '%s'\n", filename.c_str()); return NULL; }; Texture::Properties properties; properties.Reset(); properties.Name = name; properties.Handle = 0; properties.Width = format.Width; properties.Height = format.Height; properties.Target = GL_TEXTURE_2D; properties.Internal = internal; properties.Format = layout; properties.DataType = GL_UNSIGNED_BYTE; properties.WrapMode = GL_MIRRORED_REPEAT; properties.MagFilterMode = GL_LINEAR; properties.MinFilterMode = GL_LINEAR_MIPMAP_LINEAR; properties.UseMipMaps = true; Texture* texture = Texture::Create2D(properties, pixels.Data); if(texture == NULL) vdLogGlobalWarning("Failed to load 2D texture '%s' from file '%s'\n", Symbol::ToString(name), filename.c_str()); vdGlobalAssertMsg(texture != NULL, "Failed to load 2D texture!"); return texture; }
void* Mallocator::New(size_t size) { void* p = Memory::RawMalloc(size); vdGlobalAssertMsg(p != NULL, "Out of memory!"); return p; }