maghoff / osmesa-webgl Goto Github PK
View Code? Open in Web Editor NEWWebGL for node, running on OSMesa
WebGL for node, running on OSMesa
Is it currently possible to load textures into osmesa-webgl using a 6 argument call to the following function:
function texImage2D(target, level, internalformat, width, height, border, format, type, pixels)
When 6 arguments are passed, webgl.js checks the arguments using the following code:
if (arguments.length == 6) {
// width is now format, height is now type, and border is now pixels
if(!(
typeof target === "number" &&
typeof level === "number" && typeof internalformat === "number" &&
typeof width === "number" && typeof height === "number" &&
(border==null || border instanceof Image))) {
throw new TypeError('Expected texImage2D(number target, number level, number internalformat, number format, number type, Image pixels)');
}
pixels=border;
type=height;
format=width;
return _texImage2D(target, level, internalformat, pixels.width, pixels.height, 0, format, type, pixels);
}
The sixth argument (border) is being checked as an instanceof the "Image" class. It appears to me that there is some code in the history of osmesa-webgl that attempted to provide an Image class as a web browser-like interface to an image object in the src/image.h and src/image.cc files. These files were later removed, and I do not believe there is a current implementation of an Image class that will work for this sixth argument.
In the 9 argument version of the function call, the pixels argument is being checked as type "object":
else if (arguments.length == 9) {
if(!(typeof target === "number" &&
typeof level === "number" && typeof internalformat === "number" &&
typeof width === "number" && typeof height === "number" && typeof border === "number" &&
typeof format === "number" && typeof type === "number" &&
(pixels==null || typeof pixels === "object"))) {
throw new TypeError('Expected texImage2D(number target, number level, number internalformat, number width, number height, number border, number format, number type, ArrayBufferView pixels)');
}
return _texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
The getImageData method is later called with the pixels object as the parameter, which then calls GetIndexedPropertiesExternalArrayData on pixels:
inline void *getImageData(Local<Value> arg) {
void *pixels = NULL;
if (!arg->IsNull()) {
Local<Object> obj = Local<Object>::Cast(arg);
if (!obj->IsObject())
ThrowException(JS_STR("Bad texture argument"));
pixels = obj->GetIndexedPropertiesExternalArrayData();
}
return pixels;
}
Does this mean that the pixels argument needs to be an instance of v8::Array with a raw array of RGB pixel data? If that is the case, I guess I would need to load the image in using a separate image library, convert to raw RGB pixel data, stuff into a v8::Array and then pass into the 8 argument version of the textImage2D method. Does that sound right?
In general, I could use a pointer on how best to load textures using osmesa-webgl. I'd be happy to do some work on the osmesa-webgl code, if necessary. I have an interest in osmesa-webgl being a viable solution for rendering images on the server.
I appreciate any insight you can give me.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.