CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Bitmap.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "TextureFormat.hpp"
11
13
17
20
21namespace CeresEngine {
22
25
28
30 class Bitmap {
32
33 private:
37
40
44
45 public:
49 Bitmap(const BitmapExtent& extents, const Format format = Format::RGBA8UInt)
50 : mFormat(format), mExtents(extents), mData(extents.width * extents.height * extents.depth * 4) {
51 // TODO: Multiply by the format size!
52 }
53
54 Bitmap(UInt32 width, const Format format = Format::RGBA8UInt) : Bitmap({width, 1, 1}, format) {}
55 Bitmap(UInt32 width, UInt32 height, const Format format = Format::RGBA8UInt) : Bitmap({width, height, 1}, format) {}
56 Bitmap(UInt32 width, UInt32 height, UInt32 depth, const Format format = Format::RGBA8UInt) : Bitmap({width, height, depth}, format) {}
57
58 public:
61
64
67
68 void copyData(const Byte* const source, const size_t length) { memcpy(mData.data(), source, std::min(length, mData.size())); }
69
71 return make_memory_view<Byte>(const_cast<Byte*>(mData.data()), mData.size());
72 }
73
74 void setByteData(const ByteMemoryView& data) {
75 copyData(data.data(), data.size());
76 }
77 };
78
79} // namespace CeresEngine
80
#define CE_META_CLASS_FRIEND(T)
Definition Forward.hpp:48
A class that wraps a bitmap into a rich class for accessing it.
Definition Bitmap.hpp:30
Format mFormat
The format used by the bitmap data.
Definition Bitmap.hpp:36
const Format & getFormat() const noexcept
The format used by the bitmap data.
Definition Bitmap.hpp:60
void setByteData(const ByteMemoryView &data)
Definition Bitmap.hpp:74
ByteMemoryView getByteData() const
Definition Bitmap.hpp:70
Bitmap(UInt32 width, const Format format=Format::RGBA8UInt)
Definition Bitmap.hpp:54
Vector< Byte > mData
The raw bitmap data.
Definition Bitmap.hpp:43
Bitmap(const BitmapExtent &extents, const Format format=Format::RGBA8UInt)
Creates a new bitmap with the given extents.
Definition Bitmap.hpp:49
BitmapData getData() const noexcept
The raw bitmap data.
Definition Bitmap.hpp:66
void copyData(const Byte *const source, const size_t length)
Definition Bitmap.hpp:68
Bitmap(UInt32 width, UInt32 height, UInt32 depth, const Format format=Format::RGBA8UInt)
Definition Bitmap.hpp:56
Bitmap(UInt32 width, UInt32 height, const Format format=Format::RGBA8UInt)
Definition Bitmap.hpp:55
const BitmapExtent & getExtents() const noexcept
Determines the size of the bitmap.
Definition Bitmap.hpp:63
BitmapExtent mExtents
Determines the size of the bitmap.
Definition Bitmap.hpp:39
A memory view is a class which attaches to an chunk of memory and provides a view to it (optionally c...
Definition MemoryView.hpp:62
Definition Application.hpp:19
Byte
Definition DataTypes.hpp:40
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
Format
Definition TextureFormat.hpp:54
@ RGBA8UInt
Color format: red, green, blue, alpha 8-bit unsigned.
TExtent3< UInt32 > BitmapExtent
A type that represents the extents of a bitmap.
Definition Bitmap.hpp:24
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25