Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions engine/includes/resources/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class ENGINE_EXPORT Texture : public Resource {
A_PROPERTY(int, height, Texture::height, Texture::setHeight),
A_PROPERTY(int, depth, Texture::depth, Texture::setDepth),
A_PROPERTY(int, format, Texture::format, Texture::setFormat),
A_PROPERTY(int, compress, Texture::compress, Texture::setCompress),
A_PROPERTY(int, wrap, Texture::wrap, Texture::setWrap),
A_PROPERTY(int, filtering, Texture::filtering, Texture::setFiltering)
)

A_METHODS(
A_METHOD(int, Texture::getPixel),
A_METHOD(bool, Texture::isCompressed),
A_METHOD(bool, Texture::isCubemap),
A_METHOD(void, Texture::setDirty),
A_METHOD(void, Texture::resize)
Expand Down Expand Up @@ -61,9 +61,13 @@ class ENGINE_EXPORT Texture : public Resource {

enum CompressionType {
Uncompressed,
DXT1,
DXT5,
ETC2
BC1,
BC3,
BC7,
ASTC,
ETC1,
ETC2,
PVRTC
};

enum FilteringType {
Expand Down Expand Up @@ -104,7 +108,6 @@ class ENGINE_EXPORT Texture : public Resource {

bool isRender() const;
bool isFeedback() const;
bool isCompressed() const;
bool isCubemap() const;
bool isArray() const;

Expand All @@ -119,6 +122,9 @@ class ENGINE_EXPORT Texture : public Resource {
int format() const;
void setFormat(int type);

int compress() const;
void setCompress(int method);

int wrap() const;
void setWrap(int type);

Expand Down Expand Up @@ -149,8 +155,6 @@ class ENGINE_EXPORT Texture : public Resource {
void switchState(Resource::State state) override;
bool isUnloadable() override;

int32_t size(int32_t width, int32_t height, int32_t depth) const;
int32_t sizeDXTc(int32_t width, int32_t height, int32_t depth) const;
int32_t sizeRGB(int32_t width, int32_t height, int32_t depth) const;

bool isDwordAligned();
Expand Down
14 changes: 5 additions & 9 deletions engine/src/editor/projectsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

#include "config.h"

#include "components/actor.h"
#include "resources/map.h"

#include "editor/assetmanager.h"
#include "editor/codebuilder.h"
#include "editor/editorplatform.h"
Expand Down Expand Up @@ -110,7 +107,6 @@ void ProjectSettings::loadSettings() {

m_projectId = QUuid::createUuid().toString().toStdString();

const MetaObject *meta = metaObject();
for(const auto &it : object) {
TString name = it.first;
name.remove('_');
Expand All @@ -122,15 +118,15 @@ void ProjectSettings::loadSettings() {
auto it = object.find(gPlatforms);
if(it != object.end()) {
m_platforms.clear();
for(auto platform : it->second.toList()) {
for(auto &platform : it->second.toList()) {
m_platforms.push_back(platform.toString());
}
}
}
{
auto it = object.find(gModules);
if(it != object.end()) {
for(auto module : it->second.toList()) {
for(auto &module : it->second.toList()) {
m_modules.insert(module.toString());
}
}
Expand All @@ -139,7 +135,7 @@ void ProjectSettings::loadSettings() {
auto it = object.find(gPlugins);
if(it != object.end()) {
VariantMap plugins = it->second.toMap();
for(auto plugin : plugins) {
for(auto &plugin : plugins) {
m_plugins[plugin.first] = plugin.second.toBool();
}
}
Expand Down Expand Up @@ -200,7 +196,7 @@ void ProjectSettings::saveSettings() {
object[gModules] = modules;
if(!m_plugins.empty()) {
VariantMap plugins;
for(auto it : m_plugins) {
for(auto &it : m_plugins) {
plugins[it.first] = it.second;
}
object[gPlugins] = plugins;
Expand Down Expand Up @@ -345,7 +341,7 @@ StringList ProjectSettings::modules() const {

StringList ProjectSettings::platforms() const {
StringList list;
for(auto it : m_supportedPlatforms) {
for(auto &it : m_supportedPlatforms) {
list.push_back(it.first.data());
}
return (m_platforms.empty()) ? list : m_platforms;
Expand Down
73 changes: 23 additions & 50 deletions engine/src/resources/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#include <cstring>

namespace {
const char *gHeader = "Header";
const char *gData = "Data";
const char *gData("Data");
}

uint32_t Texture::s_maxTextureSize = 1024;
Expand Down Expand Up @@ -89,31 +88,16 @@ Texture::~Texture() {
void Texture::loadUserData(const VariantMap &data) {
clear();

{
auto it = data.find(gData);
if(it != data.end()) {
const VariantList &surfaces = (*it).second.value<VariantList>();
for(auto &s : surfaces) {
Surface img;
int32_t w = m_width;
int32_t h = m_height;
int32_t d = m_depth;
const VariantList &lods = s.value<VariantList>();
for(auto &l : lods) {
ByteArray bits = l.toByteArray();
uint32_t s = size(w, h, d);
if(s && !bits.empty()) {
ByteArray pixels;
pixels.resize(s);
memcpy(&pixels[0], &bits[0], s);
img.push_back(pixels);
}
w = MAX(w / 2, 1);
h = MAX(h / 2, 1);
d = MAX(d / 2, 1);
}
addSurface(img);
auto it = data.find(gData);
if(it != data.end()) {
const VariantList &surfaces = (*it).second.value<VariantList>();
for(auto &s : surfaces) {
Surface surface;

for(auto &l : s.value<VariantList>()) {
surface.push_back(l.toByteArray());
}
addSurface(surface);
}
}
}
Expand Down Expand Up @@ -246,9 +230,8 @@ void Texture::resize(int width, int height) {
if(!(m_flags & Flags::Render) || (m_flags & Flags::Feedback)) {
clear();

int32_t length = size(m_width, m_height, m_depth);
ByteArray pixels;
pixels.resize(length);
pixels.resize(sizeRGB(m_width, m_height, m_depth));

addSurface({pixels});
}
Expand Down Expand Up @@ -342,18 +325,23 @@ void Texture::setFlags(int flags) {
m_flags = flags;

if(isFeedback() && sides() == 0) {
int32_t length = size(m_width, m_height, m_depth);
ByteArray pixels;
pixels.resize(length);
pixels.resize(sizeRGB(m_width, m_height, m_depth));

addSurface({pixels});
}
}
/*!
Returns true if texture uses one of the compression formats; otherwise returns false.
Returns compression method.
*/
int Texture::compress() const {
return m_compress;
}
/*!
Set the compression \a method.
*/
bool Texture::isCompressed() const {
return m_compress != Uncompressed;
void Texture::setCompress(int method) {
m_compress = method;
}
/*!
Returns true if the texture is a cube map; otherwise returns false.
Expand Down Expand Up @@ -426,22 +414,7 @@ void Texture::setMaxCubemapSize(uint32_t size) {
/*!
\internal
*/
int32_t Texture::size(int32_t width, int32_t height, int32_t depth) const {
int32_t (Texture::*sizefunc)(int32_t, int32_t, int32_t) const;
sizefunc = (isCompressed() ? &Texture::sizeDXTc : &Texture::sizeRGB);

return (this->*sizefunc)(width, height, depth);
}
/*!
\internal
*/
inline int32_t Texture::sizeDXTc(int32_t width, int32_t height, int32_t depth) const {
return ((width + 3) / 4) * ((height + 3) / 4) * ((depth + 3) / 4) * (m_compress == DXT1 ? 8 : 16);
}
/*!
\internal
*/
inline int32_t Texture::sizeRGB(int32_t width, int32_t height, int32_t depth) const {
int32_t Texture::sizeRGB(int32_t width, int32_t height, int32_t depth) const {
int32_t s = 1;
switch(m_format) {
case RGBA32Float: s = 4; break;
Expand All @@ -455,7 +428,7 @@ inline int32_t Texture::sizeRGB(int32_t width, int32_t height, int32_t depth) co
*/
bool Texture::isDwordAligned() {
int dwordLineSize = dwordAlignedLineSize(width(), components() * 8);
int curLineSize = width() * components();
int curLineSize = width() * components();

return (dwordLineSize == curLineSize);
}
Expand Down
Loading
Loading