mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2025-04-29 15:34:10 -04:00
Updated to OVR 0.4.3. Added support for event char to read keyboard text input.
This commit is contained in:
parent
ace930ebd9
commit
31efb2991f
13 changed files with 146 additions and 25 deletions
examples
10-font
common
include
src
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "font/font_manager.h"
|
#include "font/font_manager.h"
|
||||||
#include "font/text_buffer_manager.h"
|
#include "font/text_buffer_manager.h"
|
||||||
|
#include "entry/input.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
@ -192,8 +193,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
textBufferManager->appendText(transientText, visitor10, L"text buffer\n");
|
textBufferManager->appendText(transientText, visitor10, L"text buffer\n");
|
||||||
textBufferManager->appendText(transientText, visitor10, fpsText);
|
textBufferManager->appendText(transientText, visitor10, fpsText);
|
||||||
|
|
||||||
float at[3] = { 0, 0, 0.0f };
|
float at[3] = { 0, 0, 0.0f };
|
||||||
float eye[3] = {0, 0, -1.0f };
|
float eye[3] = { 0, 0, -1.0f };
|
||||||
|
|
||||||
float view[16];
|
float view[16];
|
||||||
bx::mtxLookAt(view, eye, at);
|
bx::mtxLookAt(view, eye, at);
|
||||||
|
@ -211,8 +212,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
|
||||||
time += 0.05f;
|
time += 0.05f;
|
||||||
|
|
||||||
const float dist = 10.0f;
|
const float dist = 10.0f;
|
||||||
const float offset0 = -proj[8] + (hmd->eye[0].adjust[0] / dist * proj[0]);
|
const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]);
|
||||||
const float offset1 = -proj[8] + (hmd->eye[1].adjust[0] / dist * proj[0]);
|
const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
|
||||||
|
|
||||||
float ortho[2][16];
|
float ortho[2][16];
|
||||||
const float offsetx = width/2.0f;
|
const float offsetx = width/2.0f;
|
||||||
|
|
|
@ -242,12 +242,12 @@ namespace entry
|
||||||
if (_shiftModifier)
|
if (_shiftModifier)
|
||||||
{
|
{
|
||||||
// Big letters.
|
// Big letters.
|
||||||
if(ascii >= 'a' && ascii <= 'z')
|
if (ascii >= 'a' && ascii <= 'z')
|
||||||
{
|
{
|
||||||
ascii += 'A' - 'a';
|
ascii += 'A' - 'a';
|
||||||
}
|
}
|
||||||
// Special cases.
|
// Special cases.
|
||||||
else if('-' == ascii)
|
else if ('-' == ascii)
|
||||||
{
|
{
|
||||||
ascii = '_';
|
ascii = '_';
|
||||||
}
|
}
|
||||||
|
@ -322,6 +322,13 @@ namespace entry
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Event::Char:
|
||||||
|
{
|
||||||
|
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||||
|
inputChar(chev->m_len, chev->m_char);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Event::Size:
|
case Event::Size:
|
||||||
{
|
{
|
||||||
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
||||||
|
@ -440,6 +447,14 @@ namespace entry
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Event::Char:
|
||||||
|
{
|
||||||
|
const CharEvent* chev = static_cast<const CharEvent*>(ev);
|
||||||
|
win.m_handle = chev->m_handle;
|
||||||
|
inputChar(chev->m_len, chev->m_char);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case Event::Size:
|
case Event::Size:
|
||||||
{
|
{
|
||||||
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
const SizeEvent* size = static_cast<const SizeEvent*>(ev);
|
||||||
|
|
|
@ -45,6 +45,7 @@ namespace entry
|
||||||
{
|
{
|
||||||
Exit,
|
Exit,
|
||||||
Key,
|
Key,
|
||||||
|
Char,
|
||||||
Mouse,
|
Mouse,
|
||||||
Size,
|
Size,
|
||||||
Window,
|
Window,
|
||||||
|
@ -75,6 +76,14 @@ namespace entry
|
||||||
bool m_down;
|
bool m_down;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct CharEvent : public Event
|
||||||
|
{
|
||||||
|
ENTRY_IMPLEMENT_EVENT(CharEvent, Event::Char);
|
||||||
|
|
||||||
|
uint8_t m_len;
|
||||||
|
uint8_t m_char[4];
|
||||||
|
};
|
||||||
|
|
||||||
struct MouseEvent : public Event
|
struct MouseEvent : public Event
|
||||||
{
|
{
|
||||||
ENTRY_IMPLEMENT_EVENT(MouseEvent, Event::Mouse);
|
ENTRY_IMPLEMENT_EVENT(MouseEvent, Event::Mouse);
|
||||||
|
@ -124,6 +133,14 @@ namespace entry
|
||||||
m_queue.push(ev);
|
m_queue.push(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void postCharEvent(WindowHandle _handle, uint8_t _len, const uint8_t _char[4])
|
||||||
|
{
|
||||||
|
CharEvent* ev = new CharEvent(_handle);
|
||||||
|
ev->m_len = _len;
|
||||||
|
memcpy(ev->m_char, _char, 4);
|
||||||
|
m_queue.push(ev);
|
||||||
|
}
|
||||||
|
|
||||||
void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz)
|
void postMouseEvent(WindowHandle _handle, int32_t _mx, int32_t _my, int32_t _mz)
|
||||||
{
|
{
|
||||||
MouseEvent* ev = new MouseEvent(_handle);
|
MouseEvent* ev = new MouseEvent(_handle);
|
||||||
|
|
|
@ -532,6 +532,26 @@ namespace entry
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case WM_CHAR:
|
||||||
|
{
|
||||||
|
uint8_t utf8[4] = {};
|
||||||
|
uint8_t len = (uint8_t)WideCharToMultiByte(CP_UTF8
|
||||||
|
, 0
|
||||||
|
, (LPCWSTR)&_wparam
|
||||||
|
, 1
|
||||||
|
, (LPSTR)utf8
|
||||||
|
, BX_COUNTOF(utf8)
|
||||||
|
, NULL
|
||||||
|
, NULL
|
||||||
|
);
|
||||||
|
if (0 != len)
|
||||||
|
{
|
||||||
|
WindowHandle handle = findHandle(_hwnd);
|
||||||
|
m_eventQueue.postCharEvent(handle, len, utf8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "entry_p.h"
|
#include "entry_p.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
|
#include <bx/ringbuffer.h>
|
||||||
#include <tinystl/allocator.h>
|
#include <tinystl/allocator.h>
|
||||||
#include <tinystl/unordered_map.h>
|
#include <tinystl/unordered_map.h>
|
||||||
namespace stl = tinystl;
|
namespace stl = tinystl;
|
||||||
|
@ -68,6 +69,7 @@ struct Mouse
|
||||||
struct Keyboard
|
struct Keyboard
|
||||||
{
|
{
|
||||||
Keyboard()
|
Keyboard()
|
||||||
|
: m_ring(BX_COUNTOF(m_char) )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +99,44 @@ struct Keyboard
|
||||||
m_once[_key] = false;
|
m_once[_key] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void pushChar(uint8_t _len, const uint8_t _char[4])
|
||||||
|
{
|
||||||
|
for (uint32_t len = m_ring.reserve(4)
|
||||||
|
; len < _len
|
||||||
|
; len = m_ring.reserve(4)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
popChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&m_char[m_ring.m_write], _char, 4);
|
||||||
|
m_ring.commit(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* popChar()
|
||||||
|
{
|
||||||
|
if (0 < m_ring.available() )
|
||||||
|
{
|
||||||
|
uint8_t* utf8 = &m_char[m_ring.m_read];
|
||||||
|
m_ring.consume(4);
|
||||||
|
return utf8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void charFlush()
|
||||||
|
{
|
||||||
|
m_ring.m_current = 0;
|
||||||
|
m_ring.m_write = 0;
|
||||||
|
m_ring.m_read = 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t m_key[256];
|
uint32_t m_key[256];
|
||||||
bool m_once[256];
|
bool m_once[256];
|
||||||
|
|
||||||
|
bx::RingBufferControl m_ring;
|
||||||
|
uint8_t m_char[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Input
|
struct Input
|
||||||
|
@ -204,6 +242,21 @@ void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down)
|
||||||
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
|
s_input.m_keyboard.setKeyState(_key, _modifiers, _down);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void inputChar(uint8_t _len, const uint8_t _char[4])
|
||||||
|
{
|
||||||
|
s_input.m_keyboard.pushChar(_len, _char);
|
||||||
|
}
|
||||||
|
|
||||||
|
const uint8_t* inputGetChar()
|
||||||
|
{
|
||||||
|
return s_input.m_keyboard.popChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void inputCharFlush()
|
||||||
|
{
|
||||||
|
s_input.m_keyboard.charFlush();
|
||||||
|
}
|
||||||
|
|
||||||
void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz)
|
void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz)
|
||||||
{
|
{
|
||||||
s_input.m_mouse.setPos(_mx, _my, _mz);
|
s_input.m_mouse.setPos(_mx, _my, _mz);
|
||||||
|
|
|
@ -34,6 +34,15 @@ void inputProcess();
|
||||||
///
|
///
|
||||||
void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down);
|
void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down);
|
||||||
|
|
||||||
|
/// Adds single UTF-8 encoded character into input buffer.
|
||||||
|
void inputChar(uint8_t _len, const uint8_t _char[4]);
|
||||||
|
|
||||||
|
/// Returns single UTF-8 encoded character from input buffer.
|
||||||
|
const uint8_t* inputGetChar();
|
||||||
|
|
||||||
|
/// Flush internal input buffer.
|
||||||
|
void inputCharFlush();
|
||||||
|
|
||||||
///
|
///
|
||||||
void inputSetMouseResolution(uint16_t _width, uint16_t _height);
|
void inputSetMouseResolution(uint16_t _width, uint16_t _height);
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,13 @@ void TextBuffer::appendText(FontHandle _fontHandle, const char* _string, const c
|
||||||
CodePoint codepoint = 0;
|
CodePoint codepoint = 0;
|
||||||
uint32_t state = 0;
|
uint32_t state = 0;
|
||||||
|
|
||||||
for (; *_string && _string<_end ; ++_string)
|
if (_end == NULL)
|
||||||
|
{
|
||||||
|
_end = _string + strlen(_string);
|
||||||
|
}
|
||||||
|
BX_CHECK(_end >= _string);
|
||||||
|
|
||||||
|
for (; *_string && _string < _end ; ++_string)
|
||||||
{
|
{
|
||||||
if (utf8_decode(&state, (uint32_t*)&codepoint, *_string) == UTF8_ACCEPT )
|
if (utf8_decode(&state, (uint32_t*)&codepoint, *_string) == UTF8_ACCEPT )
|
||||||
{
|
{
|
||||||
|
@ -260,7 +266,7 @@ void TextBuffer::appendText(FontHandle _fontHandle, const wchar_t* _string, cons
|
||||||
|
|
||||||
if (_end == NULL)
|
if (_end == NULL)
|
||||||
{
|
{
|
||||||
_end = _string + (uint32_t) wcslen(_string);
|
_end = _string + wcslen(_string);
|
||||||
}
|
}
|
||||||
BX_CHECK(_end >= _string);
|
BX_CHECK(_end >= _string);
|
||||||
|
|
||||||
|
|
|
@ -162,9 +162,9 @@ void TextLineMetrics::getSubText(const char* _string, uint32_t _firstLine, uint3
|
||||||
{
|
{
|
||||||
for (; *_string; ++_string)
|
for (; *_string; ++_string)
|
||||||
{
|
{
|
||||||
if(utf8_decode(&state, (uint32_t*)&codepoint, *_string) == UTF8_ACCEPT)
|
if (utf8_decode(&state, (uint32_t*)&codepoint, *_string) == UTF8_ACCEPT)
|
||||||
{
|
{
|
||||||
if(codepoint == L'\n')
|
if (codepoint == L'\n')
|
||||||
{
|
{
|
||||||
++currentLine;
|
++currentLine;
|
||||||
++_string;
|
++_string;
|
||||||
|
|
|
@ -788,8 +788,8 @@ struct Imgui
|
||||||
time += 0.05f;
|
time += 0.05f;
|
||||||
|
|
||||||
const float dist = 10.0f;
|
const float dist = 10.0f;
|
||||||
const float offset0 = -proj[8] + (hmd->eye[0].adjust[0] / dist * proj[0]);
|
const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]);
|
||||||
const float offset1 = -proj[8] + (hmd->eye[1].adjust[0] / dist * proj[0]);
|
const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
|
||||||
|
|
||||||
float ortho[2][16];
|
float ortho[2][16];
|
||||||
const float viewOffset = _width/4.0f;
|
const float viewOffset = _width/4.0f;
|
||||||
|
|
|
@ -378,7 +378,7 @@ namespace bgfx
|
||||||
float rotation[4]; //!< Eye rotation represented as quaternion.
|
float rotation[4]; //!< Eye rotation represented as quaternion.
|
||||||
float translation[3]; //!< Eye translation.
|
float translation[3]; //!< Eye translation.
|
||||||
float fov[4]; //!< Field of view (up, down, left, right).
|
float fov[4]; //!< Field of view (up, down, left, right).
|
||||||
float adjust[3]; //!< Eye view matrix translation adjustment.
|
float viewOffset[3]; //!< Eye view matrix translation adjustment.
|
||||||
float pixelsPerTanAngle[2]; //!<
|
float pixelsPerTanAngle[2]; //!<
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
12
src/ovr.cpp
12
src/ovr.cpp
|
@ -153,8 +153,8 @@ ovrError:
|
||||||
|
|
||||||
m_timing = ovrHmd_BeginFrame(m_hmd, 0);
|
m_timing = ovrHmd_BeginFrame(m_hmd, 0);
|
||||||
|
|
||||||
m_pose[0] = ovrHmd_GetEyePose(m_hmd, ovrEye_Left);
|
m_pose[0] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Left);
|
||||||
m_pose[1] = ovrHmd_GetEyePose(m_hmd, ovrEye_Right);
|
m_pose[1] = ovrHmd_GetHmdPosePerEye(m_hmd, ovrEye_Right);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ ovrError:
|
||||||
for (int ii = 0; ii < 2; ++ii)
|
for (int ii = 0; ii < 2; ++ii)
|
||||||
{
|
{
|
||||||
ovrPosef& pose = m_pose[ii];
|
ovrPosef& pose = m_pose[ii];
|
||||||
pose = ovrHmd_GetEyePose(m_hmd, eye[ii]);
|
pose = ovrHmd_GetHmdPosePerEye(m_hmd, eye[ii]);
|
||||||
|
|
||||||
HMD::Eye& eye = _hmd.eye[ii];
|
HMD::Eye& eye = _hmd.eye[ii];
|
||||||
eye.rotation[0] = pose.Orientation.x;
|
eye.rotation[0] = pose.Orientation.x;
|
||||||
|
@ -191,9 +191,9 @@ ovrError:
|
||||||
eye.fov[1] = erd.Fov.DownTan;
|
eye.fov[1] = erd.Fov.DownTan;
|
||||||
eye.fov[2] = erd.Fov.LeftTan;
|
eye.fov[2] = erd.Fov.LeftTan;
|
||||||
eye.fov[3] = erd.Fov.RightTan;
|
eye.fov[3] = erd.Fov.RightTan;
|
||||||
eye.adjust[0] = erd.ViewAdjust.x;
|
eye.viewOffset[0] = erd.HmdToEyeViewOffset.x;
|
||||||
eye.adjust[1] = erd.ViewAdjust.y;
|
eye.viewOffset[1] = erd.HmdToEyeViewOffset.y;
|
||||||
eye.adjust[2] = erd.ViewAdjust.z;
|
eye.viewOffset[2] = erd.HmdToEyeViewOffset.z;
|
||||||
eye.pixelsPerTanAngle[0] = erd.PixelsPerTanAngleAtCenter.x;
|
eye.pixelsPerTanAngle[0] = erd.PixelsPerTanAngleAtCenter.x;
|
||||||
eye.pixelsPerTanAngle[1] = erd.PixelsPerTanAngleAtCenter.y;
|
eye.pixelsPerTanAngle[1] = erd.PixelsPerTanAngleAtCenter.y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2967,9 +2967,9 @@ RENDERDOC_IMPORT
|
||||||
for (uint32_t eye = 0; eye < 2; ++eye)
|
for (uint32_t eye = 0; eye < 2; ++eye)
|
||||||
{
|
{
|
||||||
const HMD::Eye& hmdEye = hmd.eye[eye];
|
const HMD::Eye& hmdEye = hmd.eye[eye];
|
||||||
viewAdjust.un.val[12] = hmdEye.adjust[0];
|
viewAdjust.un.val[12] = hmdEye.viewOffset[0];
|
||||||
viewAdjust.un.val[13] = hmdEye.adjust[1];
|
viewAdjust.un.val[13] = hmdEye.viewOffset[1];
|
||||||
viewAdjust.un.val[14] = hmdEye.adjust[2];
|
viewAdjust.un.val[14] = hmdEye.viewOffset[2];
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4136,9 +4136,9 @@ namespace bgfx
|
||||||
for (uint32_t eye = 0; eye < 2; ++eye)
|
for (uint32_t eye = 0; eye < 2; ++eye)
|
||||||
{
|
{
|
||||||
const HMD::Eye& hmdEye = hmd.eye[eye];
|
const HMD::Eye& hmdEye = hmd.eye[eye];
|
||||||
viewAdjust.un.val[12] = hmdEye.adjust[0];
|
viewAdjust.un.val[12] = hmdEye.viewOffset[0];
|
||||||
viewAdjust.un.val[13] = hmdEye.adjust[1];
|
viewAdjust.un.val[13] = hmdEye.viewOffset[1];
|
||||||
viewAdjust.un.val[14] = hmdEye.adjust[2];
|
viewAdjust.un.val[14] = hmdEye.viewOffset[2];
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
for (uint32_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue