mirror of
https://github.com/danbulant/node-x11
synced 2026-06-14 04:01:10 +00:00
add TexImage2D and TexParameter functions
This commit is contained in:
parent
baf67a3c69
commit
1545b39196
1 changed files with 78 additions and 2 deletions
|
|
@ -101,6 +101,14 @@ module.exports = function(GLX, ctx) {
|
|||
buffers.push(res);
|
||||
}
|
||||
|
||||
function serialize3i(opcode, i1, i2, i3) {
|
||||
var res = commandBuffer(opcode, 16);
|
||||
res.writeUInt32LE(i1, 4);
|
||||
res.writeUInt32LE(i2, 8);
|
||||
res.writeUInt32LE(i3, 12);
|
||||
buffers.push(res);
|
||||
}
|
||||
|
||||
function serialize2i1f(opcode, i1, i2, f1) {
|
||||
var res = commandBuffer(opcode, 16);
|
||||
res.writeUInt32LE(i1, 4);
|
||||
|
|
@ -109,6 +117,15 @@ module.exports = function(GLX, ctx) {
|
|||
buffers.push(res);
|
||||
}
|
||||
|
||||
function serialize2ifv(opcode, i1, i2, fv) {
|
||||
var res = commandBuffer(opcode, 12 + fv.length*4);
|
||||
res.writeUInt32LE(i1, 4);
|
||||
res.writeUInt32LE(i2, 8);
|
||||
for (var i=0; i < fv.length; ++i)
|
||||
res.writeFloatLE(fv[i], 12+i*4);
|
||||
buffers.push(res);
|
||||
}
|
||||
|
||||
function serialize2i4f(opcode, i1, i2, f1, f2, f3, f4) {
|
||||
var res = commandBuffer(opcode, 28);
|
||||
res.writeUInt32LE(i1, 4);
|
||||
|
|
@ -222,7 +239,7 @@ module.exports = function(GLX, ctx) {
|
|||
serialize2i(85, target, mode);
|
||||
},
|
||||
BindTexture: function(target, texture) {
|
||||
serialize2i(4117, target, texture);
|
||||
serialize2i(4117, target, texture);
|
||||
},
|
||||
TexEnvf: function(target, pname, param) {
|
||||
serialize2i1f(112, target, pname, param);
|
||||
|
|
@ -230,7 +247,66 @@ module.exports = function(GLX, ctx) {
|
|||
TexParameterf: function(target, pname, param) {
|
||||
serialize2i1f(105, target, pname, param);
|
||||
},
|
||||
TexCoords2f: function(x, y) {
|
||||
TexParameterfv: function(target, pname, param) {
|
||||
serialize2ifv(106, target, pname, param);
|
||||
},
|
||||
TexParameteri: function(target, pname, param) {
|
||||
serialize3i(107, target, pname, param);
|
||||
},
|
||||
TexImage2D: function(target, level, internalFormat, width, height, border, format, type, data) {
|
||||
|
||||
var typeSize = [];
|
||||
typeSize[constants.FLOAT] = 4;
|
||||
typeSize[constants.BYTE] = 1;
|
||||
typeSize[constants.UNSIGNED_BYTE] = 1;
|
||||
|
||||
var res = commandBuffer(110, 56 + data.length*typeSize[type]);
|
||||
res[4] = 0; // swapbytes
|
||||
res[5] = 0; // lsbfirst
|
||||
res.writeUInt16LE(0, 6); // unused
|
||||
|
||||
/*
|
||||
defaults: (from http://stackoverflow.com/questions/21563590/glteximage2d-protocol-arguments?noredirect=1#comment32577251_21563590 )
|
||||
|
||||
GL_UNPACK_SWAP_BYTES boolean false true or false
|
||||
GL_UNPACK_LSB_FIRST boolean false true or false
|
||||
GL_UNPACK_ROW_LENGTH integer 0 [0,oo)
|
||||
GL_UNPACK_SKIP_ROWS integer 0 [0,oo)
|
||||
GL_UNPACK_SKIP_PIXELS integer 0 [0,oo)
|
||||
GL_UNPACK_ALIGNMENT integer 4 1, 2, 4, or 8
|
||||
|
||||
*/
|
||||
|
||||
res.writeUInt32LE(0, 8); // rowlength
|
||||
res.writeUInt32LE(0, 12); // skiprows
|
||||
res.writeUInt32LE(0, 16); // skippixels
|
||||
res.writeUInt32LE(4, 20); // alignment
|
||||
|
||||
res.writeUInt32LE(target, 24);
|
||||
res.writeUInt32LE(level, 28);
|
||||
res.writeUInt32LE(internalFormat, 32);
|
||||
res.writeUInt32LE(width, 36);
|
||||
res.writeUInt32LE(height, 40);
|
||||
res.writeUInt32LE(border, 44);
|
||||
res.writeUInt32LE(format, 48);
|
||||
res.writeUInt32LE(type, 52);
|
||||
|
||||
switch(type) {
|
||||
case constants.FLOAT:
|
||||
for (var i=0; i < data.length; ++i)
|
||||
res.writeFloatLE(data[i], 56+i*typeSize[type]);
|
||||
break;
|
||||
case constants.BYTE:
|
||||
case constants.UNSIGNED_BYTE:
|
||||
for (var i=0; i < data.length; ++i)
|
||||
res[56+i] = data[i];
|
||||
break;
|
||||
default:
|
||||
throw new Error('unsupported texture type:' + type);
|
||||
}
|
||||
buffers.push(res);
|
||||
},
|
||||
TexCoord2f: function(x, y) {
|
||||
serialize2f(54, x, y);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue