mirror of
https://github.com/danbulant/node-x11
synced 2026-06-24 17:21:47 +00:00
import constants; Light,Material,Normal,BlendFunc
This commit is contained in:
parent
2aa2001067
commit
2777e6dd01
1 changed files with 62 additions and 5 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
// see http://cgit.freedesktop.org/mesa/mesa/tree/src/mapi/glapi/gen/gl_API.xml
|
// see http://cgit.freedesktop.org/mesa/mesa/tree/src/mapi/glapi/gen/gl_API.xml
|
||||||
|
|
||||||
module.exports = function(GLX) {
|
var constants = require('./glxconstants');
|
||||||
|
|
||||||
|
module.exports = function(GLX, ctx) {
|
||||||
buffers = [];
|
buffers = [];
|
||||||
|
|
||||||
function commandBuffer(opcode, len) {
|
function commandBuffer(opcode, len) {
|
||||||
|
|
@ -52,15 +54,40 @@ module.exports = function(GLX) {
|
||||||
buffers.push(res);
|
buffers.push(res);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function serialize1i(opcode, value) {
|
function serialize1i(opcode, value) {
|
||||||
var res = commandBuffer(opcode, 8);
|
var res = commandBuffer(opcode, 8);
|
||||||
res.writeUInt32LE(value, 4);
|
res.writeUInt32LE(value, 4);
|
||||||
buffers.push(res);
|
buffers.push(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
function serialize1f(opcode, value) {
|
||||||
render: function(ctx) {
|
var res = commandBuffer(opcode, 8);
|
||||||
|
res.writeFloatLE(value, 4);
|
||||||
|
buffers.push(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize2i(opcode, i1, i2) {
|
||||||
|
var res = commandBuffer(opcode, 12);
|
||||||
|
res.writeUInt32LE(i1, 4);
|
||||||
|
res.writeUInt32LE(i2, 8);
|
||||||
|
buffers.push(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
function serialize2i4f(opcode, i1, i2, f1, f2, f3, f4) {
|
||||||
|
var res = commandBuffer(opcode, 28);
|
||||||
|
res.writeUInt32LE(i1, 4);
|
||||||
|
res.writeUInt32LE(i2, 8);
|
||||||
|
res.writeFloatLE(f1, 12);
|
||||||
|
res.writeFloatLE(f2, 16);
|
||||||
|
res.writeFloatLE(f3, 20);
|
||||||
|
res.writeFloatLE(f4, 24);
|
||||||
|
buffers.push(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
var renderContext = {
|
||||||
|
render: function(ctxLocal) {
|
||||||
|
if (!ctxLocal) // ctxLocalOverrides ctx passed during creation of renderContext
|
||||||
|
ctxLocal = ctx;
|
||||||
GLX.Render(ctx, buffers);
|
GLX.Render(ctx, buffers);
|
||||||
buffers = [];
|
buffers = [];
|
||||||
},
|
},
|
||||||
|
|
@ -78,6 +105,7 @@ module.exports = function(GLX) {
|
||||||
},
|
},
|
||||||
PopMatrix: function() {
|
PopMatrix: function() {
|
||||||
serialize0(183);
|
serialize0(183);
|
||||||
|
|
||||||
},
|
},
|
||||||
PushMatrix: function() {
|
PushMatrix: function() {
|
||||||
serialize0(184);
|
serialize0(184);
|
||||||
|
|
@ -100,6 +128,9 @@ module.exports = function(GLX) {
|
||||||
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) {
|
||||||
|
serialize3fv(30, x, y, z);
|
||||||
|
},
|
||||||
Color4f: function(r, g, b, a) {
|
Color4f: function(r, g, b, a) {
|
||||||
serialize4fv(16, r, g, b, a);
|
serialize4fv(16, r, g, b, a);
|
||||||
},
|
},
|
||||||
|
|
@ -119,7 +150,16 @@ module.exports = function(GLX) {
|
||||||
serialize1i(139, value);
|
serialize1i(139, value);
|
||||||
},
|
},
|
||||||
Lightfv: function(light, name, p1, p2, p3, p4) {
|
Lightfv: function(light, name, p1, p2, p3, p4) {
|
||||||
seralize2i4f(87, light, name, p1, p2, p3, p4);
|
if (p1.length)
|
||||||
|
serialize2i4f(87, light, name, p1[0], p1[1], p1[2], p1[3]);
|
||||||
|
else
|
||||||
|
serialize2i4f(87, light, name, p1, p2, p3, p4);
|
||||||
|
},
|
||||||
|
Materialfv: function(light, name, p1, p2, p3, p4) {
|
||||||
|
if (p1.length)
|
||||||
|
serialize2i4f(97, light, name, p1[0], p1[1], p1[2], p1[3]);
|
||||||
|
else
|
||||||
|
serialize2i4f(97, light, name, p1, p2, p3, p4);
|
||||||
},
|
},
|
||||||
Clear: function(mask) {
|
Clear: function(mask) {
|
||||||
serialize1i(0x7f, mask);
|
serialize1i(0x7f, mask);
|
||||||
|
|
@ -127,6 +167,23 @@ module.exports = function(GLX) {
|
||||||
ShadeModel: function(model) {
|
ShadeModel: function(model) {
|
||||||
serialize1i(104, model);
|
serialize1i(104, model);
|
||||||
},
|
},
|
||||||
|
BlendFunc: function(sfactor, dfactor) {
|
||||||
|
serialize2i(160, sfactor, dfactor);
|
||||||
|
},
|
||||||
|
PointSize: function(r) {
|
||||||
|
serialize1f(100, r);
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// import all constants
|
||||||
|
for (var c in constants)
|
||||||
|
renderContext[c] = constants[c];
|
||||||
|
|
||||||
|
// bind some glx functions
|
||||||
|
'NewList EndList GenLists SwapBuffers Finish'.split(' ').forEach(function(name) {
|
||||||
|
renderContext[name] = GLX[name].bind(GLX, ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
return renderContext;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue