Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gl-react-native-v2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Jira
Jira
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ym
gl-react-native-v2
Commits
84261f28
Commit
84261f28
authored
Sep 09, 2015
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement imagesToPreload support (GL.View preload prop)
parent
354af388
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
8 deletions
+46
-8
Examples/Tests/Blur.js
Examples/Tests/Blur.js
+1
-2
Examples/Tests/index.ios.js
Examples/Tests/index.ios.js
+1
-1
RNGL/GLCanvas.m
RNGL/GLCanvas.m
+43
-5
src/View.js
src/View.js
+1
-0
No files found.
Examples/Tests/Blur.js
View file @
84261f28
...
@@ -29,13 +29,12 @@ function directionForPass (p, factor, total) {
...
@@ -29,13 +29,12 @@ function directionForPass (p, factor, total) {
class
Blur
extends
GL
.
Component
{
class
Blur
extends
GL
.
Component
{
render
()
{
render
()
{
const
{
width
,
height
,
factor
,
children
,
passes
}
=
this
.
props
;
const
{
width
,
height
,
factor
,
children
,
passes
}
=
this
.
props
;
const
rec
=
p
=>
p
<=
0
?
children
:
const
rec
=
p
=>
p
<=
0
?
children
:
<
Blur1D
width
=
{
width
}
height
=
{
height
}
direction
=
{
directionForPass
(
p
,
factor
,
passes
)}
>
<
Blur1D
width
=
{
width
}
height
=
{
height
}
direction
=
{
directionForPass
(
p
,
factor
,
passes
)}
>
{
rec
(
p
-
1
)}
{
rec
(
p
-
1
)}
<
/Blur1D>
;
<
/Blur1D>
;
return
rec
(
passes
);
return
rec
(
passes
||
0
);
}
}
}
}
...
...
Examples/Tests/index.ios.js
View file @
84261f28
...
@@ -34,7 +34,7 @@ const Tests = React.createClass({
...
@@ -34,7 +34,7 @@ const Tests = React.createClass({
<
/Text>
)
}
<
/Text>
)
}
<
/View>
;
<
/View>
;
const
img
=
"
http://i.imgur.com/zJIxPEo.jpg
"
;
const
img
=
"
http://i.imgur.com/zJIxPEo.jpg
?t=
"
+
Date
.
now
()
;
const
blurredImage
=
const
blurredImage
=
<
Blur
factor
=
{
4
}
passes
=
{
6
}
width
=
{
200
}
height
=
{
200
}
>
<
Blur
factor
=
{
4
}
passes
=
{
6
}
width
=
{
200
}
height
=
{
200
}
>
...
...
RNGL/GLCanvas.m
View file @
84261f28
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
@implementation
GLCanvas
@implementation
GLCanvas
{
{
RCTBridge
*
_bridge
;
// bridge is required to instanciate GLReactImage
RCTBridge
*
_bridge
;
// bridge is required to instanciate GLReactImage
GLRenderData
*
_renderData
;
GLRenderData
*
_renderData
;
NSArray
*
_contentTextures
;
NSArray
*
_contentTextures
;
...
@@ -26,6 +26,9 @@
...
@@ -26,6 +26,9 @@
BOOL
_deferredRendering
;
// This flag indicates a render has been deferred to the next frame (when using contents)
BOOL
_deferredRendering
;
// This flag indicates a render has been deferred to the next frame (when using contents)
GLint
defaultFBO
;
GLint
defaultFBO
;
NSMutableArray
*
_preloaded
;
BOOL
_preloadingDone
;
}
}
-
(
instancetype
)
initWithBridge
:(
RCTBridge
*
)
bridge
-
(
instancetype
)
initWithBridge
:(
RCTBridge
*
)
bridge
...
@@ -34,6 +37,8 @@
...
@@ -34,6 +37,8 @@
if
((
self
=
[
super
init
]))
{
if
((
self
=
[
super
init
]))
{
_bridge
=
bridge
;
_bridge
=
bridge
;
_images
=
@{};
_images
=
@{};
_preloaded
=
[[
NSMutableArray
alloc
]
init
];
_preloadingDone
=
false
;
self
.
context
=
context
;
self
.
context
=
context
;
}
}
return
self
;
return
self
;
...
@@ -41,6 +46,14 @@
...
@@ -41,6 +46,14 @@
RCT_NOT_IMPLEMENTED
(
-
init
)
RCT_NOT_IMPLEMENTED
(
-
init
)
-
(
void
)
setImagesToPreload
:(
NSArray
*
)
imagesToPreload
{
if
(
_preloadingDone
)
return
;
if
([
imagesToPreload
count
]
==
0
)
{
_preloadingDone
=
true
;
}
_imagesToPreload
=
imagesToPreload
;
}
-
(
void
)
setOpaque
:(
BOOL
)
opaque
-
(
void
)
setOpaque
:(
BOOL
)
opaque
{
{
...
@@ -83,7 +96,7 @@ NSString* srcResource (id res)
...
@@ -83,7 +96,7 @@ NSString* srcResource (id res)
{
{
[
EAGLContext
setCurrentContext
:
self
.
context
];
[
EAGLContext
setCurrentContext
:
self
.
context
];
@autoreleasepool
{
@autoreleasepool
{
NSDictionary
*
prevImages
=
_images
;
NSDictionary
*
prevImages
=
_images
;
NSMutableDictionary
*
images
=
[[
NSMutableDictionary
alloc
]
init
];
NSMutableDictionary
*
images
=
[[
NSMutableDictionary
alloc
]
init
];
...
@@ -135,7 +148,7 @@ NSString* srcResource (id res)
...
@@ -135,7 +148,7 @@ NSString* srcResource (id res)
if
(
!
src
)
{
if
(
!
src
)
{
RCTLogError
(
@"invalid uniform '%@' texture value '%@'"
,
uniformName
,
value
);
RCTLogError
(
@"invalid uniform '%@' texture value '%@'"
,
uniformName
,
value
);
}
}
GLImage
*
image
=
images
[
src
];
GLImage
*
image
=
images
[
src
];
if
(
image
==
nil
)
{
if
(
image
==
nil
)
{
image
=
prevImages
[
src
];
image
=
prevImages
[
src
];
...
@@ -144,7 +157,7 @@ NSString* srcResource (id res)
...
@@ -144,7 +157,7 @@ NSString* srcResource (id res)
}
}
if
(
image
==
nil
)
{
if
(
image
==
nil
)
{
image
=
[[
GLImage
alloc
]
initWithBridge
:
_bridge
withOnLoad
:
^
{
image
=
[[
GLImage
alloc
]
initWithBridge
:
_bridge
withOnLoad
:
^
{
[
self
requestSyncData
];
[
self
onImageLoad
:
src
];
}];
}];
image
.
src
=
src
;
image
.
src
=
src
;
images
[
src
]
=
image
;
images
[
src
]
=
image
;
...
@@ -171,7 +184,7 @@ NSString* srcResource (id res)
...
@@ -171,7 +184,7 @@ NSString* srcResource (id res)
RCTLogError
(
@"All defined uniforms must be provided. Missing '%@'"
,
uniformName
);
RCTLogError
(
@"All defined uniforms must be provided. Missing '%@'"
,
uniformName
);
}
}
}
}
return
[[
GLRenderData
alloc
]
return
[[
GLRenderData
alloc
]
initWithShader:
shader
initWithShader:
shader
withUniforms:
uniforms
withUniforms:
uniforms
...
@@ -190,6 +203,30 @@ NSString* srcResource (id res)
...
@@ -190,6 +203,30 @@ NSString* srcResource (id res)
}
}
}
}
-
(
bool
)
allPreloaded
{
for
(
id
toload
in
_imagesToPreload
)
{
if
(
!
[
_preloaded
containsObject
:
srcResource
(
toload
)])
return
false
;
}
return
true
;
}
-
(
void
)
onImageLoad
:(
NSString
*
)
loaded
{
if
(
!
_preloadingDone
)
{
[
_preloaded
addObject
:
loaded
];
if
([
self
allPreloaded
])
{
_preloadingDone
=
true
;
[
self
requestSyncData
];
}
}
else
{
// Any texture image load will trigger a future re-sync of data (if no preloaded)
[
self
requestSyncData
];
}
}
-
(
void
)
setNbContentTextures
:(
NSNumber
*
)
nbContentTextures
-
(
void
)
setNbContentTextures
:(
NSNumber
*
)
nbContentTextures
{
{
[
self
resizeUniformContentTextures
:[
nbContentTextures
intValue
]];
[
self
resizeUniformContentTextures
:[
nbContentTextures
intValue
]];
...
@@ -233,6 +270,7 @@ NSString* srcResource (id res)
...
@@ -233,6 +270,7 @@ NSString* srcResource (id res)
-
(
void
)
drawRect
:(
CGRect
)
rect
-
(
void
)
drawRect
:(
CGRect
)
rect
{
{
if
(
!
_preloadingDone
)
return
;
BOOL
needsDeferredRendering
=
_nbContentTextures
>
0
;
BOOL
needsDeferredRendering
=
_nbContentTextures
>
0
;
if
(
needsDeferredRendering
&&
!
_deferredRendering
)
{
if
(
needsDeferredRendering
&&
!
_deferredRendering
)
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
dispatch_async
(
dispatch_get_main_queue
(),
^
{
...
...
src/View.js
View file @
84261f28
...
@@ -13,6 +13,7 @@ const GLCanvas = requireNativeComponent("GLCanvas", null);
...
@@ -13,6 +13,7 @@ const GLCanvas = requireNativeComponent("GLCanvas", null);
const
renderVcontent
=
function
(
width
,
height
,
id
,
children
)
{
const
renderVcontent
=
function
(
width
,
height
,
id
,
children
)
{
const
childrenStyle
=
{
const
childrenStyle
=
{
key
:
id
,
position
:
"
absolute
"
,
position
:
"
absolute
"
,
top
:
0
,
top
:
0
,
left
:
0
,
left
:
0
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment