compilable (not linkable yet) on linux
This commit is contained in:
parent
1c00f5e031
commit
963be7a0f2
38 changed files with 656 additions and 772 deletions
BIN
projects/genie
Executable file
BIN
projects/genie
Executable file
Binary file not shown.
|
@ -184,7 +184,7 @@ if _OPTIONS["no-lua-script"] == nil then
|
|||
table.insert(base_plugins, "lua_script")
|
||||
end
|
||||
|
||||
if _OPTIONS["no-gui"] == nil or _ACTION ~= "vs2019" then
|
||||
if _OPTIONS["no-gui"] == nil then
|
||||
table.insert(plugins, "gui")
|
||||
table.insert(base_plugins, "gui")
|
||||
end
|
||||
|
@ -223,7 +223,6 @@ newoption {
|
|||
value = "GCC",
|
||||
description = "Choose GCC flavor",
|
||||
allowed = {
|
||||
{ "android-x86", "Android - x86" },
|
||||
{ "linux-gcc", "Linux (GCC compiler)" },
|
||||
{ "linux-gcc-5", "Linux (GCC-5 compiler)" },
|
||||
{ "linux-clang", "Linux (Clang compiler)" }
|
||||
|
@ -242,7 +241,6 @@ function defaultConfigurations()
|
|||
flags { "Symbols", "Optimize" }
|
||||
|
||||
configuration "linux"
|
||||
buildoptions { "-std=c++14" }
|
||||
defines { "_GLIBCXX_USE_CXX11_ABI=0" }
|
||||
links { "pthread" }
|
||||
|
||||
|
@ -363,87 +361,7 @@ end
|
|||
solution "LumixEngine"
|
||||
flags { "Cpp17" }
|
||||
if _ACTION == "gmake" then
|
||||
configuration { "android-*" }
|
||||
flags {
|
||||
"NoImportLib",
|
||||
}
|
||||
includedirs {
|
||||
"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/include",
|
||||
"$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
|
||||
}
|
||||
linkoptions {
|
||||
"-nostdlib",
|
||||
"-static-libgcc",
|
||||
}
|
||||
links {
|
||||
"c",
|
||||
"dl",
|
||||
"m",
|
||||
"android",
|
||||
"log",
|
||||
"gnustl_static",
|
||||
"gcc",
|
||||
}
|
||||
buildoptions {
|
||||
"-fPIC",
|
||||
"-no-canonical-prefixes",
|
||||
"-Wa,--noexecstack",
|
||||
"-fstack-protector",
|
||||
"-ffunction-sections",
|
||||
"-Wno-psabi",
|
||||
"-Wunused-value",
|
||||
"-Wundef",
|
||||
}
|
||||
buildoptions_cpp {
|
||||
"-std=c++14",
|
||||
}
|
||||
linkoptions {
|
||||
"-no-canonical-prefixes",
|
||||
"-Wl,--no-undefined",
|
||||
"-Wl,-z,noexecstack",
|
||||
"-Wl,-z,relro",
|
||||
"-Wl,-z,now",
|
||||
}
|
||||
|
||||
configuration { "android-x86" }
|
||||
androidPlatform = "android-24"
|
||||
libdirs {
|
||||
path.join(_libDir, "lib/android-x86"),
|
||||
"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86",
|
||||
}
|
||||
includedirs {
|
||||
"$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/include",
|
||||
}
|
||||
buildoptions {
|
||||
"--sysroot=" .. path.join("$(ANDROID_NDK_ROOT)/platforms", androidPlatform, "arch-x86"),
|
||||
"-march=i686",
|
||||
"-mtune=atom",
|
||||
"-mstackrealign",
|
||||
"-msse3",
|
||||
"-mfpmath=sse",
|
||||
"-Wunused-value",
|
||||
"-Wundef",
|
||||
}
|
||||
linkoptions {
|
||||
"--sysroot=" .. path.join("$(ANDROID_NDK_ROOT)/platforms", androidPlatform, "arch-x86"),
|
||||
path.join("$(ANDROID_NDK_ROOT)/platforms", androidPlatform, "arch-x86/usr/lib/crtbegin_so.o"),
|
||||
path.join("$(ANDROID_NDK_ROOT)/platforms", androidPlatform, "arch-x86/usr/lib/crtend_so.o"),
|
||||
}
|
||||
|
||||
configuration {}
|
||||
|
||||
|
||||
if "android-x86" == _OPTIONS["gcc"] then
|
||||
if not os.getenv("ANDROID_NDK_X86") or not os.getenv("ANDROID_NDK_ROOT") then
|
||||
print("Set ANDROID_NDK_X86 and ANDROID_NDK_ROOT envrionment variables.")
|
||||
end
|
||||
|
||||
premake.gcc.cc = "\"$(ANDROID_NDK_X86)/bin/i686-linux-android-gcc\""
|
||||
premake.gcc.cxx = "\"$(ANDROID_NDK_X86)/bin/i686-linux-android-g++\""
|
||||
premake.gcc.ar = "\"$(ANDROID_NDK_X86)/bin/i686-linux-android-ar\""
|
||||
LOCATION = "tmp/android-x86_gmake"
|
||||
|
||||
elseif "linux-gcc" == _OPTIONS["gcc"] then
|
||||
if "linux-gcc" == _OPTIONS["gcc"] then
|
||||
LOCATION = "tmp/gcc"
|
||||
|
||||
elseif "linux-gcc-5" == _OPTIONS["gcc"] then
|
||||
|
@ -466,8 +384,9 @@ solution "LumixEngine"
|
|||
removefiles { "../src/**/editor/*" }
|
||||
end
|
||||
|
||||
configuration { "linux-*" }
|
||||
configuration { "linux" }
|
||||
buildoptions {
|
||||
"-m64",
|
||||
"-fPIC",
|
||||
"-no-canonical-prefixes",
|
||||
"-Wa,--noexecstack",
|
||||
|
@ -477,21 +396,13 @@ solution "LumixEngine"
|
|||
"-Wunused-value",
|
||||
"-Wundef",
|
||||
"-msse2",
|
||||
"-Wno-multichar",
|
||||
"-Wno-undef",
|
||||
}
|
||||
linkoptions {
|
||||
"-Wl,--gc-sections",
|
||||
}
|
||||
|
||||
configuration { "linux-*", "x32" }
|
||||
buildoptions {
|
||||
"-m32",
|
||||
}
|
||||
|
||||
configuration { "linux-*", "x64" }
|
||||
buildoptions {
|
||||
"-m64",
|
||||
}
|
||||
|
||||
configuration {}
|
||||
|
||||
configurations { "Debug", "RelWithDebInfo" }
|
||||
|
@ -520,12 +431,6 @@ solution "LumixEngine"
|
|||
configuration "not windows"
|
||||
removefiles { "../src/**/win/*"}
|
||||
|
||||
configuration "android-*"
|
||||
removefiles { "../src/**/win/*"}
|
||||
|
||||
configuration "not asmjs"
|
||||
removefiles { "../src/**/asmjs/*"}
|
||||
|
||||
if _OPTIONS["static-plugins"] then
|
||||
defines {"STATIC_PLUGINS"}
|
||||
end
|
||||
|
|
Binary file not shown.
|
@ -8,8 +8,8 @@
|
|||
#include "engine/crc32.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/profiler.h"
|
||||
#include "engine/reflection.h"
|
||||
#include "engine/resource_manager.h"
|
||||
|
|
|
@ -451,6 +451,16 @@ void GroupNode::deserialize(InputMemoryStream& stream, Controller& ctrl) {
|
|||
}
|
||||
}
|
||||
|
||||
void Node::serialize(OutputMemoryStream& stream) const {
|
||||
stream.writeString(m_name.c_str());
|
||||
}
|
||||
|
||||
void Node::deserialize(InputMemoryStream& stream, Controller& ctrl) {
|
||||
char tmp[64];
|
||||
stream.readString(Span(tmp));
|
||||
m_name = tmp;
|
||||
}
|
||||
|
||||
Node* Node::create(GroupNode* parent, Type type, IAllocator& allocator) {
|
||||
switch (type) {
|
||||
case Node::ANIMATION: return LUMIX_NEW(allocator, AnimationNode)(parent, allocator);
|
||||
|
|
|
@ -53,15 +53,8 @@ struct Node {
|
|||
virtual void enter(RuntimeContext& ctx) const = 0;
|
||||
virtual void skip(RuntimeContext& ctx) const = 0;
|
||||
virtual void getPose(RuntimeContext& ctx, float weight, Ref<Pose> pose, u32 mask) const = 0;
|
||||
virtual void serialize(OutputMemoryStream& stream) const = 0 {
|
||||
stream.writeString(m_name.c_str());
|
||||
}
|
||||
|
||||
virtual void deserialize(InputMemoryStream& stream, Controller& ctrl) = 0 {
|
||||
char tmp[64];
|
||||
stream.readString(Span(tmp));
|
||||
m_name = tmp;
|
||||
}
|
||||
virtual void serialize(OutputMemoryStream& stream) const = 0;
|
||||
virtual void deserialize(InputMemoryStream& stream, Controller& ctrl) = 0;
|
||||
|
||||
static Node* create(GroupNode* parent, Type type, IAllocator& allocator);
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#include "audio_device.h"
|
||||
#include "clip_manager.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/iplugin.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/mt/task.h"
|
||||
#include "engine/system.h"
|
||||
#include <alsa/asoundlib.h>
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "editor/platform_interface.h"
|
||||
#include "engine/hash_map.h"
|
||||
#include "engine/mt/task.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/profiler.h"
|
||||
#include "engine/string.h"
|
||||
#include "file_system_watcher.h"
|
||||
|
@ -66,7 +66,7 @@ struct FileSystemWatcherImpl : public FileSystemWatcher
|
|||
bool start(const char* path)
|
||||
{
|
||||
task = LUMIX_NEW(allocator, FileSystemWatcherTask)(path, *this, allocator);
|
||||
if (!task->create("FileSystemWatcherTask"))
|
||||
if (!task->create("FileSystemWatcherTask", true))
|
||||
{
|
||||
LUMIX_DELETE(allocator, task);
|
||||
task = nullptr;
|
||||
|
@ -107,14 +107,14 @@ void FileSystemWatcher::destroy(FileSystemWatcher* watcher)
|
|||
|
||||
static void addWatch(FileSystemWatcherTask& task, const char* path, int root_length)
|
||||
{
|
||||
if (!PlatformInterface::dirExists(path)) return;
|
||||
if (!OS::dirExists(path)) return;
|
||||
|
||||
int wd = inotify_add_watch(task.fd, path, IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_CLOSE_WRITE);
|
||||
task.watched.insert(wd, path + root_length);
|
||||
|
||||
auto iter = PlatformInterface::createFileIterator(path, task.allocator);
|
||||
PlatformInterface::FileInfo info;
|
||||
while (PlatformInterface::getNextFile(iter, &info))
|
||||
auto iter = OS::createFileIterator(path, task.allocator);
|
||||
OS::FileInfo info;
|
||||
while (OS::getNextFile(iter, &info))
|
||||
{
|
||||
if (!info.is_directory) continue;
|
||||
if (Lumix::equalStrings(info.filename, ".")) continue;
|
||||
|
@ -123,7 +123,7 @@ static void addWatch(FileSystemWatcherTask& task, const char* path, int root_len
|
|||
Lumix::StaticString<Lumix::MAX_PATH_LENGTH> tmp(path, info.filename, "/");
|
||||
addWatch(task, tmp, root_length);
|
||||
}
|
||||
PlatformInterface::destroyFileIterator(iter);
|
||||
OS::destroyFileIterator(iter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -133,12 +133,12 @@ static void getName(FileSystemWatcherTask& task, inotify_event* event, char* out
|
|||
|
||||
if (iter == task.watched.end())
|
||||
{
|
||||
Lumix::copyString(out, max_size, event->name);
|
||||
Lumix::copyString(Span(out, max_size), event->name);
|
||||
return;
|
||||
}
|
||||
|
||||
Lumix::copyString(out, max_size, iter.value());
|
||||
Lumix::catString(out, max_size, event->name);
|
||||
Lumix::copyString(Span(out, max_size), iter.value());
|
||||
Lumix::catString(Span(out, max_size), event->name);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
#include "engine/engine.h"
|
||||
#include "engine/fibers.h"
|
||||
#include "engine/file_system.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/page_allocator.h"
|
||||
#include "engine/profiler.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "engine/file_system.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/input_system.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
|
|
|
@ -2228,7 +2228,7 @@ public:
|
|||
return 0;
|
||||
};
|
||||
|
||||
lua_pushlightuserdata(L, static_cast<void*>(creator));
|
||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(creator));
|
||||
lua_pushlightuserdata(L, this);
|
||||
lua_pushcclosure(L, f, 2);
|
||||
lua_setfield(L, -2, name);
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
#include "lumix.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#error unsupported platform
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#define LUMIX_CRT_API LUMIX_LIBRARY_IMPORT
|
||||
#ifndef MCW_EM
|
||||
#define _EM_OVERFLOW 0x00000004
|
||||
|
@ -24,7 +21,6 @@
|
|||
extern "C" {
|
||||
typedef char* va_list;
|
||||
|
||||
|
||||
LUMIX_CRT_API void* __cdecl _aligned_malloc(size_t size, size_t align);
|
||||
LUMIX_CRT_API void __cdecl _aligned_free(void* ptr);
|
||||
LUMIX_CRT_API void* __cdecl _aligned_realloc(void* ptr, size_t size, size_t align);
|
||||
|
@ -77,3 +73,11 @@ extern "C" {
|
|||
double __cdecl tan(double _X);
|
||||
LUMIX_CRT_API float __cdecl tanf(float x);
|
||||
}
|
||||
#elif defined(__linux__)
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
inline int stricmp(const char* a, const char* b) { return strcasecmp(a, b); }
|
||||
#endif
|
|
@ -6,6 +6,7 @@
|
|||
#include "engine/file_system.h"
|
||||
#include "engine/input_system.h"
|
||||
#include "engine/iplugin.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
|
|
|
@ -18,13 +18,14 @@ namespace Fiber
|
|||
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef void* Handle;
|
||||
typedef void(__stdcall *FiberProc)(void*);
|
||||
using Handle = void*;
|
||||
using FiberProc = void(__stdcall *)(void*);
|
||||
constexpr Handle INVALID_FIBER = nullptr;
|
||||
#else
|
||||
typedef ucontext_t Handle;
|
||||
typedef void (*FiberProc)(void*);
|
||||
using Handle = ucontext_t*;
|
||||
using FiberProc = void (*)(void*);
|
||||
constexpr Handle INVALID_FIBER = nullptr;
|
||||
#endif
|
||||
constexpr void* INVALID_FIBER = nullptr;
|
||||
|
||||
|
||||
void initThread(FiberProc proc, Handle* handle);
|
||||
|
|
|
@ -133,14 +133,14 @@ private:
|
|||
HM* hm;
|
||||
u32 idx;
|
||||
|
||||
template <typename HM, typename K, typename V>
|
||||
bool operator !=(const iterator_base<HM, K, V>& rhs) const {
|
||||
template <typename HM2, typename K2, typename V2>
|
||||
bool operator !=(const iterator_base<HM2, K2, V2>& rhs) const {
|
||||
ASSERT(hm == rhs.hm);
|
||||
return idx != rhs.idx;
|
||||
}
|
||||
|
||||
template <typename HM, typename K, typename V>
|
||||
bool operator ==(const iterator_base<HM, K, V>& rhs) const {
|
||||
template <typename HM2, typename K2, typename V2>
|
||||
bool operator ==(const iterator_base<HM2, K2, V2>& rhs) const {
|
||||
ASSERT(hm == rhs.hm);
|
||||
return idx == rhs.idx;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "engine/mt/atomic.h"
|
||||
#include "job_system.h"
|
||||
#include "engine/array.h"
|
||||
#include "engine/engine.h"
|
||||
|
@ -5,7 +6,6 @@
|
|||
#include "engine/allocator.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/mt/sync.h"
|
||||
#include "engine/mt/task.h"
|
||||
#include "engine/mt/thread.h"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "engine/allocator.h"
|
||||
#include "engine/controller_device.h"
|
||||
#include "engine/iallocator.h"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "engine/debug/debug.h"
|
||||
#include "engine/debug.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/string.h"
|
||||
#include "engine/system.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
|
@ -64,7 +63,7 @@ void StackTree::refreshModuleList()
|
|||
}
|
||||
|
||||
|
||||
int StackTree::getPath(StackNode* node, StackNode** output, int max_size)
|
||||
int StackTree::getPath(StackNode* node, Span<StackNode*> output)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -76,7 +75,7 @@ StackNode* StackTree::getParent(StackNode* node)
|
|||
}
|
||||
|
||||
|
||||
bool StackTree::getFunction(StackNode* node, char* out, int max_size, int* line)
|
||||
bool StackTree::getFunction(StackNode* node, Span<char> out, Ref<int> line)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -108,7 +107,6 @@ static const u32 ALLOCATION_GUARD = 0xFDFDFDFD;
|
|||
Allocator::Allocator(IAllocator& source)
|
||||
: m_source(source)
|
||||
, m_root(nullptr)
|
||||
, m_mutex(false)
|
||||
, m_total_size(0)
|
||||
, m_is_fill_enabled(true)
|
||||
, m_are_guards_enabled(true)
|
||||
|
@ -151,13 +149,13 @@ Allocator::~Allocator()
|
|||
|
||||
void Allocator::lock()
|
||||
{
|
||||
m_mutex.lock();
|
||||
m_mutex.enter();
|
||||
}
|
||||
|
||||
|
||||
void Allocator::unlock()
|
||||
{
|
||||
m_mutex.unlock();
|
||||
m_mutex.exit();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -12,38 +12,41 @@ namespace Fiber
|
|||
|
||||
|
||||
thread_local Handle g_finisher;
|
||||
thread_local ucontext_t g_finisher_obj;
|
||||
|
||||
|
||||
void initThread(FiberProc proc, Handle* out)
|
||||
{
|
||||
g_finisher = &g_finisher_obj;
|
||||
*out = create(64*1024, proc, nullptr);
|
||||
getcontext(&g_finisher);
|
||||
out->uc_link = &g_finisher;
|
||||
getcontext(g_finisher);
|
||||
(*out)->uc_link = g_finisher;
|
||||
switchTo(&g_finisher, *out);
|
||||
}
|
||||
|
||||
|
||||
Handle create(int stack_size, FiberProc proc, void* parameter)
|
||||
{
|
||||
ucontext_t fib;
|
||||
getcontext(&fib);
|
||||
fib.uc_stack.ss_sp = (::malloc)(stack_size);
|
||||
fib.uc_stack.ss_size = stack_size;
|
||||
fib.uc_link = 0;
|
||||
makecontext(&fib, (void(*)())proc, 1, parameter);
|
||||
ucontext_t* fib = new ucontext_t;
|
||||
getcontext(fib);
|
||||
fib->uc_stack.ss_sp = (::malloc)(stack_size);
|
||||
fib->uc_stack.ss_size = stack_size;
|
||||
fib->uc_link = 0;
|
||||
makecontext(fib, (void(*)())proc, 1, parameter);
|
||||
return fib;
|
||||
}
|
||||
|
||||
|
||||
void destroy(Handle fiber)
|
||||
{
|
||||
delete fiber;
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
|
||||
void switchTo(Handle* prev, Handle fiber)
|
||||
{
|
||||
swapcontext(prev, &fiber);
|
||||
swapcontext(*prev, fiber);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -124,23 +124,89 @@ void get(lua_State* L, const char* head, Args... tail) {
|
|||
get_tail(L, tail...);
|
||||
}
|
||||
|
||||
template <typename T> inline bool checkField(lua_State* L, int idx, const char* k, T* out)
|
||||
template <typename T> inline bool isType(lua_State* L, int index)
|
||||
{
|
||||
lua_getfield(L, idx, k);
|
||||
if(!isType<T>(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
return false;
|
||||
return lua_islightuserdata(L, index) != 0;
|
||||
}
|
||||
*out = toType<T>(L, -1);
|
||||
lua_pop(L, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline int getField(lua_State* L, int idx, const char* k)
|
||||
template <> inline bool isType<int>(lua_State* L, int index)
|
||||
{
|
||||
lua_getfield(L, idx, k);
|
||||
return lua_type(L, -1);
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<u16>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<Path>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isstring(L, index);
|
||||
}
|
||||
template <> inline bool isType<u8>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<EntityRef>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<EntityPtr>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<ComponentType>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<Vec3>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 3;
|
||||
}
|
||||
template <> inline bool isType<DVec3>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 3;
|
||||
}
|
||||
template <> inline bool isType<Vec4>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
|
||||
}
|
||||
template <> inline bool isType<Vec2>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 2;
|
||||
}
|
||||
template <> inline bool isType<Matrix>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 16;
|
||||
}
|
||||
template <> inline bool isType<Quat>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
|
||||
}
|
||||
template <> inline bool isType<u32>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<u64>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<i64>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<bool>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isboolean(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<float>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<const char*>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isstring(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<void*>(lua_State* L, int index)
|
||||
{
|
||||
return lua_islightuserdata(L, index) != 0;
|
||||
}
|
||||
|
||||
template <typename T> inline T toType(lua_State* L, int index)
|
||||
|
@ -148,31 +214,6 @@ template <typename T> inline T toType(lua_State* L, int index)
|
|||
return (T)lua_touserdata(L, index);
|
||||
}
|
||||
|
||||
template <typename T, typename F> bool forEachArrayItem(lua_State* L, int index, const char* error_msg, F&& func)
|
||||
{
|
||||
if (!lua_istable(L, index)) {
|
||||
if (error_msg) luaL_argerror(L, index, error_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool all_match = true;
|
||||
const int n = (int)lua_objlen(L, index);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
lua_rawgeti(L, index, i + 1);
|
||||
if(isType<T>(L, -1)) {
|
||||
func(toType<T>(L, -1));
|
||||
}
|
||||
else if (error_msg) {
|
||||
lua_pop(L, 1);
|
||||
luaL_argerror(L, index, error_msg);
|
||||
}
|
||||
else {
|
||||
all_match = false;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return all_match;
|
||||
}
|
||||
template <> inline int toType(lua_State* L, int index)
|
||||
{
|
||||
return (int)lua_tointeger(L, index);
|
||||
|
@ -339,6 +380,51 @@ template <> inline void* toType(lua_State* L, int index)
|
|||
return lua_touserdata(L, index);
|
||||
}
|
||||
|
||||
template <typename T> inline bool checkField(lua_State* L, int idx, const char* k, T* out)
|
||||
{
|
||||
lua_getfield(L, idx, k);
|
||||
if(!isType<T>(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
return false;
|
||||
}
|
||||
*out = toType<T>(L, -1);
|
||||
lua_pop(L, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline int getField(lua_State* L, int idx, const char* k)
|
||||
{
|
||||
lua_getfield(L, idx, k);
|
||||
return lua_type(L, -1);
|
||||
}
|
||||
|
||||
template <typename T, typename F> bool forEachArrayItem(lua_State* L, int index, const char* error_msg, F&& func)
|
||||
{
|
||||
if (!lua_istable(L, index)) {
|
||||
if (error_msg) luaL_argerror(L, index, error_msg);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool all_match = true;
|
||||
const int n = (int)lua_objlen(L, index);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
lua_rawgeti(L, index, i + 1);
|
||||
if(isType<T>(L, -1)) {
|
||||
func(toType<T>(L, -1));
|
||||
}
|
||||
else if (error_msg) {
|
||||
lua_pop(L, 1);
|
||||
luaL_argerror(L, index, error_msg);
|
||||
}
|
||||
else {
|
||||
all_match = false;
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return all_match;
|
||||
}
|
||||
|
||||
|
||||
template <typename T> inline const char* typeToString()
|
||||
{
|
||||
|
@ -386,98 +472,6 @@ template <> inline const char* typeToString<float>()
|
|||
return "number|float";
|
||||
}
|
||||
|
||||
|
||||
template <typename T> inline bool isType(lua_State* L, int index)
|
||||
{
|
||||
return lua_islightuserdata(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<int>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<u16>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<Path>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isstring(L, index);
|
||||
}
|
||||
template <> inline bool isType<u8>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<EntityRef>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<EntityPtr>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<ComponentType>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<Vec3>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 3;
|
||||
}
|
||||
template <> inline bool isType<DVec3>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 3;
|
||||
}
|
||||
template <> inline bool isType<Vec4>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
|
||||
}
|
||||
template <> inline bool isType<Vec2>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 2;
|
||||
}
|
||||
template <> inline bool isType<Matrix>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 16;
|
||||
}
|
||||
template <> inline bool isType<Quat>(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) != 0 && lua_objlen(L, index) == 4;
|
||||
}
|
||||
template <> inline bool isType<u32>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<u64>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<i64>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<bool>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isboolean(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<float>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isnumber(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<const char*>(lua_State* L, int index)
|
||||
{
|
||||
return lua_isstring(L, index) != 0;
|
||||
}
|
||||
template <> inline bool isType<void*>(lua_State* L, int index)
|
||||
{
|
||||
return lua_islightuserdata(L, index) != 0;
|
||||
}
|
||||
|
||||
template <typename T> inline void setField(lua_State* L, int table_idx, const char* name, T value)
|
||||
{
|
||||
push(L, value);
|
||||
lua_setfield(L, table_idx - 1, name);
|
||||
}
|
||||
|
||||
template <typename T> inline void push(lua_State* L, T value)
|
||||
{
|
||||
lua_pushlightuserdata(L, value);
|
||||
|
@ -640,6 +634,11 @@ template <> inline void push(lua_State* L, void* value)
|
|||
lua_pushlightuserdata(L, value);
|
||||
}
|
||||
|
||||
template <typename T> inline void setField(lua_State* L, int table_idx, const char* name, T value)
|
||||
{
|
||||
push(L, value);
|
||||
lua_setfield(L, table_idx - 1, name);
|
||||
}
|
||||
|
||||
inline void createSystemVariable(lua_State* L, const char* system, const char* var_name, void* value)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <signal.h> // SIGTRAP
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#if !defined(_WIN32) && !defined(__linux__)
|
||||
#error Platform not supported
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "math.h"
|
||||
#include "simd.h"
|
||||
#include <random>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
|
|
@ -175,52 +175,5 @@ bool Event::poll()
|
|||
}
|
||||
|
||||
|
||||
SpinMutex::SpinMutex(bool locked)
|
||||
: m_id(0)
|
||||
{
|
||||
if (locked)
|
||||
{
|
||||
lock();
|
||||
}
|
||||
}
|
||||
|
||||
SpinMutex::~SpinMutex()
|
||||
{
|
||||
}
|
||||
|
||||
void SpinMutex::lock()
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (compareAndExchange(&m_id, 1, 0))
|
||||
{
|
||||
memoryBarrier();
|
||||
return;
|
||||
}
|
||||
|
||||
while (m_id)
|
||||
{
|
||||
yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SpinMutex::poll()
|
||||
{
|
||||
if (compareAndExchange(&m_id, 1, 0))
|
||||
{
|
||||
memoryBarrier();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void SpinMutex::unlock()
|
||||
{
|
||||
memoryBarrier();
|
||||
m_id = 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace MT
|
||||
} // namespace Lumix
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "engine/allocator.h"
|
||||
#include "engine/lumix.h"
|
||||
#include "engine/iallocator.h"
|
||||
#include "engine/mt/task.h"
|
||||
#include "engine/mt/thread.h"
|
||||
#include "engine/profiler.h"
|
||||
|
@ -55,7 +55,7 @@ Task::~Task()
|
|||
LUMIX_DELETE(m_implementation->allocator, m_implementation);
|
||||
}
|
||||
|
||||
bool Task::create(const char* name)
|
||||
bool Task::create(const char* name, bool is_extended)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
int res = pthread_attr_init(&attr);
|
||||
|
@ -87,11 +87,6 @@ void Task::setAffinityMask(u64 affinity_mask)
|
|||
pthread_setaffinity_np(m_implementation->handle, sizeof(set), &set);
|
||||
}
|
||||
|
||||
u64 Task::getAffinityMask() const
|
||||
{
|
||||
return m_implementation->affinity_mask;
|
||||
}
|
||||
|
||||
bool Task::isRunning() const
|
||||
{
|
||||
return m_implementation->is_running;
|
||||
|
@ -102,26 +97,11 @@ bool Task::isFinished() const
|
|||
return m_implementation->exited;
|
||||
}
|
||||
|
||||
bool Task::isForceExit() const
|
||||
{
|
||||
return m_implementation->force_exit;
|
||||
}
|
||||
|
||||
IAllocator& Task::getAllocator()
|
||||
{
|
||||
return m_implementation->allocator;
|
||||
}
|
||||
|
||||
void Task::forceExit(bool wait)
|
||||
{
|
||||
m_implementation->force_exit = true;
|
||||
|
||||
if (wait)
|
||||
{
|
||||
pthread_join(m_implementation->handle, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace MT
|
||||
} // namespace Lumix
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifdef _WIN32
|
||||
#define INITGUID
|
||||
#define NOGDI
|
||||
#include <Windows.h>
|
||||
#include <evntcons.h>
|
||||
|
||||
#endif
|
||||
|
||||
#include "engine/array.h"
|
||||
#include "engine/crt.h"
|
||||
|
@ -46,6 +47,7 @@ struct ThreadContext
|
|||
u32 thread_id;
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SWITCH_CONTEXT_OPCODE 36
|
||||
|
||||
#pragma pack(1)
|
||||
|
@ -83,7 +85,14 @@ struct TraceTask : MT::Task {
|
|||
|
||||
TRACEHANDLE open_handle;
|
||||
};
|
||||
|
||||
#else
|
||||
struct TraceTask {
|
||||
TraceTask(IAllocator&) {}
|
||||
void destroy() {}
|
||||
int open_handle;
|
||||
};
|
||||
void CloseTrace(int) {}
|
||||
#endif
|
||||
|
||||
static struct Instance
|
||||
{
|
||||
|
@ -105,6 +114,7 @@ static struct Instance
|
|||
|
||||
void startTrace()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
static TRACEHANDLE trace_handle;
|
||||
static TraceProps props = {};
|
||||
props.base.Wnode.BufferSize = sizeof(props);
|
||||
|
@ -137,6 +147,7 @@ static struct Instance
|
|||
trace.EventRecordCallback = TraceTask::callback;
|
||||
trace_task.open_handle = OpenTrace(&trace);
|
||||
trace_task.create("Profiler trace", true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -280,7 +291,7 @@ void write(ThreadContext& ctx, EventType type, const u8* data, int size)
|
|||
cpy(data, size);
|
||||
};
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
TraceTask::TraceTask(IAllocator& allocator)
|
||||
: MT::Task(allocator)
|
||||
{}
|
||||
|
@ -304,7 +315,7 @@ void TraceTask::callback(PEVENT_RECORD event) {
|
|||
rec.reason = cs->OldThreadWaitReason;
|
||||
write(g_instance.global_context, rec.timestamp, Profiler::EventType::CONTEXT_SWITCH, rec);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void pushInt(const char* key, int value)
|
||||
{
|
||||
|
|
|
@ -39,16 +39,6 @@ namespace Lumix
|
|||
Iterator begin() { return {this, m_rd}; }
|
||||
Iterator end() { return {this, m_wr}; }
|
||||
|
||||
T& emplace()
|
||||
{
|
||||
ASSERT(m_wr - m_rd < count);
|
||||
|
||||
u32 idx = m_wr & (count - 1);
|
||||
T& res = ::new (NewPlaceholder(), &m_buffer[idx]) T(item);
|
||||
++m_wr;
|
||||
return res;
|
||||
}
|
||||
|
||||
void push(const T& item)
|
||||
{
|
||||
ASSERT(m_wr - m_rd < count);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
|
||||
#define PASCAL __stdcall
|
||||
#ifndef _W64
|
||||
#define _W64 __w64
|
||||
|
|
|
@ -665,7 +665,8 @@ namespace Lumix
|
|||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
T val;
|
||||
prop.getValue(cmp, idx, OutputMemoryStream(&val, sizeof(val)));
|
||||
OutputMemoryStream blob(&val, sizeof(val));
|
||||
prop.getValue(cmp, idx, blob);
|
||||
count = 1;
|
||||
LuaWrapper::push(L, val);
|
||||
}
|
||||
|
@ -684,7 +685,8 @@ namespace Lumix
|
|||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
char tmp[MAX_PATH_LENGTH];
|
||||
prop.getValue(cmp, idx, OutputMemoryStream(tmp, sizeof(tmp)));
|
||||
OutputMemoryStream blob(tmp, sizeof(tmp));
|
||||
prop.getValue(cmp, idx, blob);
|
||||
count = 1;
|
||||
LuaWrapper::push(L, tmp);
|
||||
}
|
||||
|
@ -693,7 +695,8 @@ namespace Lumix
|
|||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
char tmp[1024];
|
||||
prop.getValue(cmp, idx, OutputMemoryStream(tmp, sizeof(tmp)));
|
||||
OutputMemoryStream blob(tmp, sizeof(tmp));
|
||||
prop.getValue(cmp, idx, blob);
|
||||
count = 1;
|
||||
LuaWrapper::push(L, tmp);
|
||||
}
|
||||
|
@ -728,7 +731,8 @@ namespace Lumix
|
|||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
const T val = LuaWrapper::toType<T>(L, 3);
|
||||
prop.setValue(cmp, idx, InputMemoryStream(&val, sizeof(val)));
|
||||
InputMemoryStream blob(&val, sizeof(val));
|
||||
prop.setValue(cmp, idx, blob);
|
||||
}
|
||||
|
||||
void visit(const Reflection::Property<float>& prop) override { set(prop); }
|
||||
|
@ -745,14 +749,16 @@ namespace Lumix
|
|||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
const char* val = LuaWrapper::toType<const char*>(L, 3);
|
||||
prop.setValue(cmp, idx, InputMemoryStream(val, 1 + stringLength(val)));
|
||||
InputMemoryStream blob(val, 1 + stringLength(val));
|
||||
prop.setValue(cmp, idx, blob);
|
||||
}
|
||||
|
||||
void visit(const Reflection::Property<const char*>& prop) override {
|
||||
if (!isSameProperty(prop.name, prop_name)) return;
|
||||
|
||||
const char* val = LuaWrapper::toType<const char*>(L, 3);
|
||||
prop.setValue(cmp, idx, InputMemoryStream(val, 1 + stringLength(val)));
|
||||
InputMemoryStream blob(val, 1 + stringLength(val));
|
||||
prop.setValue(cmp, idx, blob);
|
||||
}
|
||||
|
||||
void visit(const Reflection::IArrayProperty& prop) override {}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "engine/associative_array.h"
|
||||
#include "engine/crc32.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
#include "engine/geometry.h"
|
||||
#include "engine/hash_map.h"
|
||||
#include "engine/allocator.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/lumix.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/mt/thread.h"
|
||||
#include "engine/page_allocator.h"
|
||||
#include "engine/profiler.h"
|
||||
|
|
|
@ -8,8 +8,13 @@ namespace ofbx
|
|||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
#ifdef _WIN32
|
||||
typedef unsigned long long u64;
|
||||
typedef long long i64;
|
||||
#else
|
||||
typedef unsigned long u64;
|
||||
typedef long i64;
|
||||
#endif
|
||||
|
||||
static_assert(sizeof(u8) == 1, "u8 is not 1 byte");
|
||||
static_assert(sizeof(u32) == 4, "u32 is not 4 bytes");
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
#include "engine/engine.h"
|
||||
#include "engine/file_system.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
#include "engine/lumix.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/mt/thread.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/path_utils.h"
|
||||
|
|
|
@ -5,11 +5,25 @@
|
|||
#include "engine/log.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/sync.h"
|
||||
#include "engine/mt/thread.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/stream.h"
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <gl/GL.h>
|
||||
#endif
|
||||
#ifdef __linux__
|
||||
#include <X11/Xlib.h>
|
||||
#define GLX_GLXEXT_LEGACY
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#endif
|
||||
#include <GL/gl.h>
|
||||
#include "renderdoc_app.h"
|
||||
|
||||
namespace Lumix {
|
||||
|
||||
namespace gpu {
|
||||
|
||||
#define GPU_GL_IMPORT(prototype, name) static prototype name;
|
||||
#define GPU_GL_IMPORT_TYPEDEFS
|
||||
|
||||
|
@ -18,13 +32,6 @@
|
|||
#undef GPU_GL_IMPORT_TYPEDEFS
|
||||
#undef GPU_GL_IMPORT
|
||||
|
||||
|
||||
namespace Lumix
|
||||
{
|
||||
|
||||
|
||||
namespace gpu {
|
||||
|
||||
struct Buffer
|
||||
{
|
||||
enum { MAX_COUNT = 8192 };
|
||||
|
@ -94,9 +101,11 @@ struct Pool
|
|||
|
||||
struct WindowContext {
|
||||
void* window_handle = nullptr;
|
||||
GLuint vao;
|
||||
#ifdef _WIN32
|
||||
HDC device_context;
|
||||
HGLRC hglrc;
|
||||
GLuint vao;
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct {
|
||||
|
@ -107,7 +116,7 @@ static struct {
|
|||
Pool<Texture, Texture::MAX_COUNT> textures;
|
||||
Pool<Program, Program::MAX_COUNT> programs;
|
||||
MT::CriticalSection handle_mutex;
|
||||
DWORD thread;
|
||||
Lumix::MT::ThreadID thread;
|
||||
int instance_attributes = 0;
|
||||
int max_vertex_attributes = 16;
|
||||
ProgramHandle last_program = INVALID_PROGRAM;
|
||||
|
@ -704,20 +713,22 @@ static void flipCompressedTexture(int w, int h, int format, void* surface)
|
|||
|
||||
void checkThread()
|
||||
{
|
||||
ASSERT(g_gpu.thread == GetCurrentThreadId());
|
||||
ASSERT(g_gpu.thread == Lumix::MT::getCurrentThreadID());
|
||||
}
|
||||
|
||||
static void try_load_renderdoc()
|
||||
{
|
||||
HMODULE lib = LoadLibrary("renderdoc.dll");
|
||||
#ifdef _WIN32
|
||||
void* lib = OS::loadLibrary("renderdoc.dll");
|
||||
if (!lib) return;
|
||||
pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)GetProcAddress(lib, "RENDERDOC_GetAPI");
|
||||
pRENDERDOC_GetAPI RENDERDOC_GetAPI = (pRENDERDOC_GetAPI)OS::getLibrarySymbol(lib, "RENDERDOC_GetAPI");
|
||||
if (RENDERDOC_GetAPI) {
|
||||
RENDERDOC_GetAPI(eRENDERDOC_API_Version_1_0_2, (void **)&g_gpu.rdoc_api);
|
||||
g_gpu.rdoc_api->MaskOverlayBits(~RENDERDOC_OverlayBits::eRENDERDOC_Overlay_Enabled, 0);
|
||||
}
|
||||
/**/
|
||||
//FreeLibrary(lib);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void logVersion() {
|
||||
|
@ -729,9 +740,18 @@ static void logVersion() {
|
|||
logInfo("Renderer") << "OpenGL renderer: " << renderer;
|
||||
}
|
||||
|
||||
static void* getGLFunc(const char* name) {
|
||||
#ifdef _WIN32
|
||||
return wglGetProcAddress(name);
|
||||
#else
|
||||
return (void*)glXGetProcAddress((const GLubyte*)name);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool load_gl(void* device_contex, u32 init_flags)
|
||||
{
|
||||
const bool vsync = init_flags & (u32)InitFlags::VSYNC;
|
||||
#ifdef _WIN32
|
||||
HDC hdc = (HDC)device_contex;
|
||||
const PIXELFORMATDESCRIPTOR pfd =
|
||||
{
|
||||
|
@ -762,8 +782,8 @@ static bool load_gl(void* device_contex, u32 init_flags)
|
|||
|
||||
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
|
||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)getGLFunc("wglCreateContextAttribsARB");
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)getGLFunc("wglSwapIntervalEXT");
|
||||
|
||||
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001
|
||||
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
|
||||
|
@ -799,13 +819,13 @@ static bool load_gl(void* device_contex, u32 init_flags)
|
|||
logVersion();
|
||||
g_gpu.contexts[0].hglrc = hglrc;
|
||||
wglSwapIntervalEXT(vsync ? 1 : 0);
|
||||
HMODULE gl_dll = LoadLibrary("opengl32.dll");
|
||||
void* gl_dll = OS::loadLibrary("opengl32.dll");
|
||||
|
||||
#define GPU_GL_IMPORT(prototype, name) \
|
||||
do { \
|
||||
name = (prototype)wglGetProcAddress(#name); \
|
||||
name = (prototype)getGLFunc(#name); \
|
||||
if (!name && gl_dll) { \
|
||||
name = (prototype)GetProcAddress(gl_dll, #name); \
|
||||
name = (prototype)OS::getLibrarySymbol(gl_dll, #name); \
|
||||
if (!name) { \
|
||||
logError("Renderer") << "Failed to load GL function " #name "."; \
|
||||
return false; \
|
||||
|
@ -816,7 +836,7 @@ static bool load_gl(void* device_contex, u32 init_flags)
|
|||
#include "gl_ext.h"
|
||||
|
||||
#undef GPU_GL_IMPORT
|
||||
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1225,6 +1245,7 @@ static void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum seve
|
|||
void setCurrentWindow(void* window_handle) {
|
||||
checkThread();
|
||||
|
||||
#ifdef _WIN32
|
||||
WindowContext& ctx = [window_handle]() -> WindowContext& {
|
||||
if (!window_handle) return g_gpu.contexts[0];
|
||||
|
||||
|
@ -1273,8 +1294,8 @@ void setCurrentWindow(void* window_handle) {
|
|||
|
||||
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
|
||||
typedef HGLRC (WINAPI * PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int *attribList);
|
||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
|
||||
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)getGLFunc("wglCreateContextAttribsARB");
|
||||
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)getGLFunc("wglSwapIntervalEXT");
|
||||
|
||||
#define WGL_CONTEXT_DEBUG_BIT_ARB 0x00000001
|
||||
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
|
||||
|
@ -1315,6 +1336,7 @@ void setCurrentWindow(void* window_handle) {
|
|||
}
|
||||
|
||||
wglMakeCurrent(ctx.device_context, ctx.hglrc);
|
||||
#endif
|
||||
useProgram(INVALID_PROGRAM);
|
||||
}
|
||||
|
||||
|
@ -1324,7 +1346,9 @@ void swapBuffers()
|
|||
checkThread();
|
||||
glFinish();
|
||||
for (const WindowContext& ctx : g_gpu.contexts) {
|
||||
#ifdef _WIN32
|
||||
SwapBuffers(ctx.device_context);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1980,6 +2004,7 @@ bool init(void* window_handle, u32 init_flags)
|
|||
const bool debug = init_flags & (u32)InitFlags::DEBUG_OUTPUT;
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
g_gpu.contexts[0].window_handle = window_handle;
|
||||
g_gpu.contexts[0].device_context = GetDC((HWND)window_handle);
|
||||
g_gpu.thread = GetCurrentThreadId();
|
||||
|
@ -2033,7 +2058,7 @@ bool init(void* window_handle, u32 init_flags)
|
|||
CHECK_GL(glLinkProgram(p.handle));
|
||||
glDeleteShader(vs);
|
||||
|
||||
|
||||
#endif
|
||||
g_gpu.last_state = 1;
|
||||
setState(0);
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#include "particle_system.h"
|
||||
#include "engine/crc32.h"
|
||||
#include "engine/crt.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/profiler.h"
|
||||
#include "engine/reflection.h"
|
||||
#include "engine/resource_manager.h"
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#include "engine/engine.h"
|
||||
#include "engine/file_system.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
#include "engine/math.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/mt/sync.h"
|
||||
#include "engine/os.h"
|
||||
#include "engine/page_allocator.h"
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
#include "engine/engine.h"
|
||||
#include "engine/file_system.h"
|
||||
#include "engine/geometry.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/lua_wrapper.h"
|
||||
#include "engine/math.h"
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include "engine/debug.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/log.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/mt/atomic.h"
|
||||
#include "engine/job_system.h"
|
||||
#include "engine/mt/sync.h"
|
||||
#include "engine/mt/task.h"
|
||||
#include "engine/mt/thread.h"
|
||||
|
|
Loading…
Reference in a new issue