Blue Brain BioExplorer
Texture2D.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
4  *
5  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 3.0 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "Texture2D.h"
22 
23 namespace core
24 {
25 Texture2D::Texture2D(const Type type_, const std::string& filename_, const uint8_t channels_, const uint8_t depth_,
26  const uint32_t width_, const uint32_t height_)
27  : type(type_)
28  , filename(filename_)
29  , channels(channels_)
30  , depth(depth_)
31  , width(width_)
32  , height(height_)
33 {
34  _rawData.resize(type == Type::cubemap ? 6 : 1);
35  setMipLevels(1);
36 }
37 
38 void Texture2D::setMipLevels(const uint8_t mips)
39 {
40  if (mips == _mipLevels)
41  return;
42  _mipLevels = mips;
43  for (auto& data : _rawData)
44  data.resize(mips);
45 }
46 
47 void Texture2D::setRawData(unsigned char* data, const size_t size, const uint8_t face, const uint8_t mip)
48 {
49  _rawData[face][mip].clear();
50  _rawData[face][mip].assign(data, data + size);
51 }
52 
53 void Texture2D::setRawData(std::vector<unsigned char>&& rawData, const uint8_t face, const uint8_t mip)
54 {
55  _rawData[face][mip] = std::move(rawData);
56 }
57 
59 {
60  uint8_t mipMapLevels = 1u;
61  auto nx = width;
62  auto ny = height;
63  while (nx % 2 == 0 && ny % 2 == 0)
64  {
65  nx /= 2;
66  ny /= 2;
67  ++mipMapLevels;
68  }
69  return mipMapLevels;
70 }
71 } // namespace core
uint8_t getPossibleMipMapsLevels() const
Definition: Texture2D.cpp:58
const Type type
Definition: Texture2D.h:146
const uint32_t width
Definition: Texture2D.h:158
void setMipLevels(const uint8_t mips)
Definition: Texture2D.cpp:38
PLATFORM_API Texture2D(const Type type, const std::string &filename, const uint8_t channels, const uint8_t depth, const uint32_t width, const uint32_t height)
Definition: Texture2D.cpp:25
const uint32_t height
Definition: Texture2D.h:161
void setRawData(unsigned char *data, const size_t size, const uint8_t face=0, const uint8_t mip=0)
Definition: Texture2D.cpp:47