Skip to content

Commit

Permalink
#5568: Handle image file selection for cube map images. Setting map e…
Browse files Browse the repository at this point in the history
…xpressions of cubemap stages will assign cube map declaration - this is not very tolerant to errors, as the openGL API will throw 1282 errors when trying to assign a non-cubemap texture in cubemap mode.
  • Loading branch information
codereader committed Mar 23, 2021
1 parent eba0c55 commit 8b0ada5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
23 changes: 22 additions & 1 deletion radiant/ui/common/ImageFilePopulator.h
Expand Up @@ -29,12 +29,16 @@ class ImageFileFunctor :
wxIcon _fileIcon;
wxIcon _folderIcon;

std::set<std::string> _cubemapSuffixes;

public:
// Constructor
ImageFileFunctor(const wxutil::TreeModel::Ptr& treeStore,
const wxutil::ResourceTreeView::Columns& columns) :
VFSTreePopulator(treeStore),
_columns(columns)
_columns(columns),
_cubemapSuffixes({ "_nx", "_ny", "_nz", "_px", "_py", "_pz",
"_forward", "_back", "_left", "_right", "_up", "_down" })
{
_fileIcon.CopyFromBitmap(wxutil::GetLocalBitmap(TEXTURE_ICON));
_folderIcon.CopyFromBitmap(wxutil::GetLocalBitmap(FOLDER_ICON));
Expand All @@ -58,6 +62,23 @@ class ImageFileFunctor :
imageFilePath = imageFilePath.substr(ddsPrefix.length());
}

// For cubemaps, cut off the suffixes
if (string::istarts_with(imageFilePath, "env/"))
{
auto underscorePos = imageFilePath.find_last_of('_');

if (underscorePos != std::string::npos)
{
auto suffix = imageFilePath.substr(underscorePos);
string::to_lower(suffix);

if (_cubemapSuffixes.count(suffix) != 0)
{
imageFilePath = imageFilePath.substr(0, imageFilePath.length() - suffix.length());
}
}
}

row[_columns.iconAndName] = wxVariant(wxDataViewIconText(leafName, isFolder ? _folderIcon : _fileIcon));
row[_columns.leafName] = leafName;
row[_columns.fullName] = imageFilePath;
Expand Down
11 changes: 10 additions & 1 deletion radiantcore/shaders/Doom3ShaderLayer.cpp
Expand Up @@ -2,6 +2,7 @@
#include "Doom3ShaderSystem.h"
#include "SoundMapExpression.h"
#include "VideoMapExpression.h"
#include "CameraCubeMapDecl.h"

namespace shaders
{
Expand Down Expand Up @@ -415,7 +416,15 @@ IMapExpression::Ptr Doom3ShaderLayer::getMapExpression() const
void Doom3ShaderLayer::setMapExpressionFromString(const std::string& expression)
{
_texture.reset();
setBindableTexture(MapExpression::createForString(expression));

if (getMapType() == IShaderLayer::MapType::CubeMap || getMapType() == IShaderLayer::MapType::CameraCubeMap)
{
setBindableTexture(CameraCubeMapDecl::createForPrefix(expression));
}
else
{
setBindableTexture(MapExpression::createForString(expression));
}
}

int Doom3ShaderLayer::getParseFlags() const
Expand Down

0 comments on commit 8b0ada5

Please sign in to comment.