Giter Club home page Giter Club logo

pex-next's Introduction

pex-gl

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Create a RenderingContext (2d, webgl, webgl2, bitmaprenderer, webgpu) for use in PEX.

Installation

npm install pex-gl

Usage

import createRenderingContext, { FALLBACKS } from "pex-gl";

// Creates a webgl context filling the window
const context = createRenderingContext();

// Creates a webgl context from an existing canvas and keeps its size
const context = createRenderingContext({ canvas });

// Creates a webgl context on a new canvas with given width and height
const context = createRenderingContext({ width, height });

// Creates a new canvas of type "webgpu"
const context = createRenderingContext({ type: "webgpu" });

// Creates a new canvas of type "webgl" or fallback to experimental-webgl in case it fails
const context = createRenderingContext({ type: "webgl" });

// Disable fallbacks for "webgl2"
FALLBACKS.webgl2 = [];
// Creates a new canvas of type "webgl2" and return null in case it fails
const context = createRenderingContext({ type: "webgl2" });

API

Constants

FALLBACKS

Context fallbacks map

Functions

createRenderingContext([opts])RenderingContext

Creates a rendering context.

Typedefs

Options : object

Options for context creation. All optional.

FALLBACKS

Context fallbacks map

Kind: global constant

createRenderingContext([opts]) ⇒ RenderingContext

Creates a rendering context.

Kind: global function

Param Type Default
[opts] Options {}

Options : object

Options for context creation. All optional.

Kind: global typedef Properties

Name Type Default Description
[width] number window.innerWidth Request an initial canvas width.
[height] number window.innerHeight Request an initial canvas height.
[pixelRatio] boolean 1 Multiply canvas dimensions with a given ratio.
[fullscreen] boolean !opts.width && !opts.height Make the canvas fullscreen.
[type] "2d" | "bitmaprenderer" | "webgl" | "webgl2" | "webgpu" "webgl" A "contextType" for getContext.
[element] HTMLElement document.body Element to append the canvas to.
[...contextAttributes] CanvasRenderingContext2DSettings | WebGLContextAttributes {} Attributes to be passed to getContext.

License

MIT. See license file.

pex-next's People

Contributors

automat avatar vorg avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

digideskio

pex-next's Issues

General Architecture

Currently considering multiple approaches:

1 - Low level intermediate mode (kind of stack-gl-ish, but also more like Foam)
https://github.com/vorg/pex-next/blob/master/00-core/basic.js

  • more control but also more boilerplate
  • less hidden state
  • no automagic

2 - Game-engine / Vulkan / Metal like command oriented renderer
https://github.com/vorg/pex-next/blob/master/01-draw-command/basic.js

  • more functional / data driven
  • potentially easier to optimize (state switching, batching)

3 - Even more OOP? SceneGraph?

shader program

I'm working on ShaderProgram abstractions that right now are not very tied to any particular framework. They are like gl-shader but with a bit more focus on modularity, simplicity, performance and developer UX.

var shader = createShader(gl, { vertex: '...', fragment: '...' })

//use program
shader.bind()

//gl.uniform1f
shader.uniforms.lights[0].radius(2)

//gl.getUniform
var radius = shader.uniforms.lights[0].radius()

//set explicit locations, to be used with VAO extension
shader.reload({ vertex: ..., fragment: ..., attributes: [ { name: 'uv', location: 2 } ])

Installing non existing module

When installing non existing module there is no page reload and no error or warning.

The server doesn't crash though.

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.