This commit is contained in:
Mike Popoloski 2014-11-15 13:32:22 -05:00
commit 893035af65
24 changed files with 369 additions and 254 deletions

View file

@ -1,10 +1,10 @@
[*] [*]
indent_style = tab indent_style = tab
indent_size = 4 indent_size = 4
end_of_line = LF end_of_line = lf
max_line_length = 100 max_line_length = 100
insert_final_newline = true insert_final_newline = true
[{*.c, *.cpp, *.sc, *.sh, *.lua, *.m, *.mm, *.mk, makefile}]
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

View file

@ -21,6 +21,7 @@
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <c99_compat.h>
/* end standard C headers. */ /* end standard C headers. */

View file

@ -25,6 +25,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <c99_compat.h>
#include "glcpp.h" #include "glcpp.h"
#include "glcpp-parse.h" #include "glcpp-parse.h"

View file

@ -44,13 +44,13 @@ _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
} }
void void
_mesa_shader_debug(struct gl_context *, GLenum, GLuint *id, _mesa_shader_debug(struct gl_context *, GLenum, GLuint *,
const char *, int) const char *, int)
{ {
} }
extern "C" void extern "C" void
_mesa_error_no_memory(const char *caller) _mesa_error_no_memory(const char *)
{ {
} }

View file

@ -236,7 +236,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float speed = 0.37f; float speed = 0.37f;
float middleGray = 0.18f; float middleGray = 0.18f;
float white = 1.1f; float white = 1.1f;
float treshold = 1.5f; float threshold = 1.5f;
int32_t scrollArea = 0; int32_t scrollArea = 0;
@ -285,7 +285,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
imguiSlider("Middle gray", middleGray, 0.1f, 1.0f, 0.01f); imguiSlider("Middle gray", middleGray, 0.1f, 1.0f, 0.01f);
imguiSlider("White point", white, 0.1f, 2.0f, 0.01f); imguiSlider("White point", white, 0.1f, 2.0f, 0.01f);
imguiSlider("Treshold", treshold, 0.1f, 2.0f, 0.01f); imguiSlider("Threshold", threshold, 0.1f, 2.0f, 0.01f);
imguiEndScrollArea(); imguiEndScrollArea();
imguiEndFrame(); imguiEndFrame();
@ -425,10 +425,10 @@ int _main_(int /*_argc*/, char** /*_argv*/)
screenSpaceQuad(1.0f, 1.0f, s_originBottomLeft); screenSpaceQuad(1.0f, 1.0f, s_originBottomLeft);
bgfx::submit(6); bgfx::submit(6);
float tonemap[4] = { middleGray, square(white), treshold, 0.0f }; float tonemap[4] = { middleGray, square(white), threshold, 0.0f };
bgfx::setUniform(u_tonemap, tonemap); bgfx::setUniform(u_tonemap, tonemap);
// Bright pass treshold is tonemap[3]. // Bright pass threshold is tonemap[3].
setOffsets4x4Lum(u_offset, width/2, height/2); setOffsets4x4Lum(u_offset, width/2, height/2);
bgfx::setTexture(0, u_texColor, fbtextures[0]); bgfx::setTexture(0, u_texColor, fbtextures[0]);
bgfx::setTexture(1, u_texLum, lum[4]); bgfx::setTexture(1, u_texLum, lum[4]);

View file

@ -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>
@ -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;

View file

@ -217,8 +217,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 viewOffset = width/4.0f; const float viewOffset = width/4.0f;

View file

@ -118,6 +118,7 @@ namespace entry
{ entry::Key::F3, entry::Modifier::None, 1, cmd, "graphics wireframe" }, { entry::Key::F3, entry::Modifier::None, 1, cmd, "graphics wireframe" },
{ entry::Key::F4, entry::Modifier::None, 1, cmd, "graphics hmd" }, { entry::Key::F4, entry::Modifier::None, 1, cmd, "graphics hmd" },
{ entry::Key::F4, entry::Modifier::LeftShift, 1, cmd, "graphics hmdrecenter" }, { entry::Key::F4, entry::Modifier::LeftShift, 1, cmd, "graphics hmdrecenter" },
{ entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" },
{ entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" }, { entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" },
{ entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" }, { entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" },
{ entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" }, { entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" },
@ -156,110 +157,6 @@ namespace entry
return result; return result;
} }
char keyToAscii(entry::Key::Enum _key, bool _shiftModifier)
{
static const char s_keyToAscii[entry::Key::Count] =
{
'\0', // None
0x1b, // Esc
0x0d, // Return
0x09, // Tab
0x20, // Space
0x08, // Backspace
'\0', // Up
'\0', // Down
'\0', // Left
'\0', // Right
'\0', // PageUp
'\0', // PageDown
'\0', // Home
'\0', // End
'\0', // Print
0x3d, // Equals
0x2d, // Minus
'\0', // F1
'\0', // F2
'\0', // F3
'\0', // F4
'\0', // F5
'\0', // F6
'\0', // F7
'\0', // F8
'\0', // F9
'\0', // F10
'\0', // F11
'\0', // F12
0x30, // NumPad0
0x31, // NumPad1
0x32, // NumPad2
0x33, // NumPad3
0x34, // NumPad4
0x35, // NumPad5
0x36, // NumPad6
0x37, // NumPad7
0x38, // NumPad8
0x39, // NumPad9
0x30, // Key0
0x31, // Key1
0x32, // Key2
0x33, // Key3
0x34, // Key4
0x35, // Key5
0x36, // Key6
0x37, // Key7
0x38, // Key8
0x39, // Key9
0x61, // KeyA
0x62, // KeyB
0x63, // KeyC
0x64, // KeyD
0x65, // KeyE
0x66, // KeyF
0x67, // KeyG
0x68, // KeyH
0x69, // KeyI
0x6a, // KeyJ
0x6b, // KeyK
0x6c, // KeyL
0x6d, // KeyM
0x6e, // KeyN
0x6f, // KeyO
0x70, // KeyP
0x71, // KeyQ
0x72, // KeyR
0x73, // KeyS
0x74, // KeyT
0x75, // KeyU
0x76, // KeyV
0x77, // KeyW
0x78, // KeyX
0x79, // KeyY
0x7a, // KeyZ
};
char ascii = s_keyToAscii[_key];
if (_shiftModifier)
{
// Big letters.
if(ascii >= 'a' && ascii <= 'z')
{
ascii += 'A' - 'a';
}
// Special cases.
else if('-' == ascii)
{
ascii = '_';
}
else if ('=' == ascii)
{
ascii = '+';
}
}
return ascii;
}
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse) bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse)
{ {
s_debug = _debug; s_debug = _debug;
@ -322,6 +219,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 +344,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);

View file

@ -155,7 +155,6 @@ namespace entry
uint8_t m_buttons[entry::MouseButton::Count]; uint8_t m_buttons[entry::MouseButton::Count];
}; };
char keyToAscii(entry::Key::Enum _key, bool _shiftModifier);
bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL); bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset, MouseState* _mouse = NULL);
bx::FileReaderI* getFileReader(); bx::FileReaderI* getFileReader();

View file

@ -9,6 +9,7 @@
#include <bx/spscqueue.h> #include <bx/spscqueue.h>
#include "entry.h" #include "entry.h"
#include <string.h> // memcpy
#ifndef ENTRY_CONFIG_USE_SDL #ifndef ENTRY_CONFIG_USE_SDL
# define ENTRY_CONFIG_USE_SDL 0 # define ENTRY_CONFIG_USE_SDL 0
@ -45,6 +46,7 @@ namespace entry
{ {
Exit, Exit,
Key, Key,
Char,
Mouse, Mouse,
Size, Size,
Window, Window,
@ -75,6 +77,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 +134,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);

View file

@ -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;
} }

View file

@ -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_current], _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
@ -119,7 +157,11 @@ struct Input
void removeBindings(const char* _name) void removeBindings(const char* _name)
{ {
m_inputBindingsMap.erase(m_inputBindingsMap.find(_name)); InputBindingMap::iterator it = m_inputBindingsMap.find(_name);
if (it != m_inputBindingsMap.end() )
{
m_inputBindingsMap.erase(it);
}
} }
void process(const InputBinding* _bindings) void process(const InputBinding* _bindings)
@ -204,6 +246,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);

View file

@ -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);

View file

@ -236,6 +236,12 @@ void TextBuffer::appendText(FontHandle _fontHandle, const char* _string, const c
CodePoint codepoint = 0; CodePoint codepoint = 0;
uint32_t state = 0; uint32_t state = 0;
if (_end == NULL)
{
_end = _string + strlen(_string);
}
BX_CHECK(_end >= _string);
for (; *_string && _string < _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);

View file

@ -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;
@ -911,15 +911,24 @@ struct Imgui
const float barHeight = (float)height / (float)sh; const float barHeight = (float)height / (float)sh;
const int32_t diff = height - sh; // Handle mouse scrolling.
if (diff < 0) if (area.m_inside && !anyActive() )
{ {
*area.m_scrollVal = (*area.m_scrollVal > diff) ? *area.m_scrollVal : diff; const int32_t min = height - sh;
} if (min > 0)
else
{ {
*area.m_scrollVal = 0; *area.m_scrollVal = 0;
} }
else if (m_scroll)
{
const int32_t val = *area.m_scrollVal + 20*m_scroll;
const int32_t max = 0;
*area.m_scrollVal = ( val > max ? max
: val < min ? min
: val
);
}
}
if (barHeight < 1.0f) if (barHeight < 1.0f)
{ {
@ -1017,15 +1026,6 @@ struct Imgui
); );
} }
} }
// Handle mouse scrolling.
if (area.m_inside) // && !anyActive() )
{
if (m_scroll)
{
*area.m_scrollVal += bx::uint32_clamp(20 * m_scroll, 0, sh - height);
}
}
} }
area.m_inside = false; area.m_inside = false;
@ -1547,8 +1547,9 @@ struct Imgui
return selected; return selected;
} }
void image(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft) bool image(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft)
{ {
const uint32_t id = getId();
Area& area = getCurrentArea(); Area& area = getCurrentArea();
int32_t xx; int32_t xx;
@ -1576,6 +1577,10 @@ struct Imgui
const int32_t yy = area.m_widgetY; const int32_t yy = area.m_widgetY;
area.m_widgetY += _height + DEFAULT_SPACING; area.m_widgetY += _height + DEFAULT_SPACING;
const bool enabled = isEnabled(m_areaId);
const bool over = enabled && inRect(xx, yy, _width, _height);
const bool res = buttonLogic(id, over);
screenQuad(xx, yy, _width, _height, _originBottomLeft); screenQuad(xx, yy, _width, _height, _originBottomLeft);
bgfx::setUniform(u_imageLod, &_lod); bgfx::setUniform(u_imageLod, &_lod);
bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture); bgfx::setTexture(0, s_texColor, bgfx::isValid(_image) ? _image : m_missingTexture);
@ -1583,20 +1588,23 @@ struct Imgui
bgfx::setProgram(m_imageProgram); bgfx::setProgram(m_imageProgram);
setCurrentScissor(); setCurrentScissor();
bgfx::submit(m_view); bgfx::submit(m_view);
return res;
} }
void image(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft) bool image(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft)
{ {
const float width = _width*float(getCurrentArea().m_widgetW); const float width = _width*float(getCurrentArea().m_widgetW);
const float height = width/_aspect; const float height = width/_aspect;
image(_image, _lod, int32_t(width), int32_t(height), _align, _originBottomLeft); return image(_image, _lod, int32_t(width), int32_t(height), _align, _originBottomLeft);
} }
void imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) bool imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align)
{ {
BX_CHECK(_channel < 4, "Channel param must be from 0 to 3!"); BX_CHECK(_channel < 4, "Channel param must be from 0 to 3!");
const uint32_t id = getId();
Area& area = getCurrentArea(); Area& area = getCurrentArea();
int32_t xx; int32_t xx;
@ -1624,6 +1632,10 @@ struct Imgui
const int32_t yy = area.m_widgetY; const int32_t yy = area.m_widgetY;
area.m_widgetY += _height + DEFAULT_SPACING; area.m_widgetY += _height + DEFAULT_SPACING;
const bool enabled = isEnabled(m_areaId);
const bool over = enabled && inRect(xx, yy, _width, _height);
const bool res = buttonLogic(id, over);
screenQuad(xx, yy, _width, _height); screenQuad(xx, yy, _width, _height);
bgfx::setUniform(u_imageLod, &_lod); bgfx::setUniform(u_imageLod, &_lod);
@ -1636,14 +1648,16 @@ struct Imgui
bgfx::setProgram(m_imageSwizzProgram); bgfx::setProgram(m_imageSwizzProgram);
setCurrentScissor(); setCurrentScissor();
bgfx::submit(m_view); bgfx::submit(m_view);
return res;
} }
void imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiAlign::Enum _align) bool imageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiAlign::Enum _align)
{ {
const float width = _width*float(getCurrentArea().m_widgetW); const float width = _width*float(getCurrentArea().m_widgetW);
const float height = width/_aspect; const float height = width/_aspect;
imageChannel(_image, _channel, _lod, int32_t(width), int32_t(height), _align); return imageChannel(_image, _channel, _lod, int32_t(width), int32_t(height), _align);
} }
bool cubeMap(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) bool cubeMap(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align)
@ -1733,7 +1747,7 @@ struct Imgui
|| ImguiAlign::Right == _align) || ImguiAlign::Right == _align)
{ {
xx = area.m_widgetX; xx = area.m_widgetX;
width = area.m_widgetW-1; //TODO: -1 ! width = area.m_widgetW;
} }
else //if (ImguiAlign::Center == _align else //if (ImguiAlign::Center == _align
//|| ImguiAlign::CenterIndented == _align). //|| ImguiAlign::CenterIndented == _align).
@ -1750,7 +1764,7 @@ struct Imgui
const bool over = enabled && inRect(xx, yy, width, height); const bool over = enabled && inRect(xx, yy, width, height);
const bool res = buttonLogic(id, over); const bool res = buttonLogic(id, over);
const float scale = float(width/2); const float scale = float(width/2)+0.25f;
float mtx[16]; float mtx[16];
bx::mtxSRT(mtx, scale, scale, 1.0f, 0.0f, 0.0f, 0.0f, float(xx), float(yy), 0.0f); bx::mtxSRT(mtx, scale, scale, 1.0f, 0.0f, 0.0f, 0.0f, float(xx), float(yy), 0.0f);
@ -3277,7 +3291,7 @@ void imguiColorWheel(const char* _text, float _rgb[3], bool& _activated, bool _e
, _rgb[2] , _rgb[2]
); );
if (imguiCollapse(_text, buf, _activated, _enabled) ) if (imguiCollapse(_text, buf, _activated) )
{ {
_activated = !_activated; _activated = !_activated;
} }
@ -3288,24 +3302,24 @@ void imguiColorWheel(const char* _text, float _rgb[3], bool& _activated, bool _e
} }
} }
void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft) bool imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align, bool _originBottomLeft)
{ {
s_imgui.image(_image, _lod, _width, _height, _align, _originBottomLeft); return s_imgui.image(_image, _lod, _width, _height, _align, _originBottomLeft);
} }
void imguiImage(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft) bool imguiImage(bgfx::TextureHandle _image, float _lod, float _width, float _aspect, ImguiAlign::Enum _align, bool _originBottomLeft)
{ {
s_imgui.image(_image, _lod, _width, _aspect, _align, _originBottomLeft); return s_imgui.image(_image, _lod, _width, _aspect, _align, _originBottomLeft);
} }
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align) bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align)
{ {
s_imgui.imageChannel(_image, _channel, _lod, _width, _height, _align); return s_imgui.imageChannel(_image, _channel, _lod, _width, _height, _align);
} }
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiAlign::Enum _align) bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _width, float _aspect, ImguiAlign::Enum _align)
{ {
s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align); return s_imgui.imageChannel(_image, _channel, _lod, _width, _aspect, _align);
} }
bool imguiCube(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align) bool imguiCube(bgfx::TextureHandle _cubemap, float _lod, bool _cross, ImguiAlign::Enum _align)

View file

@ -174,10 +174,10 @@ uint32_t imguiChooseUseMacroInstead(uint32_t _selected, ...);
void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, bool _enabled = true); void imguiColorWheel(float _rgb[3], bool _respectIndentation = false, bool _enabled = true);
void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, bool _enabled = true); void imguiColorWheel(const char* _str, float _rgb[3], bool& _activated, bool _enabled = true);
void imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false); bool imguiImage(bgfx::TextureHandle _image, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false);
void imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false); bool imguiImage(bgfx::TextureHandle _image, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented, bool _originBottomLeft = false);
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, int32_t _width, int32_t _height, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
void imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); bool imguiImageChannel(bgfx::TextureHandle _image, uint8_t _channel, float _lod, float _scale, float _aspect, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented); bool imguiCube(bgfx::TextureHandle _cubemap, float _lod = 0.0f, bool _cross = true, ImguiAlign::Enum _align = ImguiAlign::LeftIndented);
float imguiGetTextLength(const char* _text, ImguiFontHandle _handle); float imguiGetTextLength(const char* _text, ImguiFontHandle _handle);

View file

@ -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]; //!<
}; };

View file

@ -202,7 +202,7 @@ ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin))
ifeq ($(UNAME),$(filter $(UNAME),Darwin)) ifeq ($(UNAME),$(filter $(UNAME),Darwin))
OS=darwin OS=darwin
BUILD_PROJECT_DIR=gmake-osx BUILD_PROJECT_DIR=gmake-osx
BUILD_OUTPUT_DIR=osx64_gcc BUILD_OUTPUT_DIR=osx64_clang
BUILD_TOOLS_CONFIG=release64 BUILD_TOOLS_CONFIG=release64
EXE= EXE=
else else

View file

@ -2225,7 +2225,12 @@ namespace bgfx
&& BGFX_CHUNK_MAGIC_FSH != magic && BGFX_CHUNK_MAGIC_FSH != magic
&& BGFX_CHUNK_MAGIC_VSH != magic) && BGFX_CHUNK_MAGIC_VSH != magic)
{ {
BX_WARN(false, "Invalid shader signature! 0x%08x.", magic); BX_WARN(false, "Invalid shader signature! %c%c%c%d."
, ( (uint8_t*)&magic)[0]
, ( (uint8_t*)&magic)[1]
, ( (uint8_t*)&magic)[2]
, ( (uint8_t*)&magic)[3]
);
ShaderHandle invalid = BGFX_INVALID_HANDLE; ShaderHandle invalid = BGFX_INVALID_HANDLE;
return invalid; return invalid;
} }

View file

@ -12,6 +12,7 @@ namespace bgfx
OVR::OVR() OVR::OVR()
: m_hmd(NULL) : m_hmd(NULL)
, m_initialized(false) , m_initialized(false)
, m_debug(false)
{ {
} }
@ -39,6 +40,46 @@ namespace bgfx
return false; return false;
} }
if (_debug)
{
switch (_config->Header.API)
{
#if BGFX_CONFIG_RENDERER_DIRECT3D9
case ovrRenderAPI_D3D9:
{
ovrD3D9ConfigData* data = (ovrD3D9ConfigData*)_config;
m_rtSize = data->Header.RTSize;
}
break;
#endif // BGFX_CONFIG_RENDERER_DIRECT3D9
#if BGFX_CONFIG_RENDERER_DIRECT3D11
case ovrRenderAPI_D3D11:
{
ovrD3D11ConfigData* data = (ovrD3D11ConfigData*)_config;
m_rtSize = data->Header.RTSize;
}
break;
#endif // BGFX_CONFIG_RENDERER_DIRECT3D11
#if BGFX_CONFIG_RENDERER_OPENGL
case ovrRenderAPI_OpenGL:
{
ovrGLConfigData* data = (ovrGLConfigData*)_config;
m_rtSize = data->Header.RTSize;
}
break;
#endif // BGFX_CONFIG_RENDERER_OPENGL
default:
BX_CHECK(false, "You should not be here!");
break;
}
m_debug = true;
return false;
}
if (!_debug) if (!_debug)
{ {
m_hmd = ovrHmd_Create(0); m_hmd = ovrHmd_Create(0);
@ -67,6 +108,7 @@ namespace bgfx
| ovrDistortionCap_Vignette | ovrDistortionCap_Vignette
| ovrDistortionCap_TimeWarp | ovrDistortionCap_TimeWarp
| ovrDistortionCap_Overdrive | ovrDistortionCap_Overdrive
| ovrDistortionCap_NoRestore
, eyeFov , eyeFov
, m_erd , m_erd
); );
@ -135,6 +177,8 @@ ovrError:
ovrHmd_Destroy(m_hmd); ovrHmd_Destroy(m_hmd);
m_hmd = NULL; m_hmd = NULL;
} }
m_debug = false;
} }
bool OVR::swap() bool OVR::swap()
@ -153,8 +197,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 +219,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,22 +235,39 @@ 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;
} }
}
else
{
for (int ii = 0; ii < 2; ++ii)
{
_hmd.eye[ii].rotation[0] = 0.0f;
_hmd.eye[ii].rotation[1] = 0.0f;
_hmd.eye[ii].rotation[2] = 0.0f;
_hmd.eye[ii].rotation[3] = 1.0f;
_hmd.eye[ii].translation[0] = 0.0f;
_hmd.eye[ii].translation[1] = 0.0f;
_hmd.eye[ii].translation[2] = 0.0f;
_hmd.eye[ii].fov[0] = 1.32928634f;
_hmd.eye[ii].fov[1] = 1.32928634f;
_hmd.eye[ii].fov[2] = 0 == ii ? 1.05865765f : 1.09236801f;
_hmd.eye[ii].fov[3] = 0 == ii ? 1.09236801f : 1.05865765f;
_hmd.eye[ii].viewOffset[0] = 0 == ii ? 0.0355070010f : -0.0375000015f;
_hmd.eye[ii].viewOffset[1] = 0.0f;
_hmd.eye[ii].viewOffset[2] = 0 == ii ? 0.00150949787f : -0.00150949787f;
_hmd.eye[ii].pixelsPerTanAngle[0] = 1;
_hmd.eye[ii].pixelsPerTanAngle[1] = 1;
}
}
_hmd.width = uint16_t(m_rtSize.w); _hmd.width = uint16_t(m_rtSize.w);
_hmd.height = uint16_t(m_rtSize.h); _hmd.height = uint16_t(m_rtSize.h);
} }
else
{
_hmd.width = 0;
_hmd.height = 0;
}
}
} // namespace bgfx } // namespace bgfx

View file

@ -44,6 +44,11 @@ namespace bgfx
return NULL != m_hmd; return NULL != m_hmd;
} }
bool isDebug() const
{
return m_debug;
}
void init(); void init();
void shutdown(); void shutdown();
@ -68,6 +73,7 @@ namespace bgfx
ovrSizei m_rtSize; ovrSizei m_rtSize;
bool m_warning; bool m_warning;
bool m_initialized; bool m_initialized;
bool m_debug;
}; };
} // namespace bgfx } // namespace bgfx
@ -104,6 +110,11 @@ namespace bgfx
return false; return false;
} }
bool isDebug() const
{
return false;
}
bool swap() bool swap()
{ {
return false; return false;

View file

@ -1915,9 +1915,9 @@ RENDERDOC_IMPORT
void ovrPreReset() void ovrPreReset()
{ {
#if BGFX_CONFIG_USE_OVR #if BGFX_CONFIG_USE_OVR
m_ovr.preReset();
if (NULL != m_ovrRtv) if (NULL != m_ovrRtv)
{ {
m_ovr.preReset();
std::swap(m_ovrRtv, m_backBufferColor); std::swap(m_ovrRtv, m_backBufferColor);
std::swap(m_ovrDsv, m_backBufferDepthStencil); std::swap(m_ovrDsv, m_backBufferDepthStencil);
BX_CHECK(NULL == m_backBufferDepthStencil, ""); BX_CHECK(NULL == m_backBufferDepthStencil, "");
@ -3041,7 +3041,7 @@ RENDERDOC_IMPORT
Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] }; Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] };
Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS]; Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS];
const bool hmdEnabled = m_ovr.isEnabled(); const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug();
_render->m_hmdEnabled = hmdEnabled; _render->m_hmdEnabled = hmdEnabled;
if (hmdEnabled) if (hmdEnabled)
@ -3056,9 +3056,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)
{ {

View file

@ -2017,9 +2017,9 @@ namespace bgfx
void ovrPreReset() void ovrPreReset()
{ {
#if BGFX_CONFIG_USE_OVR #if BGFX_CONFIG_USE_OVR
m_ovr.preReset();
if (m_ovr.isEnabled() ) if (m_ovr.isEnabled() )
{ {
m_ovr.preReset();
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) ); GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
GL_CHECK(glDeleteFramebuffers(1, &m_msaaBackBufferFbo) ); GL_CHECK(glDeleteFramebuffers(1, &m_msaaBackBufferFbo) );
m_msaaBackBufferFbo = m_ovrFbo; m_msaaBackBufferFbo = m_ovrFbo;
@ -4121,7 +4121,7 @@ namespace bgfx
Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] }; Matrix4* mtxView[2] = { _render->m_view, mtxViewTmp[1] };
Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS]; Matrix4 mtxViewProj[2][BGFX_CONFIG_MAX_VIEWS];
const bool hmdEnabled = m_ovr.isEnabled(); const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug();
_render->m_hmdEnabled = hmdEnabled; _render->m_hmdEnabled = hmdEnabled;
if (hmdEnabled) if (hmdEnabled)
@ -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)
{ {