Browse Source

Do not upload whole static buffer, instead use glBufferSubData. This commit fixes lag (and skipped iinputs) when other people are drawing

ssao
A.Olokhtonov 1 year ago
parent
commit
c5928dd5bd
  1. 24
      client/index.html
  2. 8
      client/index.js
  3. 14
      client/webgl_draw.js
  4. 6
      client/webgl_geometry.js

24
client/index.html

@ -7,20 +7,20 @@ @@ -7,20 +7,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="icons/favicon.svg" id="favicon">
<link rel="stylesheet" type="text/css" href="default.css?v=45">
<link rel="stylesheet" type="text/css" href="default.css?v=50">
<script type="text/javascript" src="aux.js?v=45"></script>
<script type="text/javascript" src="math.js?v=45"></script>
<script type="text/javascript" src="tools.js?v=45"></script>
<script type="text/javascript" src="webgl_geometry.js?v=45"></script>
<script type="text/javascript" src="webgl_shaders.js?v=45"></script>
<script type="text/javascript" src="webgl_listeners.js?v=45"></script>
<script type="text/javascript" src="webgl_draw.js?v=45"></script>
<script type="text/javascript" src="index.js?v=45"></script>
<script type="text/javascript" src="aux.js?v=50"></script>
<script type="text/javascript" src="math.js?v=50"></script>
<script type="text/javascript" src="tools.js?v=50"></script>
<script type="text/javascript" src="webgl_geometry.js?v=50"></script>
<script type="text/javascript" src="webgl_shaders.js?v=50"></script>
<script type="text/javascript" src="webgl_listeners.js?v=50"></script>
<script type="text/javascript" src="webgl_draw.js?v=50"></script>
<script type="text/javascript" src="index.js?v=50"></script>
<script type="text/javascript" src="client_send.js?v=45"></script>
<script type="text/javascript" src="client_recv.js?v=45"></script>
<script type="text/javascript" src="websocket.js?v=45"></script>
<script type="text/javascript" src="client_send.js?v=50"></script>
<script type="text/javascript" src="client_recv.js?v=50"></script>
<script type="text/javascript" src="websocket.js?v=50"></script>
</head>
<body>
<div class="main">

8
client/index.js

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
document.addEventListener('DOMContentLoaded', main);
const config = {
ws_url: 'wss://desk.local/ws/',
ping_url: 'https://desk.local/api/ping',
image_url: 'https://desk.local/images/',
ws_url: 'wss://192.168.100.2/ws/',
ping_url: 'https://192.168.100.2/api/ping',
image_url: 'https://192.168.100.2/images/',
sync_timeout: 1000,
ws_reconnect_timeout: 2000,
brush_preview_timeout: 1000,
@ -114,6 +114,8 @@ function main() { @@ -114,6 +114,8 @@ function main() {
'frametime_window': [],
'frametime_window_head': 0,
'static_upload_from': 0,
'need_static_allocate': true,
'need_static_upload': true,
'need_dynamic_upload': false,

14
client/webgl_draw.js

@ -47,9 +47,21 @@ function draw(state, context) { @@ -47,9 +47,21 @@ function draw(state, context) {
gl.vertexAttribPointer(locations['a_line'], 4, gl.FLOAT, false, config.bytes_per_point, 4 * 3);
gl.vertexAttribPointer(locations['a_color'], 3, gl.UNSIGNED_BYTE, true, config.bytes_per_point, 4 * 3 + 4 * 4);
if (context.need_static_allocate) {
console.debug('static allocate');
gl.bufferData(gl.ARRAY_BUFFER, context.static_serializer.size, gl.DYNAMIC_DRAW);
context.need_static_allocate = false;
context.static_upload_from = 0;
context.need_static_upload = true;
}
if (context.need_static_upload) {
gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array(context.static_serializer.buffer, 0, context.static_serializer.offset), gl.STATIC_DRAW);
console.debug('static upload');
const upload_offset = context.static_upload_from;
const upload_size = context.static_serializer.offset - upload_offset;
gl.bufferSubData(gl.ARRAY_BUFFER, upload_offset, new Uint8Array(context.static_serializer.buffer, upload_offset, upload_size));
context.need_static_upload = false;
context.static_upload_from = context.static_serializer.offset;
}
gl.drawArrays(gl.TRIANGLES, 0, static_points);

6
client/webgl_geometry.js

@ -84,6 +84,10 @@ function geometry_prepare_stroke(state) { @@ -84,6 +84,10 @@ function geometry_prepare_stroke(state) {
return null;
}
if (state.players[state.me].points.length === 0) {
return null;
}
return {
'color': state.players[state.me].color,
'width': state.players[state.me].width,
@ -101,10 +105,10 @@ function geometry_add_stroke(state, context, stroke) { @@ -101,10 +105,10 @@ function geometry_add_stroke(state, context, stroke) {
if (bytes_left < bytes_needed) {
const extend_to = Math.ceil((context.static_serializer.size + bytes_needed) * 1.62);
context.static_serializer = ser_extend(context.static_serializer, extend_to);
context.need_static_allocate = true;
}
push_stroke(context.static_serializer, stroke);
context.need_static_upload = true;
}

Loading…
Cancel
Save