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
5a5fccf5
Commit
5a5fccf5
authored
Jan 09, 2016
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make the Simple blur over ui example more efficient & more profile
parent
0c589f77
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
31 deletions
+36
-31
Examples/Simple/src/Blur1D.js
Examples/Simple/src/Blur1D.js
+9
-12
Examples/Simple/src/index.js
Examples/Simple/src/index.js
+13
-18
ios/GLCanvas.m
ios/GLCanvas.m
+14
-1
No files found.
Examples/Simple/src/Blur1D.js
View file @
5a5fccf5
...
@@ -11,23 +11,20 @@ uniform vec2 direction;
...
@@ -11,23 +11,20 @@ uniform vec2 direction;
uniform vec2 resolution;
uniform vec2 resolution;
// from https://github.com/Jam3/glsl-fast-gaussian-blur
// from https://github.com/Jam3/glsl-fast-gaussian-blur
vec4 blur
13
(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 blur
9
(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.411764705882353) * direction;
vec2 off1 = vec2(1.3846153846) * direction;
vec2 off2 = vec2(3.2941176470588234) * direction;
vec2 off2 = vec2(3.2307692308) * direction;
vec2 off3 = vec2(5.176470588235294) * direction;
color += texture2D(image, uv) * 0.2270270270;
color += texture2D(image, uv) * 0.1964825501511404;
color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
return color;
return color;
}
}
void main () {
void main () {
gl_FragColor = blur
13
(t, uv, resolution, direction);
gl_FragColor = blur
9
(t, uv, resolution, direction);
}
}
`
`
}
}
...
...
Examples/Simple/src/index.js
View file @
5a5fccf5
...
@@ -256,25 +256,20 @@ class Simple extends Component {
...
@@ -256,25 +256,20 @@ class Simple extends Component {
width
=
{
256
}
width
=
{
256
}
height
=
{
160
}
height
=
{
160
}
factor
=
{
factor
}
>
factor
=
{
factor
}
>
<
Blur
<
View
style
=
{{
width
:
256
,
height
:
160
,
padding
:
10
,
backgroundColor
:
"
#f9f9f9
"
}}
>
width
=
{
256
}
<
Slider
height
=
{
160
}
style
=
{{
height
:
80
}}
factor
=
{
factor
/
2
}
>
max
=
{
1
}
<
View
style
=
{{
width
:
256
,
height
:
160
,
padding
:
10
,
backgroundColor
:
"
#f9f9f9
"
}}
>
onChange
=
{
factor
=>
this
.
setState
({
factor
})}
<
Slider
/
>
style
=
{{
height
:
80
}}
<
View
style
=
{{
height
:
60
,
flexDirection
:
"
row
"
,
alignItems
:
"
center
"
}}
>
max
=
{
2
}
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch1
}
onCheckedChange
=
{({
checked
:
switch1
})
=>
this
.
setState
({
switch1
})}
/
>
onChange
=
{
factor
=>
this
.
setState
({
factor
})}
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch2
}
onCheckedChange
=
{({
checked
:
switch2
})
=>
this
.
setState
({
switch2
})}
/
>
/
>
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch3
}
onCheckedChange
=
{({
checked
:
switch3
})
=>
this
.
setState
({
switch3
})}
/
>
<
View
style
=
{{
height
:
60
,
flexDirection
:
"
row
"
,
alignItems
:
"
center
"
}}
>
<
/View
>
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch1
}
onCheckedChange
=
{({
checked
:
switch1
})
=>
this
.
setState
({
switch1
})}
/
>
<
Progress
progress
=
{
factor
}
style
=
{{
height
:
10
,
marginTop
:
8
,
flex
:
1
}}
/
>
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch2
}
onCheckedChange
=
{({
checked
:
switch2
})
=>
this
.
setState
({
switch2
})}
/
>
<
Switch
style
=
{{
flex
:
1
}}
checked
=
{
switch3
}
onCheckedChange
=
{({
checked
:
switch3
})
=>
this
.
setState
({
switch3
})}
/
>
<
/View
>
<
Progress
progress
=
{
factor
}
style
=
{{
height
:
10
,
marginTop
:
8
,
flex
:
1
}}
/
>
<
/View
>
<
/View
>
<
/Blur
>
<
/Blur
>
<
/Blur
>
<
/HueRotate
>
<
/HueRotate
>
<
/Surface
>
<
/Surface
>
...
...
ios/GLCanvas.m
View file @
5a5fccf5
#import "RCTBridge.h"
#import "RCTBridge.h"
#import "RCTUtils.h"
#import "RCTUtils.h"
#import "RCTConvert.h"
#import "RCTConvert.h"
...
@@ -492,6 +491,9 @@ RCT_NOT_IMPLEMENTED(-init)
...
@@ -492,6 +491,9 @@ RCT_NOT_IMPLEMENTED(-init)
for
(
GLRenderData
*
child
in
renderData
.
children
)
for
(
GLRenderData
*
child
in
renderData
.
children
)
weak_recDraw
(
child
);
weak_recDraw
(
child
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"node"
,
nil
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"bind fbo"
,
nil
);
if
(
renderData
.
fboId
==
-
1
)
{
if
(
renderData
.
fboId
==
-
1
)
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
defaultFBO
);
glBindFramebuffer
(
GL_FRAMEBUFFER
,
defaultFBO
);
glViewport
(
0
,
0
,
w
,
h
);
glViewport
(
0
,
0
,
w
,
h
);
...
@@ -501,23 +503,34 @@ RCT_NOT_IMPLEMENTED(-init)
...
@@ -501,23 +503,34 @@ RCT_NOT_IMPLEMENTED(-init)
[
fbo
setShapeWithWidth
:
w
withHeight
:
h
];
[
fbo
setShapeWithWidth
:
w
withHeight
:
h
];
[
fbo
bind
];
[
fbo
bind
];
}
}
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"bind shader"
,
nil
);
[
renderData
.
shader
bind
];
[
renderData
.
shader
bind
];
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"bind textures"
,
nil
);
for
(
NSString
*
uniformName
in
renderData
.
textures
)
{
for
(
NSString
*
uniformName
in
renderData
.
textures
)
{
GLTexture
*
texture
=
renderData
.
textures
[
uniformName
];
GLTexture
*
texture
=
renderData
.
textures
[
uniformName
];
int
unit
=
[((
NSNumber
*
)
renderData
.
uniforms
[
uniformName
])
intValue
];
int
unit
=
[((
NSNumber
*
)
renderData
.
uniforms
[
uniformName
])
intValue
];
[
texture
bind
:
unit
];
[
texture
bind
:
unit
];
}
}
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"bind set uniforms"
,
nil
);
for
(
NSString
*
uniformName
in
renderData
.
uniforms
)
{
for
(
NSString
*
uniformName
in
renderData
.
uniforms
)
{
[
renderData
.
shader
setUniform
:
uniformName
withValue
:
renderData
.
uniforms
[
uniformName
]];
[
renderData
.
shader
setUniform
:
uniformName
withValue
:
renderData
.
uniforms
[
uniformName
]];
}
}
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"draw"
,
nil
);
glBlendFunc
(
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA
);
glBlendFunc
(
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA
);
glClearColor
(
0
.
0
,
0
.
0
,
0
.
0
,
0
.
0
);
glClearColor
(
0
.
0
,
0
.
0
,
0
.
0
,
0
.
0
);
glClear
(
GL_COLOR_BUFFER_BIT
);
glClear
(
GL_COLOR_BUFFER_BIT
);
glDrawArrays
(
GL_TRIANGLES
,
0
,
6
);
glDrawArrays
(
GL_TRIANGLES
,
0
,
6
);
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
RCT_PROFILE_END_EVENT
(
0
,
@"gl"
,
nil
);
};
};
// DRAWING THE SCENE
// DRAWING THE SCENE
...
...
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