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
479bfb4f
Commit
479bfb4f
authored
Nov 16, 2015
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
c75cf213
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
89 deletions
+54
-89
android/src/main/java/com/projectseptember/RNGL/GLCanvas.java
...oid/src/main/java/com/projectseptember/RNGL/GLCanvas.java
+43
-29
android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java
.../main/java/com/projectseptember/RNGL/GLCanvasManager.java
+0
-2
android/src/main/java/com/projectseptember/RNGL/GLFBO.java
android/src/main/java/com/projectseptember/RNGL/GLFBO.java
+5
-34
android/src/main/java/com/projectseptember/RNGL/GLImage.java
android/src/main/java/com/projectseptember/RNGL/GLImage.java
+4
-24
android/src/main/java/com/projectseptember/RNGL/RNGLContext.java
.../src/main/java/com/projectseptember/RNGL/RNGLContext.java
+2
-0
No files found.
android/src/main/java/com/projectseptember/RNGL/GLCanvas.java
View file @
479bfb4f
...
...
@@ -4,6 +4,7 @@ import static android.opengl.GLES20.*;
import
android.graphics.Bitmap
;
import
android.graphics.PixelFormat
;
import
android.net.Uri
;
import
android.opengl.GLSurfaceView
;
import
android.util.DisplayMetrics
;
import
android.util.Log
;
...
...
@@ -49,11 +50,10 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
private
boolean
visibleContent
;
private
int
captureNextFrameId
;
private
GLData
data
;
private
ReadableArray
imagesToPreload
;
// TODO we need to make a List<Uri> I guess? probably Uri should be resolved in advance. not in GLImage
private
List
<
Uri
>
imagesToPreload
;
private
List
<
Uri
>
preloaded
;
List
<
String
>
preloaded
;
// TODO List<Uri>
private
Map
<
String
,
GLImage
>
images
=
new
HashMap
<>();
private
Map
<
Uri
,
GLImage
>
images
=
new
HashMap
<>();
private
List
<
GLTexture
>
contentTextures
=
new
ArrayList
<>();
private
List
<
Bitmap
>
contentBitmaps
=
new
ArrayList
<>();
...
...
@@ -69,16 +69,13 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
getHolder
().
setFormat
(
PixelFormat
.
RGBA_8888
);
setRenderer
(
this
);
setRenderMode
(
GLSurfaceView
.
RENDERMODE_WHEN_DIRTY
);
Log
.
i
(
"GLCanvas"
,
"created"
);
}
@Override
protected
void
onAttachedToWindow
()
{
Log
.
i
(
"GLCanvas"
,
"onAttachedToWindow"
);
super
.
onAttachedToWindow
();
syncContentBitmaps
();
requestRender
();
preloadingDone
=
true
;
// TODO
}
@Override
...
...
@@ -93,7 +90,6 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
@Override
public
void
onDrawFrame
(
GL10
gl
)
{
Log
.
i
(
"GLCanvas"
,
"onDrawFrame"
);
runAll
(
mRunOnDraw
);
syncEventsThrough
();
// FIXME, really need to do this ?
...
...
@@ -200,9 +196,12 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
}
public
void
setImagesToPreload
(
ReadableArray
imagesToPreload
)
{
// FIXME setImageToPreload, working correctly?
public
void
setImagesToPreload
(
ReadableArray
imagesToPreloadRA
)
{
if
(
preloadingDone
)
return
;
List
<
Uri
>
imagesToPreload
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
imagesToPreloadRA
.
size
();
i
++)
{
imagesToPreload
.
add
(
resolveSrc
(
imagesToPreloadRA
.
getString
(
i
)));
}
if
(
imagesToPreload
.
size
()
==
0
)
{
dispatchOnLoad
();
preloadingDone
=
true
;
...
...
@@ -210,7 +209,6 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
else
{
preloadingDone
=
false
;
}
this
.
imagesToPreload
=
imagesToPreload
;
}
...
...
@@ -234,7 +232,6 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
public
void
requestSyncData
()
{
runInGLThread
(
new
Runnable
()
{
public
void
run
()
{
Log
.
i
(
"GLCanvas"
,
"requestSyncData"
);
if
(
ensureCompiledShader
(
data
))
syncData
();
else
...
...
@@ -287,15 +284,15 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
private
int
countPreloaded
()
{
int
nb
=
0
;
for
(
int
i
=
0
;
i
<
imagesToPreload
.
size
();
i
++)
{
/*
if (
[_preloaded containsObject:srcResource(toload)]) // TODO
nb++;
*/
for
(
Uri
toload:
imagesToPreload
)
{
if
(
preloaded
.
contains
(
toload
))
{
nb
++;
}
}
return
nb
;
}
private
void
onImageLoad
(
String
loaded
)
{
private
void
onImageLoad
(
Uri
loaded
)
{
if
(!
preloadingDone
)
{
preloaded
.
add
(
loaded
);
int
count
=
countPreloaded
();
...
...
@@ -314,17 +311,35 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
}
}
public
Uri
resolveSrc
(
String
src
)
{
Uri
uri
=
null
;
if
(
src
!=
null
)
{
try
{
uri
=
Uri
.
parse
(
src
);
// Verify scheme is set, so that relative uri (used by static resources) are not handled.
if
(
uri
.
getScheme
()
==
null
)
{
uri
=
null
;
}
}
catch
(
Exception
e
)
{
// ignore malformed uri, then attempt to extract resource ID.
}
if
(
uri
==
null
)
{
uri
=
GLImage
.
getResourceDrawableUri
(
reactContext
,
src
);
}
}
return
uri
;
}
public
String
srcResource
(
ReadableMap
res
)
{
public
Uri
srcResource
(
ReadableMap
res
)
{
String
src
=
null
;
boolean
isStatic
=
res
.
hasKey
(
"isStatic"
)
&&
res
.
getBoolean
(
"isStatic"
);
if
(
res
.
hasKey
(
"path"
))
src
=
res
.
getString
(
"path"
);
if
(
src
==
null
||
isStatic
)
src
=
res
.
getString
(
"uri"
);
return
src
;
return
resolveSrc
(
src
)
;
}
public
GLRenderData
recSyncData
(
GLData
data
,
HashMap
<
String
,
GLImage
>
images
)
{
Map
<
String
,
GLImage
>
prevImages
=
this
.
images
;
public
GLRenderData
recSyncData
(
GLData
data
,
HashMap
<
Uri
,
GLImage
>
images
)
{
Map
<
Uri
,
GLImage
>
prevImages
=
this
.
images
;
GLShader
shader
=
rnglContext
.
getShader
(
data
.
shader
);
Map
<
String
,
Integer
>
uniformsInteger
=
new
HashMap
<>();
...
...
@@ -368,6 +383,9 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
String
t
=
value
.
getString
(
"type"
);
if
(
t
.
equals
(
"content"
))
{
int
id
=
value
.
getInt
(
"id"
);
if
(
id
>=
contentTextures
.
size
())
{
resizeUniformContentTextures
(
id
+
1
);
}
textures
.
put
(
uniformName
,
contentTextures
.
get
(
id
));
}
else
if
(
t
.
equals
(
"fbo"
))
{
...
...
@@ -376,8 +394,8 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
textures
.
put
(
uniformName
,
fbo
.
color
.
get
(
0
));
}
else
if
(
t
.
equals
(
"uri"
))
{
final
String
src
=
srcResource
(
value
);
if
(
src
==
null
||
src
.
equals
(
""
)
)
{
final
Uri
src
=
srcResource
(
value
);
if
(
src
==
null
)
{
shader
.
runtimeException
(
"texture uniform '"
+
uniformName
+
"': Invalid uri format '"
+
value
+
"'"
);
}
...
...
@@ -539,16 +557,13 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
}
public
void
syncData
()
{
Log
.
i
(
"GLCanvas"
,
"syncData "
+
data
);
if
(
data
==
null
)
return
;
HashMap
<
String
,
GLImage
>
images
=
new
HashMap
<>();
HashMap
<
Uri
,
GLImage
>
images
=
new
HashMap
<>();
renderData
=
recSyncData
(
data
,
images
);
this
.
images
=
images
;
this
.
requestRender
();
// FIXME don't do it here since syncData is called in render phase
}
public
void
recRender
(
GLRenderData
renderData
)
{
Log
.
i
(
"GLCanvas"
,
"recRender "
+
renderData
.
fboId
);
DisplayMetrics
dm
=
reactContext
.
getResources
().
getDisplayMetrics
();
int
w
=
Float
.
valueOf
(
renderData
.
width
.
floatValue
()
*
dm
.
density
).
intValue
();
...
...
@@ -576,7 +591,6 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
GLTexture
texture
=
renderData
.
textures
.
get
(
uniformName
);
int
unit
=
renderData
.
uniformsInteger
.
get
(
uniformName
);
texture
.
bind
(
unit
);
Log
.
i
(
"GLCanvas"
,
uniformName
+
" "
+
unit
);
}
Map
<
String
,
Integer
>
uniformTypes
=
renderData
.
shader
.
getUniformTypes
();
...
...
@@ -601,8 +615,8 @@ public class GLCanvas extends GLSurfaceView implements GLSurfaceView.Renderer, R
public
void
render
()
{
if
(
renderData
==
null
)
return
;
syncContentTextures
();
Log
.
i
(
"GLCanvas"
,
"render"
);
syncContentTextures
();
int
[]
defaultFBOArr
=
new
int
[
1
];
glGetIntegerv
(
GL_FRAMEBUFFER_BINDING
,
defaultFBOArr
,
0
);
...
...
android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java
View file @
479bfb4f
package
com.projectseptember.RNGL
;
import
android.support.annotation.Nullable
;
import
android.util.Log
;
import
com.facebook.react.bridge.ReadableArray
;
import
com.facebook.react.bridge.ReadableMap
;
...
...
@@ -65,7 +64,6 @@ public class GLCanvasManager extends SimpleViewManager<GLCanvas> {
@Override
public
GLCanvas
createViewInstance
(
ThemedReactContext
context
)
{
Log
.
i
(
"GLCanvas"
,
"createViewInstance..."
);
return
new
GLCanvas
(
context
);
}
}
android/src/main/java/com/projectseptember/RNGL/GLFBO.java
View file @
479bfb4f
package
com.projectseptember.RNGL
;
import
android.util.Log
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -21,47 +19,23 @@ public class GLFBO {
return
texture
;
}
/*
int initRenderBuffer (int width, int height, int component, int attachment)
{
int[] handleArr = new int[1];
glGenRenderbuffers(1, handleArr, 0);
int handle = handleArr[0];
glBindRenderbuffer(GL_RENDERBUFFER, handle);
glRenderbufferStorage(GL_RENDERBUFFER, component, width, height);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, attachment, GL_RENDERBUFFER, handle);
return handle;
}
*/
/*
class
FBOState
{
private
int
fbo
;
private int rbo;
private int tex;
public
FBOState
()
{
int[] fbo = new int[1]
, rbo = new int[1], tex = new int[1]
;
int
[]
fbo
=
new
int
[
1
];
glGetIntegerv
(
GL_FRAMEBUFFER_BINDING
,
fbo
,
0
);
glGetIntegerv(GL_RENDERBUFFER_BINDING, rbo, 0);
glGetIntegerv(GL_TEXTURE_BINDING_2D, tex, 0);
this
.
fbo
=
fbo
[
0
];
this.rbo = rbo[0];
this.tex = tex[0];
}
private
void
restore
()
{
glBindFramebuffer
(
GL_FRAMEBUFFER
,
fbo
);
glBindRenderbuffer(GL_FRAMEBUFFER, rbo);
glBindTexture(GL_FRAMEBUFFER, tex);
}
}
*/
public
GLFBO
()
{
Log
.
i
(
"GLFBO"
,
"new"
);
//FBOState state = new FBOState();
FBOState
state
=
new
FBOState
();
int
[]
handleArr
=
new
int
[
1
];
glGenFramebuffers
(
1
,
handleArr
,
0
);
...
...
@@ -74,12 +48,11 @@ public class GLFBO {
for
(
int
i
=
0
;
i
<
numColors
;
++
i
)
{
color
.
add
(
initTexture
(
width
,
height
,
GL_COLOR_ATTACHMENT0
+
i
));
}
//
state.restore();
state
.
restore
();
}
@Override
protected
void
finalize
()
throws
Throwable
{
Log
.
i
(
"GLFBO"
,
"finalize"
);
super
.
finalize
();
int
[]
handleArr
=
new
int
[]
{
handle
};
glDeleteFramebuffers
(
1
,
handleArr
,
0
);
...
...
@@ -105,13 +78,11 @@ public class GLFBO {
}
public
void
bind
()
{
Log
.
i
(
"GLFBO"
,
"bind"
);
glBindFramebuffer
(
GL_FRAMEBUFFER
,
handle
);
glViewport
(
0
,
0
,
width
,
height
);
}
public
void
setShape
(
int
w
,
int
h
)
{
Log
.
i
(
"GLFBO"
,
"setShape "
+
w
+
" "
+
h
);
if
(
w
==
width
&&
h
==
height
)
return
;
int
[]
maxFBOSize
=
new
int
[
1
];
glGetIntegerv
(
GL_MAX_RENDERBUFFER_SIZE
,
maxFBOSize
,
0
);
...
...
@@ -121,7 +92,7 @@ public class GLFBO {
width
=
w
;
height
=
h
;
//
FBOState state = new FBOState();
FBOState
state
=
new
FBOState
();
for
(
GLTexture
clr:
color
)
{
clr
.
setShape
(
w
,
h
);
...
...
@@ -130,6 +101,6 @@ public class GLFBO {
glBindFramebuffer
(
GL_FRAMEBUFFER
,
handle
);
checkStatus
();
//
state.restore();
state
.
restore
();
}
}
android/src/main/java/com/projectseptember/RNGL/GLImage.java
View file @
479bfb4f
...
...
@@ -24,11 +24,9 @@ https://github.com/CyberAgent/android-gpuimage/blob/master/library/src/jp/co/cyb
*/
public
class
GLImage
{
private
final
Context
context
;
private
String
src
;
private
Uri
src
;
private
GLTexture
texture
;
private
Uri
uri
;
private
boolean
isLocalImage
;
private
boolean
isDirty
;
private
AsyncTask
<
Void
,
Void
,
Bitmap
>
task
;
private
Runnable
onload
;
...
...
@@ -41,31 +39,13 @@ public class GLImage {
this
.
texture
=
new
GLTexture
();
}
public
void
setSrc
(
String
src
)
{
public
void
setSrc
(
Uri
src
)
{
if
(
this
.
src
==
src
)
return
;
this
.
src
=
src
;
reloadImage
();
}
private
void
reloadImage
()
{
uri
=
null
;
if
(
src
!=
null
)
{
try
{
uri
=
Uri
.
parse
(
src
);
// Verify scheme is set, so that relative uri (used by static resources) are not handled.
if
(
uri
.
getScheme
()
==
null
)
{
uri
=
null
;
}
}
catch
(
Exception
e
)
{
// ignore malformed uri, then attempt to extract resource ID.
}
if
(
uri
==
null
)
{
uri
=
getResourceDrawableUri
(
context
,
src
);
isLocalImage
=
true
;
}
else
{
isLocalImage
=
false
;
}
}
isDirty
=
true
;
}
...
...
@@ -81,13 +61,13 @@ public class GLImage {
public
GLTexture
getTexture
()
{
if
(
isDirty
)
{
if
(
task
!=
null
)
task
.
cancel
(
true
);
task
=
new
LoadImageUriTask
(
this
,
uri
).
execute
();
task
=
new
LoadImageUriTask
(
this
,
src
).
execute
();
isDirty
=
false
;
}
return
texture
;
}
p
rivate
static
@Nullable
Uri
getResourceDrawableUri
(
Context
context
,
@Nullable
String
name
)
{
p
ublic
static
@Nullable
Uri
getResourceDrawableUri
(
Context
context
,
@Nullable
String
name
)
{
if
(
name
==
null
||
name
.
isEmpty
())
{
return
null
;
}
...
...
android/src/main/java/com/projectseptember/RNGL/RNGLContext.java
View file @
479bfb4f
package
com.projectseptember.RNGL
;
import
android.opengl.GLES20
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
import
com.facebook.react.bridge.ReactMethod
;
...
...
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