Code Monkey home page Code Monkey logo

webgl-inspector's Introduction

About

WebGL Inspector is a tool inspired by gDEBugger and PIX with the goal of making the development of advanced WebGL applications easier. What Firebug and Developer Tools are to HTML/JS, WebGL Inspector is to WebGL.

Features

  • Embed in an existing application with a single <script> include
  • Use as an extension without changing target code
  • Capture entire frames of GL activity
  • Annotated call log with redundant call warnings
  • Ability to step through all calls in a frame incrementally (back/forward/jump/etc)
  • Pixel history - see all draw calls that contributed to a pixel + blending information
  • Non-destructive to host page - everything happens in a separate GL context
  • Internal GL state display
  • Resource information (textures/buffers/programs/shaders)
  • Performance tuning options and statistics

Getting Started

Running the Inspector

There are currently two ways to use the inspector - one is to directly embed it in your GL application (should work in all browsers that support WebGL), and the other is to use one of the supported extensions.

Before starting, run core/buildextensions.sh - this will cat all required files together and copy them into the right places. Note that this is not required when using the debug variants.

Directly Embedding

Include a single script: <script src="core/embed.js"></script> No other changes should be required!

If you want to debug the inspector, before the script include set gliEmbedDebug = true;: <script> var gliEmbedDebug = true; </script> <script src="core/embed.js"></script> This will use the un-cat'ed script/css files, making debugging easier.

LIVE: Instead of grabbing the code, building, and embedding, you can include the script directly from the sample site. This version will change whenever I release a new version. <script src="http://benvanik.github.com/WebGL-Inspector/core/embed.js"></script>

Note: when running the debug version require.js is used to load the inspector. This can have issues for when the inspector gets a chance to wrap HTMLCanvasContext.getContext and when code tries to use it.

The first thing to try is make sure you code waits for window.onload before creating a webgl context. If that doesn't work you can also wait for gliready

window.addEventListener('gliready', runYourWebGLCode);

If your app also uses require.js you need to make your app dependent on the inspector like this. One example would be to do this. Assume your program before used data-main as in

<script data-main="myApp.js" src="require.js">

Remove the data-main part and change it to something like

<script "myApp.js" src="require.js">
<script>
require(['../../core/gli'], function() {
  require.config({
    baseUrl: "/path/to/appfolder",
  });
  require(['twgl-amd'], function() {
  });
});
</script>

Note: This is only needed for running the inspector in debug mode to debug the inspector itself.

Extensions

Chromium

  • Navigate to chrome://extensions
  • Click 'load unpacked extension...' and select the extensions/chrome/ directory
  • If you will be trying to inspect file:// pages, make sure to check 'Allow access to file URLs'
  • Open a page with WebGL content and click the 'GL' icon in the top right of the address bar (click again to disable)

DEBUGGING: If you want to debug the inspector code, instead load the extension from core/ - this will use the non-cat'ed files and makes things much easier when navigating source. You'll also be able to just reload pages when you make changes to the extension (although sometimes the CSS requires a full browser restart to update).

Firefox

Download WebGL Inspector from Mozilla AMO or build manually:

  • cd core && ./buildextensions.sh
  • Open core/extensions/firefox/webglinspector.xpi in Firefox.

DEBUGGING

  • cd core/extensions/firefox
  • make run or
  • PROFILE=/path/to/dev/profile make run

WebKit

  • Open the Extension Builder
  • Add existing extension
  • Select extensions/safari/webglinspector.safariextension
  • Open a page with WebGL content and click the 'GL' icon in the top left of the toolbar (click again to disable)

DEBUGGING: There is currently no debug version of the extension - since Chromium is so similar it's best to just use that.

Frame Termination

Due to the way WebGL implicitly ends frames, accurately determining when a host application has finished is tricky. To ensure frame captures are exactly what they should be there is an extension that can be used to tell the inspector when you are done.

Query the extension - it will only exist when the inspector is attached: var glext_ft = gl.getExtension("GLI_frame_terminator");

At the end of your frame, call the termination method:

if (glext_ft) {
    glext_ft.frameTerminator();
}

Do this if you are consistently seeing multiple frames getting captured at the same time.

Samples

Included in the repository is the Learning WebGL Lesson 05 under samples/lesson05/. embedded.html shows the inspector inlined on the page using the single <script> include. Diff the file against original.html (or look for 'WebGL Inspector' comments) to see what was changed.

Once you have an extension installed, here are some fun demos to test it with:

TODO

In no particular order, here are some of the major features I'd like to see added:

  • Call statistics (with pretty graphs/etc)
  • Save traces/resources/buffer snapshots/etc
  • Serialization of call stream (could do remote debugging/save and replay/etc)
  • Editing of buffers/shaders in replay
  • Editing of state/call history (tweak arguments/etc)

On top of those there are plenty of little things (UI tweaks, etc) that would be helpful. For example, global key bindings would make stepping better.

Some crazier things may be possible in the future, too. For example, if the serialization was implemented it'd be possible to do remote debugging/playback of scenes from Android/iOS/etc devices (once they support WebGL), as well as build test frameworks for WebGL content.

webgl-inspector's People

Contributors

applmak avatar benvanik avatar bpl avatar darwin avatar gilead avatar greggman avatar jdarpinian avatar lj1102 avatar lordi avatar stephomi avatar thekk avatar zombie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webgl-inspector's Issues

Implement Timeline tab

Multiple timelines:

  • lifetime: show resource allocations/deletions/uploads/etc
  • per-frame: show draws/uploads/etc

Support arrays in uniform viewer

Currently Program.js only captures the first element of uniform arrays.
ex,
uniform float4x4 matrices[10];

  • will show as matrices[0] in all displays (should show as matrices[SIZE])
  • in draw info, all but the first element index will be undefined
  • possible replay issues caused by naming

Displayed pixel color values are clamped to 1.0 (255)

When rendering to a floating point texture, color values can be greater than 1, but when I click the texture in the Trace tab, they are always clamped to 1.0 (or 255). I'm not sure, but I think that currently the texture data is rendered onto 2D canvas and the color values are read from there.

Is it possible to read these values directly from the texture or maybe store it in a typed array and read it from there?

Support Chromium on OSX

In Chromium for Mac the extension's icon does not show in the toolbar.

The inspector does however seem to function correctly...

crash in webkit nightly inspecting textures

Am using webkit nightly 5.0.3 (6533.19.4, r72487).

Installed extension:
https://github.com/downloads/benvanik/WebGL-Inspector/WebGL-Inspector-v1.1.safariextz

Open this page: http://visual-demos.dev.concord.org/seasons/earth/index.html

click: GL
click: Capture
click: UI
click: Textures
click: Texture 23 4096x2048

... crash

Here's an excerpt from the crash report:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   com.apple.GeForceGLDriver       0x0000000200012910 gldAttachDrawable + 2528
1   com.apple.GeForceGLDriver       0x00000002000d5787 gldUpdateDispatch + 14359
2   GLEngine                        0x000000011a09da7a glFlush_Exec + 133
3   com.apple.WebCore               0x0000000100fb6704 WebCore::GraphicsContext3D::reshape(int, int) + 724
4   com.apple.WebCore               0x0000000100fe0f6a WebCore::HTMLCanvasElement::reset() + 442
5   com.apple.WebCore               0x0000000100fe0faa WebCore::HTMLCanvasElement::parseMappedAttribute(WebCore::Attribute*) + 58
6   com.apple.WebCore               0x000000010172e076 WebCore::StyledElement::attributeChanged(WebCore::Attribute*, bool) + 150
7   com.apple.WebCore               0x0000000100ef276a WebCore::Element::setAttribute(WebCore::QualifiedName const&, WTF::AtomicString const&, int&) + 314
8   com.apple.WebCore               0x0000000100ef2bf1 WebCore::Element::setAttribute(WebCore::QualifiedName const&, WTF::AtomicString const&) + 17
9   com.apple.WebCore               0x0000000100fe059a WebCore::HTMLCanvasElement::setHeight(int) + 90
10  com.apple.WebCore               0x000000010125e21a WebCore::JSHTMLCanvasElement::put(JSC::ExecState*, JSC::Identifier const&, JSC::JSValue, JSC::PutPropertySlot&) + 186
11  com.apple.JavaScriptCore        0x000000010082220f cti_op_put_by_id + 111
12  ???                             0x00003905ce0c6c2c 0 + 62697094540332
13  com.apple.JavaScriptCore        0x00000001007dc676 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 1094
14  ???                             0x0000000122d6fcc0 0 + 4879482048
15  ???                             0x0000000119b8f820 0 + 4726519840
16  com.apple.JavaScriptCore        0x0000000100840c30 JSC::JSFunction::~JSFunction() + 0
17  ???                             0x0000000000841f0f 0 + 8658703

Better matrix display

For uniforms on programs tab as well as uniform calls in the trace listing. Maybe a popup?

Show resources used this frame

Such as used this frame, written this frame, etc.

As resource state changes/etc, the UI would have to update.

Can probably fit in with the existing alive/dead tracker.

Left listing enhancements

The scroll position gets lost when switching tabs.

Allow for keyboard selection changes (up/down? may be overridden by page?).

Reverse navigation from resource->trace

Instead of just trace->resource it would be useful to see, on a resource information page, exactly where the resource was used that frame and allow navigating back. For example, all the draw calls that used the program, all the bufferDatas that changed a buffer, etc.

Support for OES_texture_half_float

Currently the extension spec is a bit lacking on info.

  • support in TextureView.js/createImageDataFromPixels
  • enum added to Info.js/textureTypes

Implement texture history

Should show off the complete upload history (stack traces, source content (such as image urls, etc)). Bonus would be to allow the user to step through the upload calls to see the texture as it changes - this could help with texSubImage2D-heavy dynamic textures.

Resource display toolbar options

Allow choice of alive/dead/all and live value/trace value - set and propagate, all views must then make sure they pull the correct versions.

Find a good way to delineate frames

Currently using setTimeout(..., 0) in hopes of getting an event, but this is not always reliable. May be possible to use MozAfterPaint in Firefox, but need a WebKit solution too.

Options system/UI

Add a UI for configuring capture/replay options, as well as storage for the settings. If running in-page maybe save in a page cookie, otherwise marshal back to the parent extension so that they are saved globally?

Support pop-out mode

Already kind of working (set usePopup = true at the top of HostUI.js), but needs surfacing.

A browser bug may prevent this in the near term, as it seems WebGL in popups causes Chromium to freak out and break rendering.

If that can be solved there still may not be a good way to do dynamic inline/popup switching as the replay canvas must be recreated and that may break things (as currently that's not supported). A global option of where to display things, or even a page reload between switches, may be good enough.

Custom trace markers and object names

Allow applications to instrument themselves by injecting custom messages into the trace. Also allow for custom object names (currently partially supported by setting displayName on any WebGL object upon creation).

Texture history support for arrays

Currently the texImage2D/texSubImage2D calls that take an array don't display anything pretty in the history. They should be packed into an ImageData and drawn to a canvas.

Draw call functions: isolate, dependencies, script

Select a draw call and get a list of all resources used for that call (programs/shaders, textures, buffers, render targets, etc).

Build the script required to draw just that call - this would allow for extracting models/etc in their entirety.

Blending/depth test broken

At least under Chromium/Windows, any demo disabling/enabling GL_BLEND or GL_DEPTH_TEST is broken.

Can be seen here:
http://learningwebgl.com/lessons/lesson09/index.html

Suspect it's an ANGLE bug, as this code demonstrates:
gl.disable(gl.DEPTH_TEST);
var value = gl.getParameter(gl.DEPTH_TEST);
console.log(value); // will print true

Also possible to see it here:
http://media.tojicode.com/q3bsp/ (so long as the replay works) - will only end up seeing the sky, almost as if the depth buffer is inverted

Generate pretty return values in trace

Currently calls that return values, such as getParameter(ARRAY_BUFFER_BINDING), will print out nasty values - they should print the same values as the arguments (with clickable links/etc)

Support Chrome 8 Beta on OSX

In Chrome 8 Beta for Mac the extension's icon does not show in the toolbar.

The inspector does however seem to function correctly...

Texture inspector preview does not support cube maps

There are two ways to do this:

  • replay all calls on just the face interested in
  • build a shader that properly picks a side against the final cube map

The advantage of the latter is that if there is any RTT going on you'll see it - if you just replay you won't get any dynamic changes.

Sexy up the page overlays

Currently the page overlay buttons (capture/ui) and notifications are ugly. They should be pretty!

Properly display any GL error instead of "unknown" in Trace

Currently there's a switch statement in TraceView.prototype.setFrame and TraceListing addCall function that checks for few hardcoded WebGL errors and for all others it returns "unknown" string. It is possible to create a hash of all WebGL constants and simply do hash lookup instead of switch statement to handle all possible WebGL errors. This hash could probably be useful in other places as well.

I can write a patch, but I'm not sure where to actually store WebGL enums hash - I thought about adding it to gli.util in shared/Utilities.js file, but there's no GL context there and I get error when I try to get it from dummy canvas element. Any ideas?

Firefox extension

Things work pretty well in the embed but it would be ideal to have an extension. Stubbed version is in extensions/firefox/, but it needs an implementation.

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.