Add unity build support

This commit is contained in:
Jérôme Leclercq 2022-03-15 08:26:57 +01:00
parent 0a4fd8f56d
commit 6bd9f1a9e4
109 changed files with 964 additions and 680 deletions

View File

@ -9,10 +9,12 @@
#include <Nazara/Prerequisites.hpp>
#include <Nazara/Audio/Enums.hpp>
#include <optional>
namespace Nz
{
inline UInt32 GetChannelCount(AudioFormat format);
inline std::optional<AudioFormat> GuessAudioFormat(UInt32 channelCount);
template<typename T> void MixToMono(T* input, T* output, UInt32 channelCount, UInt64 frameCount);
}

View File

@ -11,11 +11,13 @@ namespace Nz
/*!
* \ingroup audio
* \brief Get the number of channels occupied by an audio format
* \returns The number of channels occupied by an audio format (mono returns 1, stero returns 2, etc.)
* \returns The number of channels occupied by an audio format (mono returns 1, stereo returns 2, etc.)
*
* \param format A valid audio format
*
* \remark The format must be valid (using AudioFormat::Unknown will trigger an error)
* \remark format cannot be AudioFormat::Unknown
*
* \see GuessAudioFormat
*/
UInt32 GetChannelCount(AudioFormat format)
{
@ -48,6 +50,42 @@ namespace Nz
return 0;
}
/*!
* \ingroup audio
* \brief Gets the common audio format associated with a specific channel count
* \returns AudioFormat associated with channel count or empty optional if none match
*
* \param channelCount Channel count
*
* \see GetChannelCount
*/
inline std::optional<AudioFormat> GuessAudioFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
/*!
* \ingroup audio
* \brief Mixes channels in mono

View File

@ -39,13 +39,24 @@ namespace Nz
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
template<typename T> void HashCombine(std::size_t& seed, const T& v);
template<typename T> bool IsPowerOfTwo(T value);
template<typename K, typename V> V& Retrieve(std::unordered_map<K, V>& map, const K& key);
template<typename K, typename V> const V& Retrieve(const std::unordered_map<K, V>& map, const K& key);
template<typename T> T ReverseBits(T integer);
template<typename To, typename From> To SafeCast(From&& value);
template<typename T, typename U>std::unique_ptr<T> StaticUniquePointerCast(std::unique_ptr<U>&& ptr);
template<typename T> constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>;
template<typename T>
struct AlwaysFalse : std::false_type {};
// Helper for std::visit
template<typename... Ts> struct Overloaded : Ts...
{
using Ts::operator()...;
};
template<typename... Ts> Overloaded(Ts...) -> Overloaded<Ts...>;
template<typename... Args>
struct OverloadResolver
{

View File

@ -363,6 +363,38 @@ namespace Nz
return (value & (value - 1)) == 0;
}
/*!
* \ingroup core
* \brief Helper function to retrieve a key in a map which has to exist
* \return Value associated with key
*
* \param map Map
* \param key Key, has to exist in map
*/
template<typename K, typename V>
V& Retrieve(std::unordered_map<K, V>& map, const K& key)
{
auto it = map.find(key);
assert(it != map.end());
return it->second;
}
/*!
* \ingroup core
* \brief Helper function to retrieve a key in a map which has to exist
* \return Value associated with key
*
* \param map Map
* \param key Key, has to exist in map
*/
template<typename K, typename V>
const V& Retrieve(const std::unordered_map<K, V>& map, const K& key)
{
auto it = map.find(key);
assert(it != map.end());
return it->second;
}
/*!
* \ingroup core
* \brief Reverse the bit order of the integer
@ -472,6 +504,12 @@ namespace Nz
#endif
}
template<typename T, typename U>
std::unique_ptr<T> StaticUniquePointerCast(std::unique_ptr<U>&& ptr)
{
return std::unique_ptr<T>(SafeCast<T*>(ptr.release()));
}
template<typename T>
constexpr auto UnderlyingCast(T value) -> std::underlying_type_t<T>
{

View File

@ -149,6 +149,16 @@
#define NAZARA_PLATFORM_x64
#endif
#ifdef NAZARA_UNITY_BUILD
#define NAZARA_ANONYMOUS_NAMESPACE NAZARA_UNITY_ID
#define NAZARA_USE_ANONYMOUS_NAMESPACE using namespace NAZARA_UNITY_ID;
#define NAZARA_ANONYMOUS_NAMESPACE_PREFIX(a) NAZARA_UNITY_ID::a
#else
#define NAZARA_ANONYMOUS_NAMESPACE
#define NAZARA_USE_ANONYMOUS_NAMESPACE
#define NAZARA_ANONYMOUS_NAMESPACE_PREFIX(a) a
#endif
// A bunch of useful macros
#define NazaraPrefix(a, prefix) prefix ## a
#define NazaraPrefixMacro(a, prefix) NazaraPrefix(a, prefix)

View File

@ -60,6 +60,7 @@ namespace Nz::ShaderAst
private:
enum class IdentifierCategory;
struct AstError;
struct CurrentFunctionData;
struct Environment;
struct FunctionData;

View File

@ -26,40 +26,13 @@ namespace Nz
{
namespace
{
std::optional<AudioFormat> GuessFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
std::size_t ReadCallback(void* pUserData, void* pBufferOut, size_t bytesToRead)
std::size_t ReadWavCallback(void* pUserData, void* pBufferOut, size_t bytesToRead)
{
Stream* stream = static_cast<Stream*>(pUserData);
return static_cast<std::size_t>(stream->Read(pBufferOut, bytesToRead));
}
drwav_bool32 SeekCallback(void* pUserData, int offset, drwav_seek_origin origin)
drwav_bool32 SeekWavCallback(void* pUserData, int offset, drwav_seek_origin origin)
{
Stream* stream = static_cast<Stream*>(pUserData);
switch (origin)
@ -76,7 +49,7 @@ namespace Nz
}
}
bool IsSupported(const std::string_view& extension)
bool IsWavSupported(const std::string_view& extension)
{
return extension == "riff" || extension == "rf64" || extension == "wav" || extension == "w64";
}
@ -88,17 +61,17 @@ namespace Nz
return Ternary::False;
drwav wav;
if (!drwav_init(&wav, &ReadCallback, &SeekCallback, &stream, nullptr))
if (!drwav_init(&wav, &ReadWavCallback, &SeekWavCallback, &stream, nullptr))
return Ternary::False;
drwav_uninit(&wav);
return Ternary::True;
}
std::shared_ptr<SoundBuffer> LoadSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
std::shared_ptr<SoundBuffer> LoadWavSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
{
drwav wav;
if (!drwav_init(&wav, &ReadCallback, &SeekCallback, &stream, nullptr))
if (!drwav_init(&wav, &ReadWavCallback, &SeekWavCallback, &stream, nullptr))
{
NazaraError("failed to decode wav stream");
return {};
@ -106,7 +79,7 @@ namespace Nz
CallOnExit uninitOnExit([&] { drwav_uninit(&wav); });
std::optional<AudioFormat> formatOpt = GuessFormat(wav.channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(wav.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(wav.channels));
@ -198,7 +171,7 @@ namespace Nz
bool Open(Stream& stream, bool forceMono)
{
if (!drwav_init(&m_decoder, &ReadCallback, &SeekCallback, &stream, nullptr))
if (!drwav_init(&m_decoder, &ReadWavCallback, &SeekWavCallback, &stream, nullptr))
{
NazaraError("failed to decode wav stream");
return {};
@ -210,7 +183,7 @@ namespace Nz
std::memset(&m_decoder, 0, sizeof(m_decoder));
});
std::optional<AudioFormat> formatOpt = GuessFormat(m_decoder.channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_decoder.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_decoder.channels));
@ -284,7 +257,7 @@ namespace Nz
bool m_mixToMono;
};
std::shared_ptr<SoundStream> LoadSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadWavSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
{
std::shared_ptr<drwavStream> soundStream = std::make_shared<drwavStream>();
if (!soundStream->Open(filePath, parameters.forceMono))
@ -296,7 +269,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadWavSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
{
std::shared_ptr<drwavStream> soundStream = std::make_shared<drwavStream>();
if (!soundStream->Open(data, size, parameters.forceMono))
@ -308,7 +281,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadWavSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
{
std::shared_ptr<drwavStream> soundStream = std::make_shared<drwavStream>();
if (!soundStream->Open(stream, parameters.forceMono))
@ -326,9 +299,9 @@ namespace Nz
SoundBufferLoader::Entry GetSoundBufferLoader_drwav()
{
SoundBufferLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsWavSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundBufferParams& parameters) { return CheckWav(stream, parameters); };
loaderEntry.streamLoader = LoadSoundBuffer;
loaderEntry.streamLoader = LoadWavSoundBuffer;
return loaderEntry;
}
@ -336,11 +309,11 @@ namespace Nz
SoundStreamLoader::Entry GetSoundStreamLoader_drwav()
{
SoundStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsWavSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundStreamParams& parameters) { return CheckWav(stream, parameters); };
loaderEntry.fileLoader = LoadSoundStreamFile;
loaderEntry.memoryLoader = LoadSoundStreamMemory;
loaderEntry.streamLoader = LoadSoundStreamStream;
loaderEntry.fileLoader = LoadWavSoundStreamFile;
loaderEntry.memoryLoader = LoadWavSoundStreamMemory;
loaderEntry.streamLoader = LoadWavSoundStreamStream;
return loaderEntry;
}

View File

@ -23,35 +23,7 @@ namespace Nz
{
namespace
{
std::optional<AudioFormat> GuessFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
struct Userdata
struct FlacUserdata
{
std::function<void(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status)> errorCallback;
std::function<void(const FLAC__StreamDecoder* decoder, const FLAC__StreamMetadata* metadata)> metadataCallback;
@ -59,22 +31,22 @@ namespace Nz
Stream* stream;
};
FLAC__bool EofCallback(const FLAC__StreamDecoder* /*decoder*/, void* client_data)
FLAC__bool FlacEofCallback(const FLAC__StreamDecoder* /*decoder*/, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
return ud->stream->EndOfStream();
}
void ErrorCallback(const FLAC__StreamDecoder* decoder, FLAC__StreamDecoderErrorStatus status, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
assert(ud->errorCallback);
return ud->errorCallback(decoder, status);
}
FLAC__StreamDecoderLengthStatus LengthCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64* stream_length, void* client_data)
FLAC__StreamDecoderLengthStatus FlacLengthCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64* stream_length, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
*stream_length = ud->stream->GetSize();
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
@ -82,14 +54,14 @@ namespace Nz
void MetadataCallback(const FLAC__StreamDecoder* decoder, const FLAC__StreamMetadata* metadata, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
if (ud->metadataCallback)
ud->metadataCallback(decoder, metadata);
}
FLAC__StreamDecoderReadStatus ReadCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__byte buffer[], size_t* bytes, void* client_data)
FLAC__StreamDecoderReadStatus FlacReadCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__byte buffer[], size_t* bytes, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
std::size_t readBytes = ud->stream->Read(buffer, *bytes);
*bytes = readBytes;
@ -99,25 +71,25 @@ namespace Nz
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
FLAC__StreamDecoderSeekStatus SeekCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64 absolute_byte_offset, void* client_data)
FLAC__StreamDecoderSeekStatus FlacSeekCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64 absolute_byte_offset, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
if (ud->stream->SetCursorPos(absolute_byte_offset))
return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
else
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
FLAC__StreamDecoderTellStatus TellCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64* absolute_byte_offset, void* client_data)
FLAC__StreamDecoderTellStatus FlacTellCallback(const FLAC__StreamDecoder* /*decoder*/, FLAC__uint64* absolute_byte_offset, void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
*absolute_byte_offset = ud->stream->GetCursorPos();
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderWriteStatus WriteCallback(const FLAC__StreamDecoder* decoder, const FLAC__Frame* frame, const FLAC__int32* const buffer[], void* client_data)
{
Userdata* ud = static_cast<Userdata*>(client_data);
FlacUserdata* ud = static_cast<FlacUserdata*>(client_data);
if (ud->writeCallback)
return ud->writeCallback(decoder, frame, buffer);
else
@ -125,7 +97,7 @@ namespace Nz
}
template<UInt32 Bits, typename TargetType>
bool DecodeFrameSamplesImpl(const FLAC__Frame* frame, const FLAC__int32* const buffer[], TargetType* samples, UInt32 frameIndex, UInt32 frameCount)
bool DecodeFlacFrameSamplesImpl(const FLAC__Frame* frame, const FLAC__int32* const buffer[], TargetType* samples, UInt32 frameIndex, UInt32 frameCount)
{
constexpr UInt32 TargetBits = sizeof(TargetType) * CHAR_BIT;
for (; frameIndex < frameCount; ++frameIndex)
@ -145,26 +117,26 @@ namespace Nz
return true;
}
bool DecodeFrameSamples(const FLAC__Frame* frame, const FLAC__int32* const buffer[], Int16* samples, UInt32 frameIndex, UInt32 frameCount)
bool DecodeFlacFrameSamples(const FLAC__Frame* frame, const FLAC__int32* const buffer[], Int16* samples, UInt32 frameIndex, UInt32 frameCount)
{
switch (frame->header.bits_per_sample)
{
case 8: return DecodeFrameSamplesImpl<8>(frame, buffer, samples, frameIndex, frameCount);
case 12: return DecodeFrameSamplesImpl<12>(frame, buffer, samples, frameIndex, frameCount);
case 16: return DecodeFrameSamplesImpl<16>(frame, buffer, samples, frameIndex, frameCount);
case 20: return DecodeFrameSamplesImpl<20>(frame, buffer, samples, frameIndex, frameCount);
case 24: return DecodeFrameSamplesImpl<24>(frame, buffer, samples, frameIndex, frameCount);
case 32: return DecodeFrameSamplesImpl<32>(frame, buffer, samples, frameIndex, frameCount);
case 8: return DecodeFlacFrameSamplesImpl<8>(frame, buffer, samples, frameIndex, frameCount);
case 12: return DecodeFlacFrameSamplesImpl<12>(frame, buffer, samples, frameIndex, frameCount);
case 16: return DecodeFlacFrameSamplesImpl<16>(frame, buffer, samples, frameIndex, frameCount);
case 20: return DecodeFlacFrameSamplesImpl<20>(frame, buffer, samples, frameIndex, frameCount);
case 24: return DecodeFlacFrameSamplesImpl<24>(frame, buffer, samples, frameIndex, frameCount);
case 32: return DecodeFlacFrameSamplesImpl<32>(frame, buffer, samples, frameIndex, frameCount);
default: return false;
}
}
bool DecodeFrameSamples(const FLAC__Frame* frame, const FLAC__int32* const buffer[], Int16* samples)
bool DecodeFlacFrameSamples(const FLAC__Frame* frame, const FLAC__int32* const buffer[], Int16* samples)
{
return DecodeFrameSamples(frame, buffer, samples, 0, frame->header.blocksize);
return DecodeFlacFrameSamples(frame, buffer, samples, 0, frame->header.blocksize);
}
bool IsSupported(const std::string_view& extension)
bool IsFlacSupported(const std::string_view& extension)
{
return extension == "flac";
}
@ -180,14 +152,14 @@ namespace Nz
bool hasError = false;
Userdata ud;
FlacUserdata ud;
ud.stream = &stream;
ud.errorCallback = [&](const FLAC__StreamDecoder* /*decoder*/, FLAC__StreamDecoderErrorStatus /*status*/)
{
hasError = true;
};
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &ReadCallback, &SeekCallback, &TellCallback, &LengthCallback, &EofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &ud);
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &FlacReadCallback, &FlacSeekCallback, &FlacTellCallback, &FlacLengthCallback, &FlacEofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &ud);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{
NazaraWarning(FLAC__StreamDecoderInitStatusString[status]); //< an error shouldn't happen at this state
@ -205,14 +177,14 @@ namespace Nz
return Ternary::True;
}
std::shared_ptr<SoundBuffer> LoadSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
std::shared_ptr<SoundBuffer> LoadFlacSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
{
FLAC__StreamDecoder* decoder = FLAC__stream_decoder_new();
CallOnExit freeDecoder([&] { FLAC__stream_decoder_delete(decoder); });
bool hasError = false;
Userdata ud;
FlacUserdata ud;
ud.stream = &stream;
ud.errorCallback = [&](const FLAC__StreamDecoder* /*decoder*/, FLAC__StreamDecoderErrorStatus status)
{
@ -249,7 +221,7 @@ namespace Nz
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
if (!DecodeFrameSamples(frame, buffer, samples.get() + sampleIndex))
if (!DecodeFlacFrameSamples(frame, buffer, samples.get() + sampleIndex))
{
NazaraError("failed to decode samples");
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
@ -260,7 +232,7 @@ namespace Nz
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
};
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &ReadCallback, &SeekCallback, &TellCallback, &LengthCallback, &EofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &ud);
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &FlacReadCallback, &FlacSeekCallback, &FlacTellCallback, &FlacLengthCallback, &FlacEofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &ud);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{
NazaraWarning(FLAC__StreamDecoderInitStatusString[status]); //< an error shouldn't happen at this state
@ -287,7 +259,7 @@ namespace Nz
return {};
}
std::optional<AudioFormat> formatOpt = GuessFormat(channelCount);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(channelCount);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(channelCount));
@ -397,7 +369,7 @@ namespace Nz
m_duration = UInt32(1000ULL * frameCount / m_sampleRate);
};
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &ReadCallback, &SeekCallback, &TellCallback, &LengthCallback, &EofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &m_userData);
FLAC__StreamDecoderInitStatus status = FLAC__stream_decoder_init_stream(decoder, &FlacReadCallback, &FlacSeekCallback, &FlacTellCallback, &FlacLengthCallback, &FlacEofCallback, &WriteCallback, &MetadataCallback, &ErrorCallback, &m_userData);
if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
{
NazaraWarning(FLAC__StreamDecoderInitStatusString[status]); //< an error shouldn't happen at this state
@ -412,7 +384,7 @@ namespace Nz
return false;
}
std::optional<AudioFormat> formatOpt = GuessFormat(m_channelCount);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_channelCount);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_channelCount));
@ -480,20 +452,20 @@ namespace Nz
if (sampleCount > 0)
{
assert(sampleCount % frame->header.channels == 0);
if (!DecodeFrameSamples(frame, framebuffer, buffer + readSample, 0, static_cast<UInt32>(sampleCount / frame->header.channels)))
if (!DecodeFlacFrameSamples(frame, framebuffer, buffer + readSample, 0, static_cast<UInt32>(sampleCount / frame->header.channels)))
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
readSample += sampleCount;
}
if (!DecodeFrameSamples(frame, framebuffer, &m_overflowBuffer[overflownOffset], static_cast<UInt32>(sampleCount / frame->header.channels), frameCount))
if (!DecodeFlacFrameSamples(frame, framebuffer, &m_overflowBuffer[overflownOffset], static_cast<UInt32>(sampleCount / frame->header.channels), frameCount))
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
sampleCount = 0;
}
else
{
if (!DecodeFrameSamples(frame, framebuffer, buffer + readSample))
if (!DecodeFlacFrameSamples(frame, framebuffer, buffer + readSample))
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
readSample += blockSampleCount;
@ -540,7 +512,7 @@ namespace Nz
std::vector<Int16> m_overflowBuffer;
FLAC__StreamDecoder* m_decoder;
AudioFormat m_format;
Userdata m_userData;
FlacUserdata m_userData;
UInt32 m_channelCount;
UInt32 m_duration;
UInt32 m_sampleRate;
@ -550,7 +522,7 @@ namespace Nz
bool m_mixToMono;
};
std::shared_ptr<SoundStream> LoadSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadFlacSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
{
std::shared_ptr<libflacStream> soundStream = std::make_shared<libflacStream>();
if (!soundStream->Open(filePath, parameters.forceMono))
@ -562,7 +534,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadFlacSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
{
std::shared_ptr<libflacStream> soundStream = std::make_shared<libflacStream>();
if (!soundStream->Open(data, size, parameters.forceMono))
@ -574,7 +546,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadFlacSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
{
std::shared_ptr<libflacStream> soundStream = std::make_shared<libflacStream>();
if (!soundStream->Open(stream, parameters.forceMono))
@ -592,9 +564,9 @@ namespace Nz
SoundBufferLoader::Entry GetSoundBufferLoader_libflac()
{
SoundBufferLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsFlacSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundBufferParams& parameters) { return CheckFlac(stream, parameters); };
loaderEntry.streamLoader = LoadSoundBuffer;
loaderEntry.streamLoader = LoadFlacSoundBuffer;
return loaderEntry;
}
@ -602,11 +574,11 @@ namespace Nz
SoundStreamLoader::Entry GetSoundStreamLoader_libflac()
{
SoundStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsFlacSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundStreamParams& parameters) { return CheckFlac(stream, parameters); };
loaderEntry.fileLoader = LoadSoundStreamFile;
loaderEntry.memoryLoader = LoadSoundStreamMemory;
loaderEntry.streamLoader = LoadSoundStreamStream;
loaderEntry.fileLoader = LoadFlacSoundStreamFile;
loaderEntry.memoryLoader = LoadFlacSoundStreamMemory;
loaderEntry.streamLoader = LoadFlacSoundStreamStream;
return loaderEntry;
}

View File

@ -26,40 +26,13 @@ namespace Nz
{
namespace
{
std::optional<AudioFormat> GuessFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
std::size_t ReadCallback(void* ptr, size_t size, size_t nmemb, void* datasource)
std::size_t VorbisReadCallback(void* ptr, size_t size, size_t nmemb, void* datasource)
{
Stream* stream = static_cast<Stream*>(datasource);
return static_cast<std::size_t>(stream->Read(ptr, size * nmemb));
}
int SeekCallback(void* datasource, ogg_int64_t offset, int whence)
int VorbisSeekCallback(void* datasource, ogg_int64_t offset, int whence)
{
Stream* stream = static_cast<Stream*>(datasource);
switch (whence)
@ -84,21 +57,21 @@ namespace Nz
return 0;
}
long TellCallback(void* datasource)
long VorbisTellCallback(void* datasource)
{
Stream* stream = static_cast<Stream*>(datasource);
return static_cast<long>(stream->GetCursorPos());
}
static ov_callbacks s_callbacks = {
&ReadCallback,
&SeekCallback,
static ov_callbacks s_vorbisCallbacks = {
&VorbisReadCallback,
&VorbisSeekCallback,
nullptr,
&TellCallback
&VorbisTellCallback
};
std::string ErrToString(int errCode)
std::string VorbisErrToString(int errCode)
{
switch (errCode)
{
@ -129,7 +102,7 @@ namespace Nz
if (readBytes < 0)
{
NazaraError("an error occurred while reading file: " + ErrToString(readBytes));
NazaraError("an error occurred while reading file: " + VorbisErrToString(readBytes));
return 0;
}
@ -143,7 +116,7 @@ namespace Nz
return sampleCount - remainingBytes / sizeof(Int16);
}
bool IsSupported(const std::string_view& extension)
bool IsVorbisSupported(const std::string_view& extension)
{
static std::set<std::string_view> supportedExtensions = {
"oga", "ogg", "ogm", "ogv", "ogx", "opus", "spx"
@ -159,20 +132,20 @@ namespace Nz
return Ternary::False;
OggVorbis_File file;
if (ov_test_callbacks(&stream, &file, nullptr, 0, s_callbacks) != 0)
if (ov_test_callbacks(&stream, &file, nullptr, 0, s_vorbisCallbacks) != 0)
return Ternary::False;
ov_clear(&file);
return Ternary::True;
}
std::shared_ptr<SoundBuffer> LoadSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
std::shared_ptr<SoundBuffer> LoadVorbisSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
{
OggVorbis_File file;
int err = ov_open_callbacks(&stream, &file, nullptr, 0, s_callbacks);
int err = ov_open_callbacks(&stream, &file, nullptr, 0, s_vorbisCallbacks);
if (err != 0)
{
NazaraError(ErrToString(err));
NazaraError(VorbisErrToString(err));
return {};
}
@ -181,7 +154,7 @@ namespace Nz
vorbis_info* info = ov_info(&file, -1);
assert(info);
std::optional<AudioFormat> formatOpt = GuessFormat(info->channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info->channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info->channels));
@ -278,10 +251,10 @@ namespace Nz
bool Open(Stream& stream, bool forceMono)
{
int err = ov_open_callbacks(&stream, &m_decoder, nullptr, 0, s_callbacks);
int err = ov_open_callbacks(&stream, &m_decoder, nullptr, 0, s_vorbisCallbacks);
if (err != 0)
{
NazaraError(ErrToString(err));
NazaraError(VorbisErrToString(err));
return {};
}
@ -294,7 +267,7 @@ namespace Nz
vorbis_info* info = ov_info(&m_decoder, -1);
assert(info);
std::optional<AudioFormat> formatOpt = GuessFormat(info->channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info->channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info->channels));
@ -374,7 +347,7 @@ namespace Nz
bool m_mixToMono;
};
std::shared_ptr<SoundStream> LoadSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadVorbisSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
{
std::shared_ptr<libvorbisStream> soundStream = std::make_shared<libvorbisStream>();
if (!soundStream->Open(filePath, parameters.forceMono))
@ -386,7 +359,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadVorbisSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
{
std::shared_ptr<libvorbisStream> soundStream = std::make_shared<libvorbisStream>();
if (!soundStream->Open(data, size, parameters.forceMono))
@ -398,7 +371,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> LoadVorbisSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
{
std::shared_ptr<libvorbisStream> soundStream = std::make_shared<libvorbisStream>();
if (!soundStream->Open(stream, parameters.forceMono))
@ -416,9 +389,9 @@ namespace Nz
SoundBufferLoader::Entry GetSoundBufferLoader_libvorbis()
{
SoundBufferLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsVorbisSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundBufferParams& parameters) { return CheckOgg(stream, parameters); };
loaderEntry.streamLoader = LoadSoundBuffer;
loaderEntry.streamLoader = LoadVorbisSoundBuffer;
return loaderEntry;
}
@ -426,11 +399,11 @@ namespace Nz
SoundStreamLoader::Entry GetSoundStreamLoader_libvorbis()
{
SoundStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.extensionSupport = IsVorbisSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundStreamParams& parameters) { return CheckOgg(stream, parameters); };
loaderEntry.fileLoader = LoadSoundStreamFile;
loaderEntry.memoryLoader = LoadSoundStreamMemory;
loaderEntry.streamLoader = LoadSoundStreamStream;
loaderEntry.fileLoader = LoadVorbisSoundStreamFile;
loaderEntry.memoryLoader = LoadVorbisSoundStreamMemory;
loaderEntry.streamLoader = LoadVorbisSoundStreamStream;
return loaderEntry;
}

View File

@ -25,34 +25,7 @@ namespace Nz
{
namespace
{
std::optional<AudioFormat> GuessFormat(UInt32 channelCount)
{
switch (channelCount)
{
case 1:
return AudioFormat::I16_Mono;
case 2:
return AudioFormat::I16_Stereo;
case 4:
return AudioFormat::I16_Quad;
case 6:
return AudioFormat::I16_5_1;
case 7:
return AudioFormat::I16_6_1;
case 8:
return AudioFormat::I16_7_1;
default:
return std::nullopt;
}
}
std::string ErrToString(int errCode)
std::string MP3ErrorToString(int errCode)
{
switch (errCode)
{
@ -66,47 +39,47 @@ namespace Nz
}
}
size_t ReadCallback(void* buf, size_t size, void* user_data)
size_t MP3ReadCallback(void* buf, size_t size, void* user_data)
{
Stream* stream = static_cast<Stream*>(user_data);
return static_cast<size_t>(stream->Read(buf, size));
}
int SeekCallback(uint64_t position, void* user_data)
int MP3SeekCallback(uint64_t position, void* user_data)
{
Stream* stream = static_cast<Stream*>(user_data);
return (stream->SetCursorPos(position)) ? 0 : MP3D_E_IOERROR;
}
bool IsSupported(const std::string_view& extension)
bool IsMP3Supported(const std::string_view& extension)
{
return extension == "mp3";
}
Ternary CheckMp3(Stream& stream, const ResourceParameters& parameters)
Ternary CheckMP3(Stream& stream, const ResourceParameters& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeMP3Loader", &skip) && skip)
return Ternary::False;
mp3dec_io_t io;
io.read = &ReadCallback;
io.read = &MP3ReadCallback;
io.read_data = &stream;
io.seek = &SeekCallback;
io.seek = &MP3SeekCallback;
io.seek_data = &stream;
std::vector<UInt8> buffer(MINIMP3_BUF_SIZE);
return (mp3dec_detect_cb(&io, buffer.data(), buffer.size()) == 0) ? Ternary::True : Ternary::False;
}
std::shared_ptr<SoundBuffer> LoadSoundBuffer(Stream& stream, const SoundBufferParams& parameters)
std::shared_ptr<SoundBuffer> LoadMP3SoundBuffer(Stream& stream, const SoundBufferParams& parameters)
{
static_assert(std::is_same_v<mp3d_sample_t, Int16>);
mp3dec_io_t io;
io.read = &ReadCallback;
io.read = &MP3ReadCallback;
io.read_data = &stream;
io.seek = &SeekCallback;
io.seek = &MP3SeekCallback;
io.seek_data = &stream;
struct UserData
@ -122,13 +95,13 @@ namespace Nz
int err = mp3dec_load_cb(&dec, &io, buffer.data(), buffer.size(), &info, nullptr, &userdata);
if (err != 0)
{
NazaraError(ErrToString(err));
NazaraError(MP3ErrorToString(err));
return {};
}
CallOnExit freeBuffer([&] { std::free(info.buffer); });
std::optional<AudioFormat> formatOpt = GuessFormat(info.channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(info.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(info.channels));
@ -214,15 +187,15 @@ namespace Nz
bool Open(Stream& stream, bool forceMono)
{
m_io.read = &ReadCallback;
m_io.read = &MP3ReadCallback;
m_io.read_data = &stream;
m_io.seek = &SeekCallback;
m_io.seek = &MP3SeekCallback;
m_io.seek_data = &stream;
int err = mp3dec_ex_open_cb(&m_decoder, &m_io, MP3D_SEEK_TO_SAMPLE);
if (err != 0)
{
NazaraError(ErrToString(err));
NazaraError(MP3ErrorToString(err));
return {};
}
@ -232,7 +205,7 @@ namespace Nz
std::memset(&m_decoder, 0, sizeof(m_decoder));
});
std::optional<AudioFormat> formatOpt = GuessFormat(m_decoder.info.channels);
std::optional<AudioFormat> formatOpt = GuessAudioFormat(m_decoder.info.channels);
if (!formatOpt)
{
NazaraError("unexpected channel count: " + std::to_string(m_decoder.info.channels));
@ -309,7 +282,7 @@ namespace Nz
bool m_mixToMono;
};
std::shared_ptr<SoundStream> LoadSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> MP3LoadSoundStreamFile(const std::filesystem::path& filePath, const SoundStreamParams& parameters)
{
std::shared_ptr<minimp3Stream> soundStream = std::make_shared<minimp3Stream>();
if (!soundStream->Open(filePath, parameters.forceMono))
@ -321,7 +294,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> MP3LoadSoundStreamMemory(const void* data, std::size_t size, const SoundStreamParams& parameters)
{
std::shared_ptr<minimp3Stream> soundStream = std::make_shared<minimp3Stream>();
if (!soundStream->Open(data, size, parameters.forceMono))
@ -333,7 +306,7 @@ namespace Nz
return soundStream;
}
std::shared_ptr<SoundStream> LoadSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
std::shared_ptr<SoundStream> MP3LoadSoundStreamStream(Stream& stream, const SoundStreamParams& parameters)
{
std::shared_ptr<minimp3Stream> soundStream = std::make_shared<minimp3Stream>();
if (!soundStream->Open(stream, parameters.forceMono))
@ -351,9 +324,9 @@ namespace Nz
SoundBufferLoader::Entry GetSoundBufferLoader_minimp3()
{
SoundBufferLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundBufferParams& parameters) { return CheckMp3(stream, parameters); };
loaderEntry.streamLoader = LoadSoundBuffer;
loaderEntry.extensionSupport = IsMP3Supported;
loaderEntry.streamChecker = [](Stream& stream, const SoundBufferParams& parameters) { return CheckMP3(stream, parameters); };
loaderEntry.streamLoader = LoadMP3SoundBuffer;
return loaderEntry;
}
@ -361,11 +334,11 @@ namespace Nz
SoundStreamLoader::Entry GetSoundStreamLoader_minimp3()
{
SoundStreamLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = [](Stream& stream, const SoundStreamParams& parameters) { return CheckMp3(stream, parameters); };
loaderEntry.fileLoader = LoadSoundStreamFile;
loaderEntry.memoryLoader = LoadSoundStreamMemory;
loaderEntry.streamLoader = LoadSoundStreamStream;
loaderEntry.extensionSupport = IsMP3Supported;
loaderEntry.streamChecker = [](Stream& stream, const SoundStreamParams& parameters) { return CheckMP3(stream, parameters); };
loaderEntry.fileLoader = MP3LoadSoundStreamFile;
loaderEntry.memoryLoader = MP3LoadSoundStreamMemory;
loaderEntry.streamLoader = MP3LoadSoundStreamStream;
return loaderEntry;
}

View File

@ -18,23 +18,15 @@ namespace Nz
{
namespace
{
DynLib s_library;
std::string s_deviceName;
std::string s_rendererName;
std::string s_vendorName;
ALCdevice* s_device = nullptr;
ALCcontext* s_context = nullptr;
unsigned int s_version;
DynLib s_openalLbrary;
std::string s_openalDeviceName;
std::string s_openalRndererName;
std::string s_openalVendorName;
ALCdevice* s_openalDevice = nullptr;
ALCcontext* s_openalContext = nullptr;
unsigned int s_openalVersion;
/*!
* \brief Parses the devices
* \return Number of devices
*
* \param deviceString String for the device (input / output)
* \param devices List of names of the devices
*/
std::size_t ParseDevices(const char* deviceString, std::vector<std::string>& devices)
std::size_t ParseOpenALDevices(const char* deviceString, std::vector<std::string>& devices)
{
if (!deviceString)
return 0;
@ -81,7 +73,7 @@ namespace Nz
std::string OpenAL::GetRendererName()
{
return s_rendererName;
return s_openalRndererName;
}
/*!
@ -91,7 +83,7 @@ namespace Nz
std::string OpenAL::GetVendorName()
{
return s_vendorName;
return s_openalVendorName;
}
/*!
@ -101,7 +93,7 @@ namespace Nz
unsigned int OpenAL::GetVersion()
{
return s_version;
return s_openalVersion;
}
/*!
@ -149,7 +141,7 @@ namespace Nz
{
ErrorFlags errFlags(ErrorMode::Silent);
std::filesystem::path libPath(path);
if (!s_library.Load(libPath))
if (!s_openalLbrary.Load(libPath))
continue;
errFlags.SetFlags(0);
@ -284,7 +276,7 @@ namespace Nz
bool OpenAL::IsInitialized()
{
return s_library.IsLoaded();
return s_openalLbrary.IsLoaded();
}
/*!
@ -300,7 +292,7 @@ namespace Nz
if (!deviceString)
return 0;
return ParseDevices(deviceString, devices);
return ParseOpenALDevices(deviceString, devices);
}
/*!
@ -316,7 +308,7 @@ namespace Nz
if (!deviceString)
return 0;
return ParseDevices(deviceString, devices);
return ParseOpenALDevices(deviceString, devices);
}
/*!
@ -328,7 +320,7 @@ namespace Nz
bool OpenAL::SetDevice(const std::string& deviceName)
{
s_deviceName = deviceName;
s_openalDeviceName = deviceName;
if (IsInitialized())
{
CloseDevice();
@ -347,9 +339,9 @@ namespace Nz
{
CloseDevice();
s_rendererName.clear();
s_vendorName.clear();
s_library.Unload();
s_openalRndererName.clear();
s_openalVendorName.clear();
s_openalLbrary.Unload();
}
ALenum OpenAL::AudioFormat[AudioFormatCount] = {0}; // Added values with loading of OpenAL
@ -362,20 +354,20 @@ namespace Nz
void OpenAL::CloseDevice()
{
if (s_device)
if (s_openalDevice)
{
if (s_context)
if (s_openalContext)
{
alcMakeContextCurrent(nullptr);
alcDestroyContext(s_context);
s_context = nullptr;
alcDestroyContext(s_openalContext);
s_openalContext = nullptr;
}
if (!alcCloseDevice(s_device))
if (!alcCloseDevice(s_openalDevice))
// We could not close the close, this means that it's still in use
NazaraWarning("Failed to close device");
s_device = nullptr;
s_openalDevice = nullptr;
}
}
@ -389,29 +381,29 @@ namespace Nz
bool OpenAL::OpenDevice()
{
// Initialisation of the module
s_device = alcOpenDevice(s_deviceName.empty() ? nullptr : s_deviceName.data()); // We choose the default device
if (!s_device)
s_openalDevice = alcOpenDevice(s_openalDeviceName.empty() ? nullptr : s_openalDeviceName.data()); // We choose the default device
if (!s_openalDevice)
{
NazaraError("Failed to open default device");
return false;
}
// One context is enough
s_context = alcCreateContext(s_device, nullptr);
if (!s_context)
s_openalContext = alcCreateContext(s_openalDevice, nullptr);
if (!s_openalContext)
{
NazaraError("Failed to create context");
return false;
}
if (!alcMakeContextCurrent(s_context))
if (!alcMakeContextCurrent(s_openalContext))
{
NazaraError("Failed to activate context");
return false;
}
s_rendererName = reinterpret_cast<const char*>(alGetString(AL_RENDERER));
s_vendorName = reinterpret_cast<const char*>(alGetString(AL_VENDOR));
s_openalRndererName = reinterpret_cast<const char*>(alGetString(AL_RENDERER));
s_openalVendorName = reinterpret_cast<const char*>(alGetString(AL_VENDOR));
const ALchar* version = alGetString(AL_VERSION);
if (version)
@ -427,20 +419,20 @@ namespace Nz
minor = 0;
}
s_version = major*100 + minor*10;
s_openalVersion = major*100 + minor*10;
NazaraDebug("OpenAL version: " + NumberToString(major) + '.' + NumberToString(minor));
}
else
{
NazaraDebug("Unable to retrieve OpenAL major version");
s_version = 0;
s_openalVersion = 0;
}
}
else
{
NazaraDebug("Unable to retrieve OpenAL version");
s_version = 0;
s_openalVersion = 0;
}
// We complete the formats table
@ -473,7 +465,7 @@ namespace Nz
OpenALFunc OpenAL::LoadEntry(const char* name, bool throwException)
{
OpenALFunc entry = reinterpret_cast<OpenALFunc>(s_library.GetSymbol(name));
OpenALFunc entry = reinterpret_cast<OpenALFunc>(s_openalLbrary.GetSymbol(name));
if (!entry && throwException)
{
std::ostringstream oss;

View File

@ -9,7 +9,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
const char* errorType[] = {
"Assert failed: ", // ErrorType::AssertFailed
@ -41,6 +41,8 @@ namespace Nz
*/
void AbstractLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::ostringstream ss;
ss << errorType[UnderlyingCast(type)] << error;

View File

@ -0,0 +1,9 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef _WINDOWS_
#error This header should only be included after including windows.h directly or indirectly in a .cpp
#endif
#undef RemoveDirectory

View File

@ -0,0 +1,10 @@
// Copyright (C) 2022 Jérôme "Lynix" Leclercq (lynix680@gmail.com)
// This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef _X11_XLIB_H_
#error This header should only be included after including X11/Xlib.h directly or indirectly in a .cpp
#endif
#undef Bool
#undef None

View File

@ -99,3 +99,8 @@ namespace Nz
DynLib& DynLib::operator=(DynLib&&) noexcept = default;
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -203,3 +203,7 @@ namespace Nz
const char* Error::s_lastErrorFile = "";
unsigned int Error::s_lastErrorLine = 0;
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -452,3 +452,8 @@ namespace Nz
return true;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -21,7 +21,7 @@ namespace Nz
* \brief Core class that represents the "Guillotine problem", combination of the "Bin packing problem" and the "cutting stock"
*/
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
/*!
* \brief Gets the score for fitting the area
@ -635,6 +635,8 @@ namespace Nz
int GuillotineBinPack::ScoreByHeuristic(int width, int height, const Rectui& freeRect, FreeRectChoiceHeuristic rectChoice)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
switch (rectChoice)
{
case RectBestAreaFit:

View File

@ -20,7 +20,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
struct VendorString
{
@ -108,6 +108,8 @@ namespace Nz
std::string_view HardwareInfo::GetProcessorBrandString()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
NazaraError("Failed to initialize HardwareInfo");
@ -136,6 +138,8 @@ namespace Nz
ProcessorVendor HardwareInfo::GetProcessorVendor()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
NazaraError("Failed to initialize HardwareInfo");
@ -151,6 +155,8 @@ namespace Nz
std::string_view HardwareInfo::GetProcessorVendorName()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
NazaraError("Failed to initialize HardwareInfo");
@ -179,6 +185,8 @@ namespace Nz
bool HardwareInfo::HasCapability(ProcessorCap capability)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_capabilities[UnderlyingCast(capability)];
}
@ -191,6 +199,8 @@ namespace Nz
bool HardwareInfo::Initialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (IsInitialized())
return true;
@ -294,6 +304,8 @@ namespace Nz
bool HardwareInfo::IsInitialized()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_initialized;
}
@ -303,6 +315,8 @@ namespace Nz
void HardwareInfo::Uninitialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
// Nothing to do
s_initialized = false;
}

View File

@ -8,7 +8,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
UInt32 crc32_reflect(UInt32 ref, unsigned int j)
{
@ -63,6 +63,8 @@ namespace Nz
CRC32Hash::CRC32Hash(UInt32 polynomial)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (polynomial == DefaultPolynomial)
m_table = crc32_table;
else
@ -84,6 +86,8 @@ namespace Nz
CRC32Hash::~CRC32Hash()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (m_table != crc32_table)
delete[] m_table;
}

View File

@ -8,7 +8,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
static const UInt64 crc64_table[] = {
0x0000000000000000ULL, 0x42F0E1EBA9EA3693ULL, 0x85E1C3D753D46D26ULL, 0xC711223CFA3E5BB5ULL,
@ -80,6 +80,8 @@ namespace Nz
void CRC64Hash::Append(const UInt8* data, std::size_t len)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
while (len--)
m_crc = (m_crc << 8) ^ crc64_table[((m_crc >> 56) ^ *data++) & 0xFF];
}

View File

@ -254,6 +254,7 @@ namespace Nz
SET(c, d, a, b, 14, 17, T15);
SET(b, c, d, a, 15, 22, T16);
#undef SET
#undef F
/* Round 2. */
/* Let [abcd k s i] denote the operation
@ -280,6 +281,7 @@ namespace Nz
SET(c, d, a, b, 7, 14, T31);
SET(b, c, d, a, 12, 20, T32);
#undef SET
#undef G
/* Round 3. */
/* Let [abcd k s t] denote the operation
@ -306,6 +308,7 @@ namespace Nz
SET(c, d, a, b, 15, 16, T47);
SET(b, c, d, a, 2, 23, T48);
#undef SET
#undef H
/* Round 4. */
/* Let [abcd k s t] denote the operation
@ -332,6 +335,9 @@ namespace Nz
SET(c, d, a, b, 2, 15, T63);
SET(b, c, d, a, 9, 21, T64);
#undef SET
#undef I
#undef ROTATE_LEFT
/* Then perform the following additions. (That is increment each
of the four registers by the value it had before this block
@ -342,3 +348,69 @@ namespace Nz
m_abcd[3] += d;
}
}
#undef T_MASK
#undef T1
#undef T2
#undef T3
#undef T4
#undef T5
#undef T6
#undef T7
#undef T8
#undef T9
#undef T10
#undef T11
#undef T12
#undef T13
#undef T14
#undef T15
#undef T16
#undef T17
#undef T18
#undef T19
#undef T20
#undef T21
#undef T22
#undef T23
#undef T24
#undef T25
#undef T26
#undef T27
#undef T28
#undef T29
#undef T30
#undef T31
#undef T32
#undef T33
#undef T34
#undef T35
#undef T36
#undef T37
#undef T38
#undef T39
#undef T40
#undef T41
#undef T42
#undef T43
#undef T44
#undef T45
#undef T46
#undef T47
#undef T48
#undef T49
#undef T50
#undef T51
#undef T52
#undef T53
#undef T54
#undef T55
#undef T56
#undef T57
#undef T58
#undef T59
#undef T60
#undef T61
#undef T62
#undef T63
#undef T64

View File

@ -1062,3 +1062,35 @@ namespace Nz
}
}
}
#undef ADDINC128
#undef K1_0_TO_19
#undef K1_20_TO_39
#undef K1_40_TO_59
#undef K1_60_TO_79
#undef REVERSE32
#undef REVERSE64
#undef ROUND1_0_TO_15
#undef ROUND1_16_TO_19
#undef ROUND1_20_TO_39
#undef ROUND1_40_TO_59
#undef ROUND1_60_TO_79
#undef ROUND256
#undef ROUND256_0_TO_15
#undef ROUND512
#undef ROUND512_0_TO_15
#undef SHR
#undef ROTL32
#undef ROTR32
#undef ROTR64
#undef Ch
#undef Maj
#undef Parity
#undef Sigma0_256
#undef Sigma1_256
#undef sigma0_256
#undef sigma1_256
#undef Sigma0_512
#undef Sigma1_512
#undef sigma0_512
#undef sigma1_512

View File

@ -73,7 +73,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
const UInt64 C0[256] = {
0X18186018C07830D8ULL, 0X23238C2305AF4626ULL, 0XC6C63FC67EF991B8ULL, 0XE8E887E8136FCDFBULL,
@ -788,6 +788,8 @@ namespace Nz
void WhirlpoolHash::ProcessBuffer()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
int i, r;
UInt64 K[8]; // the round key
UInt64 block[8]; // mu(buffer)
@ -1020,3 +1022,8 @@ namespace Nz
m_hash[7] ^= state[7] ^ block[7];
}
}
#undef ONE64
#undef ROTR64
#undef R
#undef T64

View File

@ -10,7 +10,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
StdLogger s_stdLogger;
}
@ -60,6 +60,8 @@ namespace Nz
void Log::SetLogger(AbstractLogger* logger)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (s_logger != &s_stdLogger)
delete s_logger;
@ -111,6 +113,8 @@ namespace Nz
bool Log::Initialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (s_logger == &s_stdLogger)
SetLogger(new FileLogger());
@ -129,6 +133,6 @@ namespace Nz
NazaraStaticSignalImpl(Log, OnLogWrite);
NazaraStaticSignalImpl(Log, OnLogWriteError);
AbstractLogger* Log::s_logger = &s_stdLogger;
AbstractLogger* Log::s_logger = &NAZARA_ANONYMOUS_NAMESPACE_PREFIX(s_stdLogger);
bool Log::s_enabled = true;
}

View File

@ -20,7 +20,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
constexpr unsigned int s_allocatedId = 0xDEADB33FUL;
constexpr unsigned int s_freedId = 0x4B1DUL;
@ -102,6 +102,8 @@ namespace Nz
void* MemoryManager::Allocate(std::size_t size, bool multi, const char* file, unsigned int line)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!s_initialized)
Initialize();
@ -182,6 +184,8 @@ namespace Nz
void MemoryManager::EnableAllocationFilling(bool allocationFilling)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
s_allocationFilling = allocationFilling;
}
@ -193,6 +197,8 @@ namespace Nz
void MemoryManager::EnableAllocationLogging(bool logAllocations)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
s_allocationLogging = logAllocations;
}
@ -207,6 +213,8 @@ namespace Nz
void MemoryManager::Free(void* pointer, bool multi)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!pointer)
return;
@ -282,6 +290,8 @@ namespace Nz
unsigned int MemoryManager::GetAllocatedBlockCount()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_allocatedBlock;
}
@ -292,6 +302,8 @@ namespace Nz
std::size_t MemoryManager::GetAllocatedSize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_allocatedSize;
}
@ -302,6 +314,8 @@ namespace Nz
unsigned int MemoryManager::GetAllocationCount()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_allocationCount;
}
@ -312,6 +326,8 @@ namespace Nz
bool MemoryManager::IsAllocationFillingEnabled()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_allocationFilling;
}
@ -322,6 +338,8 @@ namespace Nz
bool MemoryManager::IsAllocationLoggingEnabled()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return s_allocationLogging;
}
@ -334,6 +352,8 @@ namespace Nz
void MemoryManager::NextFree(const char* file, unsigned int line)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
s_nextFreeFile = file;
s_nextFreeLine = line;
}
@ -344,6 +364,8 @@ namespace Nz
void MemoryManager::Initialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
char timeStr[23];
TimeInfo(timeStr);
@ -384,6 +406,8 @@ namespace Nz
void MemoryManager::Uninitialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
#ifdef NAZARA_PLATFORM_WINDOWS
DeleteCriticalSection(&s_mutex);
#elif defined(NAZARA_PLATFORM_POSIX)
@ -430,3 +454,7 @@ namespace Nz
std::fclose(log);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -11,7 +11,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
using PluginLoad = int (*)();
using PluginUnload = void (*)();
@ -78,6 +78,8 @@ namespace Nz
bool PluginManager::Mount(Plugin plugin)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::filesystem::path pluginName = s_pluginFiles[UnderlyingCast(plugin)];
#ifdef NAZARA_DEBUG
@ -107,6 +109,8 @@ namespace Nz
bool PluginManager::Mount(const std::filesystem::path& pluginPath, bool appendExtension)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
{
NazaraError("Failed to initialize PluginManager");
@ -176,6 +180,8 @@ namespace Nz
void PluginManager::RemoveDirectory(const std::filesystem::path& directoryPath)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
{
NazaraError("Failed to initialize PluginManager");
@ -196,6 +202,8 @@ namespace Nz
void PluginManager::Unmount(Plugin plugin)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Unmount(s_pluginFiles[UnderlyingCast(plugin)]);
}
@ -210,6 +218,8 @@ namespace Nz
void PluginManager::Unmount(const std::filesystem::path& pluginPath)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!Initialize())
{
NazaraError("Failed to initialize PluginManager");
@ -237,6 +247,8 @@ namespace Nz
void PluginManager::Uninitialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!s_initialized)
return;

View File

@ -9,7 +9,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
const char* errorType[] = {
"Assert failed", // ErrorType::AssertFailed
@ -81,6 +81,8 @@ namespace Nz
void StdLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
fprintf(stderr, "%s: ", errorType[UnderlyingCast(type)]);
fwrite(error.data(), sizeof(char), error.size(), stdout);

View File

@ -11,7 +11,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
bool IsSpace(char32_t character)
{
@ -115,6 +115,8 @@ namespace Nz
std::string FromWideString(const std::wstring_view& wstr)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return WideConverter<sizeof(wchar_t)>::From(wstr.data(), wstr.size());
}
@ -163,6 +165,8 @@ namespace Nz
std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
utf8::unchecked::iterator<const char*> it(str.data());
utf8::unchecked::iterator<const char*> end(str.data() + str.size());
@ -254,6 +258,8 @@ namespace Nz
bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (rhs.size() > lhs.size())
return false;
@ -343,6 +349,8 @@ namespace Nz
std::string ToLower(const std::string_view& str)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::string result;
result.reserve(str.size());
std::transform(str.begin(), str.end(), std::back_inserter(result), Overload<char>(ToLower));
@ -368,6 +376,8 @@ namespace Nz
std::string ToUpper(const std::string_view& str)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::string result;
result.reserve(str.size());
std::transform(str.begin(), str.end(), std::back_inserter(result), Overload<char>(ToUpper));
@ -409,11 +419,15 @@ namespace Nz
std::wstring ToWideString(const std::string_view& str)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return WideConverter<sizeof(wchar_t)>::To(str);
}
std::string_view TrimLeft(std::string_view str)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
while (!str.empty() && IsSpace(str.front()))
str.remove_prefix(1);
@ -422,6 +436,8 @@ namespace Nz
std::string_view TrimLeft(std::string_view str, UnicodeAware)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
utf8::unchecked::iterator<const char*> it(str.data());
utf8::unchecked::iterator<const char*> end(str.data() + str.size());
while (it != end && IsSpace(*it))
@ -465,6 +481,8 @@ namespace Nz
std::string_view TrimRight(std::string_view str)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
while (!str.empty() && IsSpace(str.back()))
str.remove_suffix(1);
@ -473,6 +491,8 @@ namespace Nz
std::string_view TrimRight(std::string_view str, UnicodeAware)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (str.empty())
return str;

View File

@ -33,7 +33,7 @@ namespace Nz
#include <Nazara/Core/UnicodeData.hpp>
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
const UnicodeCharacter* GetCharacter(Nz::UInt32 codepoint)
{
@ -74,6 +74,8 @@ namespace Nz
*/
Unicode::Category Unicode::GetCategory(char32_t character)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (const UnicodeCharacter* characterData = GetCharacter(character))
return characterData->category;
else
@ -89,6 +91,8 @@ namespace Nz
Unicode::Direction Unicode::GetDirection(char32_t character)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (const UnicodeCharacter* characterData = GetCharacter(character))
return characterData->direction;
else
@ -104,6 +108,8 @@ namespace Nz
char32_t Unicode::GetLowercase(char32_t character)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (const UnicodeCharacterSimpleMapping* characterMapping = GetCharacterMapping(character, unicodeLower))
return characterMapping->character;
else
@ -118,6 +124,8 @@ namespace Nz
*/
char32_t Unicode::GetTitlecase(char32_t character)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (const UnicodeCharacterSimpleMapping* characterMapping = GetCharacterMapping(character, unicodeTitle))
return characterMapping->character;
else
@ -132,6 +140,8 @@ namespace Nz
*/
char32_t Unicode::GetUppercase(char32_t character)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (const UnicodeCharacterSimpleMapping* characterMapping = GetCharacterMapping(character, unicodeUpper))
return characterMapping->character;
else

View File

@ -10,18 +10,22 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
LARGE_INTEGER s_frequency; // La fréquence ne varie pas pas au cours de l'exécution
}
bool ClockImplInitializeHighPrecision()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
return QueryPerformanceFrequency(&s_frequency) != 0;
}
UInt64 ClockImplGetElapsedMicroseconds()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644904(v=vs.85).aspx
//HANDLE thread = GetCurrentThread();
//DWORD oldMask = SetThreadAffinityMask(thread, 1);
@ -43,3 +47,5 @@ namespace Nz
#endif
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -47,3 +47,5 @@ namespace Nz
}
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -45,3 +45,5 @@ namespace Nz
}
#endif // NAZARA_CORE_WIN32_FILEIMPL_HPP
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -110,3 +110,5 @@ namespace Nz
#endif
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -246,3 +246,5 @@ namespace Nz
std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_workerThreads; // Doivent être contigus
DWORD TaskSchedulerImpl::s_workerCount;
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -26,3 +26,5 @@ namespace Nz
return std::mktime(&timeinfo);
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -19,7 +19,7 @@ namespace Nz
{
namespace
{
const UInt8 r_shader[] = {
const UInt8 r_basicMaterialShader[] = {
#include <Nazara/Graphics/Resources/Shaders/basic_material.nzsl.h>
};
}
@ -254,7 +254,7 @@ namespace Nz
#endif
if (!shaderModule)
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_shader), sizeof(r_shader)));
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_basicMaterialShader), sizeof(r_basicMaterialShader)));
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, std::move(shaderModule));

View File

@ -11,7 +11,7 @@ namespace Nz
{
namespace
{
const UInt8 r_shader[] = {
const UInt8 r_depthMaterialShader[] = {
#include <Nazara/Graphics/Resources/Shaders/depth_material.nzsl.h>
};
}
@ -36,7 +36,7 @@ namespace Nz
#endif
if (!shaderModule)
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_shader), sizeof(r_shader)));
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_depthMaterialShader), sizeof(r_depthMaterialShader)));
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, std::move(shaderModule));

View File

@ -6,6 +6,7 @@
// https://themaister.net/blog/2017/08/15/render-graphs-and-vulkan-a-deep-dive/
#include <Nazara/Graphics/FrameGraph.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Graphics/Graphics.hpp>
#include <stdexcept>
@ -16,13 +17,6 @@ namespace Nz
{
namespace
{
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
template<typename T> void UniquePushBack(std::vector<T>& vec, const T& value)
{
auto it = std::find(vec.begin(), vec.end(), value);

View File

@ -19,7 +19,7 @@ namespace Nz
{
namespace
{
const UInt8 r_shader[] = {
const UInt8 r_phongMaterialShader[] = {
#include <Nazara/Graphics/Resources/Shaders/phong_material.nzsl.h>
};
}
@ -335,7 +335,7 @@ namespace Nz
#endif
if (!shaderModule)
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_shader), sizeof(r_shader)));
shaderModule = ShaderLang::Parse(std::string_view(reinterpret_cast<const char*>(r_phongMaterialShader), sizeof(r_phongMaterialShader)));
auto shader = std::make_shared<UberShader>(ShaderStageType::Fragment | ShaderStageType::Vertex, std::move(shaderModule));

View File

@ -23,7 +23,7 @@ namespace Nz
{
namespace
{
static std::size_t s_commandSizes[ENetProtocolCommand_Count] =
static std::size_t s_enetCommandSizes[ENetProtocolCommand_Count] =
{
0,
sizeof(ENetProtocolAcknowledge),
@ -567,7 +567,7 @@ namespace Nz
if (commandNumber >= ENetProtocolCommand_Count)
break;
std::size_t commandSize = s_commandSizes[commandNumber];
std::size_t commandSize = s_enetCommandSizes[commandNumber];
if (commandSize == 0 || currentData + commandSize > &m_receivedData[m_receivedDataLength])
break;
@ -893,7 +893,7 @@ namespace Nz
canPing = false;
assert((outgoingCommand->command.header.command & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
std::size_t commandSize = s_commandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
std::size_t commandSize = s_enetCommandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
if (m_commandCount >= m_commands.size() || m_bufferCount + 1 >= m_buffers.size() || peer->GetMtu() - m_packetSize < commandSize ||
(outgoingCommand->packet && UInt16(peer->GetMtu() - m_packetSize) < UInt16(commandSize + outgoingCommand->fragmentLength)))
{
@ -1146,7 +1146,7 @@ namespace Nz
auto outgoingCommand = currentCommand;
assert((outgoingCommand->command.header.command & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
std::size_t commandSize = s_commandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
std::size_t commandSize = s_enetCommandSizes[outgoingCommand->command.header.command & ENetProtocolCommand_Mask];
if (m_commandCount >= m_commands.size() || m_bufferCount + 1 >= m_buffers.size() || peer->m_mtu - m_packetSize < commandSize ||
(outgoingCommand->packet && peer->m_mtu - m_packetSize < commandSize + outgoingCommand->fragmentLength))
@ -1360,7 +1360,7 @@ namespace Nz
std::size_t ENetHost::GetCommandSize(UInt8 commandNumber)
{
assert((commandNumber & ENetProtocolCommand_Mask) < ENetProtocolCommand_Count);
return s_commandSizes[commandNumber & ENetProtocolCommand_Mask];
return s_enetCommandSizes[commandNumber & ENetProtocolCommand_Mask];
}
bool ENetHost::Initialize()

View File

@ -120,3 +120,7 @@ namespace Nz
return m_deviceInfos;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -18,7 +18,7 @@
namespace Nz::GL
{
thread_local const Context* s_currentContext = nullptr;
thread_local const Context* s_currentGLContext = nullptr;
namespace
{
@ -32,7 +32,7 @@ namespace Nz::GL
{
return [](Args... args) -> Ret
{
const Context* context = s_currentContext; //< pay TLS cost once
const Context* context = s_currentGLContext; //< pay TLS cost once
assert(context);
FuncType funcPtr = reinterpret_cast<FuncType>(context->GetFunctionByIndex(FuncIndex));
@ -755,12 +755,12 @@ namespace Nz::GL
const Context* Context::GetCurrentContext()
{
return s_currentContext;
return s_currentGLContext;
}
bool Context::SetCurrentContext(const Context* context)
{
const Context*& currentContext = s_currentContext; //< Pay TLS cost once
const Context*& currentContext = s_currentGLContext; //< Pay TLS cost once
if (currentContext == context)
return true;
@ -810,7 +810,7 @@ namespace Nz::GL
void Context::NotifyContextDestruction(Context* context)
{
const Context*& currentContext = s_currentContext; //< Pay TLS cost only once
const Context*& currentContext = s_currentGLContext; //< Pay TLS cost only once
if (currentContext == context)
currentContext = nullptr;
}

View File

@ -337,3 +337,7 @@ namespace Nz::GL
return true;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -236,3 +236,7 @@ namespace Nz::GL
return false;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -26,7 +26,7 @@ namespace Nz::GL
if (!ChooseConfig(configs.data(), configs.size(), &configCount))
return false;
::Window winHandle = static_cast<::Window>(window.x11.window);
::NativeWindowType winHandle = static_cast<::NativeWindowType>(window.x11.window);
std::size_t configIndex = 0;
for (; configIndex < configCount; ++configIndex)

View File

@ -391,3 +391,5 @@ namespace Nz::GL
return true;
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -128,3 +128,5 @@ namespace Nz::GL
return func;
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -83,3 +83,5 @@ namespace Nz::GL
m_ownedWindow.reset();
}
}
#include <Nazara/Core/AntiWindows.hpp>

View File

@ -17,7 +17,7 @@ namespace Nz
{
namespace
{
constexpr cpSpaceDebugColor white = { 1.f, 1.f, 1.f, 1.f };
constexpr cpSpaceDebugColor s_chipmunkWhite = { 1.f, 1.f, 1.f, 1.f };
Vector2f FromChipmunk(const cpVect& v)
{
@ -54,14 +54,14 @@ namespace Nz
using CallbackType = std::decay_t<decltype(callback)>;
cpSpaceDebugDrawOptions drawOptions;
drawOptions.collisionPointColor = white;
drawOptions.constraintColor = white;
drawOptions.shapeOutlineColor = white;
drawOptions.collisionPointColor = s_chipmunkWhite;
drawOptions.constraintColor = s_chipmunkWhite;
drawOptions.shapeOutlineColor = s_chipmunkWhite;
drawOptions.data = const_cast<void*>(static_cast<const void*>(&callback));
drawOptions.flags = CP_SPACE_DEBUG_DRAW_SHAPES;
// Callback trampoline
drawOptions.colorForShape = [](cpShape* /*shape*/, cpDataPointer /*userdata*/) { return white; };
drawOptions.colorForShape = [](cpShape* /*shape*/, cpDataPointer /*userdata*/) { return s_chipmunkWhite; };
drawOptions.drawCircle = [](cpVect pos, cpFloat /*angle*/, cpFloat radius, cpSpaceDebugColor /*outlineColor*/, cpSpaceDebugColor /*fillColor*/, cpDataPointer userdata)
{
const auto& callback = *static_cast<const CallbackType*>(userdata);

View File

@ -22,23 +22,21 @@ namespace Nz
return cpSpaceDebugColor{ c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f };
}
void DrawCircle(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
void CpCircleCallback(cpVect pos, cpFloat angle, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->circleCallback)
drawOptions->circleCallback(Vector2f(float(pos.x), float(pos.y)), RadianAnglef(float(angle)), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
}
void DrawDot(cpFloat size, cpVect pos, cpSpaceDebugColor color, cpDataPointer userdata)
void CpDotCallback(cpFloat size, cpVect pos, cpSpaceDebugColor color, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->dotCallback)
drawOptions->dotCallback(Vector2f(float(pos.x), float(pos.y)), float(size), CpDebugColorToColor(color), drawOptions->userdata);
}
using DebugDrawPolygonCallback = std::function<void(const Vector2f* vertices, std::size_t vertexCount, float radius, Color outlineColor, Color fillColor, void* userdata)>;
void DrawPolygon(int vertexCount, const cpVect* vertices, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
void CpPolygonCallback(int vertexCount, const cpVect* vertices, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->polygonCallback)
@ -53,21 +51,21 @@ namespace Nz
}
}
void DrawSegment(cpVect a, cpVect b, cpSpaceDebugColor color, cpDataPointer userdata)
void CpSegmentCallback(cpVect a, cpVect b, cpSpaceDebugColor color, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->segmentCallback)
drawOptions->segmentCallback(Vector2f(float(a.x), float(a.y)), Vector2f(float(b.x), float(b.y)), CpDebugColorToColor(color), drawOptions->userdata);
}
void DrawThickSegment(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
void CpThickSegmentCallback(cpVect a, cpVect b, cpFloat radius, cpSpaceDebugColor outlineColor, cpSpaceDebugColor fillColor, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->thickSegmentCallback)
drawOptions->thickSegmentCallback(Vector2f(float(a.x), float(a.y)), Vector2f(float(b.x), float(b.y)), float(radius), CpDebugColorToColor(outlineColor), CpDebugColorToColor(fillColor), drawOptions->userdata);
}
cpSpaceDebugColor GetColorForShape(cpShape* shape, cpDataPointer userdata)
cpSpaceDebugColor CpShapeColorCallback(cpShape* shape, cpDataPointer userdata)
{
auto drawOptions = static_cast<PhysWorld2D::DebugDrawOptions*>(userdata);
if (drawOptions->colorCallback)
@ -120,12 +118,12 @@ namespace Nz
drawOptions.flags = static_cast<cpSpaceDebugDrawFlags>(drawFlags);
// Callback trampoline
drawOptions.colorForShape = GetColorForShape;
drawOptions.drawCircle = DrawCircle;
drawOptions.drawDot = DrawDot;
drawOptions.drawFatSegment = DrawThickSegment;
drawOptions.drawPolygon = DrawPolygon;
drawOptions.drawSegment = DrawSegment;
drawOptions.colorForShape = CpShapeColorCallback;
drawOptions.drawCircle = CpCircleCallback;
drawOptions.drawDot = CpDotCallback;
drawOptions.drawFatSegment = CpThickSegmentCallback;
drawOptions.drawPolygon = CpPolygonCallback;
drawOptions.drawSegment = CpSegmentCallback;
cpSpaceDebugDraw(m_handle, &drawOptions);
}

View File

@ -23,8 +23,6 @@ namespace Nz
{
namespace
{
WindowImpl* fullscreenWindow = nullptr;
Mouse::Button SDLToNazaraButton(Uint8 sdlButton)
{
switch (sdlButton)
@ -88,8 +86,6 @@ namespace Nz
{
x = 0;
y = 0;
fullscreenWindow = this;
}
else
{

View File

@ -12,9 +12,9 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
Window* fullscreenWindow = nullptr;
Window* s_fullscreenWindow = nullptr;
}
Window::Window() :
@ -52,6 +52,8 @@ namespace Nz
bool Window::Create(VideoMode mode, const std::string& title, WindowStyleFlags style)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
// If the window is already open, we keep its position
bool opened = IsOpen();
Vector2i position;
@ -63,9 +65,9 @@ namespace Nz
// Inspired by the code of the SFML by Laurent Gomila (and its team)
if (style & WindowStyle::Fullscreen)
{
if (fullscreenWindow)
if (s_fullscreenWindow)
{
NazaraError("Window " + PointerToString(fullscreenWindow) + " already in fullscreen mode");
NazaraError("Window " + PointerToString(s_fullscreenWindow) + " already in fullscreen mode");
style &= ~WindowStyle::Fullscreen;
}
else
@ -76,7 +78,7 @@ namespace Nz
mode = VideoMode::GetFullscreenModes()[0];
}
fullscreenWindow = this;
s_fullscreenWindow = this;
}
}
else if (style & WindowStyle::Closable || style & WindowStyle::Resizable)
@ -152,6 +154,8 @@ namespace Nz
void Window::Destroy()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
m_cursor.reset();
if (m_impl)
@ -162,8 +166,8 @@ namespace Nz
delete m_impl;
m_impl = nullptr;
if (fullscreenWindow == this)
fullscreenWindow = nullptr;
if (s_fullscreenWindow == this)
s_fullscreenWindow = nullptr;
}
}

View File

@ -10,14 +10,8 @@
namespace Nz::ShaderAst
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
template<typename T, typename U>
std::unique_ptr<T> static_unique_pointer_cast(std::unique_ptr<U>&& ptr)
{
return std::unique_ptr<T>(static_cast<T*>(ptr.release()));
}
template <typename T>
struct is_complete_helper
{
@ -1138,6 +1132,8 @@ namespace Nz::ShaderAst
template<BinaryType Type>
ExpressionPtr AstConstantPropagationVisitor::PropagateBinaryConstant(const ConstantValueExpression& lhs, const ConstantValueExpression& rhs)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg1)
{
@ -1167,6 +1163,8 @@ namespace Nz::ShaderAst
template<typename TargetType>
ExpressionPtr AstConstantPropagationVisitor::PropagateSingleValueCast(const ConstantValueExpression& operand)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg)
@ -1184,6 +1182,8 @@ namespace Nz::ShaderAst
template<std::size_t TargetComponentCount>
ExpressionPtr AstConstantPropagationVisitor::PropagateConstantSwizzle(const std::array<UInt32, 4>& components, const ConstantValueExpression& operand)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg)
{
@ -1204,6 +1204,8 @@ namespace Nz::ShaderAst
template<UnaryType Type>
ExpressionPtr AstConstantPropagationVisitor::PropagateUnaryConstant(const ConstantValueExpression& operand)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
std::visit([&](auto&& arg)
{
@ -1227,6 +1229,8 @@ namespace Nz::ShaderAst
template<typename TargetType>
ExpressionPtr AstConstantPropagationVisitor::PropagateVec2Cast(TargetType v1, TargetType v2)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstant<Vector2<TargetType>, TargetType, TargetType>;
@ -1240,6 +1244,8 @@ namespace Nz::ShaderAst
template<typename TargetType>
ExpressionPtr AstConstantPropagationVisitor::PropagateVec3Cast(TargetType v1, TargetType v2, TargetType v3)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstant<Vector3<TargetType>, TargetType, TargetType, TargetType>;
@ -1253,6 +1259,8 @@ namespace Nz::ShaderAst
template<typename TargetType>
ExpressionPtr AstConstantPropagationVisitor::PropagateVec4Cast(TargetType v1, TargetType v2, TargetType v3, TargetType v4)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::unique_ptr<ConstantValueExpression> optimized;
using CCType = CastConstant<Vector4<TargetType>, TargetType, TargetType, TargetType, TargetType>;

View File

@ -12,8 +12,8 @@ namespace Nz::ShaderAst
{
namespace
{
constexpr UInt32 s_magicNumber = 0x4E534852;
constexpr UInt32 s_currentVersion = 1;
constexpr UInt32 s_shaderAstMagicNumber = 0x4E534852;
constexpr UInt32 s_shaderAstCurrentVersion = 1;
class ShaderSerializerVisitor : public AstExpressionVisitor, public AstStatementVisitor
{
@ -375,7 +375,7 @@ namespace Nz::ShaderAst
void ShaderAstSerializer::Serialize(ModulePtr& module)
{
m_stream << s_magicNumber << s_currentVersion;
m_stream << s_shaderAstMagicNumber << s_shaderAstCurrentVersion;
SerializeModule(module);
@ -588,11 +588,11 @@ namespace Nz::ShaderAst
UInt32 magicNumber;
UInt32 version;
m_stream >> magicNumber;
if (magicNumber != s_magicNumber)
if (magicNumber != s_shaderAstMagicNumber)
throw std::runtime_error("invalid shader file");
m_stream >> version;
if (version > s_currentVersion)
if (version > s_shaderAstCurrentVersion)
throw std::runtime_error("unsupported version");
ModulePtr module;

View File

@ -7,23 +7,6 @@
namespace Nz::ShaderAst
{
namespace
{
template<typename T> T& Retrieve(std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
}
void DependencyCheckerVisitor::Process(Statement& statement, const Config& config)
{
m_config = config;

View File

@ -25,19 +25,10 @@
namespace Nz::ShaderAst
{
namespace
struct SanitizeVisitor::AstError
{
struct AstError
{
std::string errMsg;
};
template<typename T, typename U>
std::unique_ptr<T> static_unique_pointer_cast(std::unique_ptr<U>&& ptr)
{
return std::unique_ptr<T>(SafeCast<T*>(ptr.release()));
}
}
std::string errMsg;
};
struct SanitizeVisitor::CurrentFunctionData
{
@ -446,7 +437,7 @@ namespace Nz::ShaderAst
for (auto& index : node.indices)
MandatoryExpr(index);
auto clone = static_unique_pointer_cast<AccessIndexExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<AccessIndexExpression>(AstCloner::Clone(node));
Validate(*clone);
// TODO: Handle AccessIndex on structs with m_context->options.useIdentifierAccessesForStructs
@ -478,7 +469,7 @@ namespace Nz::ShaderAst
MandatoryExpr(node.left);
MandatoryExpr(node.right);
auto clone = static_unique_pointer_cast<AssignExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<AssignExpression>(AstCloner::Clone(node));
Validate(*clone);
return clone;
@ -486,7 +477,7 @@ namespace Nz::ShaderAst
ExpressionPtr SanitizeVisitor::Clone(BinaryExpression& node)
{
auto clone = static_unique_pointer_cast<BinaryExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<BinaryExpression>(AstCloner::Clone(node));
Validate(*clone);
return clone;
@ -590,7 +581,7 @@ namespace Nz::ShaderAst
ExpressionPtr SanitizeVisitor::Clone(CastExpression& node)
{
auto clone = static_unique_pointer_cast<CastExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<CastExpression>(AstCloner::Clone(node));
Validate(*clone);
const ExpressionType& targetType = clone->targetType.GetResultingValue();
@ -690,7 +681,7 @@ namespace Nz::ShaderAst
if (std::holds_alternative<NoValue>(node.value))
throw std::runtime_error("expected a value");
auto clone = static_unique_pointer_cast<ConstantValueExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<ConstantValueExpression>(AstCloner::Clone(node));
clone->cachedExpressionType = GetExpressionType(clone->value);
return clone;
@ -772,7 +763,7 @@ namespace Nz::ShaderAst
ExpressionPtr SanitizeVisitor::Clone(UnaryExpression& node)
{
auto clone = static_unique_pointer_cast<UnaryExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<UnaryExpression>(AstCloner::Clone(node));
Validate(*clone);
return clone;
@ -780,7 +771,7 @@ namespace Nz::ShaderAst
ExpressionPtr SanitizeVisitor::Clone(VariableValueExpression& node)
{
auto clone = static_unique_pointer_cast<VariableValueExpression>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<VariableValueExpression>(AstCloner::Clone(node));
Validate(*clone);
return clone;
@ -887,7 +878,7 @@ namespace Nz::ShaderAst
StatementPtr SanitizeVisitor::Clone(DeclareConstStatement& node)
{
auto clone = static_unique_pointer_cast<DeclareConstStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<DeclareConstStatement>(AstCloner::Clone(node));
if (!clone->expression)
throw AstError{ "const variables must have an expression" };
@ -917,7 +908,7 @@ namespace Nz::ShaderAst
{
assert(m_context);
auto clone = static_unique_pointer_cast<DeclareExternalStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<DeclareExternalStatement>(AstCloner::Clone(node));
UInt32 defaultBlockSet = 0;
if (clone->bindingSet.HasValue())
@ -1051,7 +1042,7 @@ namespace Nz::ShaderAst
if (m_context->currentFunction)
throw AstError{ "options must be declared outside of functions" };
auto clone = static_unique_pointer_cast<DeclareOptionStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<DeclareOptionStatement>(AstCloner::Clone(node));
if (clone->optName.empty())
throw AstError{ "empty option name" };
@ -1083,7 +1074,7 @@ namespace Nz::ShaderAst
if (m_context->currentFunction)
throw AstError{ "structs must be declared outside of functions" };
auto clone = static_unique_pointer_cast<DeclareStructStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<DeclareStructStatement>(AstCloner::Clone(node));
if (clone->isExported.HasValue())
clone->isExported = ComputeExprValue(clone->isExported);
@ -1140,7 +1131,7 @@ namespace Nz::ShaderAst
if (!m_context->currentFunction)
throw AstError{ "global variables outside of external blocks are forbidden" };
auto clone = static_unique_pointer_cast<DeclareVariableStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<DeclareVariableStatement>(AstCloner::Clone(node));
Validate(*clone);
return clone;
@ -1615,7 +1606,7 @@ namespace Nz::ShaderAst
MandatoryExpr(node.condition);
MandatoryStatement(node.body);
auto clone = static_unique_pointer_cast<WhileStatement>(AstCloner::Clone(node));
auto clone = StaticUniquePointerCast<WhileStatement>(AstCloner::Clone(node));
Validate(*clone);
ExpressionValue<LoopUnroll> unrollValue;
@ -1902,7 +1893,7 @@ namespace Nz::ShaderAst
};
// Run optimizer on constant value to hopefully retrieve a single constant value
return static_unique_pointer_cast<T>(ShaderAst::PropagateConstants(node, optimizerOptions));
return StaticUniquePointerCast<T>(ShaderAst::PropagateConstants(node, optimizerOptions));
}
void SanitizeVisitor::PreregisterIndices(const Module& module)

View File

@ -22,19 +22,12 @@ namespace Nz
{
namespace
{
static const char* s_flipYUniformName = "_NzFlipYValue";
static const char* s_inputPrefix = "_NzIn_";
static const char* s_outputPrefix = "_NzOut_";
static const char* s_outputVarName = "_nzOutput";
static const char* s_glslWriterFlipYUniformName = "_NzFlipYValue";
static const char* s_glslWriterInputPrefix = "_NzIn_";
static const char* s_glslWriterOutputPrefix = "_NzOut_";
static const char* s_glslWriterOutputVarName = "_nzOutput";
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
struct PreVisitor : ShaderAst::AstRecursiveVisitor
struct GlslWriterPreVisitor : ShaderAst::AstRecursiveVisitor
{
using AstRecursiveVisitor::Visit;
@ -110,13 +103,13 @@ namespace Nz
ShaderAst::DeclareFunctionStatement* entryPoint = nullptr;
};
struct Builtin
struct GlslBuiltin
{
std::string identifier;
ShaderStageTypeFlags stageFlags;
};
std::unordered_map<ShaderAst::BuiltinEntry, Builtin> s_builtinMapping = {
std::unordered_map<ShaderAst::BuiltinEntry, GlslBuiltin> s_glslBuiltinMapping = {
{ ShaderAst::BuiltinEntry::FragCoord, { "gl_FragCoord", ShaderStageType::Fragment } },
{ ShaderAst::BuiltinEntry::FragDepth, { "gl_FragDepth", ShaderStageType::Fragment } },
{ ShaderAst::BuiltinEntry::VertexPosition, { "gl_Position", ShaderStageType::Vertex } }
@ -152,7 +145,7 @@ namespace Nz
std::vector<InOutField> outputFields;
Bitset<> declaredFunctions;
const GlslWriter::BindingMapping& bindingMapping;
PreVisitor previsitor;
GlslWriterPreVisitor previsitor;
const States* states = nullptr;
bool isInEntryPoint = false;
unsigned int indentLevel = 0;
@ -249,7 +242,7 @@ namespace Nz
const char* GlslWriter::GetFlipYUniformName()
{
return s_flipYUniformName;
return s_glslWriterFlipYUniformName;
}
ShaderAst::SanitizeVisitor::Options GlslWriter::GetSanitizeOptions()
@ -724,10 +717,10 @@ namespace Nz
if (member.builtin.HasValue())
{
auto it = s_builtinMapping.find(member.builtin.GetResultingValue());
assert(it != s_builtinMapping.end());
auto it = s_glslBuiltinMapping.find(member.builtin.GetResultingValue());
assert(it != s_glslBuiltinMapping.end());
const Builtin& builtin = it->second;
const GlslBuiltin& builtin = it->second;
if (m_currentState->stage && !builtin.stageFlags.Test(*m_currentState->stage))
continue; //< This builtin is not active in this stage, skip it
@ -770,12 +763,12 @@ namespace Nz
const auto& inputStruct = Retrieve(m_currentState->structs, inputStructIndex);
AppendCommentSection("Inputs");
AppendInOut(inputStruct, m_currentState->inputFields, "in", s_inputPrefix);
AppendInOut(inputStruct, m_currentState->inputFields, "in", s_glslWriterInputPrefix);
}
if (m_currentState->stage == ShaderStageType::Vertex && m_environment.flipYPosition)
{
AppendLine("uniform float ", s_flipYUniformName, ";");
AppendLine("uniform float ", s_glslWriterFlipYUniformName, ";");
AppendLine();
}
@ -787,7 +780,7 @@ namespace Nz
const auto& outputStruct = Retrieve(m_currentState->structs, outputStructIndex);
AppendCommentSection("Outputs");
AppendInOut(outputStruct, m_currentState->outputFields, "out", s_outputPrefix);
AppendInOut(outputStruct, m_currentState->outputFields, "out", s_glslWriterOutputPrefix);
}
}
@ -1344,11 +1337,11 @@ namespace Nz
else
{
AppendLine();
Append(structData.nameOverride, " ", s_outputVarName, " = ");
Append(structData.nameOverride, " ", s_glslWriterOutputVarName, " = ");
node.returnExpr->Visit(*this);
AppendLine(";");
outputStructVarName = s_outputVarName;
outputStructVarName = s_glslWriterOutputVarName;
}
AppendLine();
@ -1362,7 +1355,7 @@ namespace Nz
{
// https://veldrid.dev/articles/backend-differences.html
if (m_environment.flipYPosition)
AppendLine(targetName, ".y *= ", s_flipYUniformName, ";");
AppendLine(targetName, ".y *= ", s_glslWriterFlipYUniformName, ";");
if (m_environment.remapZPosition)
AppendLine(targetName, ".z = ", targetName, ".z * 2.0 - ", targetName, ".w; ");

View File

@ -17,16 +17,6 @@
namespace Nz
{
namespace
{
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
}
struct LangWriter::BindingAttribute
{
const ShaderAst::ExpressionValue<UInt32>& bindingIndex;

View File

@ -12,7 +12,7 @@
namespace Nz::ShaderLang
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
std::unordered_map<std::string, ShaderAst::DepthWriteMode> s_depthWriteModes = {
{ "greater", ShaderAst::DepthWriteMode::Greater },
@ -58,15 +58,6 @@ namespace Nz::ShaderLang
{ "never", ShaderAst::LoopUnroll::Never }
};
template<typename T, typename U>
std::optional<T> BoundCast(U val)
{
if (val < std::numeric_limits<T>::min() || val > std::numeric_limits<T>::max())
return std::nullopt;
return static_cast<T>(val);
}
template<typename T>
void HandleUniqueAttribute(const std::string_view& attributeName, ShaderAst::ExpressionValue<T>& targetAttribute, ShaderAst::ExprValue::Param&& param)
{
@ -491,6 +482,8 @@ namespace Nz::ShaderLang
ShaderAst::StatementPtr Parser::ParseExternalBlock(std::vector<ShaderAst::ExprValue> attributes)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Expect(Advance(), TokenType::External);
Expect(Advance(), TokenType::OpenCurlyBracket);
@ -573,6 +566,8 @@ namespace Nz::ShaderLang
ShaderAst::StatementPtr Parser::ParseForDeclaration(std::vector<ShaderAst::ExprValue> attributes)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Expect(Advance(), TokenType::For);
std::string varName = ParseIdentifierAsName();
@ -647,6 +642,8 @@ namespace Nz::ShaderLang
ShaderAst::StatementPtr Parser::ParseFunctionDeclaration(std::vector<ShaderAst::ExprValue> attributes)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Expect(Advance(), TokenType::FunctionDeclaration);
std::string functionName = ParseIdentifierAsName();
@ -941,6 +938,8 @@ namespace Nz::ShaderLang
ShaderAst::StatementPtr Parser::ParseStructDeclaration(std::vector<ShaderAst::ExprValue> attributes)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Expect(Advance(), TokenType::Struct);
ShaderAst::StructDescription description;
@ -1083,6 +1082,8 @@ namespace Nz::ShaderLang
ShaderAst::StatementPtr Parser::ParseWhileStatement(std::vector<ShaderAst::ExprValue> attributes)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
Expect(Advance(), TokenType::While);
Expect(Advance(), TokenType::OpenParenthesis);
@ -1353,6 +1354,8 @@ namespace Nz::ShaderLang
ShaderAst::AttributeType Parser::ParseIdentifierAsAttributeType()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
const Token& identifierToken = Expect(Advance(), TokenType::Identifier);
const std::string& identifier = std::get<std::string>(identifierToken.data);

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/SpirvAstVisitor.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Core/StackVector.hpp>
@ -15,16 +16,6 @@
namespace Nz
{
namespace
{
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
}
UInt32 SpirvAstVisitor::AllocateResultId()
{
return m_writer.AllocateResultId();

View File

@ -15,11 +15,7 @@ namespace Nz
{
namespace
{
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
StructFieldType TypeToStructFieldType(const SpirvConstantCache::AnyType& type)
StructFieldType SpirvTypeToStructFieldType(const SpirvConstantCache::AnyType& type)
{
if (std::holds_alternative<SpirvConstantCache::Bool>(type))
return StructFieldType::Bool1;
@ -920,12 +916,12 @@ namespace Nz
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& fieldOffsets, const Bool& type, std::size_t arrayLength) const
{
return fieldOffsets.AddFieldArray(TypeToStructFieldType(type), arrayLength);
return fieldOffsets.AddFieldArray(SpirvTypeToStructFieldType(type), arrayLength);
}
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& fieldOffsets, const Float& type, std::size_t arrayLength) const
{
return fieldOffsets.AddFieldArray(TypeToStructFieldType(type), arrayLength);
return fieldOffsets.AddFieldArray(SpirvTypeToStructFieldType(type), arrayLength);
}
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& /*fieldOffsets*/, const Function& /*type*/, std::size_t /*arrayLength*/) const
@ -940,7 +936,7 @@ namespace Nz
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& fieldOffsets, const Integer& type, std::size_t arrayLength) const
{
return fieldOffsets.AddFieldArray(TypeToStructFieldType(type), arrayLength);
return fieldOffsets.AddFieldArray(SpirvTypeToStructFieldType(type), arrayLength);
}
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& fieldOffsets, const Matrix& type, std::size_t arrayLength) const
@ -949,7 +945,7 @@ namespace Nz
throw std::runtime_error("unexpected column type");
const Vector& vecType = std::get<Vector>(type.columnType->type);
return fieldOffsets.AddMatrixArray(TypeToStructFieldType(vecType.componentType->type), type.columnCount, vecType.componentCount, true, arrayLength);
return fieldOffsets.AddMatrixArray(SpirvTypeToStructFieldType(vecType.componentType->type), type.columnCount, vecType.componentCount, true, arrayLength);
}
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& /*fieldOffsets*/, const Pointer& /*type*/, std::size_t /*arrayLength*/) const
@ -979,7 +975,7 @@ namespace Nz
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& fieldOffsets, const Vector& type, std::size_t arrayLength) const
{
assert(type.componentCount > 0 && type.componentCount <= 4);
return fieldOffsets.AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(TypeToStructFieldType(type.componentType->type)) + type.componentCount), arrayLength);
return fieldOffsets.AddFieldArray(static_cast<StructFieldType>(UnderlyingCast(SpirvTypeToStructFieldType(type.componentType->type)) + type.componentCount), arrayLength);
}
std::size_t SpirvConstantCache::RegisterArrayField(FieldOffsets& /*fieldOffsets*/, const Void& /*type*/, std::size_t /*arrayLength*/) const
@ -998,7 +994,7 @@ namespace Nz
{
UInt32 resultId = id;
std::visit(overloaded
std::visit(Overloaded
{
[&](const AnyConstant& constant) { Write(constant, resultId, constants); },
[&](const AnyType& type) { Write(type, resultId, annotations, constants, debugInfos); },

View File

@ -11,17 +11,11 @@
namespace Nz
{
namespace
{
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
}
UInt32 SpirvExpressionLoad::Evaluate(ShaderAst::Expression& node)
{
node.Visit(*this);
return std::visit(overloaded
return std::visit(Overloaded
{
[this](const Pointer& pointer) -> UInt32
{
@ -89,7 +83,7 @@ namespace Nz
assert(node.indices.size() == 1);
UInt32 indexId = m_visitor.EvaluateExpression(node.indices.front());
std::visit(overloaded
std::visit(Overloaded
{
[&](const Pointer& pointer)
{

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Shader/SpirvExpressionStore.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/StackArray.hpp>
#include <Nazara/Shader/SpirvAstVisitor.hpp>
#include <Nazara/Shader/SpirvBlock.hpp>
@ -12,17 +13,11 @@
namespace Nz
{
namespace
{
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...)->overloaded<Ts...>;
}
void SpirvExpressionStore::Store(ShaderAst::ExpressionPtr& node, UInt32 resultId)
{
node->Visit(*this);
std::visit(overloaded
std::visit(Overloaded
{
[&](const Pointer& pointer)
{
@ -93,7 +88,7 @@ namespace Nz
const ShaderAst::ExpressionType& exprType = GetExpressionType(node);
std::visit(overloaded
std::visit(Overloaded
{
[&](const Pointer& pointer)
{
@ -118,7 +113,7 @@ namespace Nz
{
node.expression->Visit(*this);
std::visit(overloaded
std::visit(Overloaded
{
[&](const Pointer& pointer)
{

View File

@ -29,34 +29,20 @@ namespace Nz
{
namespace
{
struct Builtin
struct SpirvBuiltin
{
const char* debugName;
ShaderStageTypeFlags compatibleStages;
SpirvBuiltIn decoration;
};
template<typename T> T& Retrieve(std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
template<typename T> const T& Retrieve(const std::unordered_map<std::size_t, T>& map, std::size_t id)
{
auto it = map.find(id);
assert(it != map.end());
return it->second;
}
std::unordered_map<ShaderAst::BuiltinEntry, Builtin> s_builtinMapping = {
std::unordered_map<ShaderAst::BuiltinEntry, SpirvBuiltin> s_spirvBuiltinMapping = {
{ ShaderAst::BuiltinEntry::FragCoord, { "FragmentCoordinates", ShaderStageType::Fragment, SpirvBuiltIn::FragCoord } },
{ ShaderAst::BuiltinEntry::FragDepth, { "FragmentDepth", ShaderStageType::Fragment, SpirvBuiltIn::FragDepth } },
{ ShaderAst::BuiltinEntry::VertexPosition, { "VertexPosition", ShaderStageType::Vertex, SpirvBuiltIn::Position } }
};
class PreVisitor : public ShaderAst::AstRecursiveVisitor
class SpirvPreVisitor : public ShaderAst::AstRecursiveVisitor
{
public:
struct UniformVar
@ -74,7 +60,7 @@ namespace Nz
using FunctionContainer = std::vector<std::reference_wrapper<ShaderAst::DeclareFunctionStatement>>;
using StructContainer = std::vector<ShaderAst::StructDescription*>;
PreVisitor(SpirvConstantCache& constantCache, std::unordered_map<std::size_t, SpirvAstVisitor::FuncData>& funcs) :
SpirvPreVisitor(SpirvConstantCache& constantCache, std::unordered_map<std::size_t, SpirvAstVisitor::FuncData>& funcs) :
m_constantCache(constantCache),
m_funcs(funcs)
{
@ -411,10 +397,10 @@ namespace Nz
{
if (member.builtin.HasValue())
{
auto it = s_builtinMapping.find(member.builtin.GetResultingValue());
assert(it != s_builtinMapping.end());
auto it = s_spirvBuiltinMapping.find(member.builtin.GetResultingValue());
assert(it != s_spirvBuiltinMapping.end());
Builtin& builtin = it->second;
SpirvBuiltin& builtin = it->second;
if ((builtin.compatibleStages & entryPointType) == 0)
return 0;
@ -481,7 +467,7 @@ namespace Nz
std::vector<UInt32> resultIds;
UInt32 nextVarIndex = 1;
SpirvConstantCache constantTypeCache; //< init after nextVarIndex
PreVisitor* previsitor;
SpirvPreVisitor* previsitor;
// Output
SpirvSection header;
@ -546,7 +532,7 @@ namespace Nz
});
// Register all extended instruction sets
PreVisitor previsitor(state.constantTypeCache, state.funcs);
SpirvPreVisitor previsitor(state.constantTypeCache, state.funcs);
for (const auto& importedModule : targetModule->importedModules)
importedModule.module->rootNode->Visit(previsitor);

View File

@ -36,7 +36,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
class IcoSphereBuilder
{
@ -667,6 +667,8 @@ namespace Nz
UInt64 ComputeCacheMissCount(IndexIterator indices, UInt32 indexCount)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
VertexCache cache(indices, indexCount);
return cache.GetMissCount();
}
@ -731,6 +733,8 @@ namespace Nz
void GenerateBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, unsigned int indexOffset)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
std::size_t xIndexCount, yIndexCount, zIndexCount;
std::size_t xVertexCount, yVertexCount, zVertexCount;
@ -926,6 +930,8 @@ namespace Nz
void GenerateIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, unsigned int indexOffset)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
IcoSphereBuilder builder(matrix);
builder.Generate(size, recursionLevel, textureCoords, vertexPointers, indices, aabb, indexOffset);
}
@ -1043,6 +1049,8 @@ namespace Nz
void OptimizeIndices(IndexIterator indices, unsigned int indexCount)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
VertexCacheOptimizer optimizer;
if (optimizer.Optimize(indices, indexCount) != VertexCacheOptimizer::Success)
NazaraWarning("Indices optimizer failed");

View File

@ -26,14 +26,13 @@ namespace Nz
{
class FreeTypeLibrary;
FT_Library s_library = nullptr;
FT_Stroker s_stroker = nullptr;
std::shared_ptr<FreeTypeLibrary> s_libraryOwner;
constexpr float s_scaleFactor = 1 << 6;
constexpr float s_invScaleFactor = 1.f / s_scaleFactor;
FT_Library s_freetypeLibrary = nullptr;
FT_Stroker s_freetypeStroker = nullptr;
std::shared_ptr<FreeTypeLibrary> s_freetypeLibraryOwner;
constexpr float s_freetypeScaleFactor = 1 << 6;
constexpr float s_freetypeInvScaleFactor = 1.f / s_freetypeScaleFactor;
extern "C"
unsigned long FT_StreamRead(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
extern "C" unsigned long FT_StreamRead(FT_Stream stream, unsigned long offset, unsigned char* buffer, unsigned long count)
{
// http://www.freetype.org/freetype2/docs/reference/ft2-system_interface.html#FT_Stream_IoFunc
Stream& inputStream = *static_cast<Stream*>(stream->descriptor.pointer);
@ -73,23 +72,23 @@ namespace Nz
public:
FreeTypeLibrary()
{
if (FT_Stroker_New(s_library, &s_stroker) != 0)
if (FT_Stroker_New(s_freetypeLibrary, &s_freetypeStroker) != 0)
{
NazaraWarning("Failed to load FreeType stroker, outline will not be possible");
s_stroker = nullptr; //< Just in case
s_freetypeStroker = nullptr; //< Just in case
}
}
~FreeTypeLibrary()
{
if (s_stroker)
if (s_freetypeStroker)
{
FT_Stroker_Done(s_stroker);
s_stroker = nullptr;
FT_Stroker_Done(s_freetypeStroker);
s_freetypeStroker = nullptr;
}
FT_Done_FreeType(s_library);
s_library = nullptr;
FT_Done_FreeType(s_freetypeLibrary);
s_freetypeLibrary = nullptr;
}
};
@ -98,7 +97,7 @@ namespace Nz
public:
FreeTypeStream() :
m_face(nullptr),
m_library(s_libraryOwner),
m_library(s_freetypeLibraryOwner),
m_characterSize(0)
{
}
@ -112,7 +111,7 @@ namespace Nz
bool Check()
{
// Test d'ouverture (http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Open_Face)
return FT_Open_Face(s_library, &m_args, -1, nullptr) == 0;
return FT_Open_Face(s_freetypeLibrary, &m_args, -1, nullptr) == 0;
}
bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, float outlineThickness, FontGlyph* dst) override
@ -165,8 +164,8 @@ namespace Nz
if (outlineThickness > 0.f)
{
FT_Stroker_Set(s_stroker, static_cast<FT_Fixed>(s_scaleFactor * outlineThickness), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
if (FT_Glyph_Stroke(&glyph, s_stroker, 1) != 0)
FT_Stroker_Set(s_freetypeStroker, static_cast<FT_Fixed>(s_freetypeScaleFactor * outlineThickness), FT_STROKER_LINECAP_ROUND, FT_STROKER_LINEJOIN_ROUND, 0);
if (FT_Glyph_Stroke(&glyph, s_freetypeStroker, 1) != 0)
{
NazaraError("Failed to outline glyph");
return false;
@ -187,7 +186,7 @@ namespace Nz
if (embolden)
{
// http://www.freetype.org/freetype2/docs/reference/ft2-bitmap_handling.html#FT_Bitmap_Embolden
FT_Bitmap_Embolden(s_library, &bitmap, boldStrength, boldStrength);
FT_Bitmap_Embolden(s_freetypeLibrary, &bitmap, boldStrength, boldStrength);
}
int outlineThicknessInt = static_cast<int>(outlineThickness * 2.f + 0.5f); //< round it
@ -266,7 +265,7 @@ namespace Nz
bool Open()
{
return FT_Open_Face(s_library, &m_args, 0, &m_face) == 0;
return FT_Open_Face(s_freetypeLibrary, &m_args, 0, &m_face) == 0;
}
int QueryKerning(unsigned int characterSize, char32_t first, char32_t second) const override
@ -302,7 +301,7 @@ namespace Nz
SetCharacterSize(characterSize);
// http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_FaceRec
return static_cast<float>(FT_MulFix(m_face->underline_position, m_face->size->metrics.y_scale)) * s_invScaleFactor;
return static_cast<float>(FT_MulFix(m_face->underline_position, m_face->size->metrics.y_scale)) * s_freetypeInvScaleFactor;
}
else
return characterSize / 10.f; // Joker ?
@ -315,7 +314,7 @@ namespace Nz
SetCharacterSize(characterSize);
// http://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_FaceRec
return static_cast<float>(FT_MulFix(m_face->underline_thickness, m_face->size->metrics.y_scale)) * s_invScaleFactor;
return static_cast<float>(FT_MulFix(m_face->underline_thickness, m_face->size->metrics.y_scale)) * s_freetypeInvScaleFactor;
}
else
return characterSize/15.f; // Joker ?
@ -357,7 +356,7 @@ namespace Nz
bool SupportsOutline(float /*outlineThickness*/) const override
{
return s_stroker != nullptr;
return s_freetypeStroker != nullptr;
}
bool SupportsStyle(TextStyleFlags style) const override
@ -384,7 +383,7 @@ namespace Nz
mutable unsigned int m_characterSize;
};
bool IsSupported(const std::string_view& extension)
bool IsFreetypeSupported(const std::string_view& extension)
{
///FIXME: Je suppose qu'il en manque quelques unes..
static std::set<std::string_view> supportedExtensions = {
@ -394,7 +393,7 @@ namespace Nz
return supportedExtensions.find(extension) != supportedExtensions.end();
}
Ternary Check(Stream& stream, const FontParams& parameters)
Ternary CheckFreetype(Stream& stream, const FontParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeFreeTypeLoader", &skip) && skip)
@ -409,7 +408,7 @@ namespace Nz
return Ternary::False;
}
std::shared_ptr<Font> LoadFile(const std::filesystem::path& filePath, const FontParams& parameters)
std::shared_ptr<Font> LoadFreetypeFile(const std::filesystem::path& filePath, const FontParams& parameters)
{
NazaraUnused(parameters);
@ -433,7 +432,7 @@ namespace Nz
return font;
}
std::shared_ptr<Font> LoadMemory(const void* data, std::size_t size, const FontParams& parameters)
std::shared_ptr<Font> LoadFreetypeMemory(const void* data, std::size_t size, const FontParams& parameters)
{
NazaraUnused(parameters);
@ -453,7 +452,7 @@ namespace Nz
return font;
}
std::shared_ptr<Font> LoadStream(Stream& stream, const FontParams& parameters)
std::shared_ptr<Font> LoadFreetypeStream(Stream& stream, const FontParams& parameters)
{
NazaraUnused(parameters);
@ -478,34 +477,34 @@ namespace Nz
{
bool InitializeFreeType()
{
NazaraAssert(!s_libraryOwner, "double initialization for FreeType");
if (FT_Init_FreeType(&s_library) != 0)
NazaraAssert(!s_freetypeLibraryOwner, "double initialization for FreeType");
if (FT_Init_FreeType(&s_freetypeLibrary) != 0)
{
NazaraWarning("failed to initialize FreeType library");
return false;
}
s_libraryOwner = std::make_shared<FreeTypeLibrary>();
s_freetypeLibraryOwner = std::make_shared<FreeTypeLibrary>();
return true;
}
FontLoader::Entry GetFontLoader_FreeType()
{
NazaraAssert(s_libraryOwner, "FreeType has not been initialized");
NazaraAssert(s_freetypeLibraryOwner, "FreeType has not been initialized");
FontLoader::Entry entry;
entry.extensionSupport = IsSupported;
entry.fileLoader = LoadFile;
entry.memoryLoader = LoadMemory;
entry.streamChecker = Check;
entry.streamLoader = LoadStream;
entry.extensionSupport = IsFreetypeSupported;
entry.fileLoader = LoadFreetypeFile;
entry.memoryLoader = LoadFreetypeMemory;
entry.streamChecker = CheckFreetype;
entry.streamLoader = LoadFreetypeStream;
return entry;
}
void UninitializeFreeType()
{
s_libraryOwner.reset();
s_freetypeLibraryOwner.reset();
}
}
}

View File

@ -21,12 +21,12 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string_view& extension)
bool IsMD2Supported(const std::string_view& extension)
{
return (extension == "md2");
}
Ternary Check(Stream& stream, const MeshParams& parameters)
Ternary CheckMD2(Stream& stream, const MeshParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeMD2Loader", &skip) && skip)
@ -47,7 +47,7 @@ namespace Nz
return Ternary::False;
}
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> LoadMD2(Stream& stream, const MeshParams& parameters)
{
MD2_Header header;
if (stream.Read(&header, sizeof(MD2_Header)) != sizeof(MD2_Header))
@ -269,9 +269,9 @@ namespace Nz
MeshLoader::Entry GetMeshLoader_MD2()
{
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
loader.extensionSupport = IsMD2Supported;
loader.streamChecker = CheckMD2;
loader.streamLoader = LoadMD2;
return loader;
}

View File

@ -12,12 +12,12 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string_view& extension)
bool IsMD5AnimSupported(const std::string_view& extension)
{
return (extension == "md5anim");
}
Ternary Check(Stream& stream, const AnimationParams& parameters)
Ternary CheckMD5Anim(Stream& stream, const AnimationParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeMD5AnimLoader", &skip) && skip)
@ -27,7 +27,7 @@ namespace Nz
return parser.Check();
}
std::shared_ptr<Animation> Load(Stream& stream, const AnimationParams& /*parameters*/)
std::shared_ptr<Animation> LoadMD5Anim(Stream& stream, const AnimationParams& /*parameters*/)
{
///TODO: Utiliser les paramètres
MD5AnimParser parser(stream);
@ -93,9 +93,9 @@ namespace Nz
AnimationLoader::Entry GetAnimationLoader_MD5Anim()
{
AnimationLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
loader.extensionSupport = IsMD5AnimSupported;
loader.streamChecker = CheckMD5Anim;
loader.streamLoader = LoadMD5Anim;
return loader;
}

View File

@ -20,12 +20,12 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string_view& extension)
bool IsMD5MeshSupported(const std::string_view& extension)
{
return (extension == "md5mesh");
}
Ternary Check(Stream& stream, const MeshParams& parameters)
Ternary CheckMD5Mesh(Stream& stream, const MeshParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeMD5MeshLoader", &skip) && skip)
@ -35,7 +35,7 @@ namespace Nz
return parser.Check();
}
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> LoadMD5Mesh(Stream& stream, const MeshParams& parameters)
{
MD5MeshParser parser(stream);
if (!parser.Parse())
@ -334,9 +334,9 @@ namespace Nz
MeshLoader::Entry GetMeshLoader_MD5Mesh()
{
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
loader.extensionSupport = IsMD5MeshSupported;
loader.streamChecker = CheckMD5Mesh;
loader.streamLoader = LoadMD5Mesh;
return loader;
}

View File

@ -22,12 +22,12 @@ namespace Nz
{
namespace
{
bool IsSupported(const std::string_view& extension)
bool IsOBJSupported(const std::string_view& extension)
{
return (extension == "obj");
}
Ternary Check(Stream& stream, const MeshParams& parameters)
Ternary CheckOBJ(Stream& stream, const MeshParams& parameters)
{
NazaraUnused(stream);
@ -157,7 +157,7 @@ namespace Nz
return true;
}
std::shared_ptr<Mesh> Load(Stream& stream, const MeshParams& parameters)
std::shared_ptr<Mesh> LoadOBJ(Stream& stream, const MeshParams& parameters)
{
long long reservedVertexCount;
if (!parameters.custom.GetIntegerParameter("NativeOBJLoader_VertexCount", &reservedVertexCount))
@ -367,9 +367,9 @@ namespace Nz
MeshLoader::Entry GetMeshLoader_OBJ()
{
MeshLoader::Entry loader;
loader.extensionSupport = IsSupported;
loader.streamChecker = Check;
loader.streamLoader = Load;
loader.extensionSupport = IsOBJSupported;
loader.streamChecker = CheckOBJ;
loader.streamLoader = LoadOBJ;
return loader;
}

View File

@ -52,12 +52,12 @@ namespace Nz
T* m_buffer;
};
bool IsSupported(const std::string_view& extension)
bool IsOBJSupportedSave(const std::string_view& extension)
{
return (extension == "obj");
}
bool SaveToStream(const Mesh& mesh, const std::string& format, Stream& stream, const MeshParams& parameters)
bool SaveOBJToStream(const Mesh& mesh, const std::string& format, Stream& stream, const MeshParams& parameters)
{
NazaraUnused(parameters);
@ -213,8 +213,8 @@ namespace Nz
MeshSaver::Entry GetMeshSaver_OBJ()
{
MeshSaver::Entry entry;
entry.formatSupport = IsSupported;
entry.streamSaver = SaveToStream;
entry.formatSupport = IsOBJSupportedSave;
entry.streamSaver = SaveOBJToStream;
return entry;
}

View File

@ -16,7 +16,7 @@ namespace Nz
{
namespace
{
struct pcx_header
struct PCXHeader
{
UInt8 manufacturer;
UInt8 version;
@ -38,14 +38,14 @@ namespace Nz
UInt8 padding[54];
};
static_assert(sizeof(pcx_header) == (6+48+54)*sizeof(UInt8) + 10*sizeof(UInt16), "pcx_header struct must be packed");
static_assert(sizeof(PCXHeader) == (6+48+54)*sizeof(UInt8) + 10*sizeof(UInt16), "pcx_header struct must be packed");
bool IsSupported(const std::string_view& extension)
bool IsPCXSupported(const std::string_view& extension)
{
return (extension == "pcx");
}
Ternary Check(Stream& stream, const ImageParams& parameters)
Ternary CheckPCX(Stream& stream, const ImageParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativePCXLoader", &skip) && skip)
@ -61,12 +61,12 @@ namespace Nz
return Ternary::False;
}
std::shared_ptr<Image> Load(Stream& stream, const ImageParams& parameters)
std::shared_ptr<Image> LoadPCX(Stream& stream, const ImageParams& parameters)
{
NazaraUnused(parameters);
pcx_header header;
if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header))
PCXHeader header;
if (stream.Read(&header, sizeof(PCXHeader)) != sizeof(PCXHeader))
{
NazaraError("Failed to read header");
return nullptr;
@ -345,9 +345,9 @@ namespace Nz
ImageLoader::Entry GetImageLoader_PCX()
{
ImageLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = Check;
loaderEntry.streamLoader = Load;
loaderEntry.extensionSupport = IsPCXSupported;
loaderEntry.streamChecker = CheckPCX;
loaderEntry.streamLoader = LoadPCX;
return loaderEntry;
}

View File

@ -17,52 +17,52 @@ namespace Nz
{
namespace
{
int Eof(void* userdata)
int StbiEof(void* userdata)
{
Stream* stream = static_cast<Stream*>(userdata);
return stream->GetCursorPos() >= stream->GetSize();
}
int Read(void* userdata, char* data, int size)
int StbiRead(void* userdata, char* data, int size)
{
Stream* stream = static_cast<Stream*>(userdata);
return static_cast<int>(stream->Read(data, size));
}
void Skip(void* userdata, int size)
void StbiSkip(void* userdata, int size)
{
Stream* stream = static_cast<Stream*>(userdata);
stream->SetCursorPos(static_cast<Int64>(stream->GetCursorPos()) + static_cast<Int64>(size));
}
static stbi_io_callbacks callbacks = {Read, Skip, Eof};
static stbi_io_callbacks s_stbiCallbacks = { StbiRead, StbiSkip, StbiEof };
bool IsSupported(const std::string_view& extension)
bool IsSTBSupported(const std::string_view& extension)
{
static std::unordered_set<std::string_view> supportedExtensions = {"bmp", "gif", "hdr", "jpg", "jpeg", "pic", "png", "ppm", "pgm", "psd", "tga"};
return supportedExtensions.find(extension) != supportedExtensions.end();
}
Ternary Check(Stream& stream, const ImageParams& parameters)
Ternary CheckSTB(Stream& stream, const ImageParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipNativeSTBLoader", &skip) && skip)
return Ternary::False;
int width, height, bpp;
if (stbi_info_from_callbacks(&callbacks, &stream, &width, &height, &bpp))
if (stbi_info_from_callbacks(&s_stbiCallbacks, &stream, &width, &height, &bpp))
return Ternary::True;
else
return Ternary::False;
}
std::shared_ptr<Image> Load(Stream& stream, const ImageParams& parameters)
std::shared_ptr<Image> LoadSTB(Stream& stream, const ImageParams& parameters)
{
// Je charge tout en RGBA8 et je converti ensuite via la méthode Convert
// Ceci à cause d'un bug de STB lorsqu'il s'agit de charger certaines images (ex: JPG) en "default"
int width, height, bpp;
UInt8* ptr = stbi_load_from_callbacks(&callbacks, &stream, &width, &height, &bpp, STBI_rgb_alpha);
UInt8* ptr = stbi_load_from_callbacks(&s_stbiCallbacks, &stream, &width, &height, &bpp, STBI_rgb_alpha);
if (!ptr)
{
NazaraError("Failed to load image: " + std::string(stbi_failure_reason()));
@ -103,9 +103,9 @@ namespace Nz
ImageLoader::Entry GetImageLoader_STB()
{
ImageLoader::Entry loaderEntry;
loaderEntry.extensionSupport = IsSupported;
loaderEntry.streamChecker = Check;
loaderEntry.streamLoader = Load;
loaderEntry.extensionSupport = IsSTBSupported;
loaderEntry.streamChecker = CheckSTB;
loaderEntry.streamLoader = LoadSTB;
return loaderEntry;
}

View File

@ -10,7 +10,7 @@ namespace Nz
{
namespace
{
const unsigned int s_atlasStartSize = 512;
const unsigned int s_guillotineAtlasStartSize = 512;
}
GuillotineImageAtlas::GuillotineImageAtlas() :
@ -119,7 +119,7 @@ namespace Nz
// Dernière couche, et le glyphe ne rentre pas, peut-on agrandir la taille de l'image ?
Vector2ui newSize = layer.binPack.GetSize()*2;
if (newSize == Vector2ui::Zero())
newSize.Set(s_atlasStartSize);
newSize.Set(s_guillotineAtlasStartSize);
// Limit image atlas size to prevent allocating too much contiguous memory blocks
if (newSize.x <= m_maxLayerSize && newSize.y <= m_maxLayerSize && ResizeLayer(layer, newSize))
@ -133,7 +133,7 @@ namespace Nz
else
{
// On ne peut plus agrandir la dernière couche, il est temps d'en créer une nouvelle
newSize.Set(s_atlasStartSize);
newSize.Set(s_guillotineAtlasStartSize);
Layer newLayer;
if (!ResizeLayer(newLayer, newSize))

View File

@ -20,7 +20,7 @@ namespace Nz
{
namespace
{
inline unsigned int GetLevelSize(unsigned int size, UInt8 level)
inline unsigned int GetImageLevelSize(unsigned int size, UInt8 level)
{
if (size == 0) // Possible dans le cas d'une image invalide
return 0;
@ -576,7 +576,7 @@ namespace Nz
}
#endif
unsigned int width = GetLevelSize(m_sharedImage->width, level);
unsigned int width = GetImageLevelSize(m_sharedImage->width, level);
#if NAZARA_UTILITY_SAFE
if (x >= width)
{
@ -585,7 +585,7 @@ namespace Nz
}
#endif
unsigned int height = GetLevelSize(m_sharedImage->height, level);
unsigned int height = GetImageLevelSize(m_sharedImage->height, level);
#if NAZARA_UTILITY_SAFE
if (y >= height)
{
@ -593,7 +593,7 @@ namespace Nz
return nullptr;
}
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetImageLevelSize(m_sharedImage->depth, level);
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@ -614,7 +614,7 @@ namespace Nz
}
#endif
return GetLevelSize(m_sharedImage->depth, level);
return GetImageLevelSize(m_sharedImage->depth, level);
}
PixelFormat Image::GetFormat() const
@ -632,7 +632,7 @@ namespace Nz
}
#endif
return GetLevelSize(m_sharedImage->height, level);
return GetImageLevelSize(m_sharedImage->height, level);
}
UInt8 Image::GetLevelCount() const
@ -674,7 +674,7 @@ namespace Nz
std::size_t Image::GetMemoryUsage(UInt8 level) const
{
return PixelFormatInfo::ComputeSize(m_sharedImage->format, GetLevelSize(m_sharedImage->width, level), GetLevelSize(m_sharedImage->height, level), ((m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level)));
return PixelFormatInfo::ComputeSize(m_sharedImage->format, GetImageLevelSize(m_sharedImage->width, level), GetImageLevelSize(m_sharedImage->height, level), ((m_sharedImage->type == ImageType::Cubemap) ? 6 : GetImageLevelSize(m_sharedImage->depth, level)));
}
Color Image::GetPixelColor(unsigned int x, unsigned int y, unsigned int z) const
@ -737,7 +737,7 @@ namespace Nz
}
#endif
unsigned int width = GetLevelSize(m_sharedImage->width, level);
unsigned int width = GetImageLevelSize(m_sharedImage->width, level);
#if NAZARA_UTILITY_SAFE
if (x >= width)
{
@ -746,7 +746,7 @@ namespace Nz
}
#endif
unsigned int height = GetLevelSize(m_sharedImage->height, level);
unsigned int height = GetImageLevelSize(m_sharedImage->height, level);
#if NAZARA_UTILITY_SAFE
if (y >= height)
{
@ -754,7 +754,7 @@ namespace Nz
return nullptr;
}
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetImageLevelSize(m_sharedImage->depth, level);
if (z >= depth)
{
NazaraError("Z value exceeds depth (" + NumberToString(z) + " >= " + NumberToString(depth) + ')');
@ -783,7 +783,7 @@ namespace Nz
}
#endif
return Vector3ui(GetLevelSize(m_sharedImage->width, level), GetLevelSize(m_sharedImage->height, level), GetLevelSize(m_sharedImage->depth, level));
return Vector3ui(GetImageLevelSize(m_sharedImage->width, level), GetImageLevelSize(m_sharedImage->height, level), GetImageLevelSize(m_sharedImage->depth, level));
}
ImageType Image::GetType() const
@ -801,7 +801,7 @@ namespace Nz
}
#endif
return GetLevelSize(m_sharedImage->width, level);
return GetImageLevelSize(m_sharedImage->width, level);
}
bool Image::HasAlpha() const
@ -1270,8 +1270,8 @@ namespace Nz
}
#endif
unsigned int width = GetLevelSize(m_sharedImage->width, level);
unsigned int height = GetLevelSize(m_sharedImage->height, level);
unsigned int width = GetImageLevelSize(m_sharedImage->width, level);
unsigned int height = GetImageLevelSize(m_sharedImage->height, level);
#if NAZARA_UTILITY_SAFE
if (!box.IsValid())
@ -1280,7 +1280,7 @@ namespace Nz
return false;
}
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetLevelSize(m_sharedImage->depth, level);
unsigned int depth = (m_sharedImage->type == ImageType::Cubemap) ? 6 : GetImageLevelSize(m_sharedImage->depth, level);
if (box.x+box.width > width || box.y+box.height > height || box.z+box.depth > depth ||
(m_sharedImage->type == ImageType::Cubemap && box.depth > 1)) // Nous n'autorisons pas de modifier plus d'une face du cubemap à la fois
{

View File

@ -10,7 +10,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
UInt32 GetterSequential(const void* buffer, std::size_t i)
{
@ -58,6 +58,8 @@ namespace Nz
IndexMapper::IndexMapper(IndexBuffer& indexBuffer, std::size_t indexCount) :
m_indexCount((indexCount != 0) ? indexCount : indexBuffer.GetIndexCount())
{
NAZARA_USE_ANONYMOUS_NAMESPACE
if (!m_mapper.Map(indexBuffer, 0, m_indexCount))
NazaraError("Failed to map buffer"); ///TODO: Unexcepted

View File

@ -10,7 +10,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
inline UInt8 c4to5(UInt8 c)
{
@ -1412,6 +1412,8 @@ namespace Nz
bool PixelFormatInfo::Initialize()
{
NAZARA_USE_ANONYMOUS_NAMESPACE
auto SetupPixelFormat = [](PixelFormat format, PixelFormatDescription&& desc)
{
s_pixelFormatInfos[UnderlyingCast(format)] = std::move(desc);

View File

@ -14,7 +14,7 @@
namespace Nz
{
namespace
namespace NAZARA_ANONYMOUS_NAMESPACE
{
std::size_t s_componentStride[ComponentTypeCount] =
{
@ -37,6 +37,8 @@ namespace Nz
VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list<ComponentEntry> components) :
m_inputRate(inputRate)
{
NAZARA_USE_ANONYMOUS_NAMESPACE
ErrorFlags errFlags(ErrorMode::ThrowException);
std::size_t offset = 0;

View File

@ -13,3 +13,7 @@ extern "C"
return renderer.release();
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -18,14 +18,14 @@ namespace Nz
{
namespace
{
struct AvailableLayer
struct AvailableVulkanLayer
{
VkLayerProperties layerProperties;
std::unordered_map<std::string, std::size_t> extensionByName;
std::vector<VkExtensionProperties> extensionList;
};
void EnumerateLayers(std::vector<AvailableLayer>& availableLayers, std::unordered_map<std::string, std::size_t>& layerByName)
void EnumerateVulkanLayers(std::vector<AvailableVulkanLayer>& availableLayers, std::unordered_map<std::string, std::size_t>& layerByName)
{
std::vector<VkLayerProperties> layerList;
if (Vk::Loader::EnumerateInstanceLayerProperties(&layerList))
@ -175,9 +175,9 @@ namespace Nz
std::vector<const char*> enabledLayers;
std::vector<AvailableLayer> availableLayers;
std::vector<AvailableVulkanLayer> availableLayers;
std::unordered_map<std::string, std::size_t> availableLayerByName;
EnumerateLayers(availableLayers, availableLayerByName);
EnumerateVulkanLayers(availableLayers, availableLayerByName);
if (!parameters.GetBooleanParameter("VkInstanceInfo_OverrideEnabledLayers", &bParam) || !bParam)
{
@ -627,3 +627,7 @@ namespace Nz
Vk::Instance Vulkan::s_instance;
ParameterList Vulkan::s_initializationParameters;
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -136,3 +136,9 @@ namespace Nz
}
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#elif defined(NAZARA_PLATFORM_LINUX)
#include <Nazara/Core/AntiX11.hpp>
#endif

View File

@ -13,3 +13,6 @@ namespace Nz
m_owner.Release(*this);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -262,3 +262,7 @@ namespace Nz
m_commandBuffer.ImageBarrier(ToVulkan(srcStageMask), ToVulkan(dstStageMask), VkDependencyFlags(0), ToVulkan(srcAccessMask), ToVulkan(dstAccessMask), ToVulkan(oldLayout), ToVulkan(newLayout), vkTexture.GetImage(), aspectFlags);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -71,3 +71,7 @@ namespace Nz
TryToShrink();
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -124,3 +124,7 @@ namespace Nz
return formatProperties.optimalTilingFeatures & flags; //< Assume optimal tiling
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -8,3 +8,7 @@
namespace Nz
{
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -91,3 +91,7 @@ namespace Nz
}
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -134,3 +134,7 @@ namespace Nz
OnRenderPassRelease(this);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -320,3 +320,7 @@ namespace Nz
m_pipelineCreateInfo.stateData->colorBlendState = BuildColorBlendInfo(m_pipelineInfo, m_pipelineCreateInfo.colorBlendAttachmentState);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -154,3 +154,7 @@ namespace Nz
TryToShrink();
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -615,3 +615,7 @@ namespace Nz
return true;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -75,3 +75,7 @@ namespace Nz
return m_deviceInfos;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -73,3 +73,7 @@ namespace Nz
m_owner.Release(*this);
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -146,3 +146,7 @@ namespace Nz
return false;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -77,3 +77,7 @@ namespace Nz
m_surface.Destroy();
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -418,3 +418,9 @@ namespace Nz
}
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#elif defined(NAZARA_PLATFORM_LINUX)
#include <Nazara/Core/AntiX11.hpp>
#endif

View File

@ -42,3 +42,7 @@ namespace Nz
throw std::runtime_error("failed to instantiate Vulkan framebuffer: " + TranslateVulkanError(m_framebuffer.GetLastErrorCode()));
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -33,3 +33,7 @@ namespace Nz
throw std::runtime_error("Failed to create sampler: " + TranslateVulkanError(m_sampler.GetLastErrorCode()));
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

View File

@ -103,3 +103,7 @@ namespace Nz
m_nextAllocationIndex = 0;
}
}
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/AntiWindows.hpp>
#endif

Some files were not shown because too many files have changed in this diff Show More