Merge branch 'master' of ssh://bitbucket.org/bkaradzic/bgfx

This commit is contained in:
bkaradzic 2013-08-07 22:29:04 -07:00
commit 7068c17b01
44 changed files with 911 additions and 362 deletions

View file

@ -266,6 +266,7 @@ Todo
- Occlusion queries.
- DX11: MSAA.
- Fullscreen mode.
- GLES: Support for ETC1 and PVR compressed textures.
Contact
-------

View file

@ -6,9 +6,7 @@
#include "common.h"
#include <bgfx.h>
#include "entry.h"
#include "dbg.h"
#include "processevents.h"
#include "entry/entry.h"
int _main_(int /*_argc*/, char** /*_argv*/)
{
@ -31,7 +29,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -7,10 +7,8 @@
#include <bgfx.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "entry/entry.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -186,7 +184,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -7,10 +7,8 @@
#include <bgfx.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "entry/entry.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -528,7 +526,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -7,10 +7,8 @@
#include <bgfx.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "entry/entry.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -235,7 +233,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -8,10 +8,8 @@
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "entry.h"
#include "dbg.h"
#include "entry/entry.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -334,7 +332,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -7,10 +7,7 @@
#include <bgfx.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -175,7 +172,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -6,12 +6,8 @@
#include "common.h"
#include <bgfx.h>
#include <bx/countof.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include <stdio.h>
#include <string.h>
@ -305,7 +301,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
const bgfx::Memory* mem;
calcTangents(s_cubeVertices, countof(s_cubeVertices), s_PosNormalTangentTexcoordDecl, s_cubeIndices, countof(s_cubeIndices) );
calcTangents(s_cubeVertices, BX_COUNTOF(s_cubeVertices), s_PosNormalTangentTexcoordDecl, s_cubeIndices, BX_COUNTOF(s_cubeIndices) );
// Create static vertex buffer.
mem = bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) );
@ -336,7 +332,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// We can destroy vertex and fragment shader here since
// their reference is kept inside bgfx after calling createProgram.
// Vertex and fragment shader will be destroyed once program is^
// Vertex and fragment shader will be destroyed once program is
// destroyed.
bgfx::destroyVertexShader(vsh);
bgfx::destroyFragmentShader(fsh);
@ -351,7 +347,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -9,7 +9,6 @@
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include <bx/string.h>
#include "dbg.h"
#include "fpumath.h"
#include "aviwriter.h"

View file

@ -8,10 +8,7 @@
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/uint32_t.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include "packrect.h"
#include <stdio.h>
@ -231,7 +228,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
int64_t timeOffset = bx::getHPCounter();
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);

View file

@ -6,13 +6,9 @@
#include "common.h"
#include <bgfx.h>
#include <bx/countof.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include "imgui/imgui.h"
#include <string.h>
@ -515,11 +511,11 @@ int _main_(int /*_argc*/, char** /*_argv*/)
uint32_t oldWidth = 0;
uint32_t oldHeight = 0;
MouseState mouseState;
entry::MouseState mouseState;
float time = 0.0f;
while (!processEvents(width, height, debug, reset, &mouseState) )
while (!entry::processEvents(width, height, debug, reset, &mouseState) )
{
if (oldWidth != width
|| oldHeight != height)

View file

@ -7,12 +7,8 @@
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/countof.h>
#include <bx/string.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include "font/font_manager.h"
#include "font/text_buffer_manager.h"
@ -100,7 +96,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
"font/five_minutes.otf"
};
const uint32_t fontCount = countof(fontNames);
const uint32_t fontCount = BX_COUNTOF(fontNames);
TrueTypeHandle fontFiles[fontCount];
FontHandle fonts[fontCount];
@ -171,7 +167,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Create a transient buffer for real-time data.
TextBufferHandle transientText = textBufferManager->createTextBuffer(FONT_TYPE_ALPHA, BufferType::Transient);
while (!processEvents(width, height, debug, reset) )
while (!entry::processEvents(width, height, debug, reset) )
{
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, width, height);
@ -189,7 +185,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Use transient text to display debug information.
wchar_t fpsText[64];
bx::swnprintf(fpsText, countof(fpsText), L"Frame: % 7.3f[ms]", double(frameTime) * toMs);
bx::swnprintf(fpsText, BX_COUNTOF(fpsText), L"Frame: % 7.3f[ms]", double(frameTime) * toMs);
textBufferManager->clearTextBuffer(transientText);
textBufferManager->setPenPosition(transientText, 20.0, 4.0f);

View file

@ -4,12 +4,10 @@
*/
#include "common.h"
#include <bgfx.h>
#include <bx/timer.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include "font/font_manager.h"
#include "font/text_metrics.h"
@ -172,7 +170,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
textBufferManager->appendText(scrollableBuffer, fontScaled, textBegin, textEnd);
MouseState mouseState;
entry::MouseState mouseState;
int32_t scrollArea = 0;
const int32_t guiPanelWidth = 250;
const int32_t guiPanelHeight = 200;
@ -181,7 +179,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float textScale = 1.0f;
float textSize = 14.0f;
while (!processEvents(width, height, debug, reset, &mouseState) )
while (!entry::processEvents(width, height, debug, reset, &mouseState) )
{
imguiBeginFrame(mouseState.m_mx
, mouseState.m_my

View file

@ -8,10 +8,7 @@
#include <bgfx.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
#include "entry.h"
#include "dbg.h"
#include "fpumath.h"
#include "processevents.h"
#include "imgui/imgui.h"
#include <stdio.h>
@ -405,8 +402,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float at[3] = { 0.0f, 1.0f, 0.0f };
float eye[3] = { 0.0f, 1.0f, -2.0f };
MouseState mouseState;
while (!processEvents(width, height, debug, reset, &mouseState) )
entry::MouseState mouseState;
while (!entry::processEvents(width, height, debug, reset, &mouseState) )
{
imguiBeginFrame(mouseState.m_mx
, mouseState.m_my

View file

@ -3,36 +3,4 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef __COMMON_H__
#define __COMMON_H__
#include "dbg.h"
#if 0
# define BX_TRACE(_format, ...) \
do { \
DBG(BX_FILE_LINE_LITERAL "BGFX " _format "\n", ##__VA_ARGS__); \
} while(0)
# define BX_WARN(_condition, _format, ...) \
do { \
if (!(_condition) ) \
{ \
DBG("WARN " _format, ##__VA_ARGS__); \
} \
} while(0)
# define BX_CHECK(_condition, _format, ...) \
do { \
if (!(_condition) ) \
{ \
DBG("CHECK " _format, ##__VA_ARGS__); \
bx::debugBreak(); \
} \
} while(0)
#endif // 0
#include <bx/bx.h>
#include <bx/debug.h>
#endif // __COMMON_H__
#include "entry/entry.h"

View file

@ -0,0 +1,228 @@
/*
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <ctype.h> // isspace
#include <stdint.h>
#include <stdlib.h> // size_t
#include <string.h> // strlen
#include <bx/hash.h>
#include "dbg.h"
#include "cmd.h"
#include <string>
#include <unordered_map>
// Reference:
// http://msdn.microsoft.com/en-us/library/a1y7w461.aspx
static const char* tokenizeCommandLine(const char* _commandLine, char* _buffer, uint32_t& _bufferSize, int& _argc, char* _argv[], int _maxArgvs, char _term)
{
int argc = 0;
const char* curr = _commandLine;
char* currOut = _buffer;
char term = ' ';
bool sub = false;
enum ParserState
{
SkipWhitespace,
SetTerm,
Copy,
Escape,
End,
};
ParserState state = SkipWhitespace;
while ('\0' != *curr
&& _term != *curr
&& argc < _maxArgvs)
{
switch (state)
{
case SkipWhitespace:
for (; isspace(*curr); ++curr); // skip whitespace
state = SetTerm;
break;
case SetTerm:
if ('"' == *curr)
{
term = '"';
++curr; // skip begining quote
}
else
{
term = ' ';
}
_argv[argc] = currOut;
++argc;
state = Copy;
break;
case Copy:
if ('\\' == *curr)
{
state = Escape;
}
else if ('"' == *curr
&& '"' != term)
{
sub = !sub;
}
else if (isspace(*curr) && !sub)
{
state = End;
}
else if (term != *curr || sub)
{
*currOut = *curr;
++currOut;
}
else
{
state = End;
}
++curr;
break;
case Escape:
{
const char* start = --curr;
for (; '\\' == *curr; ++curr);
if ('"' != *curr)
{
int count = (int)(curr-start);
curr = start;
for (int ii = 0; ii < count; ++ii)
{
*currOut = *curr;
++currOut;
++curr;
}
}
else
{
curr = start+1;
*currOut = *curr;
++currOut;
++curr;
}
}
state = Copy;
break;
case End:
*currOut = '\0';
++currOut;
state = SkipWhitespace;
break;
}
}
*currOut = '\0';
if (0 < argc
&& '\0' == _argv[argc-1][0])
{
--argc;
}
_bufferSize = (uint32_t)(currOut - _buffer);
_argc = argc;
if ('\0' != *curr)
{
++curr;
}
return curr;
}
struct CmdContext
{
CmdContext()
{
}
~CmdContext()
{
}
void add(const char* _name, ConsoleFn _fn, void* _userData)
{
uint32_t cmd = bx::hashMurmur2A(_name, (uint32_t)strlen(_name) );
BX_CHECK(m_lookup.end() == m_lookup.find(cmd), "Command \"%s\" already exist.", _name);
Func fn = { _fn, _userData };
m_lookup.insert(std::make_pair(cmd, fn) );
}
void exec(const char* _cmd)
{
for (const char* next = _cmd; '\0' != *next; _cmd = next)
{
char commandLine[1024];
uint32_t size = sizeof(commandLine);
int argc;
char* argv[64];
next = tokenizeCommandLine(_cmd, commandLine, size, argc, argv, BX_COUNTOF(argv), '\n');
if (argc > 0)
{
int err = -1;
uint32_t cmd = bx::hashMurmur2A(argv[0], (uint32_t)strlen(argv[0]) );
CmdLookup::iterator it = m_lookup.find(cmd);
if (it != m_lookup.end() )
{
Func& fn = it->second;
err = fn.m_fn(this, fn.m_userData, argc, argv);
}
switch (err)
{
case 0:
break;
case -1:
{
std::string tmp(_cmd, next-_cmd - (*next == '\0' ? 0 : 1) );
DBG("Command '%s' doesn't exist.", tmp.c_str() );
}
break;
default:
{
std::string tmp(_cmd, next-_cmd - (*next == '\0' ? 0 : 1) );
DBG("Failed '%s' err: %d.", tmp.c_str(), err);
}
break;
}
}
}
}
struct Func
{
ConsoleFn m_fn;
void* m_userData;
};
typedef std::unordered_map<uint32_t, Func> CmdLookup;
CmdLookup m_lookup;
};
static CmdContext s_cmdContext;
void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData)
{
s_cmdContext.add(_name, _fn, _userData);
}
void cmdExec(const char* _cmd)
{
s_cmdContext.exec(_cmd);
}

View file

@ -0,0 +1,15 @@
/*
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef __CMD_H__
#define __CMD_H__
struct CmdContext;
typedef int (*ConsoleFn)(CmdContext* _context, void* _userData, int _argc, char const* const* _argv);
void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData = NULL);
void cmdExec(const char* _cmd);
#endif // __CMD_H__

View file

@ -3,8 +3,6 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

View file

@ -0,0 +1,190 @@
/*
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include <bgfx.h>
#include <bx/string.h>
#include "entry_p.h"
#include "cmd.h"
#include "input.h"
extern int _main_(int _argc, char** _argv);
namespace entry
{
static uint32_t s_debug = BGFX_DEBUG_NONE;
static uint32_t s_reset = BGFX_RESET_NONE;
static bool s_exit = false;
bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
{
if (0 == strcmp(_argv[_first], _name) )
{
int arg = _first+1;
if (_argc > arg)
{
_flags &= ~_bit;
_flags |= bx::toBool(_argv[arg]) ? _bit : 0;
}
else
{
_flags ^= _bit;
}
return true;
}
return false;
}
void cmd(const void* _userData)
{
cmdExec( (const char*)_userData);
}
int cmdMouseLock(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
{
if (_argc > 1)
{
inputSetMouseLock(_argc > 1 ? bx::toBool(_argv[1]) : !inputIsMouseLocked() );
return 0;
}
return 1;
}
int cmdGraphics(CmdContext* /*_context*/, void* /*_userData*/, int _argc, char const* const* _argv)
{
if (_argc > 1)
{
if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv)
|| setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) )
{
return 0;
}
else if (setOrToggle(s_debug, "stats", BGFX_DEBUG_STATS, 1, _argc, _argv)
|| setOrToggle(s_debug, "ifh", BGFX_DEBUG_IFH, 1, _argc, _argv)
|| setOrToggle(s_debug, "text", BGFX_DEBUG_TEXT, 1, _argc, _argv) )
{
bgfx::setDebug(s_debug);
return 0;
}
}
return 1;
}
int cmdExit(CmdContext* /*_context*/, void* /*_userData*/, int /*_argc*/, char const* const* /*_argv*/)
{
s_exit = true;
return 0;
}
static const InputBinding s_bindings[] =
{
{ entry::Key::KeyQ, entry::Modifier::LeftCtrl, 1, cmd, "exit" },
{ entry::Key::F1, entry::Modifier::None, 1, cmd, "graphics stats" },
{ entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" },
{ entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" },
INPUT_BINDING_END
};
int main(int _argc, char** _argv)
{
cmdAdd("mouselock", cmdMouseLock);
cmdAdd("graphics", cmdGraphics );
cmdAdd("exit", cmdExit );
inputAddBindings("bindings", s_bindings);
int32_t result = ::_main_(_argc, _argv);
return result;
}
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
{
s_debug = _debug;
bool mouseLock = inputIsMouseLocked();
const Event* ev;
do
{
struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
ev = scopeEvent.m_ev;
if (NULL != ev)
{
switch (ev->m_type)
{
case Event::Exit:
return true;
case Event::Mouse:
{
const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
if (mouse->m_move)
{
inputSetMousePos(mouse->m_mx, mouse->m_my);
}
else
{
inputSetMouseButtonState(mouse->m_button, mouse->m_down);
}
if (NULL != _mouse
&& !mouseLock)
{
if (mouse->m_move)
{
_mouse->m_mx = mouse->m_mx;
_mouse->m_my = mouse->m_my;
}
else
{
_mouse->m_buttons[mouse->m_button] = mouse->m_down;
}
}
}
break;
case Event::Key:
{
const KeyEvent* key = static_cast<const KeyEvent*>(ev);
inputSetKeyState(key->m_key, key->m_modifiers, key->m_down);
}
break;
case Event::Size:
{
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
_width = size->m_width;
_height = size->m_height;
_reset = !s_reset; // force reset
}
break;
default:
break;
}
}
} while (NULL != ev);
if (_reset != s_reset)
{
_reset = s_reset;
bgfx::reset(_width, _height, _reset);
inputSetMouseResolution(_width, _height);
}
inputProcess();
_debug = s_debug;
return s_exit;
}
} // namespace entry

View file

@ -6,6 +6,11 @@
#ifndef __ENTRY_H__
#define __ENTRY_H__
#include "dbg.h"
#include <bx/bx.h>
#include <bx/debug.h>
namespace entry
{
struct MouseButton
@ -119,47 +124,24 @@ namespace entry
};
};
struct Event
struct MouseState
{
enum Enum
MouseState()
: m_mx(0)
, m_my(0)
{
Exit,
Key,
Mouse,
Size,
for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
{
m_buttons[ii] = entry::MouseButton::None;
}
}
uint32_t m_mx;
uint32_t m_my;
uint8_t m_buttons[entry::MouseButton::Count];
};
Event::Enum m_type;
};
struct KeyEvent : public Event
{
Key::Enum m_key;
uint8_t m_modifiers;
bool m_down;
};
struct MouseEvent : public Event
{
int32_t m_mx;
int32_t m_my;
MouseButton::Enum m_button;
bool m_down;
bool m_move;
};
struct SizeEvent : public Event
{
uint32_t m_width;
uint32_t m_height;
};
const Event* poll();
void release(const Event* _event);
void setWindowSize(uint32_t _width, uint32_t _height);
void toggleWindowFrame();
void setMouseLock(bool _lock);
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
} // namespace entry

View file

@ -3,7 +3,7 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include "entry.h"
#if BX_PLATFORM_ANDROID
@ -23,8 +23,6 @@ extern "C"
#include <android_native_app_glue.c>
} // extern "C"
extern int _main_(int _argc, char** _argv);
namespace entry
{
struct MainThreadEntry
@ -218,15 +216,13 @@ namespace entry
int32_t MainThreadEntry::threadFunc(void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = _main_(self->m_argc, self->m_argv);
int32_t result = main(self->m_argc, self->m_argv);
// PostMessage(s_ctx.m_hwnd, WM_QUIT, 0, 0);
return result;
}
} // namespace entry
extern int _main_(int _argc, char** _argv);
extern "C" void android_main(android_app* _app)
{
using namespace entry;

View file

@ -3,7 +3,7 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include "entry.h"
#if BX_PLATFORM_LINUX
@ -24,8 +24,6 @@
#define DEFAULT_WIDTH 1280
#define DEFAULT_HEIGHT 720
extern int _main_(int _argc, char** _argv);
namespace entry
{
static uint8_t s_translateKey[512];
@ -33,7 +31,7 @@ namespace entry
static void initTranslateKey(uint16_t _xk, Key::Enum _key)
{
_xk += 256;
BX_CHECK(_xk < countof(s_translateKey), "Out of bounds %d.", _xk);
BX_CHECK(_xk < BX_COUNTOF(s_translateKey), "Out of bounds %d.", _xk);
s_translateKey[_xk&0x1ff] = (uint8_t)_key;
}
@ -295,7 +293,7 @@ namespace entry
int32_t MainThreadEntry::threadFunc(void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = _main_(self->m_argc, self->m_argv);
int32_t result = main(self->m_argc, self->m_argv);
s_ctx.m_exit = true;
return result;
}

View file

@ -3,10 +3,12 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include "entry.h"
#if BX_PLATFORM_NACL
#include "entry_p.h"
#include <stdio.h>
#include <string.h>
#include <pthread.h>
@ -32,8 +34,6 @@
#include "entry.h"
extern int _main_(int _argc, char** _argv);
namespace entry
{
const PPB_Core* g_coreInterface;
@ -112,7 +112,7 @@ namespace entry
PP_Resource resource = g_messageLoopInterface->Create(g_instance);
g_messageLoopInterface->AttachToCurrentThread(resource);
int32_t result = _main_(self->m_argc, self->m_argv);
int32_t result = main(self->m_argc, self->m_argv);
return result;
}

View file

View file

@ -9,11 +9,54 @@
#include <bgfxplatform.h>
#include <bx/spscqueue.h>
#include "dbg.h"
#include "entry.h"
namespace entry
{
int main(int _argc, char** _argv);
struct Event
{
enum Enum
{
Exit,
Key,
Mouse,
Size,
};
Event::Enum m_type;
};
struct KeyEvent : public Event
{
Key::Enum m_key;
uint8_t m_modifiers;
bool m_down;
};
struct MouseEvent : public Event
{
int32_t m_mx;
int32_t m_my;
MouseButton::Enum m_button;
bool m_down;
bool m_move;
};
struct SizeEvent : public Event
{
uint32_t m_width;
uint32_t m_height;
};
const Event* poll();
void release(const Event* _event);
void setWindowSize(uint32_t _width, uint32_t _height);
void toggleWindowFrame();
void setMouseLock(bool _lock);
class EventQueue
{
public:

View file

@ -3,7 +3,7 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include "entry.h"
#if BX_PLATFORM_QNX
@ -35,11 +35,9 @@ namespace entry
} // namespace entry
extern int _main_(int _argc, char** _argv);
int main(int _argc, char** _argv)
{
_main_(_argc, _argv);
entry::main(_argc, _argv);
}
#endif // BX_PLATFORM_QNX

View file

@ -3,13 +3,12 @@
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "common.h"
#include "entry.h"
#if BX_PLATFORM_WINDOWS
#include "entry_p.h"
#include <bx/countof.h>
#include <bx/uint32_t.h>
#include <bx/thread.h>
@ -22,8 +21,6 @@
#define WM_USER_TOGGLE_WINDOW_FRAME (WM_USER+1)
#define WM_USER_MOUSE_LOCK (WM_USER+2)
extern int _main_(int _argc, char** _argv);
namespace entry
{
struct TranslateKeyModifiers
@ -47,7 +44,7 @@ namespace entry
static uint8_t translateKeyModifiers()
{
uint8_t modifiers = 0;
for (uint32_t ii = 0; ii < countof(s_translateKeyModifiers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(s_translateKeyModifiers); ++ii)
{
const TranslateKeyModifiers& tkm = s_translateKeyModifiers[ii];
modifiers |= 0 > GetKeyState(tkm.m_vk) ? tkm.m_modifier : Modifier::None;
@ -626,7 +623,7 @@ namespace entry
int32_t MainThreadEntry::threadFunc(void* _userData)
{
MainThreadEntry* self = (MainThreadEntry*)_userData;
int32_t result = _main_(self->m_argc, self->m_argv);
int32_t result = main(self->m_argc, self->m_argv);
PostMessage(s_ctx.m_hwnd, WM_QUIT, 0, 0);
return result;
}

View file

@ -0,0 +1,251 @@
/*
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#include "entry_p.h"
#include "input.h"
#include <memory.h>
#include <string>
#include <unordered_map>
struct Mouse
{
Mouse()
: m_width(1280)
, m_height(720)
, m_lock(false)
{
}
void reset()
{
if (m_lock)
{
m_norm[0] = 0.0f;
m_norm[1] = 0.0f;
}
memset(m_buttons, 0, sizeof(m_buttons) );
}
void setResolution(uint16_t _width, uint16_t _height)
{
m_width = _width;
m_height = _height;
}
void setPos(int32_t _mx, int32_t _my)
{
m_absolute[0] = _mx;
m_absolute[1] = _my;
m_norm[0] = float(_mx)/float(m_width);
m_norm[1] = float(_my)/float(m_height);
}
void setButtonState(entry::MouseButton::Enum _button, uint8_t _state)
{
m_buttons[_button] = _state;
}
void read(bool _mouseLock)
{
if (_mouseLock != m_lock)
{
m_lock = _mouseLock;
if (_mouseLock)
{
m_norm[0] = 0.0f;
m_norm[1] = 0.0f;
}
}
}
int32_t m_absolute[2];
float m_norm[2];
int32_t m_wheel;
uint8_t m_buttons[entry::MouseButton::Count];
uint16_t m_width;
uint16_t m_height;
bool m_lock;
};
struct Keyboard
{
Keyboard()
{
}
void reset()
{
memset(m_key, 0, sizeof(m_key) );
memset(m_once, 0xff, sizeof(m_once) );
}
static uint32_t encodeKeyState(uint8_t _modifiers, bool _down)
{
uint32_t state = 0;
state |= uint32_t(_modifiers)<<16;
state |= uint32_t(_down)<<8;
return state;
}
static void decodeKeyState(uint32_t _state, uint8_t& _modifiers, bool& _down)
{
_modifiers = (_state>>16)&0xff;
_down = 0 != ( (_state>>8)&0xff);
}
void setKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
{
m_key[_key] = encodeKeyState(_modifiers, _down);
m_once[_key] = false;
}
uint32_t m_key[256];
bool m_once[256];
};
struct Input
{
Input()
{
reset();
}
~Input()
{
}
void addBindings(const char* _name, const InputBinding* _bindings)
{
m_inputBindingsMap.insert(std::make_pair(_name, _bindings) );
}
void removeBindings(const char* _name)
{
m_inputBindingsMap.erase(_name);
}
void process(const InputBinding* _bindings)
{
for (const InputBinding* binding = _bindings; binding->m_key != entry::Key::None; ++binding)
{
uint8_t modifiers;
bool down;
Keyboard::decodeKeyState(m_keyboard.m_key[binding->m_key], modifiers, down);
if (binding->m_flags == 1)
{
if (down
&& modifiers == binding->m_modifiers)
{
if (!m_keyboard.m_once[binding->m_key])
{
binding->m_fn(binding->m_userData);
m_keyboard.m_once[binding->m_key] = true;
}
}
else
{
m_keyboard.m_once[binding->m_key] = false;
}
}
else
{
if (down
&& modifiers == binding->m_modifiers)
{
binding->m_fn(binding->m_userData);
}
}
}
}
void process()
{
m_mouse.read(m_mouse.m_lock);
for (InputBindingMap::const_iterator it = m_inputBindingsMap.begin(); it != m_inputBindingsMap.end(); ++it)
{
process(it->second);
}
}
void reset()
{
m_mouse.reset();
m_keyboard.reset();
}
typedef std::unordered_map<std::string, const InputBinding*> InputBindingMap;
InputBindingMap m_inputBindingsMap;
Mouse m_mouse;
Keyboard m_keyboard;
};
static Input s_input;
void inputAddBindings(const char* _name, const InputBinding* _bindings)
{
s_input.addBindings(_name, _bindings);
}
void inputRemoveBindings(const char* _name)
{
s_input.removeBindings(_name);
}
void inputProcess()
{
s_input.process();
}
void inputSetMouseResolution(uint16_t _width, uint16_t _height)
{
s_input.m_mouse.setResolution(_width, _height);
}
void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
{
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
}
void inputSetMousePos(int32_t _mx, int32_t _my)
{
s_input.m_mouse.setPos(_mx, _my);
}
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state)
{
s_input.m_mouse.setButtonState(_button, _state);
}
void inputGetMouse(float _mouse[2])
{
_mouse[0] = s_input.m_mouse.m_norm[0];
_mouse[1] = s_input.m_mouse.m_norm[1];
s_input.m_mouse.m_norm[0] = 0.0f;
s_input.m_mouse.m_norm[1] = 0.0f;
}
bool inputIsMouseLocked()
{
return s_input.m_mouse.m_lock;
}
void inputSetMouseLock(bool _lock)
{
if (s_input.m_mouse.m_lock != _lock)
{
s_input.m_mouse.m_lock = _lock;
entry::setMouseLock(_lock);
if (_lock)
{
s_input.m_mouse.m_norm[0] = 0.0f;
s_input.m_mouse.m_norm[1] = 0.0f;
}
}
}

View file

@ -0,0 +1,55 @@
/*
* Copyright 2010-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef __INPUT_H__
#define __INPUT_H__
#include <stdint.h>
#include "entry.h"
typedef void (*InputBindingFn)(const void* _userData);
struct InputBinding
{
entry::Key::Enum m_key;
uint8_t m_modifiers;
uint8_t m_flags;
InputBindingFn m_fn;
const void* m_userData;
};
#define INPUT_BINDING_END { entry::Key::None, entry::Modifier::None, NULL, NULL }
///
void inputAddBindings(const char* _name, const InputBinding* _bindings);
///
void inputRemoveBindings(const char* _name);
///
void inputProcess();
///
void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down);
///
void inputSetMouseResolution(uint16_t _width, uint16_t _height);
///
void inputSetMousePos(int32_t _mx, int32_t _my);
///
void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state);
///
void inputSetMouseLock(bool _lock);
///
void inputGetMouse(float _mouse[2]);
///
bool inputIsMouseLocked();
#endif // __INPUT_H__

View file

@ -399,7 +399,7 @@ struct Imgui
drawText(_x + AREA_HEADER / 2
, _y + AREA_HEADER / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _name
, imguiRGBA(255, 255, 255, 128)
);
@ -554,7 +554,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200)
);
@ -563,7 +563,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(128, 128, 128, 200)
);
@ -601,7 +601,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(255, 255, 255, 200)
);
@ -610,7 +610,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(128, 128, 128, 200)
);
@ -671,7 +671,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200)
);
@ -680,7 +680,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(128, 128, 128, 200)
);
@ -731,7 +731,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200)
);
@ -740,7 +740,7 @@ struct Imgui
{
drawText(xx + BUTTON_HEIGHT
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(128, 128, 128, 200)
);
@ -750,7 +750,7 @@ struct Imgui
{
drawText(xx + width - BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_RIGHT
, ImguiTextAlign::Right
, _subtext
, imguiRGBA(255, 255, 255, 128)
);
@ -776,7 +776,7 @@ struct Imgui
m_widgetY += BUTTON_HEIGHT;
drawText(xx
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, out
, imguiRGBA(255, 255, 255, 255)
);
@ -791,7 +791,7 @@ struct Imgui
drawText(xx + ww - BUTTON_HEIGHT / 2
, yy + BUTTON_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_RIGHT
, ImguiTextAlign::Right
, _text
, imguiRGBA(255, 255, 255, 200)
);
@ -889,14 +889,14 @@ struct Imgui
{
drawText(xx + SLIDER_HEIGHT / 2
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200)
);
drawText(xx + width - SLIDER_HEIGHT / 2
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_RIGHT
, ImguiTextAlign::Right
, msg
, isHot(id) ? imguiRGBA(255, 196, 0, 255) : imguiRGBA(255, 255, 255, 200)
);
@ -905,14 +905,14 @@ struct Imgui
{
drawText(xx + SLIDER_HEIGHT / 2
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_LEFT
, ImguiTextAlign::Left
, _text
, imguiRGBA(128, 128, 128, 200)
);
drawText(xx + width - SLIDER_HEIGHT / 2
, yy + SLIDER_HEIGHT / 2 + TEXT_HEIGHT / 2
, IMGUI_ALIGN_RIGHT
, ImguiTextAlign::Right
, msg
, imguiRGBA(128, 128, 128, 200)
);
@ -1247,12 +1247,12 @@ struct Imgui
return len;
}
void drawText(int32_t _x, int32_t _y, imguiTextAlign _align, const char* _text, uint32_t _abgr)
void drawText(int32_t _x, int32_t _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _abgr)
{
drawText( (float)_x, (float)_y, _text, _align, _abgr);
}
void drawText(float _x, float _y, const char* _text, imguiTextAlign _align, uint32_t _abgr)
void drawText(float _x, float _y, const char* _text, ImguiTextAlign::Enum _align, uint32_t _abgr)
{
if (!_text)
{
@ -1260,11 +1260,11 @@ struct Imgui
}
uint32_t numVertices = 0;
if (_align == IMGUI_ALIGN_CENTER)
if (_align == ImguiTextAlign::Center)
{
_x -= getTextLength(m_cdata, _text, numVertices) / 2;
}
else if (_align == IMGUI_ALIGN_RIGHT)
else if (_align == ImguiTextAlign::Right)
{
_x -= getTextLength(m_cdata, _text, numVertices);
}
@ -1505,7 +1505,7 @@ bool imguiSlider(const char* _text, float* _val, float _vmin, float _vmax, float
return s_imgui.slider(_text, _val, _vmin, _vmax, _vinc, _enabled);
}
void imguiDrawText(int32_t _x, int32_t _y, imguiTextAlign _align, const char* _text, uint32_t _argb)
void imguiDrawText(int32_t _x, int32_t _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb)
{
s_imgui.drawText(_x, _y, _align, _text, _argb);
}

View file

@ -26,17 +26,17 @@
#ifndef __IMGUI_H__
#define __IMGUI_H__
enum imguiMouseButton
{
IMGUI_MBUT_LEFT = 0x01,
IMGUI_MBUT_RIGHT = 0x02,
};
#define IMGUI_MBUT_LEFT 0x01
#define IMGUI_MBUT_RIGHT 0x02
enum imguiTextAlign
struct ImguiTextAlign
{
IMGUI_ALIGN_LEFT,
IMGUI_ALIGN_CENTER,
IMGUI_ALIGN_RIGHT,
enum Enum
{
Left,
Center,
Right,
};
};
inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
@ -71,7 +71,7 @@ void imguiLabel(const char* _format, ...);
void imguiValue(const char* _text);
bool imguiSlider(const char* _text, float* val, float vmin, float vmax, float vinc, bool _enabled = true);
void imguiDrawText(int _x, int _y, imguiTextAlign _align, const char* _text, uint32_t _argb);
void imguiDrawText(int _x, int _y, ImguiTextAlign::Enum _align, const char* _text, uint32_t _argb);
void imguiDrawLine(float _x0, float _y0, float _x1, float _y1, float _r, uint32_t _argb);
void imguiDrawRoundedRect(float _x, float _y, float _w, float _h, float _r, uint32_t _argb);
void imguiDrawRect(float _x, float _y, float _w, float _h, uint32_t _argb);

View file

@ -1,130 +0,0 @@
/*
* Copyright 2011-2013 Branimir Karadzic. All rights reserved.
* License: http://www.opensource.org/licenses/BSD-2-Clause
*/
#ifndef __PROCESS_EVENTS_H__
#define __PROCESS_EVENTS_H__
struct MouseState
{
MouseState()
: m_mx(0)
, m_my(0)
{
for (uint32_t ii = 0; ii < entry::MouseButton::Count; ++ii)
{
m_buttons[ii] = entry::MouseButton::None;
}
}
uint32_t m_mx;
uint32_t m_my;
uint8_t m_buttons[entry::MouseButton::Count];
};
inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL)
{
using namespace entry;
bool reset = false;
const Event* ev;
do
{
struct SE { const Event* m_ev; SE() : m_ev(poll() ) {} ~SE() { if (NULL != m_ev) { release(m_ev); } } } scopeEvent;
ev = scopeEvent.m_ev;
if (NULL != ev)
{
switch (ev->m_type)
{
case Event::Exit:
return true;
case Event::Mouse:
if (NULL != _mouse)
{
const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
if (mouse->m_move)
{
_mouse->m_mx = mouse->m_mx;
_mouse->m_my = mouse->m_my;
}
else
{
_mouse->m_buttons[mouse->m_button] = mouse->m_down;
}
}
break;
case Event::Key:
{
const KeyEvent* key = static_cast<const KeyEvent*>(ev);
if ( (key->m_key == Key::KeyQ && (key->m_modifiers & (Modifier::LeftCtrl|Modifier::RightCtrl) ) )
|| ( (key->m_key == Key::Esc) ) )
{
return true;
}
else if (key->m_down)
{
if (key->m_key == Key::F1)
{
_debug ^= BGFX_DEBUG_STATS;
bgfx::setDebug(_debug);
return false;
}
else if (key->m_key == Key::F7)
{
_reset ^= BGFX_RESET_VSYNC;
reset = true;
}
else if (key->m_key == Key::F8)
{
_reset ^= BGFX_RESET_MSAA_X16;
reset = true;
}
else if (key->m_key == Key::F9)
{
setWindowSize(640, 480);
_width = 640;
_height = 480;
}
else if (key->m_key == Key::F10)
{
setWindowSize(1280, 720);
_width = 1280;
_height = 720;
}
else if (key->m_key == Key::F11)
{
toggleWindowFrame();
}
}
}
break;
case Event::Size:
{
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
_width = size->m_width;
_height = size->m_height;
reset = true;
}
break;
default:
break;
}
}
} while (NULL != ev);
if (reset)
{
bgfx::reset(_width, _height, _reset);
}
return false;
}
#endif // __PROCESS_EVENTS_H__

View file

@ -744,7 +744,7 @@ namespace bgfx
memset(m_seq, 0, sizeof(m_seq) );
memset(m_seqMask, 0, sizeof(m_seqMask) );
for (uint32_t ii = 0; ii < countof(m_rect); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_rect); ++ii)
{
m_rect[ii].m_width = 1;
m_rect[ii].m_height = 1;

View file

@ -57,7 +57,6 @@ namespace bgfx
#include <bx/bx.h>
#include <bx/debug.h>
#include <bx/blockalloc.h>
#include <bx/countof.h>
#include <bx/endian.h>
#include <bx/handlealloc.h>
#include <bx/hash.h>

View file

@ -82,7 +82,7 @@ namespace bgfx
{
BX_TRACE("---");
bool valid = true;
for (uint32_t attr = 6; attr < countof(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
for (uint32_t attr = 6; attr < BX_COUNTOF(attrsGlx)-1 && attrsGlx[attr] != None; attr += 2)
{
int value;
glXGetFBConfigAttrib(s_display, configs[ii], attrsGlx[attr], &value);

View file

@ -373,8 +373,8 @@ namespace bgfx
{
BX_TRACE("Adapter #%d", ii);
char description[countof(desc.Description)];
wcstombs(description, desc.Description, countof(desc.Description) );
char description[BX_COUNTOF(desc.Description)];
wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) );
BX_TRACE("\tDescription: %s", description);
BX_TRACE("\tVendorId: 0x%08x, DeviceId: 0x%08x, SubSysId: 0x%08x, Revision: 0x%08x"
, desc.VendorId
@ -478,37 +478,37 @@ namespace bgfx
invalidateCache();
for (uint32_t ii = 0; ii < countof(m_indexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
{
m_indexBuffers[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_vertexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
{
m_vertexBuffers[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_vertexShaders); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexShaders); ++ii)
{
m_vertexShaders[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_fragmentShaders); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_fragmentShaders); ++ii)
{
m_fragmentShaders[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_textures); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
m_textures[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_renderTargets); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_renderTargets); ++ii)
{
m_renderTargets[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_uniforms); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_uniforms); ++ii)
{
m_uniforms[ii].destroy();
}
@ -590,7 +590,7 @@ namespace bgfx
void updateMsaa()
{
for (uint32_t ii = 1, last = 0; ii < countof(s_msaa); ++ii)
for (uint32_t ii = 1, last = 0; ii < BX_COUNTOF(s_msaa); ++ii)
{
uint32_t msaa = s_checkMsaa[ii];
uint32_t quality = 0;
@ -2259,7 +2259,7 @@ namespace bgfx
void Context::rendererUpdateViewName(uint8_t _id, const char* _name)
{
mbstowcs(&s_viewNameW[_id][0], _name, countof(s_viewNameW[0]) );
mbstowcs(&s_viewNameW[_id][0], _name, BX_COUNTOF(s_viewNameW[0]) );
}
void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size)
@ -2864,8 +2864,8 @@ namespace bgfx
tvm.printf(0, pos++, BGFX_CONFIG_DEBUG ? 0x89 : 0x8f, " " BGFX_RENDERER_NAME " ");
const DXGI_ADAPTER_DESC& desc = s_renderCtx.m_adapterDesc;
char description[countof(desc.Description)];
wcstombs(description, desc.Description, countof(desc.Description) );
char description[BX_COUNTOF(desc.Description)];
wcstombs(description, desc.Description, BX_COUNTOF(desc.Description) );
tvm.printf(0, pos++, 0x0f, " Device: %s", description);
tvm.printf(0, pos++, 0x0f, " Memory: %" PRIi64 " (video), %" PRIi64 " (system), %" PRIi64 " (shared)"
, desc.DedicatedVideoMemory

View file

@ -339,7 +339,7 @@ namespace bgfx
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
};
for (uint32_t ii = 0; ii < countof(behaviorFlags) && NULL == m_device; ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(behaviorFlags) && NULL == m_device; ++ii)
{
#if 0 // BGFX_CONFIG_RENDERER_DIRECT3D9EX
DX_CHECK(m_d3d9->CreateDeviceEx(m_adapter
@ -473,37 +473,37 @@ namespace bgfx
{
preReset();
for (uint32_t ii = 0; ii < countof(m_indexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
{
m_indexBuffers[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_vertexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
{
m_vertexBuffers[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_vertexShaders); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexShaders); ++ii)
{
m_vertexShaders[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_fragmentShaders); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_fragmentShaders); ++ii)
{
m_fragmentShaders[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_textures); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
m_textures[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_vertexDecls); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexDecls); ++ii)
{
m_vertexDecls[ii].destroy();
}
for (uint32_t ii = 0; ii < countof(m_renderTargets); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_renderTargets); ++ii)
{
m_renderTargets[ii].destroy();
}
@ -532,7 +532,7 @@ namespace bgfx
void updateMsaa()
{
for (uint32_t ii = 1, last = 0; ii < countof(s_checkMsaa); ++ii)
for (uint32_t ii = 1, last = 0; ii < BX_COUNTOF(s_checkMsaa); ++ii)
{
D3DMULTISAMPLE_TYPE msaa = s_checkMsaa[ii];
DWORD quality;
@ -730,17 +730,17 @@ namespace bgfx
capturePreReset();
for (uint32_t ii = 0; ii < countof(m_indexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
{
m_indexBuffers[ii].preReset();
}
for (uint32_t ii = 0; ii < countof(m_vertexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
{
m_vertexBuffers[ii].preReset();
}
for (uint32_t ii = 0; ii < countof(m_renderTargets); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_renderTargets); ++ii)
{
m_renderTargets[ii].preReset();
}
@ -753,17 +753,17 @@ namespace bgfx
capturePostReset();
for (uint32_t ii = 0; ii < countof(m_indexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii)
{
m_indexBuffers[ii].postReset();
}
for (uint32_t ii = 0; ii < countof(m_vertexBuffers); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_vertexBuffers); ++ii)
{
m_vertexBuffers[ii].postReset();
}
for (uint32_t ii = 0; ii < countof(m_renderTargets); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(m_renderTargets); ++ii)
{
m_renderTargets[ii].postReset();
}
@ -2196,7 +2196,7 @@ namespace bgfx
void Context::rendererUpdateViewName(uint8_t _id, const char* _name)
{
mbstowcs(&s_viewNameW[_id][0], _name, countof(s_viewNameW[0]) );
mbstowcs(&s_viewNameW[_id][0], _name, BX_COUNTOF(s_viewNameW[0]) );
}
void Context::rendererUpdateUniform(uint16_t _loc, const void* _data, uint32_t _size)

View file

@ -1212,7 +1212,7 @@ namespace bgfx
m_used[used] = Attrib::Count;
used = 0;
for (uint32_t ii = 0; ii < countof(s_instanceDataName); ++ii)
for (uint32_t ii = 0; ii < BX_COUNTOF(s_instanceDataName); ++ii)
{
GLuint loc = glGetAttribLocation(m_id, s_instanceDataName[ii]);
if (GLuint(-1) != loc )

View file

@ -650,12 +650,12 @@ namespace bgfx
{
void create()
{
glGenQueries(countof(m_queries), m_queries);
glGenQueries(BX_COUNTOF(m_queries), m_queries);
}
void destroy()
{
glDeleteQueries(countof(m_queries), m_queries);
glDeleteQueries(BX_COUNTOF(m_queries), m_queries);
}
void begin(uint16_t _id, GLenum _target) const

View file

@ -7,7 +7,6 @@
#include <bx/debug.h>
#include <bx/hash.h>
#include <bx/uint32_t.h>
#include <bx/countof.h>
#include <bx/string.h>
#include "vertexdecl.h"

View file

@ -11,7 +11,6 @@
#include <string.h>
#include <algorithm>
#include <vector>
namespace std { namespace tr1 {} using namespace tr1; } // namespace std
#include <unordered_map>
#include <forsythtriangleorderoptimizer.h>
@ -51,7 +50,6 @@ namespace std { namespace tr1 {} using namespace tr1; } // namespace std
#include <bx/bx.h>
#include <bx/debug.h>
#include <bx/countof.h>
#include <bx/commandline.h>
#include <bx/timer.h>
#include <bx/readerwriter.h>
@ -429,7 +427,7 @@ int main(int _argc, const char* _argv[])
const char* next = data;
do
{
next = tokenizeCommandLine(next, commandLine, len, argc, argv, countof(argv), '\n');
next = tokenizeCommandLine(next, commandLine, len, argc, argv, BX_COUNTOF(argv), '\n');
if (0 < argc)
{
if (0 == strcmp(argv[0], "#") )

View file

@ -18,8 +18,6 @@
#include <vector>
#include <unordered_map>
namespace std { namespace tr1 {} using namespace tr1; } // namespace std
#define MAX_TAGS 256
extern "C"
{
@ -36,7 +34,6 @@ extern "C"
#include <bx/bx.h>
#include <bx/commandline.h>
#include <bx/countof.h>
#include <bx/endian.h>
#include <bx/uint32_t.h>
#include <bx/readerwriter.h>
@ -568,7 +565,7 @@ bool compileHLSLShaderDx9(bx::CommandLine& _cmdLine, const std::string& _code, b
uint32_t optimization = 3;
if (_cmdLine.hasArg(optimization, 'O') )
{
optimization = bx::uint32_min(optimization, countof(s_optimizationLevelDx9)-1);
optimization = bx::uint32_min(optimization, BX_COUNTOF(s_optimizationLevelDx9)-1);
flags |= s_optimizationLevelDx9[optimization];
}
else
@ -749,7 +746,7 @@ bool compileHLSLShaderDx11(bx::CommandLine& _cmdLine, const std::string& _code,
uint32_t optimization = 3;
if (_cmdLine.hasArg(optimization, 'O') )
{
optimization = bx::uint32_min(optimization, countof(s_optimizationLevelDx11)-1);
optimization = bx::uint32_min(optimization, BX_COUNTOF(s_optimizationLevelDx11)-1);
flags |= s_optimizationLevelDx11[optimization];
}
else
@ -1051,7 +1048,7 @@ struct Preprocessor
void setDefaultDefine(const char* _name)
{
char temp[1024];
bx::snprintf(temp, countof(temp)
bx::snprintf(temp, BX_COUNTOF(temp)
, "#ifndef %s\n"
"# define %s 0\n"
"#endif // %s\n"