diff options
author | chai <chaifix@163.com> | 2019-08-16 08:54:08 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-16 08:54:08 +0800 |
commit | a077eb38b01292611f4f6031b75e3e2c1c20f06e (patch) | |
tree | 8f760483d7b0290952bbdb5bcd8f3943102aeb3a /Source/modules/asura-core | |
parent | 6a065c913e9308cc72e1ad0723b6167048f439b6 (diff) |
Diffstat (limited to 'Source/modules/asura-core')
44 files changed, 419 insertions, 2042 deletions
diff --git a/Source/modules/asura-core/Font/TTF.h b/Source/modules/asura-core/Font/TTF.h deleted file mode 100644 index b83cf76..0000000 --- a/Source/modules/asura-core/Font/TTF.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _ASURA_TTF_H_ -#define _ASURA_TTF_H_ - -namespace AsuraEngine -{ - namespace Text - { - - class TTF - { - - }; - - } -} - -#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Font/TTF.cpp b/Source/modules/asura-core/Font/TTFImporter.cpp index e69de29..e69de29 100644 --- a/Source/modules/asura-core/Font/TTF.cpp +++ b/Source/modules/asura-core/Font/TTFImporter.cpp diff --git a/Source/modules/asura-core/Graphics/Mesh2D.cpp b/Source/modules/asura-core/Font/TTFImporter.h index e69de29..e69de29 100644 --- a/Source/modules/asura-core/Graphics/Mesh2D.cpp +++ b/Source/modules/asura-core/Font/TTFImporter.h diff --git a/Source/modules/asura-core/Font/Utf.hpp b/Source/modules/asura-core/Font/Utf.hpp deleted file mode 100644 index 59f62ed..0000000 --- a/Source/modules/asura-core/Font/Utf.hpp +++ /dev/null @@ -1,720 +0,0 @@ -#ifndef _ASURA_UTF_HPP_ -#define _ASURA_UTF_HPP_ - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include <algorithm> -#include <locale> -#include <string> -#include <cstdlib> - -namespace AsuraEngine -{ - namespace Text - { - - template <unsigned int N> - class Utf; - - //////////////////////////////////////////////////////////// - /// \brief Specialization of the Utf template for UTF-8 - /// - //////////////////////////////////////////////////////////// - template <> - class Utf<8> - { - public: - - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-8 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-8 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-8 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-8. - /// - /// \param input Codepoint to encode as UTF-8 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename Out> - static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-8 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Next(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-8 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static std::size_t Count(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-8 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromLatin1(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-8 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf8(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf16(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf32(In begin, In end, Out output); - }; - - //////////////////////////////////////////////////////////// - /// \brief Specialization of the Utf template for UTF-16 - /// - //////////////////////////////////////////////////////////// - template <> - class Utf<16> - { - public: - - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-16 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-16 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-16 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-16. - /// - /// \param input Codepoint to encode as UTF-16 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename Out> - static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-16 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Next(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-16 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static std::size_t Count(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-16 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromLatin1(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf8(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-16 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf16(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf32(In begin, In end, Out output); - }; - - //////////////////////////////////////////////////////////// - /// \brief Specialization of the Utf template for UTF-32 - /// - //////////////////////////////////////////////////////////// - template <> - class Utf<32> - { - public: - - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-32 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// For UTF-32, the character value is the same as the codepoint. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-32 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-32. - /// For UTF-32, the codepoint is the same as the character value. - /// - /// \param input Codepoint to encode as UTF-32 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename Out> - static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-32 character - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static In Next(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-32 sequence - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template <typename In> - static std::size_t Count(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-32 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out FromLatin1(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToLatin1(In begin, In end, Out output, char replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf8(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf16(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-32 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename In, typename Out> - static Out ToUtf32(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Decode a single ANSI character to UTF-32 - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input ANSI character - /// \param locale Locale to use for conversion - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template <typename In> - static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Decode a single wide character to UTF-32 - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input wide character - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template <typename In> - static Uint32 DecodeWide(In input); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to ANSI - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename Out> - static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to wide - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template <typename Out> - static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); - }; - -#include "Utf.inc" - - // Make typedefs to get rid of the template syntax - typedef Utf<8> Utf8; - typedef Utf<16> Utf16; - typedef Utf<32> Utf32; - - } // namespace sf - -} - - -#endif // SFML_UTF_HPP diff --git a/Source/modules/asura-core/Font/Utf.inc b/Source/modules/asura-core/Font/Utf.inc deleted file mode 100644 index 69a523b..0000000 --- a/Source/modules/asura-core/Font/Utf.inc +++ /dev/null @@ -1,752 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2019 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -// References: -// -// https://www.unicode.org/ -// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c -// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h -// https://people.w3.org/rishida/scripts/uniview/conversion -// -//////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement) -{ - // Some useful precomputed data - static const int trailing[256] = - { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 - }; - static const Uint32 offsets[6] = - { - 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080 - }; - - // decode the character - int trailingBytes = trailing[static_cast<Uint8>(*begin)]; - if (begin + trailingBytes < end) - { - output = 0; - switch (trailingBytes) - { - case 5: output += static_cast<Uint8>(*begin++); output <<= 6; - case 4: output += static_cast<Uint8>(*begin++); output <<= 6; - case 3: output += static_cast<Uint8>(*begin++); output <<= 6; - case 2: output += static_cast<Uint8>(*begin++); output <<= 6; - case 1: output += static_cast<Uint8>(*begin++); output <<= 6; - case 0: output += static_cast<Uint8>(*begin++); - } - output -= offsets[trailingBytes]; - } - else - { - // Incomplete character - begin = end; - output = replacement; - } - - return begin; -} - - -//////////////////////////////////////////////////////////// -template <typename Out> -Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement) -{ - // Some useful precomputed data - static const Uint8 firstBytes[7] = - { - 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC - }; - - // encode the character - if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF))) - { - // Invalid character - if (replacement) - *output++ = replacement; - } - else - { - // Valid character - - // Get the number of bytes to write - std::size_t bytestoWrite = 1; - if (input < 0x80) bytestoWrite = 1; - else if (input < 0x800) bytestoWrite = 2; - else if (input < 0x10000) bytestoWrite = 3; - else if (input <= 0x0010FFFF) bytestoWrite = 4; - - // Extract the bytes to write - Uint8 bytes[4]; - switch (bytestoWrite) - { - case 4: bytes[3] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; - case 3: bytes[2] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; - case 2: bytes[1] = static_cast<Uint8>((input | 0x80) & 0xBF); input >>= 6; - case 1: bytes[0] = static_cast<Uint8> (input | firstBytes[bytestoWrite]); - } - - // Add them to the output - output = std::copy(bytes, bytes + bytestoWrite, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<8>::Next(In begin, In end) -{ - Uint32 codepoint; - return Decode(begin, end, codepoint); -} - - -//////////////////////////////////////////////////////////// -template <typename In> -std::size_t Utf<8>::Count(In begin, In end) -{ - std::size_t length = 0; - while (begin < end) - { - begin = Next(begin, end); - ++length; - } - - return length; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale) -{ - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); - output = Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::FromWide(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeWide(*begin++); - output = Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::FromLatin1(In begin, In end, Out output) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - output = Encode(*begin++, output); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeWide(codepoint, output, replacement); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToLatin1(In begin, In end, Out output, char replacement) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint < 256 ? static_cast<char>(codepoint) : replacement; - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToUtf8(In begin, In end, Out output) -{ - return std::copy(begin, end, output); -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToUtf16(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<16>::Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<8>::ToUtf32(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint; - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement) -{ - Uint16 first = *begin++; - - // If it's a surrogate pair, first convert to a single UTF-32 character - if ((first >= 0xD800) && (first <= 0xDBFF)) - { - if (begin < end) - { - Uint32 second = *begin++; - if ((second >= 0xDC00) && (second <= 0xDFFF)) - { - // The second element is valid: convert the two elements to a UTF-32 character - output = ((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000; - } - else - { - // Invalid character - output = replacement; - } - } - else - { - // Invalid character - begin = end; - output = replacement; - } - } - else - { - // We can make a direct copy - output = first; - } - - return begin; -} - - -//////////////////////////////////////////////////////////// -template <typename Out> -Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement) -{ - if (input <= 0xFFFF) - { - // The character can be copied directly, we just need to check if it's in the valid range - if ((input >= 0xD800) && (input <= 0xDFFF)) - { - // Invalid character (this range is reserved) - if (replacement) - *output++ = replacement; - } - else - { - // Valid character directly convertible to a single UTF-16 character - *output++ = static_cast<Uint16>(input); - } - } - else if (input > 0x0010FFFF) - { - // Invalid character (greater than the maximum Unicode value) - if (replacement) - *output++ = replacement; - } - else - { - // The input character will be converted to two UTF-16 elements - input -= 0x0010000; - *output++ = static_cast<Uint16>((input >> 10) + 0xD800); - *output++ = static_cast<Uint16>((input & 0x3FFUL) + 0xDC00); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<16>::Next(In begin, In end) -{ - Uint32 codepoint; - return Decode(begin, end, codepoint); -} - - -//////////////////////////////////////////////////////////// -template <typename In> -std::size_t Utf<16>::Count(In begin, In end) -{ - std::size_t length = 0; - while (begin < end) - { - begin = Next(begin, end); - ++length; - } - - return length; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale) -{ - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); - output = Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::FromWide(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint = Utf<32>::DecodeWide(*begin++); - output = Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::FromLatin1(In begin, In end, Out output) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - return std::copy(begin, end, output); -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<32>::EncodeWide(codepoint, output, replacement); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToLatin1(In begin, In end, Out output, char replacement) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - *output++ = *begin < 256 ? static_cast<char>(*begin) : replacement; - begin++; - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToUtf8(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - output = Utf<8>::Encode(codepoint, output); - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToUtf16(In begin, In end, Out output) -{ - return std::copy(begin, end, output); -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<16>::ToUtf32(In begin, In end, Out output) -{ - while (begin < end) - { - Uint32 codepoint; - begin = Decode(begin, end, codepoint); - *output++ = codepoint; - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<32>::Decode(In begin, In /*end*/, Uint32& output, Uint32 /*replacement*/) -{ - output = *begin++; - return begin; -} - - -//////////////////////////////////////////////////////////// -template <typename Out> -Out Utf<32>::Encode(Uint32 input, Out output, Uint32 /*replacement*/) -{ - *output++ = input; - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -In Utf<32>::Next(In begin, In /*end*/) -{ - return ++begin; -} - - -//////////////////////////////////////////////////////////// -template <typename In> -std::size_t Utf<32>::Count(In begin, In end) -{ - return begin - end; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale) -{ - while (begin < end) - *output++ = DecodeAnsi(*begin++, locale); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::FromWide(In begin, In end, Out output) -{ - while (begin < end) - *output++ = DecodeWide(*begin++); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::FromLatin1(In begin, In end, Out output) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - return std::copy(begin, end, output); -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) -{ - while (begin < end) - output = EncodeAnsi(*begin++, output, replacement, locale); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement) -{ - while (begin < end) - output = EncodeWide(*begin++, output, replacement); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToLatin1(In begin, In end, Out output, char replacement) -{ - // Latin-1 is directly compatible with Unicode encodings, - // and can thus be treated as (a sub-range of) UTF-32 - while (begin < end) - { - *output++ = *begin < 256 ? static_cast<char>(*begin) : replacement; - begin++; - } - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToUtf8(In begin, In end, Out output) -{ - while (begin < end) - output = Utf<8>::Encode(*begin++, output); - - return output; -} - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToUtf16(In begin, In end, Out output) -{ - while (begin < end) - output = Utf<16>::Encode(*begin++, output); - - return output; -} - - -//////////////////////////////////////////////////////////// -template <typename In, typename Out> -Out Utf<32>::ToUtf32(In begin, In end, Out output) -{ - return std::copy(begin, end, output); -} - - -//////////////////////////////////////////////////////////// -template <typename In> -Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale) -{ - // On Windows, GCC's standard library (glibc++) has almost - // no support for Unicode stuff. As a consequence, in this - // context we can only use the default locale and ignore - // the one passed as parameter. - - #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ - (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ - !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - - (void)locale; // to avoid warnings - - wchar_t character = 0; - mbtowc(&character, &input, 1); - return static_cast<Uint32>(character); - - #else - - // Get the facet of the locale which deals with character conversion - const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale); - - // Use the facet to convert each character of the input string - return static_cast<Uint32>(facet.widen(input)); - - #endif -} - - -//////////////////////////////////////////////////////////// -template <typename In> -Uint32 Utf<32>::DecodeWide(In input) -{ - // The encoding of wide characters is not well defined and is left to the system; - // however we can safely assume that it is UCS-2 on Windows and - // UCS-4 on Unix systems. - // In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4, - // and UCS-4 *is* UTF-32). - - return input; -} - - -//////////////////////////////////////////////////////////// -template <typename Out> -Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale) -{ - // On Windows, gcc's standard library (glibc++) has almost - // no support for Unicode stuff. As a consequence, in this - // context we can only use the default locale and ignore - // the one passed as parameter. - - #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ - (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ - !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ - - (void)locale; // to avoid warnings - - char character = 0; - if (wctomb(&character, static_cast<wchar_t>(codepoint)) >= 0) - *output++ = character; - else if (replacement) - *output++ = replacement; - - return output; - - #else - - // Get the facet of the locale which deals with character conversion - const std::ctype<wchar_t>& facet = std::use_facet< std::ctype<wchar_t> >(locale); - - // Use the facet to convert each character of the input string - *output++ = facet.narrow(static_cast<wchar_t>(codepoint), replacement); - - return output; - - #endif -} - - -//////////////////////////////////////////////////////////// -template <typename Out> -Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement) -{ - // The encoding of wide characters is not well defined and is left to the system; - // however we can safely assume that it is UCS-2 on Windows and - // UCS-4 on Unix systems. - // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). - // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). - - switch (sizeof(wchar_t)) - { - case 4: - { - *output++ = static_cast<wchar_t>(codepoint); - break; - } - - default: - { - if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) - { - *output++ = static_cast<wchar_t>(codepoint); - } - else if (replacement) - { - *output++ = replacement; - } - break; - } - } - - return output; -} diff --git a/Source/modules/asura-core/Graphics/DrawInfo.h b/Source/modules/asura-core/Graphics/DrawInfo.h index 0082102..6167359 100644 --- a/Source/modules/asura-core/Graphics/DrawInfo.h +++ b/Source/modules/asura-core/Graphics/DrawInfo.h @@ -6,6 +6,14 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +struct ShaderUniform; + +struct ShaderUniformSheet +{ + + +}; + /// struct DrawInfo { diff --git a/Source/modules/asura-core/Graphics/GPUBuffer.cpp b/Source/modules/asura-core/Graphics/GPUBuffer.cpp index f28b914..ded4708 100644 --- a/Source/modules/asura-core/Graphics/GPUBuffer.cpp +++ b/Source/modules/asura-core/Graphics/GPUBuffer.cpp @@ -69,16 +69,16 @@ bool GPUBuffer::Fill(const void * data, size_t size, uint offset) return false; if (m_Buffer == 0) { - g_Device.WipeError(); + g_GfxDevice.WipeError(); glGenBuffers(1, &m_Buffer); if (m_Buffer == 0) throw Exception("OpenGL glGenBuffers failed."); glBindBuffer(m_Target, m_Buffer); glBufferData(m_Target, m_Size, NULL, m_Usage); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) { glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferData failed. Errorcode=%d.", g_Device.GetError()); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", g_GfxDevice.GetError()); } #if ASURA_DEBUG m_Data = (byte*)malloc(size); @@ -87,11 +87,12 @@ bool GPUBuffer::Fill(const void * data, size_t size, uint offset) } else glBindBuffer(m_Target, m_Buffer); - glBufferSubData(m_Target, offset, size, data); - if (g_Device.HasError()) + //glBufferSubData(m_Target, offset, size, data); + GL_CALL(glBufferSubData, m_Target, offset, size, data); + if (g_GfxDevice.HasError()) { glBindBuffer(m_Target, 0); - throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", g_Device.GetError()); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", g_GfxDevice.GetError()); } glBindBuffer(m_Target, 0); #if ASURA_DEBUG diff --git a/Source/modules/asura-core/Graphics/GfxDevice.cpp b/Source/modules/asura-core/Graphics/GfxDevice.cpp index 529a76c..ab5e281 100644 --- a/Source/modules/asura-core/Graphics/GfxDevice.cpp +++ b/Source/modules/asura-core/Graphics/GfxDevice.cpp @@ -7,7 +7,7 @@ #include "MatrixStack.h" #include "Color.h" -using namespace AEMath; + namespace_begin(AsuraEngine) namespace_begin(Graphics) @@ -16,7 +16,13 @@ namespace_begin(Graphics) static bool instantiated = false; #endif -GfxDevice g_Device; +#if ASURA_GL_PROFILE +#define Stats(f) m_Stats.f +#else +#define Stats(f) +#endif + +GfxDevice g_GfxDevice; GfxDevice::GfxDevice() { @@ -32,12 +38,12 @@ GfxDevice::~GfxDevice() GfxDevice& GfxDevice::Get() { - return g_Device; + return g_GfxDevice; } static bool inited = false; -bool GfxDevice::Init(const AEMath::Recti& view) +bool GfxDevice::Init(const Recti& view) { bool loaded = false; #if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD @@ -74,113 +80,101 @@ GLenum GfxDevice::GetError() void GfxDevice::SetDrawColor(float r, float g, float b, float a) { - state.drawColor.Set(r, g, b, a); + m_State.drawColor.Set(r, g, b, a); } Color& GfxDevice::GetDrawColor() { - return state.drawColor; + return m_State.drawColor; } void GfxDevice::SetViewport(const Recti v) { - state.viewport = v; + m_State.viewport = v; glViewport(v.x, v.y, v.w, v.h); } const Recti& GfxDevice::GetViewport() { - return state.viewport; + return m_State.viewport; } void GfxDevice::SetActiveShader(Shader* shader) { - if (state.shader == shader) + if (m_State.activeShader == shader) return; - if (state.shader) - state.shader->OnDisable(); - state.shader = shader; + if (m_State.activeShader) + m_State.activeShader->OnDisable(); + m_State.activeShader = shader; if (shader) { GLint program = shader->GetGLProgram(); glUseProgram(program); -#if ASURA_GL_PROFILE - ++stats.shaderSwitch; -#endif shader->OnEnable(); + Stats(AddShaderSwitch()); } } Shader* GfxDevice::GetActiveShader() const { - return state.shader; -} - -void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) -{ - glDrawArrays(mode, first, count); -#if ASURA_GL_PROFILE - ++stats.drawCall; -#endif - if (state.shader) - state.shader->OnUsed(); + return m_State.activeShader; } void GfxDevice::PushMatrix () { - state.matrix[state.matrixMode].Push (); + m_State.matrix[m_State.matrixMode].Push (); } void GfxDevice::PopMatrix () { - state.matrix[state.matrixMode].Pop(); + m_State.matrix[m_State.matrixMode].Pop(); } void GfxDevice::LoadIdentity() { - state.matrix[state.matrixMode].LoadIdentity(); + m_State.matrix[m_State.matrixMode].LoadIdentity(); } void GfxDevice::Rotate (float angle) { - state.matrix[state.matrixMode].Rotate(angle); + m_State.matrix[m_State.matrixMode].Rotate(angle); } void GfxDevice::Translate (float x, float y) { - state.matrix[state.matrixMode].Translate(x, y); + m_State.matrix[m_State.matrixMode].Translate(x, y); } void GfxDevice::Scale (float x, float y) { - state.matrix[state.matrixMode].Scale(x, y); + m_State.matrix[m_State.matrixMode].Scale(x, y); } void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) { - state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); + m_State.matrix[m_State.matrixMode].Ortho(l, r, b, t, n, f); } -AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +Matrix44& GfxDevice::GetMatrix(MatrixMode mode) { - return state.matrix[mode].GetTop(); + return m_State.matrix[mode].GetTop(); } -AEMath::Matrix44 GfxDevice::GetMVPMatrix() +Matrix44 GfxDevice::GetMVPMatrix() { - return state.matrix[MATRIX_MODE_PROJECTION].GetTop() - * state.matrix[MATRIX_MODE_VIEW].GetTop() - * state.matrix[MATRIX_MODE_MODEL].GetTop(); + return m_State.matrix[MATRIX_MODE_PROJECTION].GetTop() + * m_State.matrix[MATRIX_MODE_VIEW].GetTop() + * m_State.matrix[MATRIX_MODE_MODEL].GetTop(); } uint GfxDevice::GetMatrixDepth() { - return state.matrix[state.matrixMode].GetCapacity(); + return m_State.matrix[m_State.matrixMode].GetCapacity(); } uint GfxDevice::GetMatrixIndex() { - return state.matrix[state.matrixMode].GetTopIndex(); + return m_State.matrix[m_State.matrixMode].GetTopIndex(); } diff --git a/Source/modules/asura-core/Graphics/GfxDevice.h b/Source/modules/asura-core/Graphics/GfxDevice.h index 2b105df..7ef03a3 100644 --- a/Source/modules/asura-core/Graphics/GfxDevice.h +++ b/Source/modules/asura-core/Graphics/GfxDevice.h @@ -16,10 +16,40 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +class Mesh; class Profiler; class Shader; class GPUBuffer; class Canvas; +class DynamicVBO; +class VBO; +class VBOList; + +#define GFX_STATS_PROPERTY(TYPE,PROP_NAME,VAR_NAME) \ +private: \ + TYPE VAR_NAME; \ +public: \ + void Set##PROP_NAME (TYPE val) { VAR_NAME = val; } \ + TYPE Get##PROP_NAME () {return VAR_NAME; } \ + void Add##PROP_NAME (TYPE v=1) { VAR_NAME+=v;}; + +struct GfxDeviceStats +{ + GFX_STATS_PROPERTY(uint, DrawCall, drawCall); ///< ͳdrawcall + GFX_STATS_PROPERTY(uint, CanvasSwitch, canvasSwitch); ///< лtextureĴ + GFX_STATS_PROPERTY(uint, ShaderSwitch, shaderSwitch); ///< лshaderĴ + GFX_STATS_PROPERTY(uint64, PrimsCount, primsCount); ///< ͼԪͳ + + void Reset() + { + drawCall = 0; + canvasSwitch = 0; + shaderSwitch = 0; + primsCount = 0; + } +}; + +#undef GFX_STATS_PROPERTY enum MatrixMode { @@ -28,6 +58,20 @@ enum MatrixMode MATRIX_MODE_VIEW = 2, }; + +enum GfxPrimitiveType +{ + GFX_PRIMITIVE_TRIANGLES = 0, + GFX_PRIMITIVE_TRIANGLESTRIPDEPRECATED, + GFX_PRIMITIVE_QUADS, + GFX_PRIMITIVE_LINES, + GFX_PRIMITIVE_LINESTRIP, + GFX_PRIMITIVE_POINTS, + + GFX_PRIMITIVE_TYPECOUNT, // KEEP THIS LAST! + GFX_PRIMITIVE_FORCE32BITINT = 0X7FFFFFFF // FORCE 32 BIT ENUM SIZE +}; + enum GLParams { GL_PARAM_MAX_TEXTURE_UNIT = 1, @@ -44,12 +88,12 @@ public: int GetParam(GLParams param); - bool Init(const AEMath::Recti& viewport); + bool Init(const Recti& viewport); bool Inited(); - void SetViewport(const AEMath::Recti viewport); + void SetViewport(const Recti viewport); - const AEMath::Recti& GetViewport(); + const Recti& GetViewport(); void PushMatrix(); void PopMatrix(); @@ -63,10 +107,8 @@ public: uint GetMatrixDepth(); uint GetMatrixIndex(); - void DrawArrays(GLenum mode, GLint first, GLsizei count); - - AEMath::Matrix44& GetMatrix(MatrixMode mode); - AEMath::Matrix44 GetMVPMatrix(); + Matrix44& GetMatrix(MatrixMode mode); + Matrix44 GetMVPMatrix(); void SetDrawColor(float r, float g, float b, float a); Color& GetDrawColor(); @@ -74,36 +116,47 @@ public: void SetActiveShader(Shader* = NULL); Shader* GetActiveShader() const; + VBO* CreateVBO(); + void DeleteVBO(); + + void DrawMesh(Mesh* mesh); + void DrawVBO(VBO* vbo); + void DrawDynamicVBO(); + void DrawTexture(Texture*); + void WipeError(); bool HasError(); GLenum GetError(); - GET_SET(MatrixMode, MatrixMode, state.matrixMode); - GET_SET(Canvas*, ActiveCanvas, state.canvas); + GET_SET(MatrixMode, MatrixMode, m_State.matrixMode); + GET_SET(Canvas*, ActiveCanvas, m_State.activeCanvas); private: + void BeforeDrawCall(); + + // Callbacks + void OnCreateVBO(VBO* vbo); + void OnDeleteVBO(VBO* vbo); + friend class Profiler; - struct - { - AEMath::Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 - MatrixStack matrix[3]; ///< model, view, projection - MatrixMode matrixMode; ///< ǰľ - Color drawColor; ///< Ƶɫ - Canvas* canvas; ///< ǰcanvas - Shader* shader; ///< ǰʹõshader - } state; + struct { + Recti viewport; ///< ǰлHDC߱ڴСı߲ˢʱ䶯 + MatrixStack matrix[3]; ///< model, view, projection + MatrixMode matrixMode; ///< ǰľ + Color drawColor; ///< Ƶɫ + Canvas* activeCanvas; ///< ǰcanvas + Shader* activeShader; ///< ǰʹõshader + } m_State; #if ASURA_GL_PROFILE - struct - { - uint drawCall; ///< ͳdrawcall - uint canvasSwitch; ///< лtextureĴ - uint shaderSwitch; ///< лshaderĴ - } stats; + GfxDeviceStats m_Stats; #endif + DynamicVBO* m_DynamicVBO; + VBOList* m_VBOList; + luaxport: LUAX_DECL_SINGLETON(GfxDevice); @@ -127,13 +180,12 @@ luaxport: }; -extern GfxDevice g_Device; - - -#define GL_CALL(x) do { x; /*GLAssert(); */} while(0) - +// ȫgfx devicerunnereditor +extern GfxDevice g_GfxDevice; +inline GfxDevice& GetGfxDevice() { return g_GfxDevice; }; +#define GL_CALL(f, ...) do { f(__VA_ARGS__); /*GLAssert(); */} while(0) namespace_end namespace_end diff --git a/Source/modules/asura-core/Graphics/Image.cpp b/Source/modules/asura-core/Graphics/Image.cpp deleted file mode 100644 index 36d2478..0000000 --- a/Source/modules/asura-core/Graphics/Image.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include <asura-base/Exception.h> - -#include "../CoreConfig.h" - -#include "Shader.h" -#include "Image.h" -#include "GfxDevice.h" - -using namespace AEFileSystem; -using namespace AEImage; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -Image::Image() - : m_Width(0) - , m_Height(0) -{ -} - -Image::~Image() -{ -} - -bool Image::Load(ImageData* imgData) -{ - if (!imgData) return false; - - if (m_TexID == 0) - { - glGenTextures(1, &m_TexID); - if (m_TexID == 0) - throw Exception("OpenGL glGenTextures failed."); - } - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexImage2D( - GL_TEXTURE_2D - , 0 - , tf.internalformat - , width, height - , 0 - , tf.externalformat - , tf.type - , imgData->pixels - ); - - m_Width = imgData->width; - m_Height = imgData->height; - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; -} - -bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) -{ - if (!imgData) return false; - - glBindTexture(GL_TEXTURE_2D, m_TexID); - imgData->Lock(); - int width = imgData->width; - int height = imgData->height; - TextureFormat tf = ConvertColorFormat(imgData->format); - glTexSubImage2D( - GL_TEXTURE_2D - , 0 - , pos.x - , pos.y - , imgData->width - , imgData->height - , tf.externalformat - , tf.type - , imgData->pixels - ); - imgData->Unlock(); - GLenum err = glGetError(); - if (err != GL_NO_ERROR) - throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); - glBindTexture(GL_TEXTURE_2D, 0); - - return true; -} - -uint32 Image::GetWidth() -{ - return m_Width; -} - -uint32 Image::GetHeight() -{ - return m_Height; -} - -namespace_end -namespace_end
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/Image.h b/Source/modules/asura-core/Graphics/Image.h deleted file mode 100644 index a76d06f..0000000 --- a/Source/modules/asura-core/Graphics/Image.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _ASURA_ENGINE_IMAGE_H_ -#define _ASURA_ENGINE_IMAGE_H_ - -// asura modules -#include <asura-base/Math/Rect.hpp> -#include <asura-base/Math/Vector2.hpp> -#include <asura-base/Scripting/Scripting.h> -#include <asura-base/FileSystem/Renewable.h> -#include <asura-base/Utilities/Stringmap.hpp> -#include <asura-base/Manager.hpp> - -// module -#include "../Image/ImageData.h" - -// folder -#include "Color.h" -#include "Color32.h" -#include "RenderState.h" -#include "GPUBuffer.h" -#include "Texture.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -class Image ASURA_FINAL : public AEScripting::Portable<Image, Texture> -{ -public: - - Image(); - ~Image(); - - bool Load(AEImage::ImageData* decodeData); - bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); - - uint GetWidth(); - uint GetHeight(); - - GPUBuffer* GenGPUBuffer(); - -private: - - uint32 m_Width, m_Height; - -luaxport: - - LUAX_DECL_FACTORY(Image, Texture); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Load); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_Render); - -}; - -namespace_end -namespace_end - -namespace AEGraphics = AsuraEngine::Graphics; - -#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/MatrixStack.cpp b/Source/modules/asura-core/Graphics/MatrixStack.cpp index 987d29c..88b9b6b 100644 --- a/Source/modules/asura-core/Graphics/MatrixStack.cpp +++ b/Source/modules/asura-core/Graphics/MatrixStack.cpp @@ -36,7 +36,7 @@ bool MatrixStack::Pop() return true; } -AEMath::Matrix44& MatrixStack::GetTop() +Matrix44& MatrixStack::GetTop() { return m_Stack[top]; } diff --git a/Source/modules/asura-core/Graphics/MatrixStack.h b/Source/modules/asura-core/Graphics/MatrixStack.h index 8dd56bf..15ae7e5 100644 --- a/Source/modules/asura-core/Graphics/MatrixStack.h +++ b/Source/modules/asura-core/Graphics/MatrixStack.h @@ -8,17 +8,9 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) -/// -/// ջľȡ -/// -#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB - -/// -/// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1] -/// ֵһϵtransform -/// -/// TODO: template<uint _capacity> MatrixStack -/// +// ջ״ָ̬֮ǰ״̬ջеһstack[i]ֵstack[0]*..*stack[i-1]ֵһϵtransform +// +// TODO: template<uint _capacity> MatrixStack class MatrixStack { public: @@ -30,11 +22,11 @@ public: bool Push(); bool Pop(); - AEMath::Matrix44& GetTop(); - void GetTop(ASURA_OUT AEMath::Matrix44& mat44); + Matrix44& GetTop(); + void GetTop(ASURA_OUT Matrix44& mat44); - void LoadMatrix(const AEMath::Matrix44& mat44); - void MultMatrix(const AEMath::Matrix44& mat44); + void LoadMatrix(const Matrix44& mat44); + void MultMatrix(const Matrix44& mat44); void Rotate(float angle); void Translate(float x, float y); @@ -47,8 +39,8 @@ public: private: - AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; - uint8 top; + Matrix44 m_Stack[32]; // 2kB + uint8 m_Top; }; diff --git a/Source/modules/asura-core/Graphics/RenderTarget.cpp b/Source/modules/asura-core/Graphics/Mesh.cpp index e69de29..e69de29 100644 --- a/Source/modules/asura-core/Graphics/RenderTarget.cpp +++ b/Source/modules/asura-core/Graphics/Mesh.cpp diff --git a/Source/modules/asura-core/Graphics/VBO.cpp b/Source/modules/asura-core/Graphics/Mesh.h index e69de29..e69de29 100644 --- a/Source/modules/asura-core/Graphics/VBO.cpp +++ b/Source/modules/asura-core/Graphics/Mesh.h diff --git a/Source/modules/asura-core/Graphics/Mesh2D.h b/Source/modules/asura-core/Graphics/Mesh2D.h deleted file mode 100644 index 7a0f62e..0000000 --- a/Source/modules/asura-core/Graphics/Mesh2D.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _ASURA_ENGINE_MESH2D_H__ -#define _ASURA_ENGINE_MESH2D_H__ - -// cpp -#include <vector> - -// asura modules -#include <asura-base/Scripting/Scripting.h> -#include <asura-base/Math/Vector2.hpp> - -// module -#include "../Mesh/Mesh2dData.h" - -// folder -#include "Color.h" -#include "VertexBuffer.h" -#include "IndexBuffer.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -/// -/// 2D meshһЩ㶯 -/// https://en.wikipedia.org/wiki/Polygon_mesh -/// -class Mesh2D ASURA_FINAL - : public Scripting::Portable<Mesh2D> -{ -public: - - Mesh2D(); - ~Mesh2D(); - - bool Load(AEMesh::Mesh2DData* data); - -private: - - VertexBuffer* m_VBO; ///< vertex buffer - IndexBuffer* m_IBO; ///< index buffer - -luaxport: - - LUAX_DECL_FACTORY(Mesh2D); - - LUAX_DECL_METHOD(_SetVertex); - -}; - -namespace_end -namespace_end - -#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/RenderTarget.h b/Source/modules/asura-core/Graphics/RenderTarget.h deleted file mode 100644 index ab09e35..0000000 --- a/Source/modules/asura-core/Graphics/RenderTarget.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _ASURA_ENGINE_RENDERTARGET_H_ -#define _ASURA_ENGINE_RENDERTARGET_H_ - -#include <asura-base/Math/Vector2.hpp> -#include <asura-base/Math/Rect.hpp> -#include <asura-base/Scripting/Scripting.h> - -#include "Texture.h" -#include "Color.h" - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -/// -/// ɱΪȾĿ࣬ -/// Canvas(RenderTexture) -/// Window(RenderWindow) -/// -class RenderTarget : public AEScripting::Object -{ -public: - - RenderTarget() {}; - - virtual ~RenderTarget() {}; - - /// - /// ɫcolRT - /// - virtual void Clear(const Color& col = Color::Black) = 0; - - /// - /// ɫcolղRT - /// - virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; - - /// - /// textureRT - /// - virtual void Draw(const Drawable* texture, const RenderState& state) = 0; - - /// - /// һtextureRT - /// - virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; - -}; - -namespace_end -namespace_end - -#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/RenderTexture.cpp b/Source/modules/asura-core/Graphics/RenderTexture.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/modules/asura-core/Graphics/RenderTexture.cpp diff --git a/Source/modules/asura-core/Graphics/RenderTexture.h b/Source/modules/asura-core/Graphics/RenderTexture.h new file mode 100644 index 0000000..08199bf --- /dev/null +++ b/Source/modules/asura-core/Graphics/RenderTexture.h @@ -0,0 +1,22 @@ +#ifndef _ASURA_ENGINE_RENDERTARGET_H_ +#define _ASURA_ENGINE_RENDERTARGET_H_ + +#include <asura-base/Math/Vector2.hpp> +#include <asura-base/Math/Rect.hpp> +#include <asura-base/Scripting/Scripting.h> + +#include "Texture.h" +#include "Color.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTexture : public Texture +{ + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/Shader.cpp b/Source/modules/asura-core/Graphics/Shader.cpp index 329b3f1..56d638d 100644 --- a/Source/modules/asura-core/Graphics/Shader.cpp +++ b/Source/modules/asura-core/Graphics/Shader.cpp @@ -24,12 +24,12 @@ Shader::~Shader() void Shader::SetActive(Shader* shader) { - g_Device.SetActiveShader(shader); + g_GfxDevice.SetActiveShader(shader); } Shader* Shader::GetActive() { - return g_Device.GetActiveShader(); + return g_GfxDevice.GetActiveShader(); } bool Shader::Load(const string& vert, const string& frag) @@ -157,56 +157,56 @@ GLuint Shader::GetGLProgram() void Shader::SetUniformFloat(uint loc, float value) { - if(g_Device.GetActiveShader() == this) + if(g_GfxDevice.GetActiveShader() == this) glUniform1f(loc, value); } bool Shader::SetUniformTexture(uint loc, const Texture& texture) { - if (g_Device.GetActiveShader() != this) + if (g_GfxDevice.GetActiveShader() != this) return false; - g_Device.WipeError(); + g_GfxDevice.WipeError(); glActiveTexture(GL_TEXTURE0 + texUnit); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; GLint tex = texture.GetGLTexture(); glBindTexture(GL_TEXTURE_2D, tex); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; glUniform1i(loc, texUnit); - if (g_Device.HasError()) + if (g_GfxDevice.HasError()) return false; ++texUnit; } void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform2f(loc, vec2.x, vec2.y); } void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform3f(loc, vec3.x, vec3.y, vec3.z); } void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); } void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); } void Shader::SetUniformColor(uint loc, const Color& color) { - if (g_Device.GetActiveShader() == this) + if (g_GfxDevice.GetActiveShader() == this) glUniform4f(loc, color.r, color.g, color.b, color.a); } diff --git a/Source/modules/asura-core/Graphics/Shader.h b/Source/modules/asura-core/Graphics/Shader.h index 615b028..6d7ef90 100644 --- a/Source/modules/asura-core/Graphics/Shader.h +++ b/Source/modules/asura-core/Graphics/Shader.h @@ -3,6 +3,7 @@ #include <map> #include <string> +#include <vector> #include <asura-base/Exception.h> #include <asura-base/Scripting/Scripting.h> @@ -23,10 +24,21 @@ namespace_begin(AsuraEngine) namespace_begin(Graphics) +enum ShaderChannel +{ + SHADER_CHANNEL_NONE = -1, + SHADER_CHANNEL_VERTEX = 0, // Vertex (vector3) + SHADER_CHANNEL_NORMAL, // Normal (vector3) + SHADER_CHANNEL_COLOR, // Vertex color + SHADER_CHANNEL_TEXCOORD0, // UV set 0 (vector2) + SHADER_CHANNEL_TEXCOORD1, // UV set 1 (vector2) + SHADER_CHANNEL_TANGENT, // Tangent (vector4) + SHADER_CHANNEL_COUNT, // Keep this last! +}; + /// -/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫ -/// ķ༭ÿshaderͨshaderҵuniforms¶frameworkmaterial -/// á +/// һshaderһڲʼ乲ijShaderuniformsͶݣֻṩ uniformsuseɫķ +/// ༭ÿshaderͨshaderҵuniforms¶frameworkmaterialá /// class Shader ASURA_FINAL : public Scripting::Portable<Shader> @@ -64,10 +76,10 @@ public: bool SetUniformTexture(uint loc, const Texture& texture); float GetUniformFloat(uint loc); - AEMath::Vector2f GetUniformVector2(uint loc); - AEMath::Vector3f GetUniformVector3(uint loc); - AEMath::Vector4f GetUniformVector4s(uint loc); - AEMath::Matrix44 GetUniformMatrix44(uint loc); + Vector2f GetUniformVector2(uint loc); + Vector3f GetUniformVector3(uint loc); + Vector4f GetUniformVector4s(uint loc); + Matrix44 GetUniformMatrix44(uint loc); GLuint GetGLProgram(); @@ -109,6 +121,7 @@ luaxport: }; +// GPU program typedef Shader GpuProgram; namespace_end diff --git a/Source/modules/asura-core/Graphics/Texture.h b/Source/modules/asura-core/Graphics/Texture.h index 76b9a8f..572fad4 100644 --- a/Source/modules/asura-core/Graphics/Texture.h +++ b/Source/modules/asura-core/Graphics/Texture.h @@ -3,6 +3,7 @@ #include <asura-base/Math/Vector2.hpp> #include <asura-base/Math/Rect.hpp> +#include <asura-base/Type.h> #include "../CoreConfig.h" @@ -14,6 +15,17 @@ namespace_begin(Graphics) class RenderTarget; +/// ͼƬ +class ImageData +{ +public: + uint8* GetData(); +private: + int m_Format; + uint8* m_ImageData; + Vector2i m_ImageSize; +}; + /// UVʽ enum WrapMode { @@ -34,8 +46,8 @@ enum FilterMode enum ColorFormat { COLOR_FORMAT_UNKNOWN, - COLOR_FORMAT_RGBA8, ///< RGBA8bits int - COLOR_FORMAT_RGBA32F, ///< RGBA32bits float + COLOR_FORMAT_RGBA8, + COLOR_FORMAT_RGBA32F, }; /// ʽGPUڲCPUⲿʽ @@ -50,11 +62,14 @@ struct TextureFormat /// 2D࣬2d meshrender targetбʹáTextureȾԭϽǣϷϲԵѿ /// ϵΪEditorҲϽΪԭ㣬Ϊ˷㡣 /// -ASURA_ABSTRACT class Texture : public AEScripting::Object +class Texture : public AEScripting::Object { public: - LUAX_DECL_ABSTRACT_FACTORY(Texture); + LUAX_DECL_FACTORY(Texture); + + // Texture generator + static Texture* GenerateTexture(); Texture(); virtual ~Texture(); @@ -67,9 +82,12 @@ public: void GetFilterMode(); void GetWrapMode(); - /// UVfilterΪ bool IsGenMipmap(); + int GetWidth(); + int GetHeight(); + Vector2i GetSize(); + protected: /// תcolor formatΪtexture format @@ -79,7 +97,12 @@ protected: FilterMode m_MinFilter; FilterMode m_MagFilter; WrapMode m_WrapMode; + int m_UsageMode; bool m_IsGenMipmap; + Vector2f m_TexelSize; + Vector2f m_UVScale; + +luaxport: LUAX_DECL_ENUM(ColorFormat, 1); LUAX_DECL_ENUM(FilterMode, 1); @@ -90,11 +113,12 @@ protected: LUAX_DECL_METHOD(_GetFilterMode); LUAX_DECL_METHOD(_GetWrapMode); LUAX_DECL_METHOD(_IsGenMipmap); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); }; -typedef Texture Drawable; - namespace_end namespace_end diff --git a/Source/modules/asura-core/Graphics/VBO.h b/Source/modules/asura-core/Graphics/VBO.h deleted file mode 100644 index f80991e..0000000 --- a/Source/modules/asura-core/Graphics/VBO.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _ASURA_ENGINE_VBO_H_ -#define _ASURA_ENGINE_VBO_H_ - -#include <asura-base/Classes.h> - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - -struct VertexBufferData -{ - -}; - -struct IndexBufferData -{ - -}; - -class VBO -{ - -}; - -namespace_end -namespace_end - -#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/VBOs.cpp b/Source/modules/asura-core/Graphics/VBOs.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Source/modules/asura-core/Graphics/VBOs.cpp diff --git a/Source/modules/asura-core/Graphics/VBOs.h b/Source/modules/asura-core/Graphics/VBOs.h new file mode 100644 index 0000000..0833534 --- /dev/null +++ b/Source/modules/asura-core/Graphics/VBOs.h @@ -0,0 +1,56 @@ +#ifndef _ASURA_ENGINE_VBO_H_ +#define _ASURA_ENGINE_VBO_H_ + +#include <asura-base/Classes.h> +#include <asura-base/Type.h> + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +struct VertexBufferData +{ + +}; + +struct IndexBufferData +{ + +}; + +class VBO +{ +public: + +private: + + + +}; + +class SharedVBO; + +class DynamicVBO +{ +public: + + void GetChunk(uint32 maxVertices, uint32 maxIndices, void** outVB, void** outIB); + void ReleaseChunk(uint32 actualVertices, uint32 actualIndices); + +private: + + // vertex buffer + SharedVBO* m_VB; + SharedVBO* m_LargeVB; + SharedVBO* m_ActiveVB; + + // index buffer + SharedVBO* m_IB; + SharedVBO* m_LargeIB; + SharedVBO* m_ActiveIB; + +}; + +namespace_end +namespace_end + +#endif
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp b/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp new file mode 100644 index 0000000..a038e67 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Canvas.binding.cpp @@ -0,0 +1,48 @@ +#include "../Canvas.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Canvas) +{ + LUAX_REGISTER_METHODS(state, + { "SetSize", _SetSize }, + { "Bind", _Bind }, + { "Unbind", _Unbind } + ); +} + +LUAX_POSTPROCESS(Canvas) +{ + +} + +// canvas:SetSize() +LUAX_IMPL_METHOD(Canvas, _SetSize) +{ + LUAX_PREPARE(L, Canvas); + return 0; + +} + +// canvas:Bind() +LUAX_IMPL_METHOD(Canvas, _Bind) +{ + LUAX_PREPARE(L, Canvas); + + return 0; +} + +// canvas:Unbind() +LUAX_IMPL_METHOD(Canvas, _Unbind) +{ + LUAX_PREPARE(L, Canvas); + return 0; + +} + +namespace_end +namespace_end
\ No newline at end of file diff --git a/Source/modules/asura-core/Graphics/binding/_color.cpp b/Source/modules/asura-core/Graphics/binding/Color.binding.cpp index 008d9c2..008d9c2 100644 --- a/Source/modules/asura-core/Graphics/binding/_color.cpp +++ b/Source/modules/asura-core/Graphics/binding/Color.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_color32.cpp b/Source/modules/asura-core/Graphics/binding/Color32.binding.cpp index 7613361..7613361 100644 --- a/Source/modules/asura-core/Graphics/binding/_color32.cpp +++ b/Source/modules/asura-core/Graphics/binding/Color32.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp b/Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp index 8c39a59..8c39a59 100644 --- a/Source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp +++ b/Source/modules/asura-core/Graphics/binding/GPUBuffer.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_gfx_device.cpp b/Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp index f6c2004..f6c2004 100644 --- a/Source/modules/asura-core/Graphics/binding/_gfx_device.cpp +++ b/Source/modules/asura-core/Graphics/binding/GfxDevice.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/Image.binding.cpp b/Source/modules/asura-core/Graphics/binding/Image.binding.cpp new file mode 100644 index 0000000..94f88b8 --- /dev/null +++ b/Source/modules/asura-core/Graphics/binding/Image.binding.cpp @@ -0,0 +1,71 @@ +#include "../image.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Image) +{ + LUAX_INHERIT(state, Texture); + + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "Render", _Render } + ); +} + +LUAX_POSTPROCESS(Image) +{ +} + +// image = Image.New() +LUAX_IMPL_METHOD(Image, _New) +{ + LUAX_STATE(L); + Image* img = new Image(); + img->PushLuaxUserdata(state); + return 1; +} + +// width = image:GetWidth() +LUAX_IMPL_METHOD(Image, _GetWidth) +{ + LUAX_PREPARE(L, Image); + state.Push(self->GetWidth()); + return 1; +} + +// height = image:GetHeight() +LUAX_IMPL_METHOD(Image, _GetHeight) +{ + LUAX_PREPARE(L, Image); + state.Push(self->GetHeight()); + return 1; +} + +// width, height = image:GetSize() +LUAX_IMPL_METHOD(Image, _GetSize) +{ + LUAX_PREPARE(L, Image); + int width = self->GetWidth(); + int height = self->GetHeight(); + state.Push(width); + state.Push(height); + return 2; +} + +// image:Render() +LUAX_IMPL_METHOD(Image, _Render) +{ + LUAX_PREPARE(L, Image); + + return 0; +} + +} +} diff --git a/Source/modules/asura-core/Graphics/binding/_index_buffer.cpp b/Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp index 151dc98..151dc98 100644 --- a/Source/modules/asura-core/Graphics/binding/_index_buffer.cpp +++ b/Source/modules/asura-core/Graphics/binding/IndexBuffer.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_mesh2d.cpp b/Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp index 4e3f426..4e3f426 100644 --- a/Source/modules/asura-core/Graphics/binding/_mesh2d.cpp +++ b/Source/modules/asura-core/Graphics/binding/Mesh.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_shader.cpp b/Source/modules/asura-core/Graphics/binding/Shader.binding.cpp index 85fd388..85fd388 100644 --- a/Source/modules/asura-core/Graphics/binding/_shader.cpp +++ b/Source/modules/asura-core/Graphics/binding/Shader.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp b/Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp index 6b7d25c..6b7d25c 100644 --- a/Source/modules/asura-core/Graphics/binding/_sprite_batch.cpp +++ b/Source/modules/asura-core/Graphics/binding/SpriteBatch.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_texture.cpp b/Source/modules/asura-core/Graphics/binding/Texture.binding.cpp index f5e5f17..f5e5f17 100644 --- a/Source/modules/asura-core/Graphics/binding/_texture.cpp +++ b/Source/modules/asura-core/Graphics/binding/Texture.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp b/Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp index 8ed487b..8ed487b 100644 --- a/Source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp +++ b/Source/modules/asura-core/Graphics/binding/VertexBuffer.binding.cpp diff --git a/Source/modules/asura-core/Graphics/binding/_canvas.cpp b/Source/modules/asura-core/Graphics/binding/_canvas.cpp deleted file mode 100644 index 44841f5..0000000 --- a/Source/modules/asura-core/Graphics/binding/_canvas.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "../Canvas.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Canvas) - { - LUAX_REGISTER_METHODS(state, - { "SetSize", _SetSize }, - { "Bind", _Bind }, - { "Unbind", _Unbind } - ); - } - - LUAX_POSTPROCESS(Canvas) - { - - } - - // canvas:SetSize() - LUAX_IMPL_METHOD(Canvas, _SetSize) - { - LUAX_PREPARE(L, Canvas); - return 0; - - } - - // canvas:Bind() - LUAX_IMPL_METHOD(Canvas, _Bind) - { - LUAX_PREPARE(L, Canvas); - - return 0; - } - - // canvas:Unbind() - LUAX_IMPL_METHOD(Canvas, _Unbind) - { - LUAX_PREPARE(L, Canvas); - return 0; - - } - - } -} diff --git a/Source/modules/asura-core/Graphics/binding/_image.cpp b/Source/modules/asura-core/Graphics/binding/_image.cpp deleted file mode 100644 index 0e4cb16..0000000 --- a/Source/modules/asura-core/Graphics/binding/_image.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "../image.h" - -using namespace std; - -namespace_begin(AsuraEngine) -namespace_begin(Graphics) - - - LUAX_REGISTRY(Image) - { - LUAX_INHERIT(state, Texture); - - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetWidth", _GetWidth }, - { "GetHeight", _GetHeight }, - { "GetSize", _GetSize }, - { "Render", _Render } - ); - } - - LUAX_POSTPROCESS(Image) - { - } - - // image = Image.New() - LUAX_IMPL_METHOD(Image, _New) - { - LUAX_STATE(L); - Image* img = new Image(); - img->PushLuaxUserdata(state); - return 1; - } - - // width = image:GetWidth() - LUAX_IMPL_METHOD(Image, _GetWidth) - { - LUAX_PREPARE(L, Image); - state.Push(self->GetWidth()); - return 1; - } - - // height = image:GetHeight() - LUAX_IMPL_METHOD(Image, _GetHeight) - { - LUAX_PREPARE(L, Image); - state.Push(self->GetHeight()); - return 1; - } - - // width, height = image:GetSize() - LUAX_IMPL_METHOD(Image, _GetSize) - { - LUAX_PREPARE(L, Image); - int width = self->GetWidth(); - int height = self->GetHeight(); - state.Push(width); - state.Push(height); - return 2; - } - - // image:Render() - LUAX_IMPL_METHOD(Image, _Render) - { - LUAX_PREPARE(L, Image); - - return 0; - } - - } -} diff --git a/Source/modules/asura-core/Input/InputDevice.h b/Source/modules/asura-core/Input/InputDevice.h index 2b3ff9b..42dfe43 100644 --- a/Source/modules/asura-core/Input/InputDevice.h +++ b/Source/modules/asura-core/Input/InputDevice.h @@ -16,6 +16,7 @@ namespace_begin(AsuraEngine) namespace_begin(Input) +// Ӳϵͳ class InputDevice ASURA_FINAL { public: @@ -35,7 +36,7 @@ public: LRESULT OnInput(HWND window, UINT message, WPARAM wParam, LPARAM lParam); LRESULT OnDeviceChange(LPCWSTR name, bool add); - static bool ConvertPositionToClientAreaCoord(HWND activeWindow, POINT position, AEMath::Vector2f& newPos); + static bool ConvertPositionToClientAreaCoord(HWND activeWindow, POINT position, Vector2f& newPos); #elif ASURA_RUNNER @@ -52,7 +53,7 @@ protected: bool UpdateState(); - MouseState m_Mouse; + MouseState m_Mouse; KeyboardState m_Keyboard; JoystickState m_Joysticks; diff --git a/Source/modules/asura-core/Input/InputEvent.h b/Source/modules/asura-core/Input/InputEvent.h index c643b75..fc7b9f6 100644 --- a/Source/modules/asura-core/Input/InputEvent.h +++ b/Source/modules/asura-core/Input/InputEvent.h @@ -32,7 +32,7 @@ struct InputEvent LRESULT OnInput(HWND window, UINT message, WPARAM wParam, LPARAM lParam); LRESULT OnDeviceChange(LPCWSTR name, bool add); - static bool ConvertPositionToClientAreaCoord(HWND activeWindow, POINT position, AEMath::Vector2f& newPos); + static bool ConvertPositionToClientAreaCoord(HWND activeWindow, POINT position, Vector2f& newPos); #elif ASURA_RUNNER diff --git a/Source/modules/asura-core/Input/InputManager.cpp b/Source/modules/asura-core/Input/InputManager.cpp index cec1b36..03200f5 100644 --- a/Source/modules/asura-core/Input/InputManager.cpp +++ b/Source/modules/asura-core/Input/InputManager.cpp @@ -82,12 +82,12 @@ bool InputManager::GetKeyUp(int key) } -const AEMath::Vector2f& InputManager::GetMouseDelta() +const Vector2f& InputManager::GetMouseDelta() { return m_MouseDelta; } -const AEMath::Vector2f& InputManager::GetMousePosition() +const Vector2f& InputManager::GetMousePosition() { return m_MousePos; } @@ -114,11 +114,11 @@ void InputManager::SetKeyState(int key, bool state) m_CurrentKeyState[key] = state; } -void InputManager::SetMouseDelta(const AEMath::Vector2f& delta) +void InputManager::SetMouseDelta(const Vector2f& delta) { } -void InputManager::SetMousePosition(const AEMath::Vector2f& pos) +void InputManager::SetMousePosition(const Vector2f& pos) { } diff --git a/Source/modules/asura-core/Input/InputManager.h b/Source/modules/asura-core/Input/InputManager.h index 3c44745..4071b66 100644 --- a/Source/modules/asura-core/Input/InputManager.h +++ b/Source/modules/asura-core/Input/InputManager.h @@ -40,15 +40,15 @@ public: bool GetKeyDown(int key); bool GetKeyUp(int key); - const AEMath::Vector2f& GetMouseDelta(); - const AEMath::Vector2f& GetMousePosition(); + const Vector2f& GetMouseDelta(); + const Vector2f& GetMousePosition(); float GetJoystickPosition(); void setJoystickPosition(); void SetKeyState(int key, bool state); - void SetMouseDelta(const AEMath::Vector2f& delta); - void SetMousePosition(const AEMath::Vector2f& pos); + void SetMouseDelta(const Vector2f& delta); + void SetMousePosition(const Vector2f& pos); void SetMouseButton(int button, bool enabled); void ProcessInput(); @@ -62,8 +62,8 @@ private: std::vector<InputAxis> m_Axis; - AEMath::Vector2f m_MouseDelta; - AEMath::Vector2f m_MousePos; + Vector2f m_MouseDelta; + Vector2f m_MousePos; bool m_MousePresent; @@ -72,7 +72,7 @@ private: std::string m_InputString; std::string m_CompositionString; - AEMath::Vector2f m_TextFieldCursorPos; + Vector2f m_TextFieldCursorPos; bool m_TextFieldInput; bool m_EatKeyPressOnTextFieldFocus; diff --git a/Source/modules/asura-core/Mesh/Mesh2DData.h b/Source/modules/asura-core/Mesh/Mesh2DData.h index 3e30a06..f041e05 100644 --- a/Source/modules/asura-core/Mesh/Mesh2DData.h +++ b/Source/modules/asura-core/Mesh/Mesh2DData.h @@ -21,9 +21,9 @@ namespace_begin(Mesh) /// struct Vertex { - AEMath::Vector2f position; ///< + Vector2f position; ///< AEGraphics::Color color; ///< ɫ - AEMath::Vector2f texCoord[4]; ///< UVs + Vector2f texCoord[4]; ///< UVs }; /// |