Linux sync from Windows changes

This commit is contained in:
Jack Andersen 2015-11-02 18:27:56 -10:00
parent facacd4e95
commit 50bca6f58e
3 changed files with 70 additions and 55 deletions

View File

@ -492,6 +492,7 @@ struct GLCommandQueue : IGraphicsCommandQueue
{ {
OpSetShaderDataBinding, OpSetShaderDataBinding,
OpSetRenderTarget, OpSetRenderTarget,
OpSetViewport,
OpSetClearColor, OpSetClearColor,
OpClearTarget, OpClearTarget,
OpSetDrawPrimitive, OpSetDrawPrimitive,
@ -505,6 +506,7 @@ struct GLCommandQueue : IGraphicsCommandQueue
{ {
const IShaderDataBinding* binding; const IShaderDataBinding* binding;
const ITextureD* target; const ITextureD* target;
SWindowRect rect;
float rgba[4]; float rgba[4];
GLbitfield flags; GLbitfield flags;
GLenum prim; GLenum prim;
@ -639,6 +641,10 @@ struct GLCommandQueue : IGraphicsCommandQueue
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tex->m_fbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tex->m_fbo);
break; break;
} }
case Command::OpSetViewport:
glViewport(cmd.rect.location[0], cmd.rect.location[1],
cmd.rect.size[0], cmd.rect.size[1]);
break;
case Command::OpSetClearColor: case Command::OpSetClearColor:
glClearColor(cmd.rgba[0], cmd.rgba[1], cmd.rgba[2], cmd.rgba[3]); glClearColor(cmd.rgba[0], cmd.rgba[1], cmd.rgba[2], cmd.rgba[3]);
break; break;
@ -686,18 +692,28 @@ struct GLCommandQueue : IGraphicsCommandQueue
m_thr.join(); m_thr.join();
} }
void setShaderDataBinding(const IShaderDataBinding* binding) void setShaderDataBinding(IShaderDataBinding* binding)
{ {
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf]; std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
cmds.emplace_back(Command::OpSetShaderDataBinding); cmds.emplace_back(Command::OpSetShaderDataBinding);
cmds.back().binding = binding; cmds.back().binding = binding;
} }
void setRenderTarget(const ITextureD* target) void setRenderTarget(ITextureD* target)
{ {
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf]; std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
cmds.emplace_back(Command::OpSetRenderTarget); cmds.emplace_back(Command::OpSetRenderTarget);
cmds.back().target = target; cmds.back().target = target;
} }
void setRenderTarget(IWindow* target)
{
/* TODO: Do */
}
void setViewport(const SWindowRect& rect)
{
std::vector<Command>& cmds = m_cmdBufs[m_fillBuf];
cmds.emplace_back(Command::OpSetViewport);
cmds.back().rect = rect;
}
void setClearColor(const float rgba[4]) void setClearColor(const float rgba[4])
{ {

View File

@ -48,42 +48,42 @@ extern int XINPUT_OPCODE;
static uint32_t translateKeysym(KeySym sym, int& specialSym, int& modifierSym) static uint32_t translateKeysym(KeySym sym, int& specialSym, int& modifierSym)
{ {
specialSym = IWindowCallback::KEY_NONE; specialSym = KEY_NONE;
modifierSym = IWindowCallback::MKEY_NONE; modifierSym = MKEY_NONE;
if (sym >= XK_F1 && sym <= XK_F12) if (sym >= XK_F1 && sym <= XK_F12)
specialSym = IWindowCallback::KEY_F1 + sym - XK_F1; specialSym = KEY_F1 + sym - XK_F1;
else if (sym == XK_Escape) else if (sym == XK_Escape)
specialSym = IWindowCallback::KEY_ESC; specialSym = KEY_ESC;
else if (sym == XK_Return) else if (sym == XK_Return)
specialSym = IWindowCallback::KEY_ENTER; specialSym = KEY_ENTER;
else if (sym == XK_BackSpace) else if (sym == XK_BackSpace)
specialSym = IWindowCallback::KEY_BACKSPACE; specialSym = KEY_BACKSPACE;
else if (sym == XK_Insert) else if (sym == XK_Insert)
specialSym = IWindowCallback::KEY_INSERT; specialSym = KEY_INSERT;
else if (sym == XK_Delete) else if (sym == XK_Delete)
specialSym = IWindowCallback::KEY_DELETE; specialSym = KEY_DELETE;
else if (sym == XK_Home) else if (sym == XK_Home)
specialSym = IWindowCallback::KEY_HOME; specialSym = KEY_HOME;
else if (sym == XK_End) else if (sym == XK_End)
specialSym = IWindowCallback::KEY_END; specialSym = KEY_END;
else if (sym == XK_Page_Up) else if (sym == XK_Page_Up)
specialSym = IWindowCallback::KEY_PGUP; specialSym = KEY_PGUP;
else if (sym == XK_Page_Down) else if (sym == XK_Page_Down)
specialSym = IWindowCallback::KEY_PGDOWN; specialSym = KEY_PGDOWN;
else if (sym == XK_Left) else if (sym == XK_Left)
specialSym = IWindowCallback::KEY_LEFT; specialSym = KEY_LEFT;
else if (sym == XK_Right) else if (sym == XK_Right)
specialSym = IWindowCallback::KEY_RIGHT; specialSym = KEY_RIGHT;
else if (sym == XK_Up) else if (sym == XK_Up)
specialSym = IWindowCallback::KEY_UP; specialSym = KEY_UP;
else if (sym == XK_Down) else if (sym == XK_Down)
specialSym = IWindowCallback::KEY_DOWN; specialSym = KEY_DOWN;
else if (sym == XK_Shift_L || sym == XK_Shift_R) else if (sym == XK_Shift_L || sym == XK_Shift_R)
modifierSym = IWindowCallback::MKEY_SHIFT; modifierSym = MKEY_SHIFT;
else if (sym == XK_Control_L || sym == XK_Control_R) else if (sym == XK_Control_L || sym == XK_Control_R)
modifierSym = IWindowCallback::MKEY_CTRL; modifierSym = MKEY_CTRL;
else if (sym == XK_Alt_L || sym == XK_Alt_R) else if (sym == XK_Alt_L || sym == XK_Alt_R)
modifierSym = IWindowCallback::MKEY_ALT; modifierSym = MKEY_ALT;
else else
return xkb_keysym_to_utf32(sym); return xkb_keysym_to_utf32(sym);
return 0; return 0;
@ -93,11 +93,11 @@ static int translateModifiers(unsigned state)
{ {
int retval = 0; int retval = 0;
if (state & ShiftMask) if (state & ShiftMask)
retval |= IWindowCallback::MKEY_SHIFT; retval |= MKEY_SHIFT;
if (state & ControlMask) if (state & ControlMask)
retval |= IWindowCallback::MKEY_CTRL; retval |= MKEY_CTRL;
if (state & Mod1Mask) if (state & Mod1Mask)
retval |= IWindowCallback::MKEY_ALT; retval |= MKEY_ALT;
return retval; return retval;
} }
@ -105,16 +105,15 @@ static int translateButton(unsigned detail)
{ {
int retval = 0; int retval = 0;
if (detail == 1) if (detail == 1)
retval = IWindowCallback::BUTTON_PRIMARY; retval = BUTTON_PRIMARY;
else if (detail == 3) else if (detail == 3)
retval = IWindowCallback::BUTTON_SECONDARY; retval = BUTTON_SECONDARY;
else if (detail == 2) else if (detail == 2)
retval = IWindowCallback::BUTTON_MIDDLE; retval = BUTTON_MIDDLE;
else if (detail == 8) else if (detail == 8)
retval = IWindowCallback::BUTTON_AUX1; retval = BUTTON_AUX1;
else if (detail == 9) else if (detail == 9)
retval = retval = BUTTON_AUX2;
IWindowCallback::BUTTON_AUX2;
return retval; return retval;
} }
@ -763,7 +762,7 @@ public:
m_wh = event->xexpose.height; m_wh = event->xexpose.height;
if (m_callback) if (m_callback)
{ {
IWindowCallback::SWindowRect rect = SWindowRect rect =
{ {m_wx, m_wy}, {m_ww, m_wh} }; { {m_wx, m_wy}, {m_ww, m_wh} };
m_callback->resized(rect); m_callback->resized(rect);
} }
@ -780,7 +779,7 @@ public:
if (m_callback) if (m_callback)
{ {
IWindowCallback::SWindowRect rect = SWindowRect rect =
{ {m_wx, m_wy}, {m_ww, m_wh} }; { {m_wx, m_wy}, {m_ww, m_wh} };
m_callback->resized(rect); m_callback->resized(rect);
} }
@ -798,12 +797,12 @@ public:
int modifierMask = translateModifiers(event->xkey.state); int modifierMask = translateModifiers(event->xkey.state);
if (charCode) if (charCode)
m_callback->charKeyDown(charCode, m_callback->charKeyDown(charCode,
(IWindowCallback::EModifierKey)modifierMask, false); (EModifierKey)modifierMask, false);
else if (specialKey) else if (specialKey)
m_callback->specialKeyDown((IWindowCallback::ESpecialKey)specialKey, m_callback->specialKeyDown((ESpecialKey)specialKey,
(IWindowCallback::EModifierKey)modifierMask, false); (EModifierKey)modifierMask, false);
else if (modifierKey) else if (modifierKey)
m_callback->modKeyDown((IWindowCallback::EModifierKey)modifierKey, false); m_callback->modKeyDown((EModifierKey)modifierKey, false);
} }
return; return;
} }
@ -818,12 +817,12 @@ public:
int modifierMask = translateModifiers(event->xkey.state); int modifierMask = translateModifiers(event->xkey.state);
if (charCode) if (charCode)
m_callback->charKeyUp(charCode, m_callback->charKeyUp(charCode,
(IWindowCallback::EModifierKey)modifierMask); (EModifierKey)modifierMask);
else if (specialKey) else if (specialKey)
m_callback->specialKeyUp((IWindowCallback::ESpecialKey)specialKey, m_callback->specialKeyUp((ESpecialKey)specialKey,
(IWindowCallback::EModifierKey)modifierMask); (EModifierKey)modifierMask);
else if (modifierKey) else if (modifierKey)
m_callback->modKeyUp((IWindowCallback::EModifierKey)modifierKey); m_callback->modKeyUp((EModifierKey)modifierKey);
} }
return; return;
} }
@ -836,27 +835,27 @@ public:
if (button) if (button)
{ {
int modifierMask = translateModifiers(event->xbutton.state); int modifierMask = translateModifiers(event->xbutton.state);
IWindowCallback::SWindowCoord coord = SWindowCoord coord =
{ {
{(unsigned)event->xbutton.x, (unsigned)event->xbutton.y}, {(unsigned)event->xbutton.x, (unsigned)event->xbutton.y},
{(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)}, {(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)},
{float(event->xbutton.x) / float(m_ww), float(event->xbutton.y) / float(m_wh)} {float(event->xbutton.x) / float(m_ww), float(event->xbutton.y) / float(m_wh)}
}; };
m_callback->mouseDown(coord, (IWindowCallback::EMouseButton)button, m_callback->mouseDown(coord, (EMouseButton)button,
(IWindowCallback::EModifierKey)modifierMask); (EModifierKey)modifierMask);
} }
/* Also handle legacy scroll events here */ /* Also handle legacy scroll events here */
if (event->xbutton.button >= 4 && event->xbutton.button <= 7 && if (event->xbutton.button >= 4 && event->xbutton.button <= 7 &&
m_hScrollValuator == -1 && m_vScrollValuator == -1) m_hScrollValuator == -1 && m_vScrollValuator == -1)
{ {
IWindowCallback::SWindowCoord coord = SWindowCoord coord =
{ {
{(unsigned)event->xbutton.x, (unsigned)event->xbutton.y}, {(unsigned)event->xbutton.x, (unsigned)event->xbutton.y},
{(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)}, {(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)},
{(float)event->xbutton.x / (float)m_ww, (float)event->xbutton.y / (float)m_wh} {(float)event->xbutton.x / (float)m_ww, (float)event->xbutton.y / (float)m_wh}
}; };
IWindowCallback::SScrollDelta scrollDelta = SScrollDelta scrollDelta =
{ {
{0.0, 0.0}, {0.0, 0.0},
false false
@ -883,14 +882,14 @@ public:
if (button) if (button)
{ {
int modifierMask = translateModifiers(event->xbutton.state); int modifierMask = translateModifiers(event->xbutton.state);
IWindowCallback::SWindowCoord coord = SWindowCoord coord =
{ {
{(unsigned)event->xbutton.x, (unsigned)event->xbutton.y}, {(unsigned)event->xbutton.x, (unsigned)event->xbutton.y},
{(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)}, {(unsigned)(event->xbutton.x / m_pixelFactor), (unsigned)(event->xbutton.y / m_pixelFactor)},
{event->xbutton.x / (float)m_ww, event->xbutton.y / (float)m_wh} {event->xbutton.x / (float)m_ww, event->xbutton.y / (float)m_wh}
}; };
m_callback->mouseUp(coord, (IWindowCallback::EMouseButton)button, m_callback->mouseUp(coord, (EMouseButton)button,
(IWindowCallback::EModifierKey)modifierMask); (EModifierKey)modifierMask);
} }
} }
return; return;
@ -900,7 +899,7 @@ public:
if (m_callback) if (m_callback)
{ {
getWindowFrame(m_wx, m_wy, m_ww, m_wh); getWindowFrame(m_wx, m_wy, m_ww, m_wh);
IWindowCallback::SWindowCoord coord = SWindowCoord coord =
{ {
{(unsigned)event->xmotion.x, (unsigned)event->xmotion.y}, {(unsigned)event->xmotion.x, (unsigned)event->xmotion.y},
{(unsigned)(event->xmotion.x / m_pixelFactor), (unsigned)(event->xmotion.y / m_pixelFactor)}, {(unsigned)(event->xmotion.x / m_pixelFactor), (unsigned)(event->xmotion.y / m_pixelFactor)},
@ -946,7 +945,7 @@ public:
} }
} }
IWindowCallback::SScrollDelta scrollDelta = SScrollDelta scrollDelta =
{ {
{newScroll[0] - m_hScrollLast, newScroll[1] - m_vScrollLast}, {newScroll[0] - m_hScrollLast, newScroll[1] - m_vScrollLast},
true true
@ -959,7 +958,7 @@ public:
{ {
unsigned event_x = unsigned(ev->event_x) >> 16; unsigned event_x = unsigned(ev->event_x) >> 16;
unsigned event_y = unsigned(ev->event_y) >> 16; unsigned event_y = unsigned(ev->event_y) >> 16;
IWindowCallback::SWindowCoord coord = SWindowCoord coord =
{ {
{event_x, event_y}, {event_x, event_y},
{(unsigned)(event_x / m_pixelFactor), (unsigned)(event_y / m_pixelFactor)}, {(unsigned)(event_x / m_pixelFactor), (unsigned)(event_y / m_pixelFactor)},
@ -986,7 +985,7 @@ public:
} }
} }
IWindowCallback::STouchCoord coord = STouchCoord coord =
{ {
{vals[0], vals[1]} {vals[0], vals[1]}
}; };
@ -1012,7 +1011,7 @@ public:
} }
} }
IWindowCallback::STouchCoord coord = STouchCoord coord =
{ {
{vals[0], vals[1]} {vals[0], vals[1]}
}; };
@ -1038,7 +1037,7 @@ public:
} }
} }
IWindowCallback::STouchCoord coord = STouchCoord coord =
{ {
{vals[0], vals[1]} {vals[0], vals[1]}
}; };

View File

@ -182,7 +182,7 @@ struct TestApplicationCallback : IApplicationCallback
CTestWindowCallback windowCallback; CTestWindowCallback windowCallback;
bool running = true; bool running = true;
const IShaderDataBinding* m_binding = nullptr; IShaderDataBinding* m_binding = nullptr;
std::mutex m_mt; std::mutex m_mt;
std::condition_variable m_cv; std::condition_variable m_cv;