Giter Site home page Giter Site logo

osmesa-webgl's Introduction

This is a node.js port of WebGL for headless servers. It is backed by OSMesa running with the high performing software backend llvmpipe.

Installation

npm install osmesa-webgl

osmesa-webgl's People

Contributors

creationix avatar maghoff avatar mikeseven avatar tmpvar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

osmesa-webgl's Issues

Loading Textures Using texImage2D

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.