From 250e30d73f09e9da2b5a81d0fbae63744ae12a73 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 2 Apr 2019 08:47:15 +0800 Subject: *misc --- source/modules/asura-core/application.cpp | 2 +- source/modules/asura-core/core_module.cpp | 3 +- source/modules/asura-core/core_module.h | 2 +- source/modules/asura-core/font/string.cpp | 752 ++++++------- source/modules/asura-core/font/string.hpp | 1189 ++++++++++---------- .../asura-core/graphics/binding/_canvas.cpp | 3 + .../asura-core/graphics/binding/_color32.cpp | 6 +- .../asura-core/graphics/binding/_image_data.cpp | 111 -- .../graphics/binding/_image_decode_task.cpp | 21 - .../asura-core/graphics/binding/_shader.cpp | 18 +- source/modules/asura-core/graphics/canvas.cpp | 13 +- source/modules/asura-core/graphics/color.cpp | 15 +- source/modules/asura-core/graphics/gl.cpp | 17 + source/modules/asura-core/graphics/gl.h | 19 +- source/modules/asura-core/graphics/image.cpp | 15 +- source/modules/asura-core/graphics/image.h | 8 +- source/modules/asura-core/graphics/image_data.cpp | 67 -- source/modules/asura-core/graphics/image_data.h | 85 -- .../asura-core/graphics/image_decode_task.cpp | 0 .../asura-core/graphics/image_decode_task.h | 25 - source/modules/asura-core/graphics/image_decoder.h | 35 - source/modules/asura-core/graphics/mesh2d.h | 2 + source/modules/asura-core/graphics/mesh2d_data.cpp | 0 source/modules/asura-core/graphics/mesh2d_data.h | 0 source/modules/asura-core/graphics/png_decoder.cpp | 19 - source/modules/asura-core/graphics/png_decoder.h | 27 - source/modules/asura-core/graphics/render_target.h | 2 - source/modules/asura-core/graphics/shader.cpp | 11 +- source/modules/asura-core/graphics/sprite_batch.h | 2 + source/modules/asura-core/graphics/stb_decoder.cpp | 70 -- source/modules/asura-core/graphics/stb_decoder.h | 28 - source/modules/asura-core/graphics/texture.cpp | 19 + source/modules/asura-core/graphics/texture.h | 18 + .../asura-core/image/binding/_image_data.cpp | 111 ++ .../image/binding/_image_decode_task.cpp | 21 + source/modules/asura-core/image/image_data.cpp | 62 + source/modules/asura-core/image/image_data.h | 85 ++ .../modules/asura-core/image/image_decode_task.cpp | 0 .../modules/asura-core/image/image_decode_task.h | 25 + source/modules/asura-core/image/image_decoder.h | 35 + source/modules/asura-core/image/png_decoder.cpp | 19 + source/modules/asura-core/image/png_decoder.h | 27 + source/modules/asura-core/image/stb_decoder.cpp | 73 ++ source/modules/asura-core/image/stb_decoder.h | 28 + source/modules/asura-core/mesh/mesh2d_data.cpp | 0 source/modules/asura-core/mesh/mesh2d_data.h | 0 source/modules/asura-core/threading/thread_ex.cpp | 1 + .../modules/asura-core/window/binding/_window.cpp | 180 +++ source/modules/asura-core/window/window.cpp | 106 ++ source/modules/asura-core/window/window.h | 151 +++ .../modules/asura-core/window/window_impl_glew.cpp | 0 .../modules/asura-core/window/window_impl_glew.h | 0 .../modules/asura-core/window/window_impl_glut.cpp | 0 .../modules/asura-core/window/window_impl_glut.h | 0 .../modules/asura-core/window/window_impl_sdl.cpp | 154 +++ source/modules/asura-core/window/window_impl_sdl.h | 47 + source/modules/asura-core/wnd/binding/_window.cpp | 180 --- source/modules/asura-core/wnd/window.cpp | 108 -- source/modules/asura-core/wnd/window.h | 149 --- source/modules/asura-core/wnd/window_impl_glew.cpp | 0 source/modules/asura-core/wnd/window_impl_glew.h | 0 source/modules/asura-core/wnd/window_impl_glut.cpp | 0 source/modules/asura-core/wnd/window_impl_glut.h | 0 source/modules/asura-core/wnd/window_impl_sdl.cpp | 147 --- source/modules/asura-core/wnd/window_impl_sdl.h | 45 - 65 files changed, 2224 insertions(+), 2134 deletions(-) delete mode 100644 source/modules/asura-core/graphics/binding/_image_data.cpp delete mode 100644 source/modules/asura-core/graphics/binding/_image_decode_task.cpp delete mode 100644 source/modules/asura-core/graphics/image_data.cpp delete mode 100644 source/modules/asura-core/graphics/image_data.h delete mode 100644 source/modules/asura-core/graphics/image_decode_task.cpp delete mode 100644 source/modules/asura-core/graphics/image_decode_task.h delete mode 100644 source/modules/asura-core/graphics/image_decoder.h delete mode 100644 source/modules/asura-core/graphics/mesh2d_data.cpp delete mode 100644 source/modules/asura-core/graphics/mesh2d_data.h delete mode 100644 source/modules/asura-core/graphics/png_decoder.cpp delete mode 100644 source/modules/asura-core/graphics/png_decoder.h delete mode 100644 source/modules/asura-core/graphics/stb_decoder.cpp delete mode 100644 source/modules/asura-core/graphics/stb_decoder.h create mode 100644 source/modules/asura-core/image/binding/_image_data.cpp create mode 100644 source/modules/asura-core/image/binding/_image_decode_task.cpp create mode 100644 source/modules/asura-core/image/image_data.cpp create mode 100644 source/modules/asura-core/image/image_data.h create mode 100644 source/modules/asura-core/image/image_decode_task.cpp create mode 100644 source/modules/asura-core/image/image_decode_task.h create mode 100644 source/modules/asura-core/image/image_decoder.h create mode 100644 source/modules/asura-core/image/png_decoder.cpp create mode 100644 source/modules/asura-core/image/png_decoder.h create mode 100644 source/modules/asura-core/image/stb_decoder.cpp create mode 100644 source/modules/asura-core/image/stb_decoder.h create mode 100644 source/modules/asura-core/mesh/mesh2d_data.cpp create mode 100644 source/modules/asura-core/mesh/mesh2d_data.h create mode 100644 source/modules/asura-core/window/binding/_window.cpp create mode 100644 source/modules/asura-core/window/window.cpp create mode 100644 source/modules/asura-core/window/window.h create mode 100644 source/modules/asura-core/window/window_impl_glew.cpp create mode 100644 source/modules/asura-core/window/window_impl_glew.h create mode 100644 source/modules/asura-core/window/window_impl_glut.cpp create mode 100644 source/modules/asura-core/window/window_impl_glut.h create mode 100644 source/modules/asura-core/window/window_impl_sdl.cpp create mode 100644 source/modules/asura-core/window/window_impl_sdl.h delete mode 100644 source/modules/asura-core/wnd/binding/_window.cpp delete mode 100644 source/modules/asura-core/wnd/window.cpp delete mode 100644 source/modules/asura-core/wnd/window.h delete mode 100644 source/modules/asura-core/wnd/window_impl_glew.cpp delete mode 100644 source/modules/asura-core/wnd/window_impl_glew.h delete mode 100644 source/modules/asura-core/wnd/window_impl_glut.cpp delete mode 100644 source/modules/asura-core/wnd/window_impl_glut.h delete mode 100644 source/modules/asura-core/wnd/window_impl_sdl.cpp delete mode 100644 source/modules/asura-core/wnd/window_impl_sdl.h (limited to 'source/modules/asura-core') diff --git a/source/modules/asura-core/application.cpp b/source/modules/asura-core/application.cpp index 1ef9414..a630d4c 100644 --- a/source/modules/asura-core/application.cpp +++ b/source/modules/asura-core/application.cpp @@ -17,7 +17,7 @@ namespace AsuraEngine bool Application::InitSubModules(uint flag) { - + return false; } } \ No newline at end of file diff --git a/source/modules/asura-core/core_module.cpp b/source/modules/asura-core/core_module.cpp index e6b0dac..989ec3e 100644 --- a/source/modules/asura-core/core_module.cpp +++ b/source/modules/asura-core/core_module.cpp @@ -2,7 +2,6 @@ using namespace AEThreading; using namespace AEGraphics; -using namespace AEWnd; namespace AsuraEngine { @@ -13,7 +12,7 @@ namespace AsuraEngine LUAX_REGISTER_ABSTRACT_FACTORY(state, Texture); LUAX_REGISTER_FACTORY(state, Image); // Wnd - LUAX_REGISTER_SINGLETON(state, Window); + LUAX_REGISTER_SINGLETON(state, AEWindow::Window); // Threading //LUAX_REGISTER_FACTORY(state, ThreadEx); } diff --git a/source/modules/asura-core/core_module.h b/source/modules/asura-core/core_module.h index 613a806..443aea4 100644 --- a/source/modules/asura-core/core_module.h +++ b/source/modules/asura-core/core_module.h @@ -6,7 +6,7 @@ #include "graphics/image.h" #include "graphics/texture.h" -#include "wnd/window.h" +#include "window/window.h" #include "threading/thread_ex.h" diff --git a/source/modules/asura-core/font/string.cpp b/source/modules/asura-core/font/string.cpp index 8c9c55a..72acaa6 100644 --- a/source/modules/asura-core/font/string.cpp +++ b/source/modules/asura-core/font/string.cpp @@ -1,376 +1,376 @@ -#include "String.hpp" -#include "Utf.hpp" - -namespace AsuraEngine -{ - namespace Text - { - - - //////////////////////////////////////////////////////////// - const std::size_t String::InvalidPos = std::basic_string::npos; - - - //////////////////////////////////////////////////////////// - String::String() - { - } - - - //////////////////////////////////////////////////////////// - String::String(char ansiChar, const std::locale& locale) - { - mString += Utf32::DecodeAnsi(ansiChar, locale); - } - - - //////////////////////////////////////////////////////////// - String::String(wchar_t wideChar) - { - mString += Utf32::DecodeWide(wideChar); - } - - - //////////////////////////////////////////////////////////// - String::String(uint32 utf32Char) - { - mString += utf32Char; - } - - - //////////////////////////////////////////////////////////// - String::String(const char* ansiString, const std::locale& locale) - { - if (ansiString) - { - std::size_t length = strlen(ansiString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); - } - } - } - - - //////////////////////////////////////////////////////////// - String::String(const std::string& ansiString, const std::locale& locale) - { - mString.reserve(ansiString.length() + 1); - Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); - } - - - //////////////////////////////////////////////////////////// - String::String(const wchar_t* wideString) - { - if (wideString) - { - std::size_t length = std::wcslen(wideString); - if (length > 0) - { - mString.reserve(length + 1); - Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); - } - } - } - - - //////////////////////////////////////////////////////////// - String::String(const std::wstring& wideString) - { - mString.reserve(wideString.length() + 1); - Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); - } - - - //////////////////////////////////////////////////////////// - String::String(const uint32* utf32String) - { - if (utf32String) - mString = utf32String; - } - - - //////////////////////////////////////////////////////////// - String::String(const std::basic_string& utf32String) : - mString(utf32String) - { - } - - - //////////////////////////////////////////////////////////// - String::String(const String& copy) : - mString(copy.mString) - { - } - - - //////////////////////////////////////////////////////////// - String::operator std::string() const - { - return ToAnsiString(); - } - - - //////////////////////////////////////////////////////////// - String::operator std::wstring() const - { - return ToWideString(); - } - - - //////////////////////////////////////////////////////////// - std::string String::ToAnsiString(const std::locale& locale) const - { - // Prepare the output string - std::string output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::wstring String::ToWideString() const - { - // Prepare the output string - std::wstring output; - output.reserve(mString.length() + 1); - - // Convert - Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string String::ToUtf8() const - { - // Prepare the output string - std::basic_string output; - output.reserve(mString.length()); - - // Convert - Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output)); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string String::ToUtf16() const - { - // Prepare the output string - std::basic_string output; - output.reserve(mString.length()); - - // Convert - Utf32::ToUtf16(mString.begin(), mString.end(), std::back_inserter(output)); - - return output; - } - - - //////////////////////////////////////////////////////////// - std::basic_string String::ToUtf32() const - { - return mString; - } - - - //////////////////////////////////////////////////////////// - String& String::operator =(const String& right) - { - mString = right.mString; - return *this; - } - - - //////////////////////////////////////////////////////////// - String& String::operator +=(const String& right) - { - mString += right.mString; - return *this; - } - - - //////////////////////////////////////////////////////////// - uint32 String::operator [](std::size_t index) const - { - return mString[index]; - } - - - //////////////////////////////////////////////////////////// - uint32& String::operator [](std::size_t index) - { - return mString[index]; - } - - - //////////////////////////////////////////////////////////// - void String::Clear() - { - mString.clear(); - } - - - //////////////////////////////////////////////////////////// - std::size_t String::GetSize() const - { - return mString.size(); - } - - - //////////////////////////////////////////////////////////// - bool String::IsEmpty() const - { - return mString.empty(); - } - - - //////////////////////////////////////////////////////////// - void String::Erase(std::size_t position, std::size_t count) - { - mString.erase(position, count); - } - - - //////////////////////////////////////////////////////////// - void String::Insert(std::size_t position, const String& str) - { - mString.insert(position, str.mString); - } - - - //////////////////////////////////////////////////////////// - std::size_t String::Find(const String& str, std::size_t start) const - { - return mString.find(str.mString, start); - } - - - //////////////////////////////////////////////////////////// - void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) - { - mString.replace(position, length, replaceWith.mString); - } - - - //////////////////////////////////////////////////////////// - void String::Replace(const String& searchFor, const String& replaceWith) - { - std::size_t step = replaceWith.GetSize(); - std::size_t len = searchFor.GetSize(); - std::size_t pos = Find(searchFor); - - // Replace each occurrence of search - while (pos != InvalidPos) - { - Replace(pos, len, replaceWith); - pos = Find(searchFor, pos + step); - } - } - - - //////////////////////////////////////////////////////////// - String String::Substring(std::size_t position, std::size_t length) const - { - return mString.substr(position, length); - } - - - //////////////////////////////////////////////////////////// - const uint32* String::GetData() const - { - return mString.c_str(); - } - - - //////////////////////////////////////////////////////////// - String::Iterator String::Begin() - { - return mString.begin(); - } - - - //////////////////////////////////////////////////////////// - String::ConstIterator String::Begin() const - { - return mString.begin(); - } - - - //////////////////////////////////////////////////////////// - String::Iterator String::End() - { - return mString.end(); - } - - - //////////////////////////////////////////////////////////// - String::ConstIterator String::End() const - { - return mString.end(); - } - - - //////////////////////////////////////////////////////////// - bool operator ==(const String& left, const String& right) - { - return left.mString == right.mString; - } - - - //////////////////////////////////////////////////////////// - bool operator !=(const String& left, const String& right) - { - return !(left == right); - } - - - //////////////////////////////////////////////////////////// - bool operator <(const String& left, const String& right) - { - return left.mString < right.mString; - } - - - //////////////////////////////////////////////////////////// - bool operator >(const String& left, const String& right) - { - return right < left; - } - - - //////////////////////////////////////////////////////////// - bool operator <=(const String& left, const String& right) - { - return !(right < left); - } - - - //////////////////////////////////////////////////////////// - bool operator >=(const String& left, const String& right) - { - return !(left < right); - } - - - //////////////////////////////////////////////////////////// - String operator +(const String& left, const String& right) - { - String string = left; - string += right; - - return string; - } - - - } -} +//#include "String.hpp" +//#include "Utf.hpp" +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// const std::size_t String::InvalidPos = std::basic_string::npos; +// +// +// //////////////////////////////////////////////////////////// +// String::String() +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(char ansiChar, const std::locale& locale) +// { +// mString += Utf32::DecodeAnsi(ansiChar, locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(wchar_t wideChar) +// { +// mString += Utf32::DecodeWide(wideChar); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(uint32 utf32Char) +// { +// mString += utf32Char; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const char* ansiString, const std::locale& locale) +// { +// if (ansiString) +// { +// std::size_t length = strlen(ansiString); +// if (length > 0) +// { +// mString.reserve(length + 1); +// Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(mString), locale); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::string& ansiString, const std::locale& locale) +// { +// mString.reserve(ansiString.length() + 1); +// Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(mString), locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const wchar_t* wideString) +// { +// if (wideString) +// { +// std::size_t length = std::wcslen(wideString); +// if (length > 0) +// { +// mString.reserve(length + 1); +// Utf32::FromWide(wideString, wideString + length, std::back_inserter(mString)); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::wstring& wideString) +// { +// mString.reserve(wideString.length() + 1); +// Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(mString)); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const uint32* utf32String) +// { +// if (utf32String) +// mString = utf32String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::basic_string& utf32String) : +// mString(utf32String) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const String& copy) : +// mString(copy.mString) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::string() const +// { +// return ToAnsiString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::wstring() const +// { +// return ToWideString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::string String::ToAnsiString(const std::locale& locale) const +// { +// // Prepare the output string +// std::string output; +// output.reserve(mString.length() + 1); +// +// // Convert +// Utf32::ToAnsi(mString.begin(), mString.end(), std::back_inserter(output), 0, locale); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::wstring String::ToWideString() const +// { +// // Prepare the output string +// std::wstring output; +// output.reserve(mString.length() + 1); +// +// // Convert +// Utf32::ToWide(mString.begin(), mString.end(), std::back_inserter(output), 0); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf8() const +// { +// // Prepare the output string +// std::basic_string output; +// output.reserve(mString.length()); +// +// // Convert +// Utf32::ToUtf8(mString.begin(), mString.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf16() const +// { +// // Prepare the output string +// std::basic_string output; +// output.reserve(mString.length()); +// +// // Convert +// Utf32::ToUtf16(mString.begin(), mString.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf32() const +// { +// return mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator =(const String& right) +// { +// mString = right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator +=(const String& right) +// { +// mString += right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32 String::operator [](std::size_t index) const +// { +// return mString[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32& String::operator [](std::size_t index) +// { +// return mString[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Clear() +// { +// mString.clear(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::GetSize() const +// { +// return mString.size(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool String::IsEmpty() const +// { +// return mString.empty(); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Erase(std::size_t position, std::size_t count) +// { +// mString.erase(position, count); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Insert(std::size_t position, const String& str) +// { +// mString.insert(position, str.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::Find(const String& str, std::size_t start) const +// { +// return mString.find(str.mString, start); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) +// { +// mString.replace(position, length, replaceWith.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(const String& searchFor, const String& replaceWith) +// { +// std::size_t step = replaceWith.GetSize(); +// std::size_t len = searchFor.GetSize(); +// std::size_t pos = Find(searchFor); +// +// // Replace each occurrence of search +// while (pos != InvalidPos) +// { +// Replace(pos, len, replaceWith); +// pos = Find(searchFor, pos + step); +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String String::Substring(std::size_t position, std::size_t length) const +// { +// return mString.substr(position, length); +// } +// +// +// //////////////////////////////////////////////////////////// +// const uint32* String::GetData() const +// { +// return mString.c_str(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::Begin() +// { +// return mString.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::Begin() const +// { +// return mString.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::End() +// { +// return mString.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::End() const +// { +// return mString.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right) +// { +// return left.mString == right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right) +// { +// return !(left == right); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right) +// { +// return left.mString < right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right) +// { +// return right < left; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right) +// { +// return !(right < left); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right) +// { +// return !(left < right); +// } +// +// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right) +// { +// String string = left; +// string += right; +// +// return string; +// } +// +// +// } +//} diff --git a/source/modules/asura-core/font/string.hpp b/source/modules/asura-core/font/string.hpp index 226735b..5a48eb7 100644 --- a/source/modules/asura-core/font/string.hpp +++ b/source/modules/asura-core/font/string.hpp @@ -1,594 +1,595 @@ -#ifndef __ASURA_ENGINE_STRING_H__ -#define __ASURA_ENGINE_STRING_H__ - -#include "Config.h" -#include -#include -#include - -namespace AsuraEngine -{ - namespace Text - { - - - //////////////////////////////////////////////////////////// - /// \brief Utility string class that automatically handles - /// conversions between types and encodings - /// - //////////////////////////////////////////////////////////// - class String - { - public: - - //////////////////////////////////////////////////////////// - // Types - //////////////////////////////////////////////////////////// - typedef std::basic_string::iterator Iterator; ///< Iterator type - typedef std::basic_string::const_iterator ConstIterator; ///< Read-only iterator type - - //////////////////////////////////////////////////////////// - // Static member data - //////////////////////////////////////////////////////////// - static const std::size_t InvalidPos; ///< Represents an invalid position in the string - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// This constructor creates an empty string. - /// - //////////////////////////////////////////////////////////// - String(); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a single ANSI character and a locale - /// - /// The source character is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiChar ANSI character to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(char ansiChar, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from single wide character - /// - /// \param wideChar Wide character to convert - /// - //////////////////////////////////////////////////////////// - String(wchar_t wideChar); - - //////////////////////////////////////////////////////////// - /// \brief Construct from single UTF-32 character - /// - /// \param utf32Char UTF-32 character to convert - /// - //////////////////////////////////////////////////////////// - String(uint utf32Char); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a null-terminated C-style ANSI string and a locale - /// - /// The source string is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiString ANSI string to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(const char* ansiString, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from an ANSI string and a locale - /// - /// The source string is converted to UTF-32 according - /// to the given locale. - /// - /// \param ansiString ANSI string to convert - /// \param locale Locale to use for conversion - /// - //////////////////////////////////////////////////////////// - String(const std::string& ansiString, const std::locale& locale = std::locale()); - - //////////////////////////////////////////////////////////// - /// \brief Construct from null-terminated C-style wide string - /// - /// \param wideString Wide string to convert - /// - //////////////////////////////////////////////////////////// - String(const wchar_t* wideString); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a wide string - /// - /// \param wideString Wide string to convert - /// - //////////////////////////////////////////////////////////// - String(const std::wstring& wideString); - - //////////////////////////////////////////////////////////// - /// \brief Construct from a null-terminated C-style UTF-32 string - /// - /// \param utf32String UTF-32 string to assign - /// - //////////////////////////////////////////////////////////// - String(const uint* utf32String); - - //////////////////////////////////////////////////////////// - /// \brief Construct from an UTF-32 string - /// - /// \param utf32String UTF-32 string to assign - /// - //////////////////////////////////////////////////////////// - String(const std::basic_string& utf32String); - - //////////////////////////////////////////////////////////// - /// \brief Copy constructor - /// - /// \param copy Instance to copy - /// - //////////////////////////////////////////////////////////// - String(const String& copy); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-8 encoded string - /// - /// \param begin Forward iterator to the beginning of the UTF-8 sequence - /// \param end Forward iterator to the end of the UTF-8 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf16, fromUtf32 - /// - //////////////////////////////////////////////////////////// - template - static String FromUtf8(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-16 encoded string - /// - /// \param begin Forward iterator to the beginning of the UTF-16 sequence - /// \param end Forward iterator to the end of the UTF-16 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf8, fromUtf32 - /// - //////////////////////////////////////////////////////////// - template - static String FromUtf16(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Create a new sf::String from a UTF-32 encoded string - /// - /// This function is provided for consistency, it is equivalent to - /// using the constructors that takes a const sf::uint* or - /// a std::basic_string. - /// - /// \param begin Forward iterator to the beginning of the UTF-32 sequence - /// \param end Forward iterator to the end of the UTF-32 sequence - /// - /// \return A sf::String containing the source string - /// - /// \see fromUtf8, fromUtf16 - /// - //////////////////////////////////////////////////////////// - template - static String FromUtf32(T begin, T end); - - //////////////////////////////////////////////////////////// - /// \brief Implicit conversion operator to std::string (ANSI string) - /// - /// The current global locale is used for conversion. If you - /// want to explicitly specify a locale, see toAnsiString. - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// This operator is defined for convenience, and is equivalent - /// to calling toAnsiString(). - /// - /// \return Converted ANSI string - /// - /// \see toAnsiString, operator std::wstring - /// - //////////////////////////////////////////////////////////// - operator std::string() const; - - //////////////////////////////////////////////////////////// - /// \brief Implicit conversion operator to std::wstring (wide string) - /// - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// This operator is defined for convenience, and is equivalent - /// to calling toWideString(). - /// - /// \return Converted wide string - /// - /// \see toWideString, operator std::string - /// - //////////////////////////////////////////////////////////// - operator std::wstring() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to an ANSI string - /// - /// The UTF-32 string is converted to an ANSI string in - /// the encoding defined by \a locale. - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// - /// \param locale Locale to use for conversion - /// - /// \return Converted ANSI string - /// - /// \see toWideString, operator std::string - /// - //////////////////////////////////////////////////////////// - std::string ToAnsiString(const std::locale& locale = std::locale()) const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a wide string - /// - /// Characters that do not fit in the target encoding are - /// discarded from the returned string. - /// - /// \return Converted wide string - /// - /// \see toAnsiString, operator std::wstring - /// - //////////////////////////////////////////////////////////// - std::wstring ToWideString() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-8 string - /// - /// \return Converted UTF-8 string - /// - /// \see toUtf16, toUtf32 - /// - //////////////////////////////////////////////////////////// - std::basic_string ToUtf8() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-16 string - /// - /// \return Converted UTF-16 string - /// - /// \see toUtf8, toUtf32 - /// - //////////////////////////////////////////////////////////// - std::basic_string ToUtf16() const; - - //////////////////////////////////////////////////////////// - /// \brief Convert the Unicode string to a UTF-32 string - /// - /// This function doesn't perform any conversion, since the - /// string is already stored as UTF-32 internally. - /// - /// \return Converted UTF-32 string - /// - /// \see toUtf8, toUtf16 - /// - //////////////////////////////////////////////////////////// - std::basic_string ToUtf32() const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of assignment operator - /// - /// \param right Instance to assign - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - String& operator =(const String& right); - - //////////////////////////////////////////////////////////// - /// \brief Overload of += operator to append an UTF-32 string - /// - /// \param right String to append - /// - /// \return Reference to self - /// - //////////////////////////////////////////////////////////// - String& operator +=(const String& right); - - //////////////////////////////////////////////////////////// - /// \brief Overload of [] operator to access a character by its position - /// - /// This function provides read-only access to characters. - /// Note: the behavior is undefined if \a index is out of range. - /// - /// \param index Index of the character to get - /// - /// \return Character at position \a index - /// - //////////////////////////////////////////////////////////// - uint operator [](std::size_t index) const; - - //////////////////////////////////////////////////////////// - /// \brief Overload of [] operator to access a character by its position - /// - /// This function provides read and write access to characters. - /// Note: the behavior is undefined if \a index is out of range. - /// - /// \param index Index of the character to get - /// - /// \return Reference to the character at position \a index - /// - //////////////////////////////////////////////////////////// - uint& operator [](std::size_t index); - - //////////////////////////////////////////////////////////// - /// \brief Clear the string - /// - /// This function removes all the characters from the string. - /// - /// \see isEmpty, erase - /// - //////////////////////////////////////////////////////////// - void Clear(); - - //////////////////////////////////////////////////////////// - /// \brief Get the size of the string - /// - /// \return Number of characters in the string - /// - /// \see isEmpty - /// - //////////////////////////////////////////////////////////// - std::size_t GetSize() const; - - //////////////////////////////////////////////////////////// - /// \brief Check whether the string is empty or not - /// - /// \return True if the string is empty (i.e. contains no character) - /// - /// \see clear, getSize - /// - //////////////////////////////////////////////////////////// - bool IsEmpty() const; - - //////////////////////////////////////////////////////////// - /// \brief Erase one or more characters from the string - /// - /// This function removes a sequence of \a count characters - /// starting from \a position. - /// - /// \param position Position of the first character to erase - /// \param count Number of characters to erase - /// - //////////////////////////////////////////////////////////// - void Erase(std::size_t position, std::size_t count = 1); - - //////////////////////////////////////////////////////////// - /// \brief Insert one or more characters into the string - /// - /// This function inserts the characters of \a str - /// into the string, starting from \a position. - /// - /// \param position Position of insertion - /// \param str Characters to insert - /// - //////////////////////////////////////////////////////////// - void Insert(std::size_t position, const String& str); - - //////////////////////////////////////////////////////////// - /// \brief Find a sequence of one or more characters in the string - /// - /// This function searches for the characters of \a str - /// in the string, starting from \a start. - /// - /// \param str Characters to find - /// \param start Where to begin searching - /// - /// \return Position of \a str in the string, or String::InvalidPos if not found - /// - //////////////////////////////////////////////////////////// - std::size_t Find(const String& str, std::size_t start = 0) const; - - //////////////////////////////////////////////////////////// - /// \brief Replace a substring with another string - /// - /// This function replaces the substring that starts at index \a position - /// and spans \a length characters with the string \a replaceWith. - /// - /// \param position Index of the first character to be replaced - /// \param length Number of characters to replace. You can pass InvalidPos to - /// replace all characters until the end of the string. - /// \param replaceWith String that replaces the given substring. - /// - //////////////////////////////////////////////////////////// - void Replace(std::size_t position, std::size_t length, const String& replaceWith); - - //////////////////////////////////////////////////////////// - /// \brief Replace all occurrences of a substring with a replacement string - /// - /// This function replaces all occurrences of \a searchFor in this string - /// with the string \a replaceWith. - /// - /// \param searchFor The value being searched for - /// \param replaceWith The value that replaces found \a searchFor values - /// - //////////////////////////////////////////////////////////// - void Replace(const String& searchFor, const String& replaceWith); - - //////////////////////////////////////////////////////////// - /// \brief Return a part of the string - /// - /// This function returns the substring that starts at index \a position - /// and spans \a length characters. - /// - /// \param position Index of the first character - /// \param length Number of characters to include in the substring (if - /// the string is shorter, as many characters as possible - /// are included). \ref InvalidPos can be used to include all - /// characters until the end of the string. - /// - /// \return String object containing a substring of this object - /// - //////////////////////////////////////////////////////////// - String Substring(std::size_t position, std::size_t length = InvalidPos) const; - - //////////////////////////////////////////////////////////// - /// \brief Get a pointer to the C-style array of characters - /// - /// This functions provides a read-only access to a - /// null-terminated C-style representation of the string. - /// The returned pointer is temporary and is meant only for - /// immediate use, thus it is not recommended to store it. - /// - /// \return Read-only pointer to the array of characters - /// - //////////////////////////////////////////////////////////// - const uint* GetData() const; - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the beginning of the string - /// - /// \return Read-write iterator to the beginning of the string characters - /// - /// \see end - /// - //////////////////////////////////////////////////////////// - Iterator Begin(); - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the beginning of the string - /// - /// \return Read-only iterator to the beginning of the string characters - /// - /// \see end - /// - //////////////////////////////////////////////////////////// - ConstIterator Begin() const; - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the end of the string - /// - /// The end iterator refers to 1 position past the last character; - /// thus it represents an invalid character and should never be - /// accessed. - /// - /// \return Read-write iterator to the end of the string characters - /// - /// \see begin - /// - //////////////////////////////////////////////////////////// - Iterator End(); - - //////////////////////////////////////////////////////////// - /// \brief Return an iterator to the end of the string - /// - /// The end iterator refers to 1 position past the last character; - /// thus it represents an invalid character and should never be - /// accessed. - /// - /// \return Read-only iterator to the end of the string characters - /// - /// \see begin - /// - //////////////////////////////////////////////////////////// - ConstIterator End() const; - - private: - - friend bool operator ==(const String& left, const String& right); - friend bool operator <(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - std::basic_string mString; ///< Internal string of UTF-32 characters - }; - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of == operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if both strings are equal - /// - //////////////////////////////////////////////////////////// - bool operator ==(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of != operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if both strings are different - /// - //////////////////////////////////////////////////////////// - bool operator !=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of < operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically before \a right - /// - //////////////////////////////////////////////////////////// - bool operator <(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of > operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically after \a right - /// - //////////////////////////////////////////////////////////// - bool operator >(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of <= operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically before or equivalent to \a right - /// - //////////////////////////////////////////////////////////// - bool operator <=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of >= operator to compare two UTF-32 strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return True if \a left is lexicographically after or equivalent to \a right - /// - //////////////////////////////////////////////////////////// - bool operator >=(const String& left, const String& right); - - //////////////////////////////////////////////////////////// - /// \relates String - /// \brief Overload of binary + operator to concatenate two strings - /// - /// \param left Left operand (a string) - /// \param right Right operand (a string) - /// - /// \return Concatenated string - /// - //////////////////////////////////////////////////////////// - String operator +(const String& left, const String& right); - - #include "String.inl" - - } -} - -#endif \ No newline at end of file +//#ifndef __ASURA_ENGINE_STRING_H__ +//#define __ASURA_ENGINE_STRING_H__ +// +//#include +// +//#include +//#include +//#include +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// /// \brief Utility string class that automatically handles +// /// conversions between types and encodings +// /// +// //////////////////////////////////////////////////////////// +// class String +// { +// public: +// +// //////////////////////////////////////////////////////////// +// // Types +// //////////////////////////////////////////////////////////// +// typedef std::basic_string::iterator Iterator; ///< Iterator type +// typedef std::basic_string::const_iterator ConstIterator; ///< Read-only iterator type +// +// //////////////////////////////////////////////////////////// +// // Static member data +// //////////////////////////////////////////////////////////// +// static const std::size_t InvalidPos; ///< Represents an invalid position in the string +// +// //////////////////////////////////////////////////////////// +// /// \brief Default constructor +// /// +// /// This constructor creates an empty string. +// /// +// //////////////////////////////////////////////////////////// +// String(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a single ANSI character and a locale +// /// +// /// The source character is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiChar ANSI character to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(char ansiChar, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single wide character +// /// +// /// \param wideChar Wide character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(wchar_t wideChar); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single UTF-32 character +// /// +// /// \param utf32Char UTF-32 character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(uint utf32Char); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const char* ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const std::string& ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from null-terminated C-style wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const wchar_t* wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const std::wstring& wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const uint* utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const std::basic_string& utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Copy constructor +// /// +// /// \param copy Instance to copy +// /// +// //////////////////////////////////////////////////////////// +// String(const String& copy); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-8 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-8 sequence +// /// \param end Forward iterator to the end of the UTF-8 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf16, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf8(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-16 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-16 sequence +// /// \param end Forward iterator to the end of the UTF-16 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf16(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-32 encoded string +// /// +// /// This function is provided for consistency, it is equivalent to +// /// using the constructors that takes a const sf::uint* or +// /// a std::basic_string. +// /// +// /// \param begin Forward iterator to the beginning of the UTF-32 sequence +// /// \param end Forward iterator to the end of the UTF-32 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf16 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf32(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::string (ANSI string) +// /// +// /// The current global locale is used for conversion. If you +// /// want to explicitly specify a locale, see toAnsiString. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toAnsiString(). +// /// +// /// \return Converted ANSI string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// operator std::string() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::wstring (wide string) +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toWideString(). +// /// +// /// \return Converted wide string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// operator std::wstring() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to an ANSI string +// /// +// /// The UTF-32 string is converted to an ANSI string in +// /// the encoding defined by \a locale. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \param locale Locale to use for conversion +// /// +// /// \return Converted ANSI string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// std::string ToAnsiString(const std::locale& locale = std::locale()) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a wide string +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \return Converted wide string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// std::wstring ToWideString() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-8 string +// /// +// /// \return Converted UTF-8 string +// /// +// /// \see toUtf16, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf8() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-16 string +// /// +// /// \return Converted UTF-16 string +// /// +// /// \see toUtf8, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf16() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-32 string +// /// +// /// This function doesn't perform any conversion, since the +// /// string is already stored as UTF-32 internally. +// /// +// /// \return Converted UTF-32 string +// /// +// /// \see toUtf8, toUtf16 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf32() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of assignment operator +// /// +// /// \param right Instance to assign +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator =(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of += operator to append an UTF-32 string +// /// +// /// \param right String to append +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator +=(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read-only access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint operator [](std::size_t index) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read and write access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Reference to the character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint& operator [](std::size_t index); +// +// //////////////////////////////////////////////////////////// +// /// \brief Clear the string +// /// +// /// This function removes all the characters from the string. +// /// +// /// \see isEmpty, erase +// /// +// //////////////////////////////////////////////////////////// +// void Clear(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Get the size of the string +// /// +// /// \return Number of characters in the string +// /// +// /// \see isEmpty +// /// +// //////////////////////////////////////////////////////////// +// std::size_t GetSize() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Check whether the string is empty or not +// /// +// /// \return True if the string is empty (i.e. contains no character) +// /// +// /// \see clear, getSize +// /// +// //////////////////////////////////////////////////////////// +// bool IsEmpty() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Erase one or more characters from the string +// /// +// /// This function removes a sequence of \a count characters +// /// starting from \a position. +// /// +// /// \param position Position of the first character to erase +// /// \param count Number of characters to erase +// /// +// //////////////////////////////////////////////////////////// +// void Erase(std::size_t position, std::size_t count = 1); +// +// //////////////////////////////////////////////////////////// +// /// \brief Insert one or more characters into the string +// /// +// /// This function inserts the characters of \a str +// /// into the string, starting from \a position. +// /// +// /// \param position Position of insertion +// /// \param str Characters to insert +// /// +// //////////////////////////////////////////////////////////// +// void Insert(std::size_t position, const String& str); +// +// //////////////////////////////////////////////////////////// +// /// \brief Find a sequence of one or more characters in the string +// /// +// /// This function searches for the characters of \a str +// /// in the string, starting from \a start. +// /// +// /// \param str Characters to find +// /// \param start Where to begin searching +// /// +// /// \return Position of \a str in the string, or String::InvalidPos if not found +// /// +// //////////////////////////////////////////////////////////// +// std::size_t Find(const String& str, std::size_t start = 0) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace a substring with another string +// /// +// /// This function replaces the substring that starts at index \a position +// /// and spans \a length characters with the string \a replaceWith. +// /// +// /// \param position Index of the first character to be replaced +// /// \param length Number of characters to replace. You can pass InvalidPos to +// /// replace all characters until the end of the string. +// /// \param replaceWith String that replaces the given substring. +// /// +// //////////////////////////////////////////////////////////// +// void Replace(std::size_t position, std::size_t length, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace all occurrences of a substring with a replacement string +// /// +// /// This function replaces all occurrences of \a searchFor in this string +// /// with the string \a replaceWith. +// /// +// /// \param searchFor The value being searched for +// /// \param replaceWith The value that replaces found \a searchFor values +// /// +// //////////////////////////////////////////////////////////// +// void Replace(const String& searchFor, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return a part of the string +// /// +// /// This function returns the substring that starts at index \a position +// /// and spans \a length characters. +// /// +// /// \param position Index of the first character +// /// \param length Number of characters to include in the substring (if +// /// the string is shorter, as many characters as possible +// /// are included). \ref InvalidPos can be used to include all +// /// characters until the end of the string. +// /// +// /// \return String object containing a substring of this object +// /// +// //////////////////////////////////////////////////////////// +// String Substring(std::size_t position, std::size_t length = InvalidPos) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Get a pointer to the C-style array of characters +// /// +// /// This functions provides a read-only access to a +// /// null-terminated C-style representation of the string. +// /// The returned pointer is temporary and is meant only for +// /// immediate use, thus it is not recommended to store it. +// /// +// /// \return Read-only pointer to the array of characters +// /// +// //////////////////////////////////////////////////////////// +// const uint* GetData() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-write iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// Iterator Begin(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-only iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator Begin() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-write iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// Iterator End(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-only iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator End() const; +// +// private: +// +// friend bool operator ==(const String& left, const String& right); +// friend bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// // Member data +// //////////////////////////////////////////////////////////// +// std::basic_string mString; ///< Internal string of UTF-32 characters +// }; +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of == operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are equal +// /// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of != operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are different +// /// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of < operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of > operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of <= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of >= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of binary + operator to concatenate two strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return Concatenated string +// /// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right); +// +// #include "String.inl" +// +// } +//} +// +//#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/binding/_canvas.cpp b/source/modules/asura-core/graphics/binding/_canvas.cpp index 7927995..6728ff3 100644 --- a/source/modules/asura-core/graphics/binding/_canvas.cpp +++ b/source/modules/asura-core/graphics/binding/_canvas.cpp @@ -25,6 +25,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Canvas, _SetSize) { LUAX_PREPARE(L, Canvas); + return 0; } @@ -33,12 +34,14 @@ namespace AsuraEngine { 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/_color32.cpp b/source/modules/asura-core/graphics/binding/_color32.cpp index ad7dad5..f2f716a 100644 --- a/source/modules/asura-core/graphics/binding/_color32.cpp +++ b/source/modules/asura-core/graphics/binding/_color32.cpp @@ -27,6 +27,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _ToColor) { LUAX_PREPARE(L, Color32); + return 0; } @@ -34,7 +35,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Color32, _GetRed) { LUAX_PREPARE(L, Color32); - + return 0; } // color32:GetGreen() @@ -42,6 +43,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetBlue() @@ -49,6 +51,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } // color32:GetAlpha() @@ -56,6 +59,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Color32); + return 0; } } diff --git a/source/modules/asura-core/graphics/binding/_image_data.cpp b/source/modules/asura-core/graphics/binding/_image_data.cpp deleted file mode 100644 index ac9473b..0000000 --- a/source/modules/asura-core/graphics/binding/_image_data.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include - -#include "../image_data.h" - -using namespace std; -using namespace AEThreading; -using namespace AEIO; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(ImageData) - { - LUAX_REGISTER_METHODS(state, - { "New", _New }, - { "GetPixel", _GetPixel }, - { "GetSize", _GetSize }, - { "GetWidth", _GetWidth }, - { "GetHeight", _GetHeight }, - { "GetPixelFormat", _GetPixelFormat }, - { "Decode", _Decode }, - { "DecodeAsync", _DecodeAsync }, - { "IsAvailable", _IsAvailable } - ); - } - - LUAX_POSTPROCESS(ImageData) - { - - } - - // ImageData.New() - LUAX_IMPL_METHOD(ImageData, _New) - { - LUAX_STATE(L); - - return 0; - } - - // imagedata:GetPixel() - LUAX_IMPL_METHOD(ImageData, _GetPixel) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetSize() - LUAX_IMPL_METHOD(ImageData, _GetSize) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetWidth() - LUAX_IMPL_METHOD(ImageData, _GetWidth) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetHeight() - LUAX_IMPL_METHOD(ImageData, _GetHeight) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:GetPixelFormat() - LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:Decode() - LUAX_IMPL_METHOD(ImageData, _Decode) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - // imagedata:DecodeAsync(thread, databuffer, callback) - LUAX_IMPL_METHOD(ImageData, _DecodeAsync) - { - LUAX_PREPARE(L, ImageData); - - Thread* thread = state.CheckUserdata(2); - DataBuffer* buffer = state.CheckUserdata(3); - - return 0; - } - - // imagedata:IsAvailable() - LUAX_IMPL_METHOD(ImageData, _IsAvailable) - { - LUAX_PREPARE(L, ImageData); - - return 0; - } - - } -} diff --git a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp b/source/modules/asura-core/graphics/binding/_image_decode_task.cpp deleted file mode 100644 index 76b544b..0000000 --- a/source/modules/asura-core/graphics/binding/_image_decode_task.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "../image_decode_task.h" - -using namespace std; - -namespace AsuraEngine -{ - namespace Graphics - { - - LUAX_REGISTRY(ImageDecodeTask) - { - - } - - LUAX_POSTPROCESS(ImageDecodeTask) - { - - } - - } -} diff --git a/source/modules/asura-core/graphics/binding/_shader.cpp b/source/modules/asura-core/graphics/binding/_shader.cpp index a06e54b..af6e981 100644 --- a/source/modules/asura-core/graphics/binding/_shader.cpp +++ b/source/modules/asura-core/graphics/binding/_shader.cpp @@ -36,12 +36,14 @@ namespace AsuraEngine { LUAX_STATE(L); + return 0; } // shader:Use() LUAX_IMPL_METHOD(Shader, _Use) { LUAX_PREPARE(L, Shader); + return 0; } @@ -49,6 +51,7 @@ namespace AsuraEngine LUAX_IMPL_METHOD(Shader, _Unuse) { LUAX_PREPARE(L, Shader); + return 0; } @@ -57,6 +60,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:HasUniform() @@ -64,6 +68,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:GetUniformLocation() @@ -71,6 +76,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetBuiltInUniforms() @@ -78,6 +84,7 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformFloat() @@ -85,41 +92,42 @@ namespace AsuraEngine { LUAX_PREPARE(L, Shader); + return 0; } // shader:SetUniformTexture() LUAX_IMPL_METHOD(Shader, _SetUniformTexture) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector2() LUAX_IMPL_METHOD(Shader, _SetUniformVector2) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector3() LUAX_IMPL_METHOD(Shader, _SetUniformVector3) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformVector4() LUAX_IMPL_METHOD(Shader, _SetUniformVector4) { LUAX_PREPARE(L, Shader); - + return 0; } // shader:SetUniformColor() LUAX_IMPL_METHOD(Shader, _SetUniformColor) { LUAX_PREPARE(L, Shader); - + return 0; } } diff --git a/source/modules/asura-core/graphics/canvas.cpp b/source/modules/asura-core/graphics/canvas.cpp index 8b556d9..89be45c 100644 --- a/source/modules/asura-core/graphics/canvas.cpp +++ b/source/modules/asura-core/graphics/canvas.cpp @@ -6,8 +6,7 @@ namespace AsuraEngine { Canvas::Canvas() - : Texture() - , mWidth(0) + : mWidth(0) , mHeight(0) { glGenFramebuffers(1, &mFBO); @@ -27,15 +26,5 @@ namespace AsuraEngine glBindTexture(GL_TEXTURE_2D, current_tex); } - void Canvas::Bind() - { - - } - - void Canvas::Unbind() - { - - } - } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/color.cpp b/source/modules/asura-core/graphics/color.cpp index 4d3691e..9343939 100644 --- a/source/modules/asura-core/graphics/color.cpp +++ b/source/modules/asura-core/graphics/color.cpp @@ -35,13 +35,18 @@ namespace AsuraEngine a = c.a / 255.f; } - Color Color::operator *(const Color& c) + Color::~Color() { - r *= c.r; - g *= c.g; - b *= c.b; - a *= c.a; } + //Color Color::operator *(const Color& c) + //{ + // r *= c.r; + // g *= c.g; + // b *= c.b; + // a *= c.a; + + //} + } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.cpp b/source/modules/asura-core/graphics/gl.cpp index 41d43a3..9ffe010 100644 --- a/source/modules/asura-core/graphics/gl.cpp +++ b/source/modules/asura-core/graphics/gl.cpp @@ -3,6 +3,8 @@ #include "../core_config.h" #include "gl.h" +using namespace AEMath; + namespace AsuraEngine { namespace Graphics @@ -23,5 +25,20 @@ namespace AsuraEngine { } + //------------------------------------------------------------------------------// + + void OpenGL::SetViewport(const Recti v) + { + glViewport(v.x, v.y, v.w, v.h); + state.viewport = v; + } + + Recti OpenGL::GetViewport() + { + return state.viewport; + } + + + } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/gl.h b/source/modules/asura-core/graphics/gl.h index bfc60ea..4d21a5a 100644 --- a/source/modules/asura-core/graphics/gl.h +++ b/source/modules/asura-core/graphics/gl.h @@ -1,7 +1,9 @@ #ifndef __ASURA_ENGINE_OPENGL_H__ #define __ASURA_ENGINE_OPENGL_H__ -#include "glad/glad.h" +#include + +#include namespace AsuraEngine { @@ -11,7 +13,9 @@ namespace AsuraEngine class Profiler; /// - /// 用来做一些opengl状态的追踪。 + /// 用来做一些opengl状态的追踪。在编辑器多窗口环境下,一个窗口对应一个hwnd,一个hdc,以及 + /// 数个opengl context,如果使用wglMakeCurrent(hdc, glc)指定当前线程耳朵渲染窗口hdc和 + /// opengl上下文glc,gl中记录的就是任意一个线程的任意一个窗口的任意一个opengl上下文的状态, /// class OpenGL { @@ -19,6 +23,9 @@ namespace AsuraEngine OpenGL(); ~OpenGL(); + void SetViewport(const AEMath::Recti viewport); + AEMath::Recti GetViewport(); + private: friend class Profiler; @@ -28,6 +35,14 @@ namespace AsuraEngine /// static bool instantiated; + /// + /// 记录opengl状态。 + /// + struct + { + AEMath::Recti viewport; + } state; + }; /// diff --git a/source/modules/asura-core/graphics/image.cpp b/source/modules/asura-core/graphics/image.cpp index bdd8c3d..2b274c2 100644 --- a/source/modules/asura-core/graphics/image.cpp +++ b/source/modules/asura-core/graphics/image.cpp @@ -18,7 +18,6 @@ namespace AsuraEngine { } - //创建\更新纹理像素信息 bool Image::Refresh(DecodedData* data) { ASSERT(data); @@ -27,14 +26,22 @@ namespace AsuraEngine ASSERT(imgData); glBindTexture(GL_TEXTURE_2D, mTex); - imgData->Lock(); int width = imgData->width; int height = imgData->height; - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgData->pixels); + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); mImageData = imgData; imgData->Unlock(); - glBindTexture(GL_TEXTURE_2D, 0); return true; diff --git a/source/modules/asura-core/graphics/image.h b/source/modules/asura-core/graphics/image.h index 30df8c0..7795c08 100644 --- a/source/modules/asura-core/graphics/image.h +++ b/source/modules/asura-core/graphics/image.h @@ -8,10 +8,11 @@ #include #include +#include "../image/image_data.h" + #include "texture.h" #include "color.h" #include "color32.h" -#include "image_data.h" #include "render_state.h" namespace AsuraEngine @@ -50,9 +51,8 @@ namespace AsuraEngine uint GetHeight(); Color32 GetPixel(uint x, uint y); - void Render(const RenderTarget* rt, const RenderState& state) override; - - void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override; + void Render(const RenderTarget* rt, const RenderState& state) override {}; + void Render(const RenderTarget* rt, const Math::Rectf& quad, const RenderState& state) override {}; private: diff --git a/source/modules/asura-core/graphics/image_data.cpp b/source/modules/asura-core/graphics/image_data.cpp deleted file mode 100644 index 64f83a8..0000000 --- a/source/modules/asura-core/graphics/image_data.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "image_data.h" -#include "png_decoder.h" -#include "stb_decoder.h" -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - using namespace std; - - // 解析image的decoder,用来作为解析策略。 - list ImageData::ImageDecoders = { - new PNGDecoder(), // png - new STBDecoder() // jpeg, tga, bmp - }; - - ImageData::ImageData() - : pixels(nullptr) - , size(0) - , width(0) - , height(0) - , format(COLOR_FORMAT_UNKNOWN) - { - } - - ImageData::~ImageData() - { - if (pixels) - delete[] pixels; - } - - ImageData::operator bool() - { - return size > 0; - } - - void ImageData::Decode(IO::DataBuffer& buffer) - { - for (ImageDecoder* decoder : ImageDecoders) - { - if (decoder->CanDecode(buffer)) - { - decoder->Decode(buffer, *this); - return; - } - } - } - - Color ImageData::GetPixel(uint x, uint y) - { - - } - - void ImageData::Lock() - { - mMutex.Lock(); - } - - void ImageData::Unlock() - { - mMutex.Unlock(); - } - - } -} \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_data.h b/source/modules/asura-core/graphics/image_data.h deleted file mode 100644 index b9d656c..0000000 --- a/source/modules/asura-core/graphics/image_data.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGEDATA_H__ -#define __ASURA_ENGINE_IMAGEDATA_H__ - -#include - -#include -#include -#include -#include -#include - -#include "texture.h" -#include "color.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecoder; - - class ImageData ASURA_FINAL - : public AEIO::DecodedData - , public Scripting::Portable - { - public: - - LUAX_DECL_FACTORY(ImageData); - - /// - /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 - /// - ImageData(); - ~ImageData(); - - void Decode(AEIO::DataBuffer& buffer) override; - - void Lock(); - void Unlock(); - - Color GetPixel(uint x, uint y); - - //----------------------------------------------------------------------------// - - uint width, height; // 像素尺寸 - ColorFormat format; // 格式 - byte* pixels; // 像素数据 - std::size_t size; // 数据长度 - - //----------------------------------------------------------------------------// - - private: - - //----------------------------------------------------------------------------// - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_GetPixel); - LUAX_DECL_METHOD(_GetSize); - LUAX_DECL_METHOD(_GetWidth); - LUAX_DECL_METHOD(_GetHeight); - LUAX_DECL_METHOD(_GetPixelFormat); - LUAX_DECL_METHOD(_Decode); - LUAX_DECL_METHOD(_DecodeAsync); - LUAX_DECL_METHOD(_IsAvailable); - - //----------------------------------------------------------------------------// - - /// - /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 - /// - static std::list ImageDecoders; - - /// - /// 写数据的锁。 - /// - AEThreading::Mutex mMutex; - - }; - - } -} - -namespace AEGraphics = AsuraEngine::Graphics; - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_decode_task.cpp b/source/modules/asura-core/graphics/image_decode_task.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/image_decode_task.h b/source/modules/asura-core/graphics/image_decode_task.h deleted file mode 100644 index ec5ed49..0000000 --- a/source/modules/asura-core/graphics/image_decode_task.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __ASURA_IMAGE_DECODE_TASK_H__ -#define __ASURA_IMAGE_DECODE_TASK_H__ - -#include -#include - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecodeTask - : public AEScripting::Portable - , public AEThreading::ThreadTask - { - public: - - LUAX_DECL_FACTORY(ImageDecodeTask); - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/image_decoder.h b/source/modules/asura-core/graphics/image_decoder.h deleted file mode 100644 index 869c82a..0000000 --- a/source/modules/asura-core/graphics/image_decoder.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ -#define __ASURA_ENGINE_IMAGE_DECODER_H__ - -#include - -#include "image_data.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - class ImageDecoder - { - public: - - ImageDecoder(); - virtual ~ImageDecoder(); - - /// - /// 判断内存是否能用本decoder解压 - /// - virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0; - - /// - /// 输入一个编码后的内存,输出一个解压后的Image data,如果解压失败返回nullptr - /// - virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/mesh2d.h b/source/modules/asura-core/graphics/mesh2d.h index 31d3629..226b9f6 100644 --- a/source/modules/asura-core/graphics/mesh2d.h +++ b/source/modules/asura-core/graphics/mesh2d.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(Mesh2D); + Mesh2D(); ~Mesh2D(); diff --git a/source/modules/asura-core/graphics/mesh2d_data.cpp b/source/modules/asura-core/graphics/mesh2d_data.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/mesh2d_data.h b/source/modules/asura-core/graphics/mesh2d_data.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/graphics/png_decoder.cpp b/source/modules/asura-core/graphics/png_decoder.cpp deleted file mode 100644 index 80463d5..0000000 --- a/source/modules/asura-core/graphics/png_decoder.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "png_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) - { - return false; - } - - void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) - { - - } - - } -} diff --git a/source/modules/asura-core/graphics/png_decoder.h b/source/modules/asura-core/graphics/png_decoder.h deleted file mode 100644 index 6377940..0000000 --- a/source/modules/asura-core/graphics/png_decoder.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __ASURA_ENGINE_PNGDECODER_H__ -#define __ASURA_ENGINE_PNGDECODER_H__ - -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// 使用lodepng解压png文件 - /// - class PNGDecoder ASURA_FINAL: public ImageDecoder - { - public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/render_target.h b/source/modules/asura-core/graphics/render_target.h index b1a695a..0749cab 100644 --- a/source/modules/asura-core/graphics/render_target.h +++ b/source/modules/asura-core/graphics/render_target.h @@ -13,8 +13,6 @@ namespace AsuraEngine namespace Graphics { - class Drawable; - /// /// 可被作为渲染目标的类,派生类有 /// Canvas(RenderTexture) diff --git a/source/modules/asura-core/graphics/shader.cpp b/source/modules/asura-core/graphics/shader.cpp index c0c6f75..f33fd1a 100644 --- a/source/modules/asura-core/graphics/shader.cpp +++ b/source/modules/asura-core/graphics/shader.cpp @@ -15,14 +15,14 @@ namespace AsuraEngine } - bool Shader::Load(const std::string& vertexShader, const std::string& fragmentShader) + bool Shader::Refresh(AEIO::DecodedData* db) { - + return false; } uint Shader::GetUniformLocation(const std::string& uniform) { - + return 0; } GLuint Shader::GetGLProgramHandle() @@ -45,11 +45,6 @@ namespace AsuraEngine } - void Shader::SetUniformFloat(uint loc, float value) - { - - } - void Shader::SetUniformTexture(uint loc, const Texture& texture) { diff --git a/source/modules/asura-core/graphics/sprite_batch.h b/source/modules/asura-core/graphics/sprite_batch.h index 3143f73..eb1c89c 100644 --- a/source/modules/asura-core/graphics/sprite_batch.h +++ b/source/modules/asura-core/graphics/sprite_batch.h @@ -16,6 +16,8 @@ namespace AsuraEngine { public: + LUAX_DECL_FACTORY(SpriteBatch); + SpriteBatch(); ~SpriteBatch(); diff --git a/source/modules/asura-core/graphics/stb_decoder.cpp b/source/modules/asura-core/graphics/stb_decoder.cpp deleted file mode 100644 index 9a14141..0000000 --- a/source/modules/asura-core/graphics/stb_decoder.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include - -#include "stb_decoder.h" -#include "stb/stb_image.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - bool STBDecoder::CanDecode(IO::DataBuffer& buffer) - { - int w = 0; - int h = 0; - int comp = 0; - - int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); - - return status == 1 && w > 0 && h > 0; - } - - void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) - { - const stbi_uc *buffer = (const stbi_uc *)db.GetData(); - // databuffer数据长 - int bufferlen = db.GetSize(); - - int width, height; - int comp = 0; - byte* data = nullptr; - ColorFormat format = COLOR_FORMAT_UNKNOWN; - std::size_t size = 0; - - if (stbi_is_hdr_from_memory(buffer, bufferlen)) - { - // 4个channel都是float - data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA32F; - size = width * height * 4 * sizeof(float); - } - else - { - data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); - format = COLOR_FORMAT_RGBA8; - size = width * height * 4; - } - if (data) - { - imageData.Lock(); - - if (imageData.pixels) - delete[] imageData.pixels; - imageData.pixels = (byte*)data; - imageData.format = format; - imageData.width = width; - imageData.height = height; - - imageData.Unlock(); - } - else - { - const char *err = stbi_failure_reason(); - if (err == nullptr) - err = "unknown error"; - throw Exception("Could not decode image with stb_image (%s).", err); - } - } - - } -} \ No newline at end of file diff --git a/source/modules/asura-core/graphics/stb_decoder.h b/source/modules/asura-core/graphics/stb_decoder.h deleted file mode 100644 index 76e70c3..0000000 --- a/source/modules/asura-core/graphics/stb_decoder.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __ASURA_ENGINE_STBDECODER_H__ -#define __ASURA_ENGINE_STBDECODER_H__ - -#include "image_decoder.h" - -namespace AsuraEngine -{ - namespace Graphics - { - - /// - /// 使用stb_image解压JPEG、TGA、BMP文件 - /// - class STBDecoder ASURA_FINAL - : public ImageDecoder - { - public: - - bool CanDecode(AEIO::DataBuffer& buffer) override; - - void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.cpp b/source/modules/asura-core/graphics/texture.cpp index c260ce9..4db6ad3 100644 --- a/source/modules/asura-core/graphics/texture.cpp +++ b/source/modules/asura-core/graphics/texture.cpp @@ -22,5 +22,24 @@ namespace AsuraEngine return mTex; } + TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) + { + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + } + return t; + } + } } \ No newline at end of file diff --git a/source/modules/asura-core/graphics/texture.h b/source/modules/asura-core/graphics/texture.h index 02d3407..f19f3a7 100644 --- a/source/modules/asura-core/graphics/texture.h +++ b/source/modules/asura-core/graphics/texture.h @@ -41,6 +41,17 @@ namespace AsuraEngine COLOR_FORMAT_RGBA32F, ///< RGBA都是32bits float }; + /// + /// 纹理格式,GPU内部和CPU外部格式 + /// + struct TextureFormat + { + GLenum internalformat; // GPU内部格式 + + GLenum externalformat; // CPU外部格式 + GLenum type; // 外部格式每个channel数值类型 + }; + /// /// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里 /// 面的上层会以笛卡尔坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了 @@ -94,6 +105,13 @@ namespace AsuraEngine //----------------------------------------------------------------------------// + /// + /// 转换color format为texture format。 + /// + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + //----------------------------------------------------------------------------// + GLuint mTex; FilterMode mMinFilter; diff --git a/source/modules/asura-core/image/binding/_image_data.cpp b/source/modules/asura-core/image/binding/_image_data.cpp new file mode 100644 index 0000000..ac9473b --- /dev/null +++ b/source/modules/asura-core/image/binding/_image_data.cpp @@ -0,0 +1,111 @@ +#include +#include + +#include "../image_data.h" + +using namespace std; +using namespace AEThreading; +using namespace AEIO; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(ImageData) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetPixel", _GetPixel }, + { "GetSize", _GetSize }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetPixelFormat", _GetPixelFormat }, + { "Decode", _Decode }, + { "DecodeAsync", _DecodeAsync }, + { "IsAvailable", _IsAvailable } + ); + } + + LUAX_POSTPROCESS(ImageData) + { + + } + + // ImageData.New() + LUAX_IMPL_METHOD(ImageData, _New) + { + LUAX_STATE(L); + + return 0; + } + + // imagedata:GetPixel() + LUAX_IMPL_METHOD(ImageData, _GetPixel) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetSize() + LUAX_IMPL_METHOD(ImageData, _GetSize) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetWidth() + LUAX_IMPL_METHOD(ImageData, _GetWidth) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetHeight() + LUAX_IMPL_METHOD(ImageData, _GetHeight) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetPixelFormat() + LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:Decode() + LUAX_IMPL_METHOD(ImageData, _Decode) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:DecodeAsync(thread, databuffer, callback) + LUAX_IMPL_METHOD(ImageData, _DecodeAsync) + { + LUAX_PREPARE(L, ImageData); + + Thread* thread = state.CheckUserdata(2); + DataBuffer* buffer = state.CheckUserdata(3); + + return 0; + } + + // imagedata:IsAvailable() + LUAX_IMPL_METHOD(ImageData, _IsAvailable) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/image/binding/_image_decode_task.cpp b/source/modules/asura-core/image/binding/_image_decode_task.cpp new file mode 100644 index 0000000..76b544b --- /dev/null +++ b/source/modules/asura-core/image/binding/_image_decode_task.cpp @@ -0,0 +1,21 @@ +#include "../image_decode_task.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Graphics + { + + LUAX_REGISTRY(ImageDecodeTask) + { + + } + + LUAX_POSTPROCESS(ImageDecodeTask) + { + + } + + } +} diff --git a/source/modules/asura-core/image/image_data.cpp b/source/modules/asura-core/image/image_data.cpp new file mode 100644 index 0000000..1a6d3a2 --- /dev/null +++ b/source/modules/asura-core/image/image_data.cpp @@ -0,0 +1,62 @@ +#include "image_data.h" +#include "png_decoder.h" +#include "stb_decoder.h" +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + using namespace std; + + // 解析image的decoder,用来作为解析策略。 + list ImageData::ImageDecoders = { + new PNGDecoder(), // png + new STBDecoder() // jpeg, tga, bmp + }; + + ImageData::ImageData() + : pixels(nullptr) + , size(0) + , width(0) + , height(0) + , format(COLOR_FORMAT_UNKNOWN) + { + } + + ImageData::~ImageData() + { + if (pixels) + delete[] pixels; + } + + void ImageData::Decode(IO::DataBuffer& buffer) + { + for (ImageDecoder* decoder : ImageDecoders) + { + if (decoder->CanDecode(buffer)) + { + decoder->Decode(buffer, *this); + return; + } + } + } + + Color ImageData::GetPixel(uint x, uint y) + { + return Color(); + } + + void ImageData::Lock() + { + mMutex.Lock(); + } + + void ImageData::Unlock() + { + mMutex.Unlock(); + } + + } +} \ No newline at end of file diff --git a/source/modules/asura-core/image/image_data.h b/source/modules/asura-core/image/image_data.h new file mode 100644 index 0000000..d9427d3 --- /dev/null +++ b/source/modules/asura-core/image/image_data.h @@ -0,0 +1,85 @@ +#ifndef __ASURA_ENGINE_IMAGEDATA_H__ +#define __ASURA_ENGINE_IMAGEDATA_H__ + +#include + +#include +#include +#include +#include +#include + +#include "../graphics/texture.h" +#include "../graphics/color.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecoder; + + class ImageData ASURA_FINAL + : public AEIO::DecodedData + , public Scripting::Portable + { + public: + + LUAX_DECL_FACTORY(ImageData); + + /// + /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 + /// + ImageData(); + ~ImageData(); + + void Decode(AEIO::DataBuffer& buffer) override; + + void Lock(); + void Unlock(); + + Color GetPixel(uint x, uint y); + + //----------------------------------------------------------------------------// + + uint width, height; // 像素尺寸 + ColorFormat format; // 格式 + byte* pixels; // 像素数据 + std::size_t size; // 数据长度 + + //----------------------------------------------------------------------------// + + private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetPixelFormat); + LUAX_DECL_METHOD(_Decode); + LUAX_DECL_METHOD(_DecodeAsync); + LUAX_DECL_METHOD(_IsAvailable); + + //----------------------------------------------------------------------------// + + /// + /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 + /// + static std::list ImageDecoders; + + /// + /// 写数据的锁。 + /// + AEThreading::Mutex mMutex; + + }; + + } +} + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/image_decode_task.cpp b/source/modules/asura-core/image/image_decode_task.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/image/image_decode_task.h b/source/modules/asura-core/image/image_decode_task.h new file mode 100644 index 0000000..15b0837 --- /dev/null +++ b/source/modules/asura-core/image/image_decode_task.h @@ -0,0 +1,25 @@ +#ifndef __ASURA_IMAGE_DECODE_TASK_H__ +#define __ASURA_IMAGE_DECODE_TASK_H__ + +#include +#include + +namespace AsuraEngine +{ + namespace Graphics + { + + class ImageDecodeTask + : public AEScripting::Portable + , public AEThreading::Task + { + public: + + LUAX_DECL_FACTORY(ImageDecodeTask); + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/image_decoder.h b/source/modules/asura-core/image/image_decoder.h new file mode 100644 index 0000000..8b82d2b --- /dev/null +++ b/source/modules/asura-core/image/image_decoder.h @@ -0,0 +1,35 @@ +#ifndef __ASURA_ENGINE_IMAGE_DECODER_H__ +#define __ASURA_ENGINE_IMAGE_DECODER_H__ + +#include + +#include "image_data.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + ASURA_ABSTRACT class ImageDecoder + { + public: + + ImageDecoder() {}; + virtual ~ImageDecoder() {}; + + /// + /// 判断内存是否能用本decoder解压 + /// + virtual bool CanDecode(AEIO::DataBuffer& buffer) = 0; + + /// + /// 输入一个编码后的内存,输出一个解压后的Image data,如果解压失败返回nullptr + /// + virtual void Decode(AEIO::DataBuffer& buffer, ImageData& data) = 0; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/png_decoder.cpp b/source/modules/asura-core/image/png_decoder.cpp new file mode 100644 index 0000000..80463d5 --- /dev/null +++ b/source/modules/asura-core/image/png_decoder.cpp @@ -0,0 +1,19 @@ +#include "png_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) + { + return false; + } + + void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) + { + + } + + } +} diff --git a/source/modules/asura-core/image/png_decoder.h b/source/modules/asura-core/image/png_decoder.h new file mode 100644 index 0000000..6377940 --- /dev/null +++ b/source/modules/asura-core/image/png_decoder.h @@ -0,0 +1,27 @@ +#ifndef __ASURA_ENGINE_PNGDECODER_H__ +#define __ASURA_ENGINE_PNGDECODER_H__ + +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// 使用lodepng解压png文件 + /// + class PNGDecoder ASURA_FINAL: public ImageDecoder + { + public: + + bool CanDecode(AEIO::DataBuffer& buffer) override; + + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.cpp b/source/modules/asura-core/image/stb_decoder.cpp new file mode 100644 index 0000000..b19f28b --- /dev/null +++ b/source/modules/asura-core/image/stb_decoder.cpp @@ -0,0 +1,73 @@ +#include + +#include "stb_decoder.h" + +#define STB_IMAGE_IMPLEMENTATION +#include + +namespace AsuraEngine +{ + namespace Graphics + { + + bool STBDecoder::CanDecode(IO::DataBuffer& buffer) + { + int w = 0; + int h = 0; + int comp = 0; + + int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); + + return status == 1 && w > 0 && h > 0; + } + + void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) + { + const stbi_uc *buffer = (const stbi_uc *)db.GetData(); + // databuffer数据长 + int bufferlen = db.GetSize(); + + int width, height; + int comp = 0; + byte* data = nullptr; + ColorFormat format = COLOR_FORMAT_UNKNOWN; + std::size_t size = 0; + + if (stbi_is_hdr_from_memory(buffer, bufferlen)) + { + // 4个channel都是float + data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA32F; + size = width * height * 4 * sizeof(float); + } + else + { + data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA8; + size = width * height * 4; + } + if (data) + { + imageData.Lock(); + + if (imageData.pixels) + free(imageData.pixels); + imageData.pixels = (byte*)data; + imageData.format = format; + imageData.width = width; + imageData.height = height; + imageData.size = size; + + imageData.Unlock(); + } + else + { + const char *err = stbi_failure_reason(); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not decode image with stb_image (%s).", err); + } + } + + } +} \ No newline at end of file diff --git a/source/modules/asura-core/image/stb_decoder.h b/source/modules/asura-core/image/stb_decoder.h new file mode 100644 index 0000000..76e70c3 --- /dev/null +++ b/source/modules/asura-core/image/stb_decoder.h @@ -0,0 +1,28 @@ +#ifndef __ASURA_ENGINE_STBDECODER_H__ +#define __ASURA_ENGINE_STBDECODER_H__ + +#include "image_decoder.h" + +namespace AsuraEngine +{ + namespace Graphics + { + + /// + /// 使用stb_image解压JPEG、TGA、BMP文件 + /// + class STBDecoder ASURA_FINAL + : public ImageDecoder + { + public: + + bool CanDecode(AEIO::DataBuffer& buffer) override; + + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/mesh/mesh2d_data.cpp b/source/modules/asura-core/mesh/mesh2d_data.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/mesh/mesh2d_data.h b/source/modules/asura-core/mesh/mesh2d_data.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/threading/thread_ex.cpp b/source/modules/asura-core/threading/thread_ex.cpp index 334e58b..4883f90 100644 --- a/source/modules/asura-core/threading/thread_ex.cpp +++ b/source/modules/asura-core/threading/thread_ex.cpp @@ -8,6 +8,7 @@ namespace AsuraEngine int ThreadEx::Process() { + return 0; } void ThreadEx::RegisterModules() diff --git a/source/modules/asura-core/window/binding/_window.cpp b/source/modules/asura-core/window/binding/_window.cpp new file mode 100644 index 0000000..e477408 --- /dev/null +++ b/source/modules/asura-core/window/binding/_window.cpp @@ -0,0 +1,180 @@ +#include "../../image/image_data.h" + +#include "../window.h" + +using namespace std; +using namespace AEGraphics; + +namespace AsuraEngine +{ + namespace Window + { + + LUAX_REGISTRY(Window) + { + LUAX_REGISTER_METHODS(state, + { "Init", _Init }, + { "Exit", _Exit }, + { "Show", _Show }, + { "Hide", _Hide }, + { "SetSize", _SetSize }, + { "SetPosition", _SetPosition }, + { "SetTitle", _SetTitle }, + { "SetIcon", _SetIcon }, + { "SwapRenderBuffer", _SwapRenderBuffer }, + { "Clear", _Clear }, + { "Draw", _Draw } + ); + } + + LUAX_POSTPROCESS(Window) + { + LUAX_REGISTER_ENUM(state, "EWindowFlag", + { "FULLSCREEN", WINDOW_FULLSCREEN }, + { "OPENGL", WINDOW_OPENGL }, + { "SHOWN", WINDOW_SHOWN }, + { "HIDDEN", WINDOW_HIDDEN }, + { "BORDERLESS", WINDOW_BORDERLESS }, + { "RESIZABLE", WINDOW_RESIZABLE }, + { "MINIMIZED", WINDOW_MINIMIZED }, + { "MAXIMIZED", WINDOW_MAXIMIZED }, + { "INPUT_GRABBED", WINDOW_INPUT_GRABBED }, + { "INPUT_FOCUS", WINDOW_INPUT_FOCUS }, + { "MOUSE_FOCUS", WINDOW_MOUSE_FOCUS }, + { "ALLOW_HIGHDPI", WINDOW_ALLOW_HIGHDPI }, + { "MOUSE_CAPTURE", WINDOW_MOUSE_CAPTURE }, + { "ALWAYS_ON_TOP", WINDOW_ALWAYS_ON_TOP } + ); + + } + + // Window.Init(config_table) + LUAX_IMPL_METHOD(Window, _Init) + { + LUAX_PREPARE(L, Window); + + WindowConfig config; + + if (!state.IsType(1, LUA_TTABLE)) + return state.ErrorType(1, "window config table"); + + config.width = state.GetField(1, "width", 0); + config.height = state.GetField(1, "height", 0); + config.x = state.GetField(1, "x", 0); + config.y = state.GetField(1, "y", 0); + config.flag = state.GetField(1, "flag", WINDOW_OPENGL); + config.title = state.GetField(1, "title", ""); + config.vsync = state.GetField(1, "vsync", true); + config.show = state.GetField(1, "show", true); + + // try set window icon + state.GetField(1, "icon"); + if (state.IsType(1, LUA_TUSERDATA)) + { + ImageData* data = state.CheckUserdata(-1); + if (data) + { + data->Lock(); + config.icon = data; + Window::Get()->Init(config); + data->Unlock(); + return 0; + } + } + else + state.Pop(); + + Window::Get()->Init(config); + + return 0; + } + + // Window.Exit() + LUAX_IMPL_METHOD(Window, _Exit) + { + LUAX_PREPARE(L, Window); + Window::Get()->Exit(); + return 0; + } + + // Window.Show() + LUAX_IMPL_METHOD(Window, _Show) + { + LUAX_PREPARE(L, Window); + Window::Get()->Show(); + return 0; + } + + // Window.Hide() + LUAX_IMPL_METHOD(Window, _Hide) + { + LUAX_PREPARE(L, Window); + Window::Get()->Hide(); + return 0; + } + + // Window.SetSize(w, h) + LUAX_IMPL_METHOD(Window, _SetSize) + { + LUAX_PREPARE(L, Window); + uint w = state.CheckValue(1); + uint h = state.CheckValue(2); + Window::Get()->SetSize(w, h); + return 0; + } + + // Window.SetPosition(x, y) + LUAX_IMPL_METHOD(Window, _SetPosition) + { + LUAX_PREPARE(L, Window); + int x = state.CheckValue(1); + int y = state.CheckValue(2); + Window::Get()->SetPosition(x, y); + return 0; + } + + // Window.SetTitle(title) + LUAX_IMPL_METHOD(Window, _SetTitle) + { + LUAX_PREPARE(L, Window); + std::string title = state.CheckValue(1); + Window::Get()->SetTitle(title); + return 0; + } + + // Window.SetIcon(imageData) + LUAX_IMPL_METHOD(Window, _SetIcon) + { + LUAX_PREPARE(L, Window); + ImageData* imgData = state.CheckUserdata(1); + imgData->Lock(); + Window::Get()->SetIcon(imgData); + imgData->Unlock(); + return 0; + } + + // Window.SwapRenderBuffer() + LUAX_IMPL_METHOD(Window, _SwapRenderBuffer) + { + LUAX_PREPARE(L, Window); + Window::Get()->SwapRenderBuffer(); + return 0; + } + + // Window.Clear() + LUAX_IMPL_METHOD(Window, _Clear) + { + LUAX_PREPARE(L, Window); + Window::Get()->Clear(); + return 0; + } + + // Window.Draw() + LUAX_IMPL_METHOD(Window, _Draw) + { + LUAX_PREPARE(L, Window); + return 0; + } + + } +} \ No newline at end of file diff --git a/source/modules/asura-core/window/window.cpp b/source/modules/asura-core/window/window.cpp new file mode 100644 index 0000000..99433d5 --- /dev/null +++ b/source/modules/asura-core/window/window.cpp @@ -0,0 +1,106 @@ +#include + +#include "window.h" + +#include "window_impl_sdl.h" +#include "window_impl_glew.h" +#include "window_impl_glut.h" + +namespace AsuraEngine +{ + namespace Window + { + + Window::Window() + : mImpl(nullptr) + { + } + + Window::~Window() + { + if (mImpl) + delete mImpl; + } + +#define try_init_window(impl) \ + if (!mImpl) \ + { \ + mImpl = new impl(); \ + if (!mImpl->Init(config)) \ + { \ + delete mImpl; \ + mImpl = nullptr; \ + } \ + } + + bool Window::Init(const WindowConfig& config) + { + ASSERT(!mImpl); +#if ASURA_WINDOW_SDL + try_init_window(WindowImplSDL); +#endif + return mImpl != nullptr; + } + + void Window::Exit() + { + if (mImpl) + delete mImpl; + } + + void Window::SetPosition(int x, int y) + { + ASSERT(mImpl); + mImpl->SetPosition(x, y); + } + + void Window::SetTitle(const std::string& title) + { + ASSERT(mImpl); + mImpl->SetTitils(title); + } + + void Window::Show() + { + ASSERT(mImpl); + mImpl->Show(); + } + + void Window::Hide() + { + ASSERT(mImpl); + mImpl->Hide(); + } + + void Window::SwapRenderBuffer() + { + ASSERT(mImpl); + mImpl->SwapRenderBuffer(); + } + + void Window::Clear(const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) + { + ASSERT(mImpl); + glClearColor(col.r, col.g, col.b, col.a); + } + + void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) + { + ASSERT(mImpl); + + } + + void Window::Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) + { + ASSERT(mImpl); + + } + + void Window::Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) + { + ASSERT(mImpl); + + } + + } +} diff --git a/source/modules/asura-core/window/window.h b/source/modules/asura-core/window/window.h new file mode 100644 index 0000000..8ce0e64 --- /dev/null +++ b/source/modules/asura-core/window/window.h @@ -0,0 +1,151 @@ +#ifndef __ASURA_ENGINE_WINDOW_H__ +#define __ASURA_ENGINE_WINDOW_H__ + +#include +#include +#include + +#include "../graphics/image.h" +#include "../graphics/render_state.h" +#include "../graphics/render_target.h" + +namespace AsuraEngine +{ + namespace Window + { + + class WindowImpl; + + /// + /// 从SDL拷贝过来的,留下一些有用的。 + /// + enum WindowFlag + { + WINDOW_FULLSCREEN = 1 << 1, ///< fullscreen window + WINDOW_OPENGL = 1 << 2, ///< window usable with OpenGL context + WINDOW_SHOWN = 1 << 3, ///< window is visible + WINDOW_HIDDEN = 1 << 4, ///< window is not visible + WINDOW_BORDERLESS = 1 << 5, ///< no window decoration + WINDOW_RESIZABLE = 1 << 6, ///< window can be resized + WINDOW_MINIMIZED = 1 << 7, ///< window is minimized + WINDOW_MAXIMIZED = 1 << 8, ///< window is maximized + WINDOW_INPUT_GRABBED = 1 << 9, ///< window has grabbed input focus + WINDOW_INPUT_FOCUS = 1 << 10, ///< window has input focus + WINDOW_MOUSE_FOCUS = 1 << 11, ///< window has mouse focus + WINDOW_ALLOW_HIGHDPI = 1 << 12, ///< window should be created in high-DPI mode if supported. + ///< On macOS NSHighResolutionCapable must be set true in the + ///< application's Info.plist for this to have any effect. + WINDOW_MOUSE_CAPTURE = 1 << 13, ///< window has mouse captured (unrelated to INPUT_GRABBED) + WINDOW_ALWAYS_ON_TOP = 1 << 14, ///< window should always be above others + }; + + /// + /// Window初始化配置项 + /// + struct WindowConfig + { + uint width, height; ///< 尺寸 + int x, y; ///< 窗口初始坐标 + std::string title; ///< 标题名 + bool vsync; ///< 垂直同步 + AEGraphics::ImageData* icon; ///< 图标 + bool show; ///< 是否显示 + int flag; ///< 窗口标记 + }; + + /// + /// 游戏的单窗口,runner只需要一个窗口。不同的客户端实现此接口并手动注册到lua。编辑器不 + /// 会导入此类,将会嫁接到编辑器的虚拟窗口上。 + /// + class Window ASURA_FINAL + : public AEGraphics::RenderTarget + , public AEScripting::Portable + , public Singleton + { + public: + + /// + /// 游戏运行时的窗口是唯一的,编辑器不会用到此类。 + /// + LUAX_DECL_SINGLETON(Window); + + Window(); + ~Window(); + + /// + /// 在这里真正创建窗口。 + /// + bool Init(const WindowConfig& config); + void Exit(); + + void SetSize(uint width, uint height); + void SetPosition(int x, int y); + void SetTitle(const std::string& title); + void SetIcon(AEGraphics::ImageData* imgData); + + void Show(); + void Hide(); + + /// + /// 如果是开启双缓冲的窗口,需要交换缓冲区来展示到前台 + /// + void SwapRenderBuffer(); + + void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; + void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; + + void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; + void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; + + private: + + //----------------------------------------------------------------------------// + + LUAX_DECL_ENUM(WindowFlag, 0); + + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_Exit); + LUAX_DECL_METHOD(_Show); + LUAX_DECL_METHOD(_Hide); + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_SetPosition); + LUAX_DECL_METHOD(_SetTitle); + LUAX_DECL_METHOD(_SetIcon); + LUAX_DECL_METHOD(_SwapRenderBuffer); + LUAX_DECL_METHOD(_Clear); + LUAX_DECL_METHOD(_Draw); + + //----------------------------------------------------------------------------// + + WindowImpl* mImpl; + + }; + + using RenderWindow = Window; + + ASURA_ABSTRACT class WindowImpl + { + public: + + WindowImpl() {}; + virtual ~WindowImpl() {}; + + virtual bool Init(const WindowConfig& config); + + virtual void SetSize(uint width, uint height) = 0; + virtual void SetPosition(int x, int y) = 0; + virtual void SetTitils(const std::string& title) = 0; + + virtual void Show() = 0; + virtual void Hide() = 0; + + virtual void SwapRenderBuffer() = 0; + + }; + + } +} + +namespace AEWindow = AsuraEngine::Window; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/window/window_impl_glew.cpp b/source/modules/asura-core/window/window_impl_glew.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/window/window_impl_glew.h b/source/modules/asura-core/window/window_impl_glew.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/window/window_impl_glut.cpp b/source/modules/asura-core/window/window_impl_glut.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/window/window_impl_glut.h b/source/modules/asura-core/window/window_impl_glut.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/window/window_impl_sdl.cpp b/source/modules/asura-core/window/window_impl_sdl.cpp new file mode 100644 index 0000000..9554e37 --- /dev/null +++ b/source/modules/asura-core/window/window_impl_sdl.cpp @@ -0,0 +1,154 @@ +#include "../core_config.h" + +#if ASURA_WINDOW_SDL + +#include + +#include + +#include "window_impl_sdl.h" + +using namespace AEGraphics; + +namespace AsuraEngine +{ + namespace Window + { + +#define asura_flag_to_sdl_flag(flag, _flag, _sdl_flag) \ + if ((flag & _flag) != 0) \ + flag |= _sdl_flag + + WindowImplSDL::WindowImplSDL() + : mWnd(nullptr) + , mGLContext(0) + { + } + + WindowImplSDL::~WindowImplSDL() + { + SDL_GL_DeleteContext(mGLContext); + SDL_DestroyWindow(mWnd); + SDL_FlushEvent(SDL_WINDOWEVENT); + } + + bool WindowImplSDL::Init(const WindowConfig& config) + { + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return false; + + int flag = 0; + asura_flag_to_sdl_flag(flag, WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN); + asura_flag_to_sdl_flag(flag, WINDOW_OPENGL, SDL_WINDOW_OPENGL); + asura_flag_to_sdl_flag(flag, WINDOW_SHOWN, SDL_WINDOW_SHOWN); + asura_flag_to_sdl_flag(flag, WINDOW_HIDDEN, SDL_WINDOW_HIDDEN); + asura_flag_to_sdl_flag(flag, WINDOW_BORDERLESS, SDL_WINDOW_BORDERLESS); + asura_flag_to_sdl_flag(flag, WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE); + asura_flag_to_sdl_flag(flag, WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED); + asura_flag_to_sdl_flag(flag, WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED); + asura_flag_to_sdl_flag(flag, WINDOW_INPUT_GRABBED, SDL_WINDOW_INPUT_GRABBED); + asura_flag_to_sdl_flag(flag, WINDOW_INPUT_FOCUS, SDL_WINDOW_INPUT_FOCUS); + asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_FOCUS, SDL_WINDOW_MOUSE_FOCUS); + asura_flag_to_sdl_flag(flag, WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_ALLOW_HIGHDPI); + asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_CAPTURE, SDL_WINDOW_MOUSE_CAPTURE); + asura_flag_to_sdl_flag(flag, WINDOW_ALWAYS_ON_TOP, SDL_WINDOW_ALWAYS_ON_TOP); + + // Set GL window / framebuffer attributes. + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); + + mWnd = SDL_CreateWindow(config.title.c_str(), config.x, config.y, config.width, config.height, flag); + + if (!mWnd) + return false; + + // 设置图标 + try + { + if (config.icon) + { + ImageData* img = config.icon; + if (img->format == COLOR_FORMAT_RGBA8) + { + SDL_Surface *surface; + + img->Lock(); + + int w = img->width, h = img->height; + surface = SDL_CreateRGBSurfaceFrom( + img->pixels, + w, h, + 32, + w * 4, + Color32::RMASK, + Color32::GMASK, + Color32::BMASK, + Color32::AMASK + ); + + img->Unlock(); + + SDL_SetWindowIcon(mWnd, surface); + SDL_FreeSurface(surface); + } + } + } + catch (...) + { + } + + mGLContext = SDL_GL_CreateContext(mWnd); + + if (!mGLContext) + { + SDL_DestroyWindow(mWnd); + return false; + } + + SDL_GL_MakeCurrent(mWnd, mGLContext); + SDL_GL_SetSwapInterval(config.vsync ? 1 : 0); + + return true; + } + + void WindowImplSDL::SetSize(uint width, uint height) + { + SDL_SetWindowSize(mWnd, width, height); + } + + void WindowImplSDL::SetPosition(int x, int y) + { + SDL_SetWindowPosition(mWnd, x, y); + } + + void WindowImplSDL::SetTitils(const std::string& title) + { + SDL_SetWindowTitle(mWnd, title.c_str()); + } + + void WindowImplSDL::Show() + { + SDL_ShowWindow(mWnd); + } + + void WindowImplSDL::Hide() + { + SDL_HideWindow(mWnd); + } + + void WindowImplSDL::SwapRenderBuffer() + { + SDL_GL_SwapWindow(mWnd); + } + + } +} + +#endif // ASURA_WINDOW_SDL \ No newline at end of file diff --git a/source/modules/asura-core/window/window_impl_sdl.h b/source/modules/asura-core/window/window_impl_sdl.h new file mode 100644 index 0000000..de4cafb --- /dev/null +++ b/source/modules/asura-core/window/window_impl_sdl.h @@ -0,0 +1,47 @@ +#ifndef __ASURA_WINDOW_SDL_H_ +#define __ASURA_WINDOW_SDL_H_ + +#include "../core_config.h" + +#if ASURA_WINDOW_SDL + +#include + +#include "window.h" + +namespace AsuraEngine +{ + namespace Window + { + + class WindowImplSDL ASURA_FINAL : public WindowImpl + { + public: + + WindowImplSDL(); + ~WindowImplSDL(); + + bool Init(const WindowConfig& config); + + void SetSize(uint width, uint height) override; + void SetPosition(int x, int y) override; + void SetTitils(const std::string& title) override; + + void Show() override; + void Hide() override; + + void SwapRenderBuffer() override; + + private: + + SDL_Window* mWnd; + SDL_GLContext mGLContext; + + }; + + } +} + +#endif // ASURA_WINDOW_SDL + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/wnd/binding/_window.cpp b/source/modules/asura-core/wnd/binding/_window.cpp deleted file mode 100644 index eb92de8..0000000 --- a/source/modules/asura-core/wnd/binding/_window.cpp +++ /dev/null @@ -1,180 +0,0 @@ -#include "../../graphics/image_data.h" - -#include "../window.h" - -using namespace std; -using namespace AEGraphics; - -namespace AsuraEngine -{ - namespace Wnd - { - - LUAX_REGISTRY(Window) - { - LUAX_REGISTER_METHODS(state, - { "Init", _Init }, - { "Exit", _Exit }, - { "Show", _Show }, - { "Hide", _Hide }, - { "SetSize", _SetSize }, - { "SetPosition", _SetPosition }, - { "SetTitle", _SetTitle }, - { "SetIcon", _SetIcon }, - { "SwapRenderBuffer", _SwapRenderBuffer }, - { "Clear", _Clear }, - { "Draw", _Draw } - ); - } - - LUAX_POSTPROCESS(Window) - { - LUAX_REGISTER_ENUM(state, "EWindowFlag", - { "FULLSCREEN", WINDOW_FULLSCREEN }, - { "OPENGL", WINDOW_OPENGL }, - { "SHOWN", WINDOW_SHOWN }, - { "HIDDEN", WINDOW_HIDDEN }, - { "BORDERLESS", WINDOW_BORDERLESS }, - { "RESIZABLE", WINDOW_RESIZABLE }, - { "MINIMIZED", WINDOW_MINIMIZED }, - { "MAXIMIZED", WINDOW_MAXIMIZED }, - { "INPUT_GRABBED", WINDOW_INPUT_GRABBED }, - { "INPUT_FOCUS", WINDOW_INPUT_FOCUS }, - { "MOUSE_FOCUS", WINDOW_MOUSE_FOCUS }, - { "ALLOW_HIGHDPI", WINDOW_ALLOW_HIGHDPI }, - { "MOUSE_CAPTURE", WINDOW_MOUSE_CAPTURE }, - { "ALWAYS_ON_TOP", WINDOW_ALWAYS_ON_TOP } - ); - - } - - // Window.Init(config_table) - LUAX_IMPL_METHOD(Window, _Init) - { - LUAX_PREPARE(L, Window); - - WindowConfig config; - - if (!state.IsType(1, LUA_TTABLE)) - return state.ErrorType(1, "window config table"); - - config.width = state.GetField(1, "width", 0); - config.height = state.GetField(1, "height", 0); - config.x = state.GetField(1, "x", 0); - config.y = state.GetField(1, "y", 0); - config.flag = state.GetField(1, "flag", WINDOW_OPENGL); - config.title = state.GetField(1, "title", ""); - config.vsync = state.GetField(1, "vsync", true); - config.show = state.GetField(1, "show", true); - - // try set window icon - state.GetField(1, "icon"); - if (state.IsType(1, LUA_TUSERDATA)) - { - ImageData* data = state.CheckUserdata(-1); - if (data) - { - data->Lock(); - config.icon = data; - Window::Get()->Init(config); - data->Unlock(); - return 0; - } - } - else - state.Pop(); - - Window::Get()->Init(config); - - return 0; - } - - // Window.Exit() - LUAX_IMPL_METHOD(Window, _Exit) - { - LUAX_PREPARE(L, Window); - Window::Get()->Exit(); - return 0; - } - - // Window.Show() - LUAX_IMPL_METHOD(Window, _Show) - { - LUAX_PREPARE(L, Window); - Window::Get()->Show(); - return 0; - } - - // Window.Hide() - LUAX_IMPL_METHOD(Window, _Hide) - { - LUAX_PREPARE(L, Window); - Window::Get()->Hide(); - return 0; - } - - // Window.SetSize(w, h) - LUAX_IMPL_METHOD(Window, _SetSize) - { - LUAX_PREPARE(L, Window); - uint w = state.CheckValue(1); - uint h = state.CheckValue(2); - Window::Get()->SetSize(w, h); - return 0; - } - - // Window.SetPosition(x, y) - LUAX_IMPL_METHOD(Window, _SetPosition) - { - LUAX_PREPARE(L, Window); - int x = state.CheckValue(1); - int y = state.CheckValue(2); - Window::Get()->SetPosition(x, y); - return 0; - } - - // Window.SetTitle(title) - LUAX_IMPL_METHOD(Window, _SetTitle) - { - LUAX_PREPARE(L, Window); - std::string title = state.CheckValue(1); - Window::Get()->SetTitle(title); - return 0; - } - - // Window.SetIcon(imageData) - LUAX_IMPL_METHOD(Window, _SetIcon) - { - LUAX_PREPARE(L, Window); - ImageData* imgData = state.CheckUserdata(1); - imgData->Lock(); - Window::Get()->SetIcon(imgData); - imgData->Unlock(); - return 0; - } - - // Window.SwapRenderBuffer() - LUAX_IMPL_METHOD(Window, _SwapRenderBuffer) - { - LUAX_PREPARE(L, Window); - Window::Get()->SwapRenderBuffer(); - return 0; - } - - // Window.Clear() - LUAX_IMPL_METHOD(Window, _Clear) - { - LUAX_PREPARE(L, Window); - Window::Get()->Clear(); - return 0; - } - - // Window.Draw() - LUAX_IMPL_METHOD(Window, _Draw) - { - LUAX_PREPARE(L, Window); - return 0; - } - - } -} \ No newline at end of file diff --git a/source/modules/asura-core/wnd/window.cpp b/source/modules/asura-core/wnd/window.cpp deleted file mode 100644 index 174d04e..0000000 --- a/source/modules/asura-core/wnd/window.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include - -#include "window.h" - -#include "window_impl_sdl.h" -#include "window_impl_glew.h" -#include "window_impl_glut.h" - -namespace AsuraEngine -{ - namespace Wnd - { - - Window::Window() - : mImpl(nullptr) - { - } - - Window::~Window() - { - if (mImpl) - delete mImpl; - } - -#define try_init_window(impl) \ - if (!mImpl) \ - { \ - try \ - { \ - mImpl = new impl(config); \ - } \ - catch (Exception& e) \ - { \ - mImpl = nullptr; \ - } \ - } - - bool Window::Init(const WindowConfig& config) - { - ASSERT(!mImpl); -#if ASURA_WINDOW_SDL - try_init_window(WindowImplSDL); -#endif - ASSERT(mImpl); - } - - void Window::Exit() - { - if (mImpl) - delete mImpl; - } - - void Window::SetPosition(int x, int y) - { - ASSERT(mImpl); - mImpl->SetPosition(x, y); - } - - void Window::SetTitle(const std::string& title) - { - ASSERT(mImpl); - mImpl->SetTitils(title); - } - - void Window::Show() - { - ASSERT(mImpl); - mImpl->Show(); - } - - void Window::Hide() - { - ASSERT(mImpl); - mImpl->Hide(); - } - - void Window::SwapRenderBuffer() - { - ASSERT(mImpl); - mImpl->SwapRenderBuffer(); - } - - void Window::Clear(const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) - { - ASSERT(mImpl); - - } - - void Window::Clear(const Math::Recti& quad, const AEGraphics::Color& col /*= AEGraphics::Color::Black*/) - { - ASSERT(mImpl); - - } - - void Window::Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) - { - ASSERT(mImpl); - - } - - void Window::Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) - { - ASSERT(mImpl); - - } - - } -} diff --git a/source/modules/asura-core/wnd/window.h b/source/modules/asura-core/wnd/window.h deleted file mode 100644 index eb8a574..0000000 --- a/source/modules/asura-core/wnd/window.h +++ /dev/null @@ -1,149 +0,0 @@ -#ifndef __ASURA_ENGINE_WINDOW_H__ -#define __ASURA_ENGINE_WINDOW_H__ - -#include -#include -#include - -#include "../graphics/image.h" -#include "../graphics/render_state.h" -#include "../graphics/render_target.h" - -namespace AsuraEngine -{ - namespace Wnd - { - - class WindowImpl; - - /// - /// 从SDL拷贝过来的,留下一些有用的。 - /// - enum WindowFlag - { - WINDOW_FULLSCREEN = 1 << 1, /**< fullscreen window */ - WINDOW_OPENGL = 1 << 2, /**< window usable with OpenGL context */ - WINDOW_SHOWN = 1 << 3, /**< window is visible */ - WINDOW_HIDDEN = 1 << 4, /**< window is not visible */ - WINDOW_BORDERLESS = 1 << 5, /**< no window decoration */ - WINDOW_RESIZABLE = 1 << 6, /**< window can be resized */ - WINDOW_MINIMIZED = 1 << 7, /**< window is minimized */ - WINDOW_MAXIMIZED = 1 << 8, /**< window is maximized */ - WINDOW_INPUT_GRABBED = 1 << 9, /**< window has grabbed input focus */ - WINDOW_INPUT_FOCUS = 1 << 10, /**< window has input focus */ - WINDOW_MOUSE_FOCUS = 1 << 11, /**< window has mouse focus */ - WINDOW_ALLOW_HIGHDPI = 1 << 12, /**< window should be created in high-DPI mode if supported. - On macOS NSHighResolutionCapable must be set true in the - application's Info.plist for this to have any effect. */ - WINDOW_MOUSE_CAPTURE = 1 << 13, /**< window has mouse captured (unrelated to INPUT_GRABBED) */ - WINDOW_ALWAYS_ON_TOP = 1 << 14, /**< window should always be above others */ - }; - - /// - /// Window初始化配置项 - /// - struct WindowConfig - { - uint width, height; ///< 尺寸 - int x, y; ///< 窗口初始坐标 - std::string title; ///< 标题名 - bool vsync; ///< 垂直同步 - AEGraphics::ImageData* icon; ///< 图标 - bool show; ///< 是否显示 - int flag; ///< 窗口标记 - }; - - /// - /// 游戏的单窗口,runner只需要一个窗口。不同的客户端实现此接口并手动注册到lua。编辑器不 - /// 会导入此类,将会嫁接到编辑器的虚拟窗口上。 - /// - class Window ASURA_FINAL - : public AEGraphics::RenderTarget - , public AEScripting::Portable - , public Singleton - { - public: - - /// - /// 游戏运行时的窗口是唯一的,编辑器不会用到此类。 - /// - LUAX_DECL_SINGLETON(Window); - - Window(); - ~Window(); - - /// - /// 在这里真正创建窗口。 - /// - bool Init(const WindowConfig& config); - void Exit(); - - void SetSize(uint width, uint height); - void SetPosition(int x, int y); - void SetTitle(const std::string& title); - void SetIcon(AEGraphics::ImageData* imgData); - - void Show(); - void Hide(); - - /// - /// 如果是开启双缓冲的窗口,需要交换缓冲区来展示到前台 - /// - void SwapRenderBuffer(); - - void Clear(const AEGraphics::Color& col = AEGraphics::Color::Black) override; - void Clear(const Math::Recti& quad, const AEGraphics::Color& col = AEGraphics::Color::Black) override; - - void Draw(const AEGraphics::Drawable* texture, const AEGraphics::RenderState& state) override; - void Draw(const AEGraphics::Drawable* texture, const Math::Recti& quad, const AEGraphics::RenderState& state) override; - - private: - - //----------------------------------------------------------------------------// - - LUAX_DECL_ENUM(WindowFlag, 0); - - LUAX_DECL_METHOD(_Init); - LUAX_DECL_METHOD(_Exit); - LUAX_DECL_METHOD(_Show); - LUAX_DECL_METHOD(_Hide); - LUAX_DECL_METHOD(_SetSize); - LUAX_DECL_METHOD(_SetPosition); - LUAX_DECL_METHOD(_SetTitle); - LUAX_DECL_METHOD(_SetIcon); - LUAX_DECL_METHOD(_SwapRenderBuffer); - LUAX_DECL_METHOD(_Clear); - LUAX_DECL_METHOD(_Draw); - - //----------------------------------------------------------------------------// - - WindowImpl* mImpl; - - }; - - using RenderWindow = Window; - - ASURA_ABSTRACT class WindowImpl - { - public: - - WindowImpl() {}; - virtual ~WindowImpl() {}; - - virtual void SetSize(uint width, uint height) = 0; - virtual void SetPosition(int x, int y) = 0; - virtual void SetTitils(const std::string& title) = 0; - - virtual void Show() = 0; - virtual void Hide() = 0; - - virtual void SwapRenderBuffer() = 0; - - }; - - } -} - -namespace AEWnd = AsuraEngine::Wnd; - -#endif \ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_glew.cpp b/source/modules/asura-core/wnd/window_impl_glew.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/wnd/window_impl_glew.h b/source/modules/asura-core/wnd/window_impl_glew.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/wnd/window_impl_glut.cpp b/source/modules/asura-core/wnd/window_impl_glut.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/wnd/window_impl_glut.h b/source/modules/asura-core/wnd/window_impl_glut.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-core/wnd/window_impl_sdl.cpp b/source/modules/asura-core/wnd/window_impl_sdl.cpp deleted file mode 100644 index e608b8b..0000000 --- a/source/modules/asura-core/wnd/window_impl_sdl.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "../core_config.h" - -#if ASURA_WINDOW_SDL - -#include - -#include - -#include "window_impl_sdl.h" - -using namespace AEGraphics; - -namespace AsuraEngine -{ - namespace Wnd - { - -#define asura_flag_to_sdl_flag(flag, _flag, _sdl_flag) \ - if ((flag & _flag) != 0) \ - flag |= _sdl_flag - - WindowImplSDL::WindowImplSDL(const WindowConfig& config) - : mWnd(nullptr) - , mGLContext(0) - { - if (SDL_Init(SDL_INIT_VIDEO) < 0) - throw Exception("Cant init sdl video."); - - int flag = 0x0; - asura_flag_to_sdl_flag(flag, WINDOW_FULLSCREEN, SDL_WINDOW_FULLSCREEN); - asura_flag_to_sdl_flag(flag, WINDOW_OPENGL, SDL_WINDOW_OPENGL); - asura_flag_to_sdl_flag(flag, WINDOW_SHOWN, SDL_WINDOW_SHOWN); - asura_flag_to_sdl_flag(flag, WINDOW_HIDDEN, SDL_WINDOW_HIDDEN); - asura_flag_to_sdl_flag(flag, WINDOW_BORDERLESS, SDL_WINDOW_BORDERLESS); - asura_flag_to_sdl_flag(flag, WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE); - asura_flag_to_sdl_flag(flag, WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED); - asura_flag_to_sdl_flag(flag, WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED); - asura_flag_to_sdl_flag(flag, WINDOW_INPUT_GRABBED, SDL_WINDOW_INPUT_GRABBED); - asura_flag_to_sdl_flag(flag, WINDOW_INPUT_FOCUS, SDL_WINDOW_INPUT_FOCUS); - asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_FOCUS, SDL_WINDOW_MOUSE_FOCUS); - asura_flag_to_sdl_flag(flag, WINDOW_ALLOW_HIGHDPI, SDL_WINDOW_ALLOW_HIGHDPI); - asura_flag_to_sdl_flag(flag, WINDOW_MOUSE_CAPTURE, SDL_WINDOW_MOUSE_CAPTURE); - asura_flag_to_sdl_flag(flag, WINDOW_ALWAYS_ON_TOP, SDL_WINDOW_ALWAYS_ON_TOP); - - // Set GL window / framebuffer attributes. - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); - - mWnd = SDL_CreateWindow(config.title.c_str(), config.x, config.y, config.width, config.height, flag); - - if (!mWnd) - throw Exception("Cant create SDL window."); - - // 设置图标 - try - { - if (config.icon) - { - ImageData* img = config.icon; - if (img->format == COLOR_FORMAT_RGBA8) - { - SDL_Surface *surface; - - img->Lock(); - - int w = img->width, h = img->height; - surface = SDL_CreateRGBSurfaceFrom( - img->pixels, - w, h, - 32, - w * 4, - Color32::RMASK, - Color32::GMASK, - Color32::BMASK, - Color32::AMASK - ); - - img->Unlock(); - - SDL_SetWindowIcon(mWnd, surface); - SDL_FreeSurface(surface); - } - } - } catch (...) - { - } - - mGLContext = SDL_GL_CreateContext(mWnd); - - if (!mGLContext) - { - SDL_DestroyWindow(mWnd); - throw Exception("Cant create SDL GL Context."); - } - - SDL_GL_MakeCurrent(mWnd, mGLContext); - SDL_GL_SetSwapInterval(config.vsync ? 1 : 0); - } - - WindowImplSDL::~WindowImplSDL() - { - SDL_GL_DeleteContext(mGLContext); - SDL_DestroyWindow(mWnd); - SDL_FlushEvent(SDL_WINDOWEVENT); - } - - void WindowImplSDL::SetSize(uint width, uint height) - { - SDL_SetWindowSize(mWnd, width, height); - } - - void WindowImplSDL::SetPosition(int x, int y) - { - SDL_SetWindowPosition(mWnd, x, y); - } - - void WindowImplSDL::SetTitils(const std::string& title) - { - SDL_SetWindowTitle(mWnd, title.c_str()); - } - - void WindowImplSDL::Show() - { - SDL_ShowWindow(mWnd); - } - - void WindowImplSDL::Hide() - { - SDL_HideWindow(mWnd); - } - - void WindowImplSDL::SwapRenderBuffer() - { - SDL_GL_SwapWindow(mWnd); - } - - } -} - -#endif // ASURA_WINDOW_SDL \ No newline at end of file diff --git a/source/modules/asura-core/wnd/window_impl_sdl.h b/source/modules/asura-core/wnd/window_impl_sdl.h deleted file mode 100644 index 0e81c0a..0000000 --- a/source/modules/asura-core/wnd/window_impl_sdl.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __ASURA_WINDOW_SDL_H_ -#define __ASURA_WINDOW_SDL_H_ - -#include "../core_config.h" - -#if ASURA_WINDOW_SDL - -#include - -#include "window.h" - -namespace AsuraEngine -{ - namespace Wnd - { - - class WindowImplSDL ASURA_FINAL : public WindowImpl - { - public: - - WindowImplSDL(const WindowConfig& config); - ~WindowImplSDL(); - - void SetSize(uint width, uint height) override; - void SetPosition(int x, int y) override; - void SetTitils(const std::string& title) override; - - void Show() override; - void Hide() override; - - void SwapRenderBuffer() override; - - private: - - SDL_Window* mWnd; - SDL_GLContext mGLContext; - - }; - - } -} - -#endif // ASURA_WINDOW_SDL - -#endif \ No newline at end of file -- cgit v1.1-26-g67d0