mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-26 07:17:23 +00:00
[client] opengl: handle configuration failure properly
This commit is contained in:
parent
30e3a43311
commit
a6f23f00b4
@ -169,8 +169,15 @@ struct Inst
|
|||||||
static bool _check_gl_error(unsigned int line, const char * name);
|
static bool _check_gl_error(unsigned int line, const char * name);
|
||||||
#define check_gl_error(name) _check_gl_error(__LINE__, name)
|
#define check_gl_error(name) _check_gl_error(__LINE__, name)
|
||||||
|
|
||||||
|
enum ConfigStatus
|
||||||
|
{
|
||||||
|
CONFIG_STATUS_OK,
|
||||||
|
CONFIG_STATUS_ERROR,
|
||||||
|
CONFIG_STATUS_NOOP
|
||||||
|
};
|
||||||
|
|
||||||
static void deconfigure(struct Inst * this);
|
static void deconfigure(struct Inst * this);
|
||||||
static bool configure(struct Inst * this, SDL_Window *window);
|
static enum ConfigStatus configure(struct Inst * this, SDL_Window *window);
|
||||||
static void update_mouse_shape(struct Inst * this, bool * newShape);
|
static void update_mouse_shape(struct Inst * this, bool * newShape);
|
||||||
static bool draw_frame(struct Inst * this);
|
static bool draw_frame(struct Inst * this);
|
||||||
static void draw_mouse(struct Inst * this);
|
static void draw_mouse(struct Inst * this);
|
||||||
@ -549,9 +556,19 @@ bool opengl_render(void * opaque, SDL_Window * window)
|
|||||||
if (!this)
|
if (!this)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (configure(this, window))
|
switch(configure(this, window))
|
||||||
|
{
|
||||||
|
case CONFIG_STATUS_ERROR:
|
||||||
|
DEBUG_ERROR("configure failed");
|
||||||
|
return false;
|
||||||
|
|
||||||
|
case CONFIG_STATUS_NOOP :
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONFIG_STATUS_OK :
|
||||||
if (!draw_frame(this))
|
if (!draw_frame(this))
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
@ -828,13 +845,13 @@ static bool _check_gl_error(unsigned int line, const char * name)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool configure(struct Inst * this, SDL_Window *window)
|
static enum ConfigStatus configure(struct Inst * this, SDL_Window *window)
|
||||||
{
|
{
|
||||||
LG_LOCK(this->formatLock);
|
LG_LOCK(this->formatLock);
|
||||||
if (!this->reconfigure)
|
if (!this->reconfigure)
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return this->configured;
|
return CONFIG_STATUS_NOOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->configured)
|
if (this->configured)
|
||||||
@ -862,7 +879,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUG_ERROR("Unknown/unsupported compression type");
|
DEBUG_ERROR("Unknown/unsupported compression type");
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate the texture size in bytes
|
// calculate the texture size in bytes
|
||||||
@ -880,30 +897,36 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (this->amdPinnedMemSupport)
|
if (this->amdPinnedMemSupport)
|
||||||
{
|
{
|
||||||
const int pagesize = getpagesize();
|
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)
|
for(int i = 0; i < BUFFER_COUNT; ++i)
|
||||||
{
|
{
|
||||||
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, this->vboID[i]);
|
this->texPixels[i] = aligned_alloc(pagesize, this->texSize);
|
||||||
|
if (!this->texPixels[i])
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("Failed to allocate memory for texture");
|
||||||
|
return CONFIG_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(this->texPixels[i], 0, this->texSize);
|
||||||
|
|
||||||
|
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, this->vboID[i]);
|
||||||
if (check_gl_error("glBindBuffer"))
|
if (check_gl_error("glBindBuffer"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD,
|
GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD,
|
||||||
this->texSize,
|
this->texSize,
|
||||||
this->texPixels[i],
|
this->texPixels[i],
|
||||||
GL_STREAM_DRAW);
|
GL_STREAM_DRAW
|
||||||
|
);
|
||||||
|
|
||||||
if (check_gl_error("glBufferData"))
|
if (check_gl_error("glBufferData"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
|
glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
|
||||||
@ -916,7 +939,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (check_gl_error("glBindBuffer"))
|
if (check_gl_error("glBindBuffer"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBufferData(
|
glBufferData(
|
||||||
@ -928,7 +951,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (check_gl_error("glBufferData"))
|
if (check_gl_error("glBufferData"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
||||||
@ -939,7 +962,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (check_gl_error("glGenTextures"))
|
if (check_gl_error("glGenTextures"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
this->hasFrames = true;
|
this->hasFrames = true;
|
||||||
|
|
||||||
@ -950,7 +973,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (check_gl_error("glBindTexture"))
|
if (check_gl_error("glBindTexture"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
@ -967,7 +990,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
if (check_gl_error("glTexImage2D"))
|
if (check_gl_error("glTexImage2D"))
|
||||||
{
|
{
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return false;
|
return CONFIG_STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// configure the texture
|
// configure the texture
|
||||||
@ -998,7 +1021,7 @@ static bool configure(struct Inst * this, SDL_Window *window)
|
|||||||
this->reconfigure = false;
|
this->reconfigure = false;
|
||||||
|
|
||||||
LG_UNLOCK(this->formatLock);
|
LG_UNLOCK(this->formatLock);
|
||||||
return true;
|
return CONFIG_STATUS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deconfigure(struct Inst * this)
|
static void deconfigure(struct Inst * this)
|
||||||
@ -1026,9 +1049,6 @@ static void deconfigure(struct Inst * this)
|
|||||||
|
|
||||||
if (this->amdPinnedMemSupport)
|
if (this->amdPinnedMemSupport)
|
||||||
{
|
{
|
||||||
if (this->texPixels[0])
|
|
||||||
free(this->texPixels[0]);
|
|
||||||
|
|
||||||
for(int i = 0; i < BUFFER_COUNT; ++i)
|
for(int i = 0; i < BUFFER_COUNT; ++i)
|
||||||
{
|
{
|
||||||
if (this->fences[i])
|
if (this->fences[i])
|
||||||
@ -1036,9 +1056,14 @@ static void deconfigure(struct Inst * this)
|
|||||||
glDeleteSync(this->fences[i]);
|
glDeleteSync(this->fences[i]);
|
||||||
this->fences[i] = NULL;
|
this->fences[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->texPixels[i])
|
||||||
|
{
|
||||||
|
free(this->texPixels[i]);
|
||||||
this->texPixels[i] = NULL;
|
this->texPixels[i] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this->configured = false;
|
this->configured = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user