Git Product home page Git Product logo

bx's Introduction

bx

Base X-platform library.

License Join the chat at https://discord.gg/9eMbv7J

Goals:

  • Provide OS/runtime/compiler independent core functionality to be able to write cross-platform applications.
  • Compile without C Runtime (CRT) and without C++ Standard Library (STL).

Contact

@bkaradzic

Project page
https://github.com/bkaradzic/bx

Copyright 2010-2024 Branimir Karadzic

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

   1. Redistributions of source code must retain the above copyright notice, this
      list of conditions and the following disclaimer.

   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

bx's People

Contributors

0-wiz-0 avatar attilaz avatar bearcage avatar beevik avatar bitshifter avatar bkaradzic avatar bwrsandman avatar cedricguillemet avatar cloudwu avatar codecat avatar cuavas avatar dariomanesku avatar jay3d avatar jmallach avatar jpcy avatar juj avatar mahlemiut avatar mendsley avatar michelmno avatar mikepopoloski avatar mmicko avatar naleksiev avatar nodrev avatar okwasniewski avatar petrppetrov avatar phniix avatar rhoot avatar richardgale avatar stevenc99 avatar vvuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bx's Issues

Mismatch between quatToEuler, mtxQuat, and mtxSRT

This code demonstrates a mismatch between the definition of "euler" angles used by quatToEuler and the definition (non-explicitly) used by mtxSRT. This created a bit of confusion for me when I was dipping my toes in BGFX.

void CheckBxEulerMath()
{
    float eulers[3] = { bx::kPiQuarter, bx::kPiQuarter, bx::kPiQuarter };
    float qX[4];
    float qY[4];
    float qZ[4];
    float qXqY[4];
    float qZqXqY[4];

    bx::quatRotateX(qX, eulers[0]);
    bx::quatRotateY(qY, eulers[1]);
    bx::quatRotateZ(qZ, eulers[2]);
    bx::quatMul(qXqY, qX, qY);
    bx::quatMul(qZqXqY, qZ, qXqY);

    float mtxFromQuat[16];
    bx::mtxQuat(mtxFromQuat, qZqXqY);
    float mtxFromSRT[16];
    bx::mtxSRT(
        mtxFromSRT,
        1.0f, 1.0f, 1.0f,
        eulers[0], eulers[1], eulers[2],
        0.0f, 0.0f, 0.0f);

    float eulersFromQuat[3];
    bx::quatToEuler(eulersFromQuat, qZqXqY);

    for (int idx = 0; idx < 16; idx++)
    {
        if (!bx::equal(mtxFromQuat[idx], mtxFromSRT[idx], 0.00001f)) {
            BX_TRACE("mtxFromQuat does not equal mtxFromSRT");
            abort();
        }
    }

    for (int idx = 0; idx < 3; idx++)
    {
        if (!bx::equal(eulers[idx], eulersFromQuat[idx], 0.1f))
        {
            BX_TRACE("eulers is way different from eulersFromQuat");
            abort();
        }
    }
}

I know that the historic correct definition for Euler angles is different from what mtxSRT gets passed but it would be nice for this discrepancy to fixed or made explicit.
Perhaps you could add these functions

void quatPitchYawRoll(float* _result, float _pitch, float _yaw, float _roll);
void quatToPitchYawRoll(float* _result, const float* _quat);

and document how to compose the output of mtxSRT using individual transformations?

Thank you for your time and your open source projects.

__alignof__ and __alignof

I saw inside macros.h you have BX_ALIGNOF which is seams only Visual studio macro, how to resolve this one?

MSVC 2010: error C4189 local variable is initialized but not referenced

The macro BX_UNUSED_1 doesn't work anymore with msvc 2010.

#define BX_UNUSED_1(_a1) do { (void)sizeof(_a1); } while(0)

working alternatives:

//classical way, by may have side effect with volative vars
#define BX_UNUSED_1(_a1) do { (void)(_a1); } while(0)
or
// pbly a better compromise
// work with incomplete struct/class definition
#define BX_UNUSED_1(_a1) ( &reinterpret_cast< const int& >( _a1 ) )

swnprintf in string.h not working properly

inline int32_t swnprintf(wchar_t* _out, size_t _count, const wchar_t* _format, ...)
{
    va_list argList;
    va_start(argList, _format);
#if defined(__MINGW32__)
    int32_t len = swprintf(_out, _format, argList);
#else       
    int32_t len = swprintf(_out, _count, _format, argList);
#endif // defined(__MINGW__)
    va_end(argList);
    return len;
}

The problem is swprintf is interpretting argList as a variadic argument not as a pointer to a list of arguments, thus creating garbage (look at example-10-font frame time as example).
The correct function under msvc is _vsnwprintf (or the secure version).

If you target modern compiler you can also use vswprintf.

GLFW example and bgfx::renderFrame();

I've been toying around following the glfw example and found that to make it work a call to "bgfx::renderFrame()" is needed before calling main.

I'm missing out something or is this supposed to work this way? Is there any other considerations to take into account?

Thanks!

Genie uses deprecated _HAS_ITERATOR_DEBUGGING flag in MSVC 14+

Per my remarks in this thread: bkaradzic/bgfx#1200

MSVC 2015 deprecated the _HAS_ITERATOR_DEBUGGING macro, and its use makes BGFX's generated Visual Studio projects incompatible with standard ones (for debug builds). Otherwise the libraries are fully compatible.

The problem can be worked around by disabling this line: https://github.com/bkaradzic/bx/blob/master/scripts/toolchain.lua#L552

I suggest removing this definition, or making it optional in Genie (and off by default).

float4x4_mul calculate error

{ 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1,35,
0, 0, 0, 1};

{ 0.974278, 0, 0, 0,
0, 1.732050, 0, 0,
0, 0, 1.000101, -0.100100,
0, 0, 1, 0};

float4x4_mul result:
0.974278 , 0 , 0 , 0
0 , 1.73205 , 0 , 0
0 , 0 , 36.0001 , 1
0 , 0 , -0.1001 , 0

OpenGL Mathematics (GLM) result:
0.974278 , 0 , 0 , 0
0 , 1.73205 , 0 , 0
0 , 0 , 1.0001 , 1
0 , 0 , 34.9034 , 35

commandline parsing reads after term if there is whitespace before it

bgfx's geometryc uses commandline for parsing obj lines.
https://github.com/bkaradzic/bgfx/blob/master/tools/geometryc/geometryc.cpp#L504

If there are spaces before end of line, it reads multiple lines instead of only one.
You can test with a simple test string like this:
"X \r\nY Z\r\n" with term='\n' this gives argc == 3, instead of 1.

If have added an extra test here:
https://github.com/bkaradzic/bx/blob/master/src/commandline.cpp#L42

for (; isSpace(*curr) && *curr != _term; ++curr) {}; // skip whitespace

swnprintf in string.h still broken under msvc 2010

inline int32_t vsnwprintf(wchar_t* _str, size_t _count, const wchar_t* _format, va_list _argList)
{
#if BX_COMPILER_MSVC
    int32_t len = ::_vsnwprintf_s(_str, _count*sizeof(wchar_t), _count, _format, _argList);
    return -1 == len ? ::_vscwprintf(_format, _argList) : len;
#elif defined(__MINGW32__)
    return ::vsnwprintf(_str, _count, _format, _argList);
#else
    return ::vswprintf(_str, _count, _format, _argList);
#endif // BX_COMPILER_MSVC
}

The problem is that _vsnwprintf_s second argument must be in "words" and not in char, the way it is now it corrupts memory.
You can validate that by looking at the definition in msvc stdio.h implementation.
There the second argument is called "size_t _SizeInWords".

Microsoft official online documentation is wrong and the argument is missnamed -_-
http://msdn.microsoft.com/en-us/library/d3xd30zz(v=vs.100).aspx
Someone also pointed this in comments.

so:

int32_t len = ::_vsnwprintf_s(_str, _count*sizeof(wchar_t), _count, _format, _argList);

should be

int32_t len = ::_vsnwprintf_s(_str, _count, _count, _format, _argList);

GCC 8 / C++11

Basically it doesn't build with GCC 8 and -std=c++11, i looked into issues and found that similar issue (bkaradzic/bgfx#1567) appeared in VS2015 and indeed constexpr was disabled for VS2015, so i did the following change to fix build:

diff --git a/include/bx/macros.h b/include/bx/macros.h
index 7a9b643..a603141 100644
--- a/include/bx/macros.h
+++ b/include/bx/macros.h
@@ -115,7 +115,7 @@
 
 /// The return value of the function is solely a function of the arguments.
 ///
-#if BX_COMPILER_MSVC && (BX_COMPILER_MSVC <= 1900)
+#if (BX_COMPILER_MSVC && (BX_COMPILER_MSVC <= 1900)) || (BX_COMPILER_GCC && (__cplusplus < 201300))
 #      define BX_CONSTEXPR_FUNC BX_CONST_FUNC
 #else
 #      define BX_CONSTEXPR_FUNC constexpr BX_CONST_FUNC

I think __cplusplus should work for VS2015 too, but i didn't check so i did this change specifically for GCC, no other changes were required as far as i can see.

Alternatively all those constexpr parts could be rewritten to fit C++11 requirements, but it won't be pretty.

I know that Genie build enables -std=c++14 on bx, but i use homemade CMake scripts for building bx/bimg/bgfx and i don't really feel like switching C++ revision to 14.

Does that fix look good? I can create PR if needed, or how would you recommend to approach this?

mingw chokes on debug.cpp's #define DBG_ADDRESS "%" PRIxPTR

/usr/bin/x86_64-w64-mingw32-g++ -DWIN32 -DMINGW_HAS_SECURE_API=1 -I../../../lib/bx/include/compat/mingw -I../../../lib/bx/include -fomit-frame-pointer -g -m64 -fno-rtti -std=c++11 -MMD -MF ../obj/x64/Release/bx/lib/bx/src/debug.o.d -c -o ../obj/x64/Release/bx/lib/bx/src/debug.o ../../../lib/bx/src/debug.cpp
../../../lib/bx/src/debug.cpp: In function โ€˜void bx::debugPrintfData(const void*, uint32_t, const char*, ...)โ€™:
../../../lib/bx/src/debug.cpp:93:25: error: expected โ€˜)โ€™ before โ€˜PRIxPTRโ€™
 #define DBG_ADDRESS "%" PRIxPTR
                         ^
../../../lib/bx/src/debug.cpp:106:26: note: in expansion of macro โ€˜DBG_ADDRESSโ€™
   debugPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
                          ^~~~~~~~~~~
../../../lib/bx/src/debug.cpp:93:25: error: expected โ€˜)โ€™ before โ€˜PRIxPTRโ€™
 #define DBG_ADDRESS "%" PRIxPTR
                         ^
../../../lib/bx/src/debug.cpp:126:23: note: in expansion of macro โ€˜DBG_ADDRESSโ€™
      debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
                       ^~~~~~~~~~~
../../../lib/bx/src/debug.cpp:93:25: error: expected โ€˜)โ€™ before โ€˜PRIxPTRโ€™
 #define DBG_ADDRESS "%" PRIxPTR
                         ^
../../../lib/bx/src/debug.cpp:136:22: note: in expansion of macro โ€˜DBG_ADDRESSโ€™
     debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
                      ^~~~~~~~~~~


mingw version 6.3.1

I'm not terribly familiar with the inttypes.h and my macro fu needs some work, so hopefully this is legit and I'm not just doing something stupid ๐Ÿ‘

update: changing -MMD to -M s-MMD flag! turns out I'm just being dumb.

update: this ticket is a dumpster fire. I just needed to define __STDC_FORMAT_MACROS, which you already define in your toolchain.lua

Build error on osx

Failed to build with themake osx command on macOS Sierra 10.12.6 on master branch (451e30b)

I get the following error:

make -C .build/projects/gmake-osx config=debug32
==== Building bx (debug32) ====
Creating ../../osx32_clang/obj/x32/Debug/bx/src
allocator.cpp
bx.cpp
commandline.cpp
crtnone.cpp
debug.cpp
dtoa.cpp
easing.cpp
file.cpp
filepath.cpp
hash.cpp
math.cpp
mutex.cpp
os.cpp
../../../src/os.cpp:280:10: fatal error: no member named 'chdir' in the global namespace; did you mean simply 'chdir'?
                return ::chdir(_path);
                       ^~~~~~~
                       chdir
../../../src/os.cpp:270:6: note: 'chdir' declared here
        int chdir(const char* _path)
            ^
1 error generated.
make[2]: *** [../../osx32_clang/obj/x32/Debug/bx/src/os.o] Error 1
make[1]: *** [bx] Error 2
make: *** [osx-debug32] Error 2

Originally was trying to build bgfx and got this error, but was able to see that it's coming from the bx library. Thought reverting to an earlier change might help and it did allow me to build bx on it's own, but bgfx failed with other problems due to missing files or other discrepencies.

iOS build error

There is a minor build error in the latest bx in mutex.h
you forget to add BX_PLATFORM_IOS to the posix thread include at line 16:

#if BX_PLATFORM_NACL || BX_PLATFORM_LINUX || BX_PLATFORM_ANDROID || BX_PLATFORM_OSX || BX_PLATFORM_IOS

Out of bounds read in strFind

template<CharFn fn>
inline const char* strFind(const char* _str, int32_t _strMax, const char* _find, int32_t _findMax)

The strFind template function will cause an out of bounds read on _str if _find is an empty string (_findMax == 0). A check should be added at the top of the function, something like:
if (!(_strMax && _findMax)) return NULL;

Setting specific WindowsPlatform

The toolchain script currently only allows configuring the windowsTargetPlatformVersion project setting if the toolset target is set to "--vs=winstore82". Otherwise the project setting will default to 8.1. It seems this parameter should be settable always. Three suggestions (can't make a pull request right now):

  1. Move the 3 lines that assign the platform, from the "winstore82" subsection up to the enclosing if, right before starting to check specific "--vs" toolsets.

     or _ACTION == "vs2013"
     or _ACTION == "vs2015"
     or _ACTION == "vs2017"
     then
    
     	local action = premake.action.current()
     	action.vstudio.windowsTargetPlatformVersion = windowsPlatform
     	action.vstudio.windowsTargetPlatformMinVersion = windowsPlatform
    
     if (_ACTION .. "-clang") == _OPTIONS["vs"] then
    
  2. Allow a smarter default for the "--with-windows" argument that sets the "windowsPlatform" variable, based on the standard environment variable "WindowsSDKVersion", and in its absence, default to a more conservative platform of 8.1.

     local windowsPlatform = "8.1"
     if os.getenv("WindowsSDKVersion") then
     	windowsPlatform = os.getenv("WindowsSDKVersion")
     end
     if _OPTIONS["with-windows"] then
     	windowsPlatform = _OPTIONS["with-windows"]
     end
    

Perhaps the various toolsets may enforce higher values for this setting, so for example if requesting winstore82 then convert 8.1 into the previous default of 10.0.10240.0

  1. Update the newoption for with-windows to describe the new default more accurately.

     newoption {
     	trigger = "with-windows",
     	value = "#",
     	description = "Set the Windows target platform version (default: $WindowsSDKVersion or 8.1).",
     }
    

Trouble compiling my own library with the bgfx library

Hey I've been trying to compile my own game engine that uses bgfx for rendering and I keep running into this error that it says is coming from the bx library. The errors are shown below.
image

Does anybody have any idea what could be causing this? I'm compiling with visual studio 2019. I should note that when I built all of the libraries necessary for bgfx seperately they compiled just fine and the .lib files are included in the project. Also the project that I am trying to build builds a .lib and not a .exe

alloca.h: No such file or directory

Compiling with MinGW produces the error:

alloca.h: No such file or directory

include/string.h:10 should be:

#if defined(WIN32) || defined(__WIN32) || defined(__WIN32__)
    #include <malloc.h>
#else
    #include <alloca.h>
#endif

setThreadName bug in iOS/MacOS (thread.cpp)

setThreadName sets the current calling thread name instead of newly created one in iOS/MacOs.
On those platforms you have to keep the name and call pthread_setname_np in thread's entry func.

Can't avoid BX_CRT_NONE=1 with musl libc environment

I wouldn't even be submitting this bug if I didn't see you were trying to account for musl libc runtimes in your platform.h with BX_CRT_MUSL, but due to musl not exposing any sort of identifying #defines, I'm not quite sure how to deal with this. Simply defining BX_CRT_MUSL=1 in an else clause seems less than optimal.

Maybe my best solution is just to ditch my Alpine Linux / musl libc test pipeline for something more sensible?

This "works" in bx/include/platform.h

#if !BX_CRT_NONE
// https://sourceforge.net/p/predef/wiki/Libraries/
#   if defined(__BIONIC__)
#       undef  BX_CRT_BIONIC
#       define BX_CRT_BIONIC 1
#   elif defined(_MSC_VER)
#       undef  BX_CRT_MSVC
#       define BX_CRT_MSVC 1
#   elif defined(__GLIBC__)
#       undef  BX_CRT_GLIBC
#       define BX_CRT_GLIBC (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100)
#   elif defined(__MINGW32__) || defined(__MINGW64__)
#       undef  BX_CRT_MINGW
#       define BX_CRT_MINGW 1
#   elif defined(__apple_build_version__) || defined(__ORBIS__) || defined(__EMSCRIPTEN__)
#       undef  BX_CRT_LIBCXX
#       define BX_CRT_LIBCXX 1
#   else
#       undef  BX_CRT_MUSL            // THIS SEEMS LIKE
#       define BX_CRT_MUSL 1          // A POOR SOLUTION
#   endif //

Better uint32_testpow2

I saw your twitter about is_pow_of_2 . There is a better implementation of uint32_testpow2 .

The current version is

uint32_t uint32_testpow2(uint32_t _a) {
	const uint32_t tmp0   = uint32_not(_a);
	const uint32_t tmp1   = uint32_inc(tmp0);
	const uint32_t tmp2   = uint32_and(_a, tmp1);
	const uint32_t tmp3   = uint32_cmpeq(tmp2, _a);
	const uint32_t tmp4   = uint32_cmpneq(_a, 0);
	const uint32_t result = uint32_and(tmp3, tmp4);

	return result;
}

You can use a better version

uint32_t uint32_testpow2(uint32_t _a) {
	const uint32_t tmp0   = uint32_dec(_a);
	const uint32_t tmp1   = uint32_xor(_a, tmp0);
	const uint32_t tmp2   = uint32_srl(tmp1, 1);
	const uint32_t result = uint32_cmpeq(tmp2, tmp0);

	return result;
}

Or, If you don't care _a is zero (return true when _a is 0) , you can also use

uint32_t uint32_testpow2(uint32_t _a) {
	const uint32_t tmp0   = uint32_dec(_a);
	const uint32_t tmp1   = uint32_and(_a, tmp0);
	const uint32_t result = uint32_cmpeq(tmp1, 0);

	return result;
}

string.h: Compile error on msvc2015

I get compile error when including strings.h the alloca.h does not exist. I guess adding msvc protector macro around it fixes it :

#ifndef BX_COMPILER_MSVC
#   include <alloca.h>
#endif

Visual Studio PS4 solution

I see in the toolchain there is no direct support for the PS4 (Orbis) in Visual Studio but just for GMake.

Building bgfx with SDL2 on Raspberry Pi

Hi,

I would like to do some full-screen 3D programming on the Raspberry Pi using SDL2 (like retropie). I would also like to use imgui as part of the UI. Given the constraints of the rpi platform and my requirements, I think C++ and bgfx is the best way. You have great documentation and your examples look fantastic.

I tried building bgfx, but I suspected ahead of time that this wouldn't work. The configuration wasn't listed in the 'building' section. If this is too far out of scope for bgfx, I will respect that.

Here is what I did.

I downloaded the latest Raspbian and installed that on a microsd.

I cloned the repos in the build instructions. I then rebuilt genie for linux.
This version of Raspbian (Pixel) already had the gcc toolchain, which was nice.

I then ran:

../genie/bin/linux/genie --with-examples --with-sdl --gcc=rpi gmake

then:

make rpi -j4

The compiles are failing on X11 includes. I didn't install those libs because I am going to run this as a fullscreen SDL2 app.

What should I change to get further?

bug in bx::commandLine

found a bug in bx/commandline.h line 142, findOption using a long name never find the result,

 const char* find(const char _short, const char* _long, int _numParams) const
    {
        for (int ii = 0; ii < m_argc; ++ii)
        {
            const char* arg = m_argv[ii];
            if ('-' == *arg)
            {
                ++arg;
                if (_short == *arg)
                {

should be :

 if ('-' == *arg)
{
       if (_short == *(arg + 1))
       {
               ++arg;

hashMurmur2A not producing valid hash from input-string on 32-bit systems

With the latest version of bx, the uniform handling of bgfx breaks. All calls to bgfx::createUniform return a handle of 0 for me.

Reason is the following:
string.h, line 612:

inline uint32_t hashMurmur2A(const char* _data)
{
    return hashMurmur2A(StringView(_data) );
}

_data is set to the name of the uniform here, and hashMurmur2A always returns 0 for me.

The failing part is the strnlen you wrote in StringView::set:

string.h, line 559:

inline size_t strnlen(const char* _str, size_t _max)
    {
        const char* end = _str + _max;
        const char* ptr;
        for (ptr = _str; ptr < end && *ptr != '\0'; ++ptr) {};
        return ptr - _str;
    }

As StringView::set sets _max to UINT32_MAX, the end pointer will actually overflow on a 32-bit system and end up being smaller than _str, which causes the for-loop to immediately exit.

mtxScale and mtxTranslate are reseting

Hay bkaradzic,

first of all, you've done a great work, but I've encountered an error:
If i set my Scale with mtxScale and after that the Translate with mtxTranslate, so my Scale is gone, if i change the order, then it cleans me my Translate in my mtxMesh.

Suggestion for prefix for debugOutput()

Android, among other platforms, have really chatty output which makes it difficult to locate debugOutput from bx.

Suggest adding BX_CONFIG_DEBUG_TAG to add a custom prefix, e.g. Android this would be:

__android_log_write(ANDROID_LOG_DEBUG, BX_CONFIG_DEBUG_TAG, _out);

Other platforms it could be a simple string prefix.

Can we use std::xxx instead of float bit hacking?

Normally I wouldn't care, but the new constexpr functions in math.inl use a C++14 feature that Visual Studio 14 2015 doesn't support.

Is it really necessary to have custom abs(), IsFinite(), IsNaN(), etc. ? Can I replace those with std::abs(), std::isinf() and std::isnan()?

Meson build system?

I'd like to add Meson build scripts to bgfx, bx and bimg in order to make them available through Meson's dependency DB (Wrap).

If it's something you'd accept, @bkaradzic, I'd be glad to throw PRs at you :)

Just to give you some background, Meson is a C/C++ focused multiplatform build system slightly similar to Gradle (IMHO).

invalid reference to stdin/stdout on android

bgfx/bx builds normally for latest android ndk (16.1 at this time). But generated bx library is unusable because of invalid references to stdin/stdout:

  ../../../../bx/src/file.cpp:0: error: undefined reference to 'stdout'
  ../../../../bx/src/file.cpp:0: error: undefined reference to 'stdout'
  ../../../../bx/src/file.cpp:0: error: undefined reference to 'stderr'

_InterlockedExchangeAdd64 can't find in WINRT

SDK version:10.0.10240.0

template<>
inline int64_t atomicFetchAndAdd<int64_t>(volatile int64_t* _ptr, int64_t _add)
{

if BX_COMPILER_MSVC

if _WIN32_WINNT >= 0x600

return _InterlockedExchangeAdd64( (volatile int64_t*)_ptr, _add);

else

....

It seems thar the function not support the Win32 platform.

https://msdn.microsoft.com/zh-cn/library/windows/desktop/191ca0sk(v=vs.85).aspx
https://msdn.microsoft.com/zh-cn/library/windows/desktop/ms683599(v=vs.85).aspx

xcode4 project generation fails

Running action 'xcode4'...
Generating ../.build/projects/xcode4/bx.xcworkspace/contents.xcworkspacedata...
[string "function string.explode(s, pattern, plain)..."]:15: stack overflow
stack traceback:
[string "function string.explode(s, pattern, plain)..."]:15: in function 'string.findlast'
[string "function path.getabsolute(p)..."]:39: in function 'path.getdirectory'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
...
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.tree = { }..."]:14: in field 'add'
[string "premake.project = { }..."]:11: in field 'buildsourcetree'
[string "local xcode = premake.xcode..."]:4: in field 'buildprjtree'
[string "local xcode = premake.xcode..."]:95: in local 'callback'
[string "premake._filelevelconfig = false..."]:5: in field 'generate'
[string "premake.xcode = { }..."]:68: in field 'onproject'
[string "premake.action = { }..."]:23: in field 'call'
[string "_WORKING_DIR = os.getcwd()..."]:82: in function '_premake_main'

can't be compiled by g++ Ubuntu64

Hi, since I wanna to compile bx as a shared library, I wrote a CMakeLists.txt file to do it. Here is my file. Pretty simple!
cmake_minimum_required (VERSION 2.8)

project (bx)

include_directories (./include)
include_directories (./3rdparty)

aux_source_directory (./src SRC_DIR)

set (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")

add_library (bx SHARED ${SRC_DIR})

After use "cmake ." command, and then use "make" command to compile it. I got a problem. The compiler told me that I defined many functions twice in amalgamated.o. I found the file, and opened it. I'm confused. Why do you need to include so many cpp files? when I delete this file, my SHARED library was finished.

I know you must have some reasons to do so, but I can't tell it. So, could you help me ?

Crtnone.cpp troubles in SDLmame compile

Hello,
I am using a G4 PowerMac with OSX 10.5.8 to compile latest SDLmame release, I have set up the makefile to use GCC 7.2 compiler but when I reach the BX libraries here is what happens:

Compiling 3rdparty/bx/src/crtnone.cpp... ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'void* strcpy(char*, const char*)': ../../../../../3rdparty/bx/src/crtnone.cpp:50:18: warning: declaration of 'void* strcpy(char*, const char*)' conflicts with built-in declaration 'char* strcpy(char*, const char*)' [-Wbuiltin-declaration-mismatch] extern "C" void* strcpy(char* _dst, const char* _src) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'void* strncpy(char*, const char*, size_t)': ../../../../../3rdparty/bx/src/crtnone.cpp:56:18: warning: declaration of 'void* strncpy(char*, const char*, size_t)' conflicts with built-in declaration 'char* strncpy(char*, const char*, long unsigned int)' [-Wbuiltin-declaration-mismatch] extern "C" void* strncpy(char* _dst, const char* _src, size_t _num) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'const char* strchr(const char*, int)': ../../../../../3rdparty/bx/src/crtnone.cpp:68:24: warning: declaration of 'const char* strchr(const char*, int)' conflicts with built-in declaration 'char* strchr(const char*, int)' [-Wbuiltin-declaration-mismatch] extern "C" const char* strchr(const char* _str, int _ch) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'const char* strstr(const char*, const char*)': ../../../../../3rdparty/bx/src/crtnone.cpp:83:24: warning: declaration of 'const char* strstr(const char*, const char*)' conflicts with built-in declaration 'char* strstr(const char*, const char*)' [-Wbuiltin-declaration-mismatch] extern "C" const char* strstr(const char* _str, const char* _find) ^~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'int isprint(int)': ../../../../../3rdparty/bx/src/crtnone.cpp:94:16: error: redefinition of 'int isprint(int)' extern "C" int isprint(int _ch) ^~~~~~~ In file included from /usr/include/_wctype.h:63:0, from /usr/include/wchar.h:114, from ../../../../../3rdparty/bx/include/bx/string.h:11, from ../../../../../3rdparty/bx/include/bx/error.h:9, from ../../../../../3rdparty/bx/include/bx/readerwriter.h:10, from ../../../../../3rdparty/bx/src/crtnone.cpp:8: /usr/include/ctype.h:272:1: note: 'int isprint(int)' previously defined here isprint(int _c) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'int toupper(int)': ../../../../../3rdparty/bx/src/crtnone.cpp:99:16: error: redefinition of 'int toupper(int)' extern "C" int toupper (int _ch) ^~~~~~~ In file included from /usr/include/_wctype.h:63:0, from /usr/include/wchar.h:114, from ../../../../../3rdparty/bx/include/bx/string.h:11, from ../../../../../3rdparty/bx/include/bx/error.h:9, from ../../../../../3rdparty/bx/include/bx/readerwriter.h:10, from ../../../../../3rdparty/bx/src/crtnone.cpp:8: /usr/include/ctype.h:315:1: note: 'int toupper(int)' previously defined here toupper(int _c) ^~~~~~~ ../../../../../3rdparty/bx/src/crtnone.cpp: In function 'float powf(float)': ../../../../../3rdparty/bx/src/crtnone.cpp:161:18: warning: declaration of 'float powf(float)' conflicts with built-in declaration 'float powf(float, float)' [-Wbuiltin-declaration-mismatch] extern "C" float powf(float _x) ^~~~ ../../../../../3rdparty/bx/src/crtnone.cpp:167:19: warning: declaration of 'double pow(double)' conflicts with built-in declaration 'double pow(double, double)' [-Wbuiltin-declaration-mismatch] extern "C" double pow(double _x) ^~~ make[2]: *** [../../../../osx_clang/obj/x32/Release/3rdparty/bx/src/crtnone.o] Error 1 make[1]: *** [bx] Error 2 make[1]: *** Waiting for unfinished jobs.... make: *** [macosx_x86] Error 2

As partial workaround to let the compile process to go ahead I have manually deleted the "toUpper" and "isPrint" definitions from crtnone.cpp but I don't know how to fix this issue since I am not strictly a programmer. Can this be fixed in some way? Many thanks in advance.

Android compilation error (various OS and NDK versions)

Hello,

I'm trying to compile the android version with:
make android-arm
or
make android-x86
with the atest repo's git files.

I alreay tested with:
macOS High Sierra (all updated XCode and files)
Ubuntu 16.04 64-bit (the 32-bit genie does not works :))
Ubuntu 17.04 64-bit as well

With the NDKs versions:
android-ndk-r10e
android-ndk-r16b (latest)

All with the same error.
First, I set the 3 main env:

ANDROID_NDK_ROOT=/dev/android/android-ndk-r16b
ANDROID_NDK_ARM=/dev/android/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
ANDROID_NDK_CLANG=/dev/android/android-ndk-r16b/toolchains/llvm/prebuilt/linux-x86_64

The first error is the:

In file included from ../../../../bx/src/bx_p.h:42:
../../../../bx/include/bx/bx.h:9:10: fatal error: 'alloca.h' file not found
#include <alloca.h> // alloca
^~~~~~~~~~
1 error generated.
bx.make:395: recipe for target '../../android-arm/obj/Debug/bx/bx/src/allocator.o' failed

It seems that android has not a compat/android-arm or compat/android to put alloca.h, so I removed the #include <alloca.h>.
Then goes to next error:

==== Building bx (debug) ====
allocator.cpp
In file included from ../../../../bx/src/allocator.cpp:6:
In file included from ../../../../bx/src/bx_p.h:42:
In file included from ../../../../bx/include/bx/bx.h:11:
In file included from /dev/android/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/stdint.h:102:
/dev/android/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/__config:169:10: fatal error:
'features.h' file not found
#include <features.h>
^~~~~~~~~~~~
1 error generated.
bx.make:395: recipe for target '../../android-arm/obj/Debug/bx/bx/src/allocator.o' failed

Everytime I try to fix some header (deleting it to check), a new error appears.

Which NDK version should I try?

Thanks.

Scons Build System

I have a Scons project that I am incorporating BGFX into. It would be great to build BGFX from Scons so I am working on the build scripts. I am getting the following errors. Any ideas?

#define DBG_ADDRESS "%" PRIxPTR
                        ^
F:/LibSources/BGFX/bx/src/debug.cpp:111:14: note: to match this '('
                debugPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);
                           ^
F:/LibSources/BGFX/bx/src/debug.cpp:131:23: error: expected ')'
                                        debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
                                                         ^
F:/LibSources/BGFX/bx/src/debug.cpp:98:25: note: expanded from macro 'DBG_ADDRESS'
#define DBG_ADDRESS "%" PRIxPTR
                        ^
F:/LibSources/BGFX/bx/src/debug.cpp:131:17: note: to match this '('
                                        debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
                                                   ^
F:/LibSources/BGFX/bx/src/debug.cpp:141:22: error: expected ')'
                                debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
                                                 ^
F:/LibSources/BGFX/bx/src/debug.cpp:98:25: note: expanded from macro 'DBG_ADDRESS'
#define DBG_ADDRESS "%" PRIxPTR
                        ^
F:/LibSources/BGFX/bx/src/debug.cpp:141:16: note: to match this '('
                                debugPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);

I have built BGFX with Clang using make successfully so it is probably something I am not setting properly.

Android crash on bx::sqrt

I get crashes in android implemnetation on sqrt calls:

I/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x9f8dffe4
05-10 14:36:05.528 273-273/? E/DEBUG: AM write failure (32 / Broken pipe)
05-10 14:36:05.528 273-273/? I/DEBUG: backtrace:
05-10 14:36:05.528 273-273/? I/DEBUG:     #00 pc 00197af4  /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrtSimd(float)+27)
05-10 14:36:05.528 273-273/? I/DEBUG:     #01 pc 00197ad1  /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrt(float)+18)
05-10 14:36:05.528 273-273/? I/DEBUG:     #02 pc 00197b69  /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrtSimd(float)+144)
05-10 14:36:05.528 273-273/? I/DEBUG:     #03 pc 00197ad1  /data/app/com.glitterbombgames.fisherboy-1/lib/arm/libfisherboy.so (bx::sqrt(float)+18)
... 

It seems like it goes through infinite recursive calls and crashes the program due to this implementation:

BX_SIMD_FORCE_INLINE simd128_langext_t simd_sqrt(simd128_langext_t _a)
{
	simd128_langext_t result;
	result.vf[0] = sqrt(_a.vf[0]);
	result.vf[1] = sqrt(_a.vf[1]);
	result.vf[2] = sqrt(_a.vf[2]);
	result.vf[3] = sqrt(_a.vf[3]);
	return result;
}

Semaphore wait times

Hi,
I'm using the SpScBlockingUnboundedQueue in my project a lot and it works great. However, I noticed something strange when I use pop method with wait time. If my wait time is anything over 1000, it seems to be working fine, but when I pass 999 or less, the wait time is very short or nonexistent. So I looked into the semaphore code and found this:

		timespec ts;
		clock_gettime(CLOCK_REALTIME, &ts);
		ts.tv_sec += _msecs/1000;
		ts.tv_nsec += (_msecs%1000)*1000;

Shouldn't it be ts.tv_nsec += (_msecs%1000)*1000000; instead because nanoseconds? Assuming _msecs means milliseconds. I'm running the code on Android.

Thanks,

Luka

Issue with WindowsSDKVersion

The Env variable contains the "default" version for the SDK for Visual Studio to use. However, for some reason, it has a backslash at the end at least on my installation. That backslash ends up in the generated vcxproj files. Apparently MSBuild has no problem with this, but the devenv IDE complains and fails to load the projects.

This fix removes the backslash if present. In toolchain.lua(183), add the line shown below:

local windowsPlatform = os.getenv("WindowsSDKVersion") or "8.1"
windowsPlatform = string.gsub(windowsPlatform, "\\", "") -- <---
if _OPTIONS["with-windows"] then

I suppose a more sophisticated option would be to remove anything that isn't a digit or '.' (devenv seems to complain about not being able to compare the versions as numbers) but without an actual test case I can't recommend it.

Executing genie.exe clean action produces an error

I think the problem could be that line 103 of toolchain.lua referes to BUILD_DIR that doesn't exist.
Possible fix could be to replace BUILD_DIR with _buildDir.

Here below the console error produced:

[string "function os.executef(cmd, ...)..."]:174: attempt to concatenate a nil value (local 'p')
stack traceback:
        [string "function os.executef(cmd, ...)..."]:174: in function 'os.rmdir'
        C:/DEV/GITHUB/bx/scripts/toolchain.lua:103: in function 'toolchain'
        C:/DEV/GITHUB/bgfx/scripts/genie.lua:89: in main chunk
        [C]: in upvalue 'builtin_dofile'
        [string "premake = { }..."]:84: in function 'dofile'
        [string "_WORKING_DIR        = os.getcwd()..."]:41: in function '_premake_main'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.