Skip to content

Commit f943b2d

Browse files
committed
gl and event fixes
1 parent b230ad9 commit f943b2d

File tree

7 files changed

+60
-67
lines changed

7 files changed

+60
-67
lines changed

_build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ do
4545
$CMAKE_DIR_PATH/SDL3/SDL3testTargets
4646
$CMAKE_DIR_PATH/SDL2_ttf/SDL2_ttf-static-targets
4747
$CMAKE_DIR_PATH/SDL3_ttf/SDL3_ttf-static-targets
48+
$CMAKE_DIR_PATH/SampleRate/SampleRateTargets
4849
"
4950

5051
for CMAKE_TARGETS_FILE_TO_PATCH in $CMAKE_TARGETS_FILES_TO_PATCH

libraries/SDL2

libraries/SDL3

libraries/webroguegfx/webroguegfx.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ void webroguegfx_gl_size(int *width, int *height) {
4141
*height = out_height;
4242
}
4343

44-
__attribute__((import_name("gl_init")))
45-
__attribute__((import_module("webrogue_gfx"))) void
46-
imported_webrogue_gfx_init_gl();
47-
48-
// TODO thread_local
49-
static char sGLInitialized;
50-
void webroguegfx_init_gl() {
51-
if(!sGLInitialized) {
52-
imported_webrogue_gfx_init_gl();
53-
sGLInitialized = 1;
54-
}
55-
}
56-
5744
__attribute__((import_name("get_gl_swap_interval")))
5845
__attribute__((import_module("webrogue_gfx"))) void
5946
imported_webrogue_gfx_get_gl_swap_interval(uint32_t *out_interval);

libraries/webroguegfx/webroguegfx.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ void *webroguegfx_gl_loader(const char *procname);
1111
void webroguegfx_get_gl_swap_interval(int *out_interval);
1212

1313
// Events
14-
struct webrogue_event_mouse_down {
15-
uint32_t x;
16-
uint32_t y;
14+
struct webrogue_event_mouse_button {
1715
uint32_t button;
18-
};
19-
struct webrogue_event_mouse_up {
16+
uint8_t down;
2017
uint32_t x;
2118
uint32_t y;
22-
uint32_t button;
2319
};
2420
struct webrogue_event_mouse_motion {
2521
uint32_t x;
2622
uint32_t y;
2723
};
24+
struct webrogue_event_key {
25+
uint8_t down;
26+
uint32_t scancode;
27+
};
2828
struct webrogue_event_quit {
2929
};
3030
enum webrogue_event_type {
3131
WEBROGUE_EVENT_TYPE_INVALID = 0,
32-
WEBROGUE_EVENT_TYPE_MOUSE_DOWN = 1,
33-
WEBROGUE_EVENT_TYPE_MOUSE_UP = 2,
34-
WEBROGUE_EVENT_TYPE_MOUSE_MOTION = 3,
35-
WEBROGUE_EVENT_TYPE_QUIT = 4,
32+
WEBROGUE_EVENT_TYPE_MOUSE_BUTTON = 16,
33+
WEBROGUE_EVENT_TYPE_MOUSE_MOTION = 17,
34+
WEBROGUE_EVENT_TYPE_KEY = 32,
35+
WEBROGUE_EVENT_TYPE_QUIT = 48,
3636
};
3737
typedef struct webrogue_event {
3838
enum webrogue_event_type type;
3939
union {
40-
struct webrogue_event_mouse_down mouse_down;
41-
struct webrogue_event_mouse_up mouse_up;
40+
struct webrogue_event_mouse_button mouse_button;
4241
struct webrogue_event_mouse_motion mouse_motion;
42+
struct webrogue_event_key key;
4343
struct webrogue_event_quit quit;
4444
} inner;
4545
} webrogue_event;

libraries/webroguegfx/webroguegfx_events.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "webroguegfx.h"
44
#include <stdlib.h>
55

6-
#define WEBROGUE_MAX_ENCODED_EVENT_SIZE 16
6+
#define WEBROGUE_MAX_ENCODED_EVENT_SIZE 20
77

88
__attribute__((import_name("poll")))
99
__attribute__((import_module("webrogue_gfx")))
@@ -53,18 +53,12 @@ webrogue_event webroguegfx_poll() {
5353
const char* current_pointer = ((const char*)buffer_data) + buffer_consumed;
5454
result.type = GET(uint32_t, 0);
5555
switch (result.type) {
56-
case WEBROGUE_EVENT_TYPE_MOUSE_DOWN: {
57-
BUF_SIZE(16);
58-
result.inner.mouse_down.x = GET(uint32_t, 4);
59-
result.inner.mouse_down.y = GET(uint32_t, 8);
60-
result.inner.mouse_down.button = GET(uint32_t, 12);
61-
return result;
62-
}
63-
case WEBROGUE_EVENT_TYPE_MOUSE_UP: {
64-
BUF_SIZE(16);
65-
result.inner.mouse_up.x = GET(uint32_t, 4);
66-
result.inner.mouse_up.y = GET(uint32_t, 8);
67-
result.inner.mouse_up.button = GET(uint32_t, 12);
56+
case WEBROGUE_EVENT_TYPE_MOUSE_BUTTON: {
57+
BUF_SIZE(20);
58+
result.inner.mouse_button.button = GET(uint32_t, 4);
59+
result.inner.mouse_button.down = GET(uint8_t, 16);
60+
result.inner.mouse_button.x = GET(uint32_t, 8);
61+
result.inner.mouse_button.y = GET(uint32_t, 12);
6862
return result;
6963
}
7064
case WEBROGUE_EVENT_TYPE_MOUSE_MOTION: {
@@ -73,6 +67,12 @@ webrogue_event webroguegfx_poll() {
7367
result.inner.mouse_motion.y = GET(uint32_t, 8);
7468
return result;
7569
}
70+
case WEBROGUE_EVENT_TYPE_KEY: {
71+
BUF_SIZE(12);
72+
result.inner.key.down = GET(uint8_t, 8);
73+
result.inner.key.scancode = GET(uint32_t, 4);
74+
return result;
75+
}
7676
case WEBROGUE_EVENT_TYPE_QUIT: {
7777
BUF_SIZE(4);
7878
return result;

libraries/webroguegfx/webroguegfx_gl.cpp

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,49 @@ extern "C" {
88
#include "webroguegfx_internal.h"
99
}
1010

11-
// clang-format off
12-
1311
#include "gl2_entry.cpp"
1412
#include "gl2_ftable.h"
1513

16-
static thread_local PFNGLFLUSHPROC sGLFlushThreadLocal;
14+
__attribute__((import_name("gl_init")))
15+
__attribute__((import_module("webrogue_gfx"))) void
16+
imported_webrogue_gfx_init_gl(uint8_t *out_status);
1717

18-
void webrogue_gfx_internal_glFlush(void) {
19-
if(sGLFlushThreadLocal) {
20-
sGLFlushThreadLocal();
21-
}
22-
}
18+
static thread_local PFNGLFLUSHPROC sGLFlush = nullptr;
2319

24-
extern "C" void* webroguegfx_gl_loader(const char* procname) {
25-
if(!getEGLThreadInfo()->hostConn) {
26-
// imported_init_gl();
20+
extern "C" void webroguegfx_init_gl() {
21+
if (!getEGLThreadInfo()->hostConn) {
22+
uint8_t status = 0;
23+
imported_webrogue_gfx_init_gl(&status);
24+
if (!status) {
25+
return;
26+
}
2727
getEGLThreadInfo()->hostConn = HostConnection::createUnique();
2828
getEGLThreadInfo()->hostConn->gl2Encoder()->setClientState(
29-
new gfxstream::guest::GLClientState(2, 0)
30-
);
31-
// TODO GLSharedGroup should be stored in getEGLThreadInfo()->currentContext->sharedGroup
29+
new gfxstream::guest::GLClientState(3, 0));
30+
// TODO GLSharedGroup should be stored in
31+
// getEGLThreadInfo()->currentContext->sharedGroup
3232
getEGLThreadInfo()->hostConn->gl2Encoder()->setSharedGroup(
33-
gfxstream::guest::GLSharedGroupPtr(
34-
new gfxstream::guest::GLSharedGroup()
35-
)
36-
);
37-
getEGLThreadInfo()->hostConn->gl2Encoder()->setVersion(
38-
3, 0,
39-
3, 0
40-
);
41-
for(int i = 0; i<gl2_num_funcs; i++) {
42-
if(strcmp(gl2_funcs_by_name[i].name, "glFlush") == 0) {
43-
sGLFlushThreadLocal = (PFNGLFLUSHPROC) gl2_funcs_by_name[i].proc;
33+
gfxstream::guest::GLSharedGroupPtr(
34+
new gfxstream::guest::GLSharedGroup()));
35+
getEGLThreadInfo()->hostConn->gl2Encoder()->setVersion(3, 0, 3, 0);
36+
for (int i = 0; i < gl2_num_funcs; i++) {
37+
if (strcmp(gl2_funcs_by_name[i].name, "glFlush") == 0) {
38+
sGLFlush = (PFNGLFLUSHPROC)gl2_funcs_by_name[i].proc;
4439
}
4540
}
4641
}
47-
for(int i = 0; i<gl2_num_funcs; i++) {
48-
if(strcmp(gl2_funcs_by_name[i].name, procname) == 0) {
42+
}
43+
44+
extern "C" void webrogue_gfx_internal_glFlush(void) {
45+
if (sGLFlush) {
46+
sGLFlush();
47+
}
48+
}
49+
50+
extern "C" void *webroguegfx_gl_loader(const char *procname) {
51+
webroguegfx_init_gl();
52+
for (int i = 0; i < gl2_num_funcs; i++) {
53+
if (strcmp(gl2_funcs_by_name[i].name, procname) == 0) {
4954
return gl2_funcs_by_name[i].proc;
5055
}
5156
}

0 commit comments

Comments
 (0)