GithubHelp home page GithubHelp logo

gre / gl-react-native-v2 Goto Github PK

View Code? Open in Web Editor NEW
1.9K 55.0 173.0 64.5 MB

DEPRECATED, Please migrate to latest version of gl-react-native that works nicely with expo-gl and unimodules

Home Page: https://github.com/gre/gl-react

Objective-C 30.88% JavaScript 32.31% Java 35.71% Ruby 0.28% Python 0.82%

gl-react-native-v2's Introduction

This repository hosts the v2 of gl-react. Please also see the v3 at https://github.com/gre/gl-react

Gitbook documentation / Github / gl-react / #gl-react on reactiflux

icon gl-react-native

OpenGL bindings for React Native to implement complex effects over images and components, in the descriptive VDOM paradigm.

gl-react-native is an implementation of gl-react for react-native. Please read the main gl-react README for more information.

Documentation

doc

Installation

npm i --save gl-react-native

Configure your React Native Application

on iOS:

or if you use Cocapods:

pod 'RNGL', :path => './node_modules/gl-react-native'

on Android:

  1. android/settings.gradle:: Add the following snippet
include ':RNGL'
project(':RNGL').projectDir = file('../node_modules/gl-react-native/android')
  1. android/app/build.gradle: Add in dependencies block.
compile project(':RNGL')
  1. in your MainApplication (or equivalent) the RNGLPackage needs to be added. Add the import at the top:
import com.projectseptember.RNGL.RNGLPackage;
  1. In order for React Native to use the package, add it the packages inside of the class extending ReactActivity.
@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
	new MainReactPackage(),
	...
	new RNGLPackage()
  );
}

gl-react-native-v2's People

Contributors

alexdm0 avatar cawfree avatar chitrangsinghvi avatar dkfl1995 avatar fireyfly avatar gevgasparyan avatar gmlion avatar gr4yscale avatar gre avatar gullitmiranda avatar ijzerenhein avatar jsierles avatar juphamzipit avatar kesha-antonov avatar lizujian avatar lshir avatar mephisto83 avatar mrspeaker avatar nikki93 avatar olofd avatar pfeiffer avatar ptmt avatar southerton81 avatar sscaff1 avatar superandrew213 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  avatar  avatar  avatar  avatar

gl-react-native-v2's Issues

support for Array uniforms

no array types are currently implemented.

It's quite easy to implement but very verbose.. It would be great if we could define some macros to generate them (to also simplify existing code)

this will be implemented with accepting a flatten array, like in gl-shader implem.

For instance if you have a vec2 foo[3], you should be able to send a array of 6 numbers

double check that alpha works correctly

I think something is weird with alpha in gl-react-native.

We need to make a test proof example that alpha works correctly (draw a linear black opacity=100% to black opacity=0% over an image, same with white. compare with the same effect done with gimp also do the same on gl-react side).

Support for RN 0.11.0

  • fix the lib examples from breaking changes of RN 0.11.0
  • release a new version for working with RN 0.11.0

WebGL "shim"

Sorry, if this is a bit out of the scope of the project but I was wondering if it would be possibile to build a "shim" for React Native that would let one transparently use OpenGL as using WebGL in the browser, and how to go about doing this?
The goal would be to use libraries like pixi.js (maybe trough react-pixi) for building universal components that render both with WebGL and OpenGL.

I've posted a related question also here: pixijs/pixijs#2120

How to export the content of GL.View?

Is there any way to export the content of a GL.View (with the fragment shader applied)?

I'd like to load an image, apply a filter using a glsl fragment shader and export the result. I can't figure out how to do the last part, i.e. exporting. I've checked the gl-react-native documentation and the GL.View page specifically, but couldn't find anything.

[Android] Performance passing rasterized React Native views as uniforms

I'm not sure if the slowness I'm seeing on Android is my code or if it's not. I've tried profiling with systrace and will post the results below.

Passing just 1 single react native view in as a texture to a shader runs very fast on iOS with my 6+ (>40fps always), but with a Samsung Galaxy A5 it runs < 10fps

Using the same technique as demonstrated in the AdvancedEffects Example.

render () {
  const { value } = this.state;
  const { width, height, children } = this.props;

  return (
  <Surface
      width={width} height={height}
      pixelRatio={2}
      ref="rgbshift"
      style={{position:'absolute', width, height, top:0, left: 0}}
  >
      <GL.Node
          shader={shaders.rgbshift}
          uniforms={{ tInput: children, time: value}}
      />
  </Surface>
  )
}

Profiling with systrace (per instructions here: https://facebook.github.io/react-native/docs/android-ui-performance.html) shows a lot of time on 'com.havit' (my package), but I suppose since I don't have markers in place there isn't anything specific. I'm doing nothing special and have tested with shouldComponentUpdate() returning false.

Any ideas for how to go about digging into this, and could you please just confirm that the slowness is indeed my code and not this fantastic libraries by taking a quick peek at the screenshots and systrace generated html (it's zipped to get around github filetype limitations)?

screen shot 2016-01-25 at 11 20 13

screen shot 2016-01-25 at 11 20 47

trace.html.zip

React Native error with Object.assign polyfill

Hi, i'm trying to apply a shader to a GLView using the below code, but get the error (see after code). It seems that you're somehow not referencing styles appropriately, requiring the style value (see GL.View style=... below) be an object literal instead of a React JS reference able style instance.

Make sense?

    render() {
        var uniforms = {time: this.state.time};
        return (
            <GL.View style={styles.mainCt} uniforms={uniforms} width={100} height={200} shader={shaders.helloGL} >
                <GL.Target uniform="texture">
                    <View style={{flexDirection:'row', justifyContent : 'center'}}>
                        <Text style={styles.titleRed}>K</Text>
                        <Text style={styles.titleGreen}>ey</Text>
                        <Text style={styles.titleRed}>G</Text>
                        <Text style={styles.titleGreen}>en</Text>
                        <Text style={[styles.titleRed, {marginLeft: 10}]}>M</Text>
                        <Text style={styles.titleGreen}>usic</Text>
                    </View>
                    ...
                </GL.Target>
            </GL.View>
        );
    }

image

ndarray support

This is a separate issue for implementing https://github.com/ProjectSeptemberInc/gl-react/issues/14 in the React Native context.

Implementation is not so trivial:

Can't reload

If I start my app by pressing the build button in Xcode, everything works. However, if I hit cmd+r the app crashes with:

2015-11-16 15:05:51.466 samanage[89608:15604349] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid number value (NaN) in JSON write'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110c21f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fdf5deb objc_exception_throw + 48
2 CoreFoundation 0x0000000110c21e7d +[NSException raise:format:] + 205
3 Foundation 0x000000010fae7907 _writeJSONNumber + 707
4 Foundation 0x000000010fae48cb _writeJSONValue + 486
5 Foundation 0x000000010fae85fa ___writeJSONObject_block_invoke + 226
6 CoreFoundation 0x0000000110b8ecb5 __65-[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 85
7 CoreFoundation 0x0000000110b8ebbd -[__NSDictionaryI enumerateKeysAndObjectsWithOptions:usingBlock:] + 237
8 Foundation 0x000000010fae7d84 _writeJSONObject + 436
9 Foundation 0x000000010fae4871 _writeJSONValue + 396
10 Foundation 0x000000010fae87bd ___writeJSONArray_block_invoke + 132
11 CoreFoundation 0x0000000110b63ced __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 77
12 CoreFoundation 0x0000000110b63bbf -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 207
13 Foundation 0x000000010fae7ff5 _writeJSONArray + 330
14 Foundation 0x000000010fae490d _writeJSONValue + 552
15 Foundation 0x000000010fae87bd ___writeJSONArray_block_invoke + 132
16 CoreFoundation 0x0000000110b63ced __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 77
17 CoreFoundation 0x0000000110b63bbf -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 207
18 Foundation 0x000000010fae7ff5 _writeJSONArray + 330
19 Foundation 0x000000010fae490d _writeJSONValue + 552
20 Foundation 0x000000010fae85fa ___writeJSONObject_block_invoke + 226
21 CoreFoundation 0x0000000110b5a3d6 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
22 CoreFoundation 0x0000000110b5a29f -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 159
23 Foundation 0x000000010fae7d84 _writeJSONObject + 436
24 Foundation 0x000000010fae4871 _writeJSONValue + 396
25 Foundation 0x000000010fae4691 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
26 Foundation 0x000000010fae70b2 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
27 samanage 0x000000010f6d18e2 RCTJSONStringify + 322
28 samanage 0x000000010f74b14a __49-[RCTWebSocketExecutor sendMessage:waitForReply:]_block_invoke + 570
29 libdispatch.dylib 0x000000011485ee5d _dispatch_call_block_and_release + 12
30 libdispatch.dylib 0x000000011487f49b _dispatch_client_callout + 8
31 libdispatch.dylib 0x00000001148658ec _dispatch_queue_drain + 2215
32 libdispatch.dylib 0x0000000114864e0d _dispatch_queue_invoke + 601
33 libdispatch.dylib 0x0000000114867a56 _dispatch_root_queue_drain + 1420
34 libdispatch.dylib 0x00000001148674c5 _dispatch_worker_thread3 + 111
35 libsystem_pthread.dylib 0x0000000114bc74f2 _pthread_wqthread + 1129
36 libsystem_pthread.dylib 0x0000000114bc5375 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

[Android] View order (z-index) is not respected for <Surface>, Native Views always get covered up

When attempting to lay native views on top of a surface using JSX similar to the below, we see that on iOS native views render on top of the surface. On Android, no matter what styling you use (I've tried position: 'absolute' on Surfaces, native views, etc), the surface renders above everything else.

  <View style={styles.container}>
    <Surface
        width={deviceWidth}
        height={300}
        opaque={false}
        ref="helloGL"
        pixelRatio={2}
    >
      <HelloGL />
    </Surface>
    <Image style={{position:'absolute', top: 100, left: 30, width: 300, height: 100}} source={{ uri: 'http://i.imgur.com/S22HNaU.png'}} width={300} height={100} />
    <Text style={{position:'absolute', top: 100, left: 30, width: 300, height: 100,backgroundColor:'transparent', color:'#FFFFFF', fontSize:36}}>SOME NATIVE TEXT ABOVE AN IMAGE, ABOVE A SHADER</Text>
  </View>

iOS screenshot:

img_8381

Android screenshot:

screenshot_2016-01-20-10-51-39

On Android with the same JSX as above, except replacing the the with a native view styled with a red backgroundColor:

img_8383

resize in surface

Hi,

I am trying to use the 4-pass blur on my app, and my image is being resize to the surface width and height but I want it to style like the <Image> component's resizeMode: 'cover

below is my code, please help.

<Surface width=400 height=600 preload>
    <Blur minBlur={0} maxBlur={3} blurMap={'http://i.imgur.com/0PkQEk1.png'} offset={[10, 0]}>
        http://cdn12.lbstatic.nu/files/looks/large/2015/12/30/4789931_deichmann-with-skirt.jpg?1451472058
    </Blur>
</Surface>

`onLoad` does not work properly in some older devices

On iPhone 6 onLoad works but not on iPad Retina (for instance).

Steps to reproduce:

  • Run Tests
  • "LOADED" should appear in the console (console.log-ed from the JavaScript code in an onLoad callback)

It is reproductible on simulator.

capture method in GLCanvasManager.m

Hello,

I'm using React Native v0.15 and I found that this library doesn't seem to be compatible with this version yet (I'm guessing). I got an error originally saying that the addUIBlock block wasn't expecting a NSDictionary to be passed, so I looked at how this was being handled in React Native and found it should be changed to RCTSparseArray instead of an NSDictionary. That seemed to fix that error, but now I'm getting an error that UIView expects a dictionary to be passed in.

Thanks in advance!

Image from live camera view is not displayed

I'm trying to apply a fragment shader to the live camera view, but I'm getting black pixels.
In my code I've used the [react-native-camera library](https://github.com/lwansbrough/react-native-camera library).

Replacing the camera with a still image works fine. Surprisingly, child components of the camera view are also visible. That is: if I nest a <Text>hello world</Text component in the camera view (the library permits this), I can see the text in the GL.View output, surrounded by black pixels. It seems that pixels taken directly from the camera view are treated as completely black in the GL.View.

Is there a way to apply a fragment shader to the live camera view?

`null` texture crash

null value for texture is supported since 1.1.0 (implemented as an empty texture), it works correctly in gl-react but crashes in gl-react-native.

Android version

(just creating this placeholder issue for now)

If anyone want to port an Android implementation, feel free.
Otherwise we will eventually go there ;)

[Android] Tests example crashes

I couldn't find a way to share a context for all canvas like in iOS version. This might result of worse performance and potentially limited amount of view at the same time...

simplify some props

Surface instead of having width and height could have a style={{ width, height }}, also instead of opaque={false} could use backgroundColor="transparent" .

Limitation in Android implementation

These are the tasks that remain to be fixed for the Android implementation.

  • Transparency is not supported for rasterized View ( http://stackoverflow.com/questions/33953512/how-to-make-view-getdrawingcache-preserving-transparency )
  • Transparency is not supported for images ( probably we can fix it )
  • eventsThrough is not working correctly. Some UI works but some don't... I bet only a subset of events goes through right now.
  • I couldn't find a way to share a context for all canvas like in iOS version. This might result of worse performance and potentially limited amount of view at the same time...
  • capture() is not yet implemented I have a PoC in feature/capture branch but it waits this to be fixed on RN: facebook/react-native#4429
  • add profiling support

Documentation at gitbook not accessible (404)

The link to gitbook docs:

http://projectseptemberinc.gitbooks.io/gl-react/content/

results in 404. Since gl-react and gl-react-native share the url, this affects both repositories.

screen shot 2015-12-03 at 11 21 47

Native module won't load in RN 0.18.0

I feel like a noob, but I have added the .xcodeproj to libraries and linked libRNGL.a in my build phases. However when I run on device I still get "React.NativeModules.GLCanvasManager is undefined".

I have cleared the project cache, rebuilt, and reinstalled the plugin without success. Any ideas? Oh and I have several other libraries included and working.

[Android] Transparency of rasterized content

The transparency of rasterized content is not supported. I'm not exactly sure where the error is and some parts behave differently on iOS vs Android.
It doesn't work if backgroundColor is set to "transparent", however, if not setting any background (both on the gl-react-native layers and on the content itself), the iOS version will support transparency but NOT Android.

Workaround: set a background color for the content (but it doesn't solve all use-cases).

Alpha issue

The Tests app shows a bug regarding alpha:

screen shot 2015-09-16 at 10 06 47

Expected result (gl-react version):

screen shot 2015-09-16 at 10 06 55

Supports for Animated objects

We have proven in this example using react-motion that gl-react can interoperate with React animation libraries and in the continuation of a "descriptive" expressivity.

Now, in react-native context, there is Animated (docs / source code).
I see nothing preventing us for being able to support this for values passed in uniforms.

As an use-case example: awesome things that solves Animated (like user interruptibility / UI driven like responsive to dragging) could be used with glsl-transitions effects:

out

Code Usage Example

For instance, I should be able to do:

// example adapted from the React Animation documentation
class Playground extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      animatedValue: new Animated.Value(0)
    };
  }
  render() {
    return (
      <GL.View
        shader={shaders.myEffect2}
        width={200}
        height={100}
        uniforms={{
          value: this.state.animatedValue
        }} />
    );
  }
  componentDidMount() {
    this.state.animatedValue.setValue(1.5);
    Animated.spring(this.state.animatedValue, { toValue: 0.8, friction: 1 }).start();
  }
}

Another and more probable use-case is using with a pre-defined GL Component, like Blur.
And I should just be able to do:

<Blur factor={this.state.animatedValue} width={w} height={h}>
  <Something/>
</Blur>

Implementation

We can implement shader uniform animations in a very efficient way in the Objective-C / OpenGL side.
Now we can't just use Animated.createAnimatedComponent for this because it is specific to animate style. Also, in our implementation uniforms props DOES NOT directly map to the final component props, in fact <GL.View/> is just an intermediary way (DSL) to express a tree of effects and gets transformed to a single "GLCanvas" (GLKView in case of iOS).

A tree of GL.View gets consumed and results of a single data that contains everything the OpenGL implementation needs to render the effects pipeline.

For example, see this example (left shows the usage part, right shows the resulting data props that represents the usage tree):

screen shot 2015-09-21 at 11 43 43

# Help Wanted on this:

Right now, if we try to use Animated.Value as uniforms props, we are going to have this data filled with Animated.Values.

So it sounds like we just need a way to resolve all Animated.Value objects in that object tree. I don't know yet the Animated specifics to implement a Animated Component from scratch and do this resolving:

  • Is there a React utility to resolve a object tree filled with some Animated.Value at a given time?
  • What do we need to do at the component level? (start/stop? render loop? setNativeProps for the props that gets animated?)

Thanks

Serious memory leak on GLImage due to withOnLoad callback

I've found a major memory leak, due this code:

image = [[GLImage alloc] initWithBridge:_bridge withOnLoad:^{
  [self onImageLoad:src];
}];

The exact reason is the self reference in the implementation of this withOnLoad callback. GLImage never get deallocated because of this.

Bizarre React Native Module Behavior

I'm having really streaky results importing modules in React Native.

This for example gives me an error:

require('gl-react/react-native');
import React from 'react-native';
import { Surface } from 'gl-react-native';
// => gl-react: React instance not available at runtime. Please read instructions.

However if I define a blank module,

// emptyModule.js
require('gl-react/react-native');
import React from 'react-native';

and import it specifically between the React and gl-react-native import,

require('gl-react/react-native');
import React from 'react-native';
import _ from 'emptyModule.js';
import { Surface } from 'gl-react-native';

everything compiles and runs without error.

Am I missing something in the docs? I've had a lot of trouble moving modules around because of unpredictable behavior. As long as I include some module that requires gl-react/react-native, the error goes away, but I end up having to import a blank module across all of my files.

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.