Misc tweaks to various GL interface objects

This commit is contained in:
Aaron Culliney 2015-04-26 18:12:56 -07:00
parent e7c0d8fe48
commit 1126a319ec
10 changed files with 129 additions and 93 deletions

View File

@ -34,6 +34,7 @@
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <zlib.h>

View File

@ -257,21 +257,11 @@ void c_joystick_reset(void)
}
#if INTERFACE_TOUCH
// is the touch joystick available
bool (*joydriver_isTouchJoystickAvailable)(void) = NULL;
// enable/disable touch joystick
void (*joydriver_setTouchJoyEnabled)(bool enabled) = NULL;
// set the joystick button parameters (7bit ASCII characters or MOUSETEXT values)
void (*joydriver_setTouchJoystickEnabled)(bool enabled) = NULL;
void (*joydriver_setTouchJoystickOwnsScreen)(bool pwnd) = NULL;
void (*joydriver_setTouchButtonValues)(char button0Val, char button1Val) = NULL;
// set the axis type
void (*joydriver_setTouchAxisType)(touchjoy_axis_type_t axisType) = NULL;
// set the axis button parameters (7bit ASCII characters or MOUSETEXT values)
void (*joydriver_setTouchAxisValues)(char up, char left, char right, char down) = NULL;
#endif

View File

@ -43,7 +43,10 @@ typedef enum touchjoy_axis_type_t {
extern bool (*joydriver_isTouchJoystickAvailable)(void);
// enable/disable touch joystick
extern void (*joydriver_setTouchJoyEnabled)(bool enabled);
extern void (*joydriver_setTouchJoystickEnabled)(bool enabled);
// grant/remove ownership of touch screeen
extern void (*joydriver_setTouchJoystickOwnsScreen)(bool pwnd);
// set the joystick button parameters (7bit ASCII characters or MOUSETEXT values)
extern void (*joydriver_setTouchButtonValues)(char button0Val, char button1Val);

View File

@ -485,10 +485,8 @@ bool c_keys_is_interface_key(int key)
#endif
#if INTERFACE_TOUCH
// is the touch keyboard module itself available?
bool (*keydriver_isTouchKeyboardAvailable)(void) = NULL;
// enable/disable touch keyboard HUD element
void (*keydriver_setTouchKeyboardEnabled)(bool enabled) = NULL;
void (*keydriver_setTouchKeyboardOwnsScreen)(bool pwnd) = NULL;
#endif

View File

@ -154,6 +154,9 @@ extern bool (*keydriver_isTouchKeyboardAvailable)(void);
// enable/disable touch keyboard HUD element
extern void (*keydriver_setTouchKeyboardEnabled)(bool enabled);
// grant/remove ownership of touch screeen
extern void (*keydriver_setTouchKeyboardOwnsScreen)(bool pwnd);
#endif
#endif

View File

@ -127,8 +127,7 @@ static void alert_render(void) {
glBindTexture(GL_TEXTURE_2D, messageModel->textureName);
if (messageModel->texDirty) {
messageModel->texDirty = false;
GLModelHUDElement *hudElement = (GLModelHUDElement *)(messageModel->custom);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, hudElement->pixWidth, hudElement->pixHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, messageModel->texPixels);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, messageModel->texWidth, messageModel->texHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, messageModel->texPixels);
}
glUniform1i(uniformTex2Use, TEXTURE_ID_MESSAGE);
glhud_renderDefault(messageModel);

View File

@ -22,8 +22,8 @@
unsigned int tplHeight; /* template height */ \
\
uint8_t *pixels; /* raw texture/FB data */ \
unsigned int pixWidth; /* FB width */ \
unsigned int pixHeight; /* FB height */ \
unsigned int pixWidth; /* FB width -- FIXME TODO : this is really the same as GLModel.texWidth */ \
unsigned int pixHeight; /* FB height -- FIXME TODO : this is really the same as GLModel.texHeight */ \
\
interface_colorscheme_t colorScheme; \
bool blackIsTransparent; \

View File

@ -18,7 +18,7 @@
#error this is a touch interface module, possibly you mean to not compile this at all?
#endif
#define MODEL_DEPTH -0.03125
#define MODEL_DEPTH -1/32.f
#define AXIS_TEMPLATE_COLS 5
#define AXIS_TEMPLATE_ROWS 5
@ -55,7 +55,9 @@ enum {
static bool isAvailable = false; // Were there any OpenGL/memory errors on gltouchjoy initialization?
static bool isEnabled = true; // Does player want touchjoy enabled?
static float minAlpha = 0.0; // Minimum alpha value of touchjoy components (at zero, will not draw)
static bool ownsScreen = false; // Does the touchjoy currently own the screen?
static float minAlphaWhenOwnsScreen = 0;
static float minAlpha = 0;
// viewport touch
static struct {
@ -123,6 +125,27 @@ static struct {
// ----------------------------------------------------------------------------
#warning FIXME TODO ... this can become a common helper function ...
static inline float _get_component_visibility(struct timespec timingBegin) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
clock_gettime(CLOCK_MONOTONIC, &now);
float alpha = minAlpha;
deltat = timespec_diff(timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = 1.0;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < minAlpha) {
alpha = minAlpha;
}
}
}
return alpha;
}
static void _setup_axis_object(GLModel *parent) {
GLModelHUDElement *hudElement = (GLModelHUDElement *)parent->custom;
@ -158,7 +181,9 @@ static void _setup_axis_object(GLModel *parent) {
static void *_create_touchjoy_hud(void) {
GLModelHUDElement *hudElement = (GLModelHUDElement *)glhud_createDefault();
hudElement->blackIsTransparent = true;
if (hudElement) {
hudElement->blackIsTransparent = true;
}
return hudElement;
}
@ -242,35 +267,19 @@ static void gltouchjoy_render(void) {
return;
}
struct timespec now = { 0 };
struct timespec deltat = { 0 };
float alpha = minAlpha;
glViewport(0, 0, touchport.width, touchport.height); // NOTE : show these HUD elements beyond the A2 framebuffer dimensions
// draw axis
clock_gettime(CLOCK_MONOTONIC, &now);
alpha = minAlpha;
deltat = timespec_diff(axes.timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = 1.0;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < minAlpha) {
alpha = minAlpha;
}
}
}
float alpha = _get_component_visibility(axes.timingBegin);
if (alpha > 0.0) {
glViewport(0, 0, touchport.width, touchport.height); // NOTE : show these HUD elements beyond the A2 framebuffer dimensions
glUniform1f(alphaValue, alpha);
glActiveTexture(TEXTURE_ACTIVE_TOUCHJOY_AXIS);
glBindTexture(GL_TEXTURE_2D, axes.model->textureName);
if (axes.model->texDirty) {
axes.model->texDirty = false;
GLModelHUDElement *hudElement = (GLModelHUDElement *)(axes.model->custom);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, hudElement->pixWidth, hudElement->pixHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, axes.model->texPixels);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, axes.model->texWidth, axes.model->texHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, axes.model->texPixels);
}
if (axes.modelDirty) {
axes.modelDirty = false;
@ -283,29 +292,15 @@ static void gltouchjoy_render(void) {
// draw button(s)
clock_gettime(CLOCK_MONOTONIC, &now);
alpha = minAlpha;
deltat = timespec_diff(buttons.timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = 1.0;
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
if (alpha < minAlpha) {
alpha = minAlpha;
}
}
}
alpha = _get_component_visibility(buttons.timingBegin);
if (alpha > 0.0) {
glViewport(0, 0, touchport.width, touchport.height); // NOTE : show these HUD elements beyond the framebuffer dimensions
glUniform1f(alphaValue, alpha);
glActiveTexture(TEXTURE_ACTIVE_TOUCHJOY_BUTTON);
glBindTexture(GL_TEXTURE_2D, buttons.model->textureName);
if (buttons.model->texDirty) {
buttons.model->texDirty = false;
GLModelHUDElement *hudElement = (GLModelHUDElement *)(buttons.model->custom);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, hudElement->pixWidth, hudElement->pixHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, buttons.model->texPixels);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, buttons.model->texWidth, buttons.model->texHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, buttons.model->texPixels);
}
if (buttons.modelDirty) {
buttons.modelDirty = false;
@ -321,6 +316,8 @@ static void gltouchjoy_reshape(int w, int h) {
LOG("gltouchjoy_reshape(%d, %d)", w, h);
touchport.axisX = 0;
touchport.axisY = 0;
touchport.buttonY = 0;
if (w > touchport.width) {
touchport.width = w;
@ -330,9 +327,7 @@ static void gltouchjoy_reshape(int w, int h) {
}
if (h > touchport.height) {
touchport.height = h;
touchport.axisY = h>>1;
touchport.axisYMax = h;
touchport.buttonY = h>>1;
touchport.buttonYMax = h;
}
}
@ -456,6 +451,9 @@ static bool gltouchjoy_onTouchEvent(interface_touch_event_t action, int pointer_
if (!isEnabled) {
return false;
}
if (!ownsScreen) {
return false;
}
bool axisConsumed = false;
bool buttonConsumed = false;
@ -575,10 +573,35 @@ static bool gltouchjoy_isTouchJoystickAvailable(void) {
return isAvailable;
}
static void gltouchjoy_setTouchJoyEnabled(bool enabled) {
static void gltouchjoy_setTouchJoystickEnabled(bool enabled) {
isEnabled = enabled;
}
static void gltouchjoy_setTouchJoystickOwnsScreen(bool pwnd) {
ownsScreen = pwnd;
if (ownsScreen) {
minAlpha = minAlphaWhenOwnsScreen;
} else {
minAlpha = 0.0;
}
}
static void _animation_showTouchJoystick(void) {
if (!isAvailable) {
return;
}
clock_gettime(CLOCK_MONOTONIC, &axes.timingBegin);
clock_gettime(CLOCK_MONOTONIC, &buttons.timingBegin);
}
static void _animation_hideTouchJoystick(void) {
if (!isAvailable) {
return;
}
axes.timingBegin = (struct timespec){ 0 };
buttons.timingBegin = (struct timespec){ 0 };
}
static void gltouchjoy_setTouchButtonValues(char char0, char char1) {
buttons.char0 = char0;
buttons.char1 = char1;
@ -624,8 +647,12 @@ static void _init_gltouchjoy(void) {
buttons.activeChar = MOUSETEXT_OPENAPPLE;
buttons.switchThreshold = BUTTON_SWITCH_THRESHOLD_DEFAULT;
video_backend->animation_showTouchJoystick = &_animation_showTouchJoystick;
video_backend->animation_hideTouchJoystick = &_animation_hideTouchJoystick;
joydriver_isTouchJoystickAvailable = &gltouchjoy_isTouchJoystickAvailable;
joydriver_setTouchJoyEnabled = &gltouchjoy_setTouchJoyEnabled;
joydriver_setTouchJoystickEnabled = &gltouchjoy_setTouchJoystickEnabled;
joydriver_setTouchJoystickOwnsScreen = &gltouchjoy_setTouchJoystickOwnsScreen;
joydriver_setTouchButtonValues = &gltouchjoy_setTouchButtonValues;
joydriver_setTouchAxisType = &gltouchjoy_setTouchAxisType;
joydriver_setTouchAxisValues = &gltouchjoy_setTouchAxisValues;

View File

@ -18,7 +18,7 @@
#error this is a touch interface module, possibly you mean to not compile this at all?
#endif
#define MODEL_DEPTH -0.03125
#define MODEL_DEPTH -1/32.f
#define KBD_TEMPLATE_COLS 10
#define KBD_TEMPLATE_ROWS 4
@ -36,7 +36,9 @@ HUD_CLASS(GLModelHUDKeyboard,
static bool isAvailable = false; // Were there any OpenGL/memory errors on gltouchkbd initialization?
static bool isEnabled = true; // Does player want touchkbd enabled?
static float minAlpha = 0.25; // Minimum alpha value of touchkbd components (at zero, will not render)
static bool ownsScreen = true; // Does the touchkbd currently own the screen to the exclusion?
static float minAlphaWhenOwnsScreen = 1/4.f;
static float minAlpha = 1/4.f;
static char kbdTemplateUCase[KBD_TEMPLATE_ROWS][KBD_TEMPLATE_COLS+1] = {
"QWERTYUIOP",
@ -80,8 +82,6 @@ static struct {
int kbdW;
int kbdH;
// TODO FIXME : support 2-players!
} touchport = { 0 };
// keyboard variables
@ -135,13 +135,13 @@ static inline void _switch_to_alpha_keyboard(void) {
}
}
static float _get_keyboard_visibility(void) {
#warning FIXME TODO ... this can become a common helper function ...
static inline float _get_keyboard_visibility(void) {
struct timespec now = { 0 };
struct timespec deltat = { 0 };
float alpha = minAlpha;
clock_gettime(CLOCK_MONOTONIC, &now);
alpha = minAlpha;
float alpha = minAlpha;
deltat = timespec_diff(kbd.timingBegin, now, NULL);
if (deltat.tv_sec == 0) {
alpha = 1.0;
@ -477,8 +477,7 @@ static void gltouchkbd_render(void) {
glBindTexture(GL_TEXTURE_2D, kbd.model->textureName);
if (kbd.model->texDirty) {
kbd.model->texDirty = false;
GLModelHUDKeyboard *hudKeyboard = (GLModelHUDKeyboard *)(kbd.model->custom);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, hudKeyboard->pixWidth, hudKeyboard->pixHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, kbd.model->texPixels);
glTexImage2D(GL_TEXTURE_2D, /*level*/0, /*internal format*/GL_RGBA, kbd.model->texWidth, kbd.model->texHeight, /*border*/0, /*format*/GL_RGBA, GL_UNSIGNED_BYTE, kbd.model->texPixels);
}
if (kbd.modelDirty) {
kbd.modelDirty = false;
@ -517,33 +516,33 @@ static bool gltouchkbd_onTouchEvent(interface_touch_event_t action, int pointer_
if (!isEnabled) {
return false;
}
if (!ownsScreen) {
return false;
}
float alpha = _get_keyboard_visibility();
if (alpha > 0.f) {
float x = x_coords[pointer_idx];
float y = y_coords[pointer_idx];
float x = x_coords[pointer_idx];
float y = y_coords[pointer_idx];
switch (action) {
case TOUCH_DOWN:
case TOUCH_POINTER_DOWN:
break;
switch (action) {
case TOUCH_DOWN:
case TOUCH_POINTER_DOWN:
break;
case TOUCH_MOVE:
break;
case TOUCH_MOVE:
break;
case TOUCH_UP:
case TOUCH_POINTER_UP:
_tap_key_at_point(x, y);
break;
case TOUCH_UP:
case TOUCH_POINTER_UP:
_tap_key_at_point(x, y);
break;
case TOUCH_CANCEL:
LOG("---KBD TOUCH CANCEL");
return false;
case TOUCH_CANCEL:
LOG("---KBD TOUCH CANCEL");
return false;
default:
LOG("!!!KBD UNKNOWN TOUCH EVENT : %d", action);
return false;
}
default:
LOG("!!!KBD UNKNOWN TOUCH EVENT : %d", action);
return false;
}
clock_gettime(CLOCK_MONOTONIC, &kbd.timingBegin);
@ -562,11 +561,26 @@ static void gltouchkbd_setTouchKeyboardEnabled(bool enabled) {
isEnabled = enabled;
}
static void gltouchkbd_setTouchKeyboardOwnsScreen(bool pwnd) {
ownsScreen = pwnd;
if (ownsScreen) {
minAlpha = minAlphaWhenOwnsScreen;
} else {
minAlpha = 0.0;
}
}
static void _animation_showTouchKeyboard(void) {
if (!isAvailable) {
return;
}
clock_gettime(CLOCK_MONOTONIC, &kbd.timingBegin);
}
static void _animation_hideTouchKeyboard(void) {
if (!isAvailable) {
return;
}
kbd.timingBegin = (struct timespec){ 0 };
}
@ -582,6 +596,7 @@ static void _init_gltouchkbd(void) {
keydriver_isTouchKeyboardAvailable = &gltouchkbd_isTouchKeyboardAvailable;
keydriver_setTouchKeyboardEnabled = &gltouchkbd_setTouchKeyboardEnabled;
keydriver_setTouchKeyboardOwnsScreen = &gltouchkbd_setTouchKeyboardOwnsScreen;
kbd.selectedCol = -1;
kbd.selectedRow = -1;

View File

@ -497,7 +497,7 @@ GLModel *mdlCreateQuad(GLfloat skew_x, GLfloat skew_y, GLfloat obj_w, GLfloat ob
model->texHeight = tex_h;
model->texFormat = tex_format;
if (tex_format == GL_RGBA) {
model->texPixels = (GLvoid *)calloc(tex_w*tex_h*4, 1);
model->texPixels = (GLvoid *)calloc(tex_w * tex_h * /*RGBA_8888*/4, 1);
} else {
ERRQUIT("non-GL_RBGA format textures untested ... FIXME!");
}