1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
//============================================================
//
// texture.cpp - Texture abstraction for BGFX layer
//
//============================================================
#include <cstring>
#include "texture.h"
bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, uint32_t flags, void* data)
: m_name(name)
, m_format(format)
, m_width(width)
, m_height(height)
{
bgfx::TextureInfo info;
bgfx::calcTextureSize(info, width, height, 1, false, false, 1, format);
if (data != nullptr)
{
m_texture = bgfx::createTexture2D(width, height, false, 1, format, flags, bgfx::copy(data, info.storageSize));
}
else
{
m_texture = bgfx::createTexture2D(width, height, false, 1, format, flags);
const bgfx::Memory* memory = bgfx::alloc(info.storageSize);
memset(memory->data, 0, info.storageSize);
bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, width, height, memory, info.storageSize / height);
}
}
bgfx_texture::bgfx_texture(std::string name, bgfx::TextureFormat::Enum format, uint16_t width, uint16_t height, const bgfx::Memory* data, uint32_t flags, uint16_t pitch, uint16_t rowpixels)
: m_name(name)
, m_format(format)
, m_width(width)
, m_height(height)
, m_rowpixels(rowpixels ? rowpixels : width)
{
bgfx::TextureInfo info;
bgfx::calcTextureSize(info, m_rowpixels, height, 1, false, false, 1, format);
m_texture = bgfx::createTexture2D(m_rowpixels, height, false, 1, format, flags, nullptr);
bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_rowpixels, height, data, pitch);
}
bgfx_texture::~bgfx_texture()
{
bgfx::destroy(m_texture);
}
void bgfx_texture::update(const bgfx::Memory *data, uint16_t pitch)
{
bgfx::updateTexture2D(m_texture, 0, 0, 0, 0, m_width, m_height, data, pitch);
}
|