mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[opengl] render a blue screen while waiting for sync
This commit is contained in:
parent
80581a4aa2
commit
a647a602bf
@ -186,8 +186,6 @@ static inline void updatePositionInfo()
|
||||
int renderThread(void * unused)
|
||||
{
|
||||
while(state.running)
|
||||
{
|
||||
if (state.started)
|
||||
{
|
||||
const uint64_t start = microtime();
|
||||
|
||||
@ -204,9 +202,6 @@ int renderThread(void * unused)
|
||||
state.fpsSleep = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
usleep(1000000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -898,6 +893,14 @@ int run()
|
||||
// also send us the current mouse shape since we won't know it yet
|
||||
DEBUG_INFO("Waiting for host to signal it's ready...");
|
||||
__sync_or_and_fetch(&state.shm->flags, KVMFR_HEADER_FLAG_RESTART);
|
||||
|
||||
// start the renderThread so we don't just display junk
|
||||
if (!(t_render = SDL_CreateThread(renderThread, "renderThread", NULL)))
|
||||
{
|
||||
DEBUG_ERROR("render create thread failed");
|
||||
break;
|
||||
}
|
||||
|
||||
while(state.running && (state.shm->flags & KVMFR_HEADER_FLAG_RESTART))
|
||||
{
|
||||
SDL_Event event;
|
||||
@ -905,13 +908,16 @@ int run()
|
||||
{
|
||||
if (event.type == SDL_QUIT)
|
||||
{
|
||||
if (!params.ignoreQuit)
|
||||
state.running = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
if (!state.running)
|
||||
break;
|
||||
|
||||
DEBUG_INFO("Host ready, starting session");
|
||||
|
||||
// check the header's magic and version are valid
|
||||
@ -941,12 +947,6 @@ int run()
|
||||
break;
|
||||
}
|
||||
|
||||
if (!(t_render = SDL_CreateThread(renderThread, "renderThread", NULL)))
|
||||
{
|
||||
DEBUG_ERROR("render create thread failed");
|
||||
break;
|
||||
}
|
||||
|
||||
while(state.running)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
@ -62,10 +62,10 @@ struct Inst
|
||||
struct Options opt;
|
||||
|
||||
bool amdPinnedMemSupport;
|
||||
bool preConfigured;
|
||||
bool configured;
|
||||
bool reconfigure;
|
||||
SDL_GLContext glContext;
|
||||
bool doneInfo;
|
||||
|
||||
SDL_Point window;
|
||||
bool resizeWindow;
|
||||
@ -84,6 +84,7 @@ struct Inst
|
||||
GLuint vboID[BUFFER_COUNT];
|
||||
uint8_t * texPixels[BUFFER_COUNT];
|
||||
LG_Lock syncLock;
|
||||
bool texReady;
|
||||
int texIndex;
|
||||
int texList;
|
||||
int fpsList;
|
||||
@ -123,10 +124,12 @@ static bool _check_gl_error(unsigned int line, const char * name);
|
||||
#define check_gl_error(name) _check_gl_error(__LINE__, name)
|
||||
|
||||
static void deconfigure(struct Inst * this);
|
||||
static bool pre_configure(struct Inst * this, SDL_Window *window);
|
||||
static bool configure(struct Inst * this, SDL_Window *window);
|
||||
static void update_mouse_shape(struct Inst * this, bool * newShape);
|
||||
static bool draw_frame(struct Inst * this);
|
||||
static void draw_mouse(struct Inst * this);
|
||||
static void render_wait();
|
||||
|
||||
const char * opengl_get_name()
|
||||
{
|
||||
@ -291,7 +294,7 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
||||
if (!this)
|
||||
return false;
|
||||
|
||||
if (!configure(this, window))
|
||||
if (!pre_configure(this, window))
|
||||
return false;
|
||||
|
||||
if (this->resizeWindow)
|
||||
@ -314,6 +317,23 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
||||
this->resizeWindow = false;
|
||||
}
|
||||
|
||||
if (!configure(this, window))
|
||||
{
|
||||
render_wait();
|
||||
SDL_GL_SwapWindow(window);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!draw_frame(this))
|
||||
return false;
|
||||
|
||||
if (!this->texReady)
|
||||
{
|
||||
render_wait();
|
||||
SDL_GL_SwapWindow(window);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this->params.showFPS && this->renderTime > 1e9)
|
||||
{
|
||||
char str[128];
|
||||
@ -392,14 +412,11 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
||||
glEndList();
|
||||
}
|
||||
|
||||
if (!draw_frame(this))
|
||||
return false;
|
||||
|
||||
bool newShape;
|
||||
update_mouse_shape(this, &newShape);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glCallList(this->texList + this->texIndex);
|
||||
draw_mouse(this);
|
||||
if (this->fpsTexture)
|
||||
@ -423,6 +440,12 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void render_wait()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
static void handle_opt_mipmap(void * opaque, const char *value)
|
||||
{
|
||||
struct Inst * this = (struct Inst *)opaque;
|
||||
@ -514,28 +537,18 @@ static bool _check_gl_error(unsigned int line, const char * name)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool configure(struct Inst * this, SDL_Window *window)
|
||||
static bool pre_configure(struct Inst * this, SDL_Window *window)
|
||||
{
|
||||
LG_LOCK(this->formatLock);
|
||||
if (!this->reconfigure)
|
||||
{
|
||||
LG_UNLOCK(this->formatLock);
|
||||
return this->configured;
|
||||
}
|
||||
|
||||
if (this->configured)
|
||||
deconfigure(this);
|
||||
if (this->preConfigured)
|
||||
return true;
|
||||
|
||||
this->glContext = SDL_GL_CreateContext(window);
|
||||
if (!this->glContext)
|
||||
{
|
||||
DEBUG_ERROR("Failed to create the OpenGL context");
|
||||
LG_UNLOCK(this->formatLock);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this->doneInfo)
|
||||
{
|
||||
DEBUG_INFO("Vendor : %s", glGetString(GL_VENDOR ));
|
||||
DEBUG_INFO("Renderer: %s", glGetString(GL_RENDERER));
|
||||
DEBUG_INFO("Version : %s", glGetString(GL_VERSION ));
|
||||
@ -558,10 +571,22 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
||||
}
|
||||
}
|
||||
|
||||
this->doneInfo = true;
|
||||
SDL_GL_SetSwapInterval(this->opt.vsync ? 1 : 0);
|
||||
this->preConfigured = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool configure(struct Inst * this, SDL_Window *window)
|
||||
{
|
||||
LG_LOCK(this->formatLock);
|
||||
if (!this->reconfigure)
|
||||
{
|
||||
LG_UNLOCK(this->formatLock);
|
||||
return this->configured;
|
||||
}
|
||||
|
||||
SDL_GL_SetSwapInterval(this->opt.vsync ? 1 : 0);
|
||||
if (this->configured)
|
||||
deconfigure(this);
|
||||
|
||||
switch(this->format.comp)
|
||||
{
|
||||
@ -635,12 +660,14 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
||||
{
|
||||
const int pagesize = getpagesize();
|
||||
this->texPixels[0] = memalign(pagesize, this->texSize * BUFFER_COUNT);
|
||||
memset(this->texPixels[0], 0, this->texSize * BUFFER_COUNT);
|
||||
for(int i = 1; i < BUFFER_COUNT; ++i)
|
||||
this->texPixels[i] = this->texPixels[0] + this->texSize;
|
||||
|
||||
for(int i = 0; i < BUFFER_COUNT; ++i)
|
||||
{
|
||||
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, this->vboID[i]);
|
||||
|
||||
if (check_gl_error("glBindBuffer"))
|
||||
{
|
||||
LG_UNLOCK(this->formatLock);
|
||||
@ -1122,6 +1149,7 @@ static bool draw_frame(struct Inst * this)
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
LG_UNLOCK(this->formatLock);
|
||||
this->texReady = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user