mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
Automatically send Render buffer if too large or before any GLX call
This commit is contained in:
parent
a951aa26cb
commit
8e833145ab
1 changed files with 39 additions and 7 deletions
|
|
@ -2,10 +2,24 @@
|
||||||
|
|
||||||
var constants = require('./glxconstants');
|
var constants = require('./glxconstants');
|
||||||
|
|
||||||
|
var MAX_SMALL_RENDER=65000;
|
||||||
|
|
||||||
module.exports = function(GLX, ctx) {
|
module.exports = function(GLX, ctx) {
|
||||||
buffers = [];
|
buffers = [];
|
||||||
|
var currentLength = 0;
|
||||||
|
|
||||||
function commandBuffer(opcode, len) {
|
function commandBuffer(opcode, len) {
|
||||||
|
if (currentLength + len > MAX_SMALL_RENDER) {
|
||||||
|
console.log("Flushing buffer ", currentLength);
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
if (len > MAX_SMALL_RENDER)
|
||||||
|
{
|
||||||
|
throw Error('Buffer too big. Please implement RenderLarge request');
|
||||||
|
// renderLarge();
|
||||||
|
}
|
||||||
|
|
||||||
|
currentLength += len;
|
||||||
var res = Buffer(len);
|
var res = Buffer(len);
|
||||||
res.writeUInt16LE(len, 0);
|
res.writeUInt16LE(len, 0);
|
||||||
res.writeUInt16LE(opcode, 2);
|
res.writeUInt16LE(opcode, 2);
|
||||||
|
|
@ -91,13 +105,17 @@ module.exports = function(GLX, ctx) {
|
||||||
buffers.push(res);
|
buffers.push(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function render(ctxLocal) {
|
||||||
|
if (!ctxLocal) // ctxLocal overrides ctx passed during creation of renderContext
|
||||||
|
ctxLocal = ctx;
|
||||||
|
console.log("render called");
|
||||||
|
GLX.Render(ctxLocal, buffers);
|
||||||
|
buffers = [];
|
||||||
|
currentLength = 0;
|
||||||
|
}
|
||||||
|
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
render: function(ctxLocal) {
|
Render: render,
|
||||||
if (!ctxLocal) // ctxLocalOverrides ctx passed during creation of renderContext
|
|
||||||
ctxLocal = ctx;
|
|
||||||
GLX.Render(ctx, buffers);
|
|
||||||
buffers = [];
|
|
||||||
},
|
|
||||||
Begin: function(what) {
|
Begin: function(what) {
|
||||||
serialize1i(4, what);
|
serialize1i(4, what);
|
||||||
},
|
},
|
||||||
|
|
@ -132,12 +150,18 @@ module.exports = function(GLX, ctx) {
|
||||||
Vertex3f: function(x, y, z) {
|
Vertex3f: function(x, y, z) {
|
||||||
serialize3fv(70, x, y, z);
|
serialize3fv(70, x, y, z);
|
||||||
},
|
},
|
||||||
|
Vertex3fv: function(v) {
|
||||||
|
serialize3fv(70, v[0], v[1], v[2]);
|
||||||
|
},
|
||||||
Color3f: function(r, g, b) {
|
Color3f: function(r, g, b) {
|
||||||
serialize3fv(8, r, g, b);
|
serialize3fv(8, r, g, b);
|
||||||
},
|
},
|
||||||
Normal3f: function(x, y, z) {
|
Normal3f: function(x, y, z) {
|
||||||
serialize3fv(30, x, y, z);
|
serialize3fv(30, x, y, z);
|
||||||
},
|
},
|
||||||
|
Normal3fv: function(v) {
|
||||||
|
serialize3fv(70, v[0], v[1], v[2]);
|
||||||
|
},
|
||||||
Color4f: function(r, g, b, a) {
|
Color4f: function(r, g, b, a) {
|
||||||
serialize4fv(16, r, g, b, a);
|
serialize4fv(16, r, g, b, a);
|
||||||
},
|
},
|
||||||
|
|
@ -191,7 +215,15 @@ module.exports = function(GLX, ctx) {
|
||||||
|
|
||||||
// bind some glx functions
|
// bind some glx functions
|
||||||
'NewList EndList GenLists SwapBuffers Finish'.split(' ').forEach(function(name) {
|
'NewList EndList GenLists SwapBuffers Finish'.split(' ').forEach(function(name) {
|
||||||
renderContext[name] = GLX[name].bind(GLX, ctx);
|
// todo: small camelCase ? to be consistent with webgl api
|
||||||
|
//renderContext[name] = GLX[name].bind(GLX, ctx);
|
||||||
|
|
||||||
|
// flush render buffer before glx requests
|
||||||
|
renderContext[name] = function(p1, p2, p3, p4, p5, p6, p7, p8) {
|
||||||
|
console.log(name);
|
||||||
|
renderContext.render();
|
||||||
|
GLX[name](ctx, p1, p2, p3, p4, p5, p6, p7, p8);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return renderContext;
|
return renderContext;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue