mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[client] slow down mouse updates to something reasonable
This commit is contained in:
parent
7986350cb8
commit
81f4a7fade
@ -56,6 +56,8 @@ struct LGR_OpenGL
|
|||||||
uint64_t frameCount;
|
uint64_t frameCount;
|
||||||
SDL_Rect fpsRect;
|
SDL_Rect fpsRect;
|
||||||
|
|
||||||
|
bool mouseUpdate;
|
||||||
|
uint64_t lastMouseDraw;
|
||||||
LG_RendererCursor mouseType;
|
LG_RendererCursor mouseType;
|
||||||
bool mouseRepair;
|
bool mouseRepair;
|
||||||
SDL_Rect mouseRepairPos;
|
SDL_Rect mouseRepairPos;
|
||||||
@ -213,6 +215,8 @@ bool lgr_opengl_initialize(void ** opaque, const LG_RendererParams params, const
|
|||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
(void*)0
|
(void*)0
|
||||||
);
|
);
|
||||||
|
if (lgr_opengl_check_error("glTexImage2D"))
|
||||||
|
return false;
|
||||||
|
|
||||||
// create the display lists
|
// create the display lists
|
||||||
glNewList(this->texList + i, GL_COMPILE);
|
glNewList(this->texList + i, GL_COMPILE);
|
||||||
@ -409,6 +413,7 @@ bool lgr_opengl_on_mouse_shape(void * opaque, const LG_RendererCursor cursor, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->mouseUpdate = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +429,7 @@ bool lgr_opengl_on_mouse_event(void * opaque, const bool visible, const int x, c
|
|||||||
this->mouseVisible = visible;
|
this->mouseVisible = visible;
|
||||||
this->mousePos.x = x;
|
this->mousePos.x = x;
|
||||||
this->mousePos.y = y;
|
this->mousePos.y = y;
|
||||||
|
this->mouseUpdate = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,8 +439,9 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data, bool resampl
|
|||||||
if (!this || !this->initialized)
|
if (!this || !this->initialized)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (++this->texIndex == VBO_BUFFERS)
|
int texIndex = this->texIndex + 1;
|
||||||
this->texIndex = 0;
|
if (texIndex == VBO_BUFFERS)
|
||||||
|
texIndex = 0;
|
||||||
|
|
||||||
if (this->params.showFPS && this->renderTime > 1e9)
|
if (this->params.showFPS && this->renderTime > 1e9)
|
||||||
{
|
{
|
||||||
@ -508,12 +514,12 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data, bool resampl
|
|||||||
}
|
}
|
||||||
|
|
||||||
// copy the buffer to the texture
|
// copy the buffer to the texture
|
||||||
memcpySSE(this->texPixels[this->texIndex], data, this->texSize);
|
memcpySSE(this->texPixels[texIndex], data, this->texSize);
|
||||||
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vboID[this->texIndex]);
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, this->vboID[texIndex]);
|
||||||
glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, this->texSize);
|
glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, 0, this->texSize);
|
||||||
|
|
||||||
// bind the texture and update it
|
// bind the texture and update it
|
||||||
glBindTexture(GL_TEXTURE_2D , this->textures[this->texIndex]);
|
glBindTexture(GL_TEXTURE_2D , this->textures[texIndex]);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT , 4 );
|
glPixelStorei(GL_UNPACK_ALIGNMENT , 4 );
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH , this->format.width );
|
glPixelStorei(GL_UNPACK_ROW_LENGTH , this->format.width );
|
||||||
|
|
||||||
@ -552,17 +558,12 @@ bool lgr_opengl_on_frame_event(void * opaque, const uint8_t * data, bool resampl
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->frameUpdate = true;
|
this->frameUpdate = true;
|
||||||
|
this->texIndex = texIndex;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void lgr_opengl_draw_mouse(struct LGR_OpenGL * this)
|
inline void lgr_opengl_draw_mouse(struct LGR_OpenGL * this)
|
||||||
{
|
{
|
||||||
if (this->mouseRepair)
|
|
||||||
{
|
|
||||||
glCallList(this->texList + this->texIndex);
|
|
||||||
this->mouseRepair = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->mouseVisible)
|
if (!this->mouseVisible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -612,27 +613,39 @@ bool lgr_opengl_render(void * opaque)
|
|||||||
glEnable(GL_SCISSOR_TEST);
|
glEnable(GL_SCISSOR_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->frameUpdate)
|
if (!this->frameUpdate)
|
||||||
{
|
{
|
||||||
glCallList(this->texList + this->texIndex);
|
if (!this->mouseUpdate)
|
||||||
this->mouseRepair = false;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
|
// don't update the mouse too fast
|
||||||
|
const uint64_t delta = nanotime() - this->lastMouseDraw;
|
||||||
|
if (delta < 1e7)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
glCallList(this->texList + this->texIndex);
|
||||||
|
lgr_opengl_draw_mouse(this);
|
||||||
|
glFinish();
|
||||||
|
|
||||||
|
this->mouseUpdate = false;
|
||||||
|
this->lastMouseDraw = nanotime();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glDrawBuffer(GL_BACK);
|
||||||
|
glCallList(this->texList + this->texIndex);
|
||||||
lgr_opengl_draw_mouse(this);
|
lgr_opengl_draw_mouse(this);
|
||||||
if (this->fpsTexture)
|
if (this->fpsTexture)
|
||||||
glCallList(this->fpsList);
|
glCallList(this->fpsList);
|
||||||
|
glDrawBuffer(GL_FRONT);
|
||||||
GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
||||||
glWaitSync(sync, 0, 1000);
|
|
||||||
glDeleteSync(sync);
|
|
||||||
|
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
glXGetVideoSyncSGI(&count);
|
glXGetVideoSyncSGI(&count);
|
||||||
if (count == this->gpuFrameCount)
|
if (count == this->gpuFrameCount)
|
||||||
glXWaitVideoSyncSGI(1, 0, &count);
|
glXWaitVideoSyncSGI(1, 0, &count);
|
||||||
|
|
||||||
SDL_GL_SwapWindow(this->params.window);
|
SDL_GL_SwapWindow(this->params.window);
|
||||||
glXGetVideoSyncSGI(&this->gpuFrameCount);
|
glXGetVideoSyncSGI(&this->gpuFrameCount);
|
||||||
|
}
|
||||||
|
|
||||||
++this->frameCount;
|
++this->frameCount;
|
||||||
const uint64_t t = nanotime();
|
const uint64_t t = nanotime();
|
||||||
@ -640,6 +653,8 @@ bool lgr_opengl_render(void * opaque)
|
|||||||
this->lastFrameTime = t;
|
this->lastFrameTime = t;
|
||||||
|
|
||||||
this->frameUpdate = false;
|
this->frameUpdate = false;
|
||||||
|
this->mouseUpdate = false;
|
||||||
|
this->lastMouseDraw = t;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user