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
8acaae75
Commit
8acaae75
authored
Dec 30, 2015
by
Gaëtan Renaudeau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement the new pixelRatio per node
parent
c3a98a8e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
69 additions
and
34 deletions
+69
-34
android/src/main/java/com/projectseptember/RNGL/GLCanvas.java
...oid/src/main/java/com/projectseptember/RNGL/GLCanvas.java
+38
-16
android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java
.../main/java/com/projectseptember/RNGL/GLCanvasManager.java
+5
-0
android/src/main/java/com/projectseptember/RNGL/GLData.java
android/src/main/java/com/projectseptember/RNGL/GLData.java
+9
-6
ios/GLCanvas.m
ios/GLCanvas.m
+5
-6
ios/GLData.h
ios/GLData.h
+2
-0
ios/GLData.m
ios/GLData.m
+2
-0
ios/GLRenderData.h
ios/GLRenderData.h
+4
-4
ios/GLRenderData.m
ios/GLRenderData.m
+2
-2
ios/RCTConvert+GLData.m
ios/RCTConvert+GLData.m
+2
-0
No files found.
android/src/main/java/com/projectseptember/RNGL/GLCanvas.java
View file @
8acaae75
...
...
@@ -70,6 +70,9 @@ public class GLCanvas extends GLSurfaceView
private
ExecutorSupplier
executorSupplier
;
private
final
Queue
<
Runnable
>
mRunOnDraw
=
new
LinkedList
<>();
private
boolean
captureFrameRequested
=
false
;
private
float
pixelRatio
;
private
float
displayDensity
;
public
GLCanvas
(
ThemedReactContext
context
,
ExecutorSupplier
executorSupplier
)
{
super
(
context
);
...
...
@@ -78,6 +81,10 @@ public class GLCanvas extends GLSurfaceView
rnglContext
=
context
.
getNativeModule
(
RNGLContext
.
class
);
setEGLContextClientVersion
(
2
);
DisplayMetrics
dm
=
reactContext
.
getResources
().
getDisplayMetrics
();
displayDensity
=
dm
.
density
;
pixelRatio
=
dm
.
density
;
setEGLConfigChooser
(
8
,
8
,
8
,
8
,
16
,
0
);
getHolder
().
setFormat
(
PixelFormat
.
RGB_888
);
setZOrderOnTop
(
true
);
...
...
@@ -123,6 +130,12 @@ public class GLCanvas extends GLSurfaceView
@Override
public
void
onSurfaceChanged
(
GL10
gl
,
int
width
,
int
height
)
{}
@Override
protected
void
onSizeChanged
(
int
w
,
int
h
,
int
oldw
,
int
oldh
)
{
super
.
onSizeChanged
(
w
,
h
,
oldw
,
oldh
);
syncSize
(
w
,
h
,
pixelRatio
);
}
@Override
public
void
onDrawFrame
(
GL10
gl
)
{
runAll
(
mRunOnDraw
);
...
...
@@ -472,8 +485,8 @@ public class GLCanvas extends GLSurfaceView
if
(
arraySizeForType
(
type
)
!=
arr
.
size
())
{
shader
.
runtimeException
(
"uniform '"
+
uniformName
+
"': Invalid array size: "
+
arr
.
size
()+
". Expected: "
+
arraySizeForType
(
type
));
"': Invalid array size: "
+
arr
.
size
()+
". Expected: "
+
arraySizeForType
(
type
));
}
uniformsFloatBuffer
.
put
(
uniformName
,
parseAsFloatArray
(
arr
));
break
;
...
...
@@ -488,8 +501,8 @@ public class GLCanvas extends GLSurfaceView
if
(
arraySizeForType
(
type
)
!=
arr2
.
size
())
{
shader
.
runtimeException
(
"uniform '"
+
uniformName
+
"': Invalid array size: "
+
arr2
.
size
()+
". Expected: "
+
arraySizeForType
(
type
));
"': Invalid array size: "
+
arr2
.
size
()+
". Expected: "
+
arraySizeForType
(
type
));
}
uniformsIntBuffer
.
put
(
uniformName
,
parseAsIntArray
(
arr2
));
break
;
...
...
@@ -497,7 +510,7 @@ public class GLCanvas extends GLSurfaceView
default
:
shader
.
runtimeException
(
"uniform '"
+
uniformName
+
"': type not supported: "
+
type
);
"': type not supported: "
+
type
);
}
}
...
...
@@ -511,9 +524,9 @@ public class GLCanvas extends GLSurfaceView
for
(
String
uniformName:
uniformTypes
.
keySet
())
{
if
(!
uniformsFloat
.
containsKey
(
uniformName
)
&&
!
uniformsInteger
.
containsKey
(
uniformName
)
&&
!
uniformsFloatBuffer
.
containsKey
(
uniformName
)
&&
!
uniformsIntBuffer
.
containsKey
(
uniformName
))
{
!
uniformsInteger
.
containsKey
(
uniformName
)
&&
!
uniformsFloatBuffer
.
containsKey
(
uniformName
)
&&
!
uniformsIntBuffer
.
containsKey
(
uniformName
))
{
shader
.
runtimeException
(
"All defined uniforms must be provided. Missing '"
+
uniformName
+
"'"
);
}
}
...
...
@@ -525,8 +538,8 @@ public class GLCanvas extends GLSurfaceView
uniformsIntBuffer
,
uniformsFloatBuffer
,
textures
,
data
.
width
,
data
.
height
,
(
int
)(
data
.
width
*
data
.
pixelRatio
)
,
(
int
)(
data
.
height
*
data
.
pixelRatio
)
,
data
.
fboId
,
contextChildren
,
children
);
...
...
@@ -538,7 +551,7 @@ public class GLCanvas extends GLSurfaceView
.
order
(
ByteOrder
.
nativeOrder
())
.
asFloatBuffer
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
buf
.
put
((
float
)
array
.
getDouble
(
i
));
buf
.
put
((
float
)
array
.
getDouble
(
i
));
buf
.
position
(
0
);
return
buf
;
}
...
...
@@ -598,11 +611,8 @@ public class GLCanvas extends GLSurfaceView
}
private
void
recRender
(
GLRenderData
renderData
)
{
DisplayMetrics
dm
=
reactContext
.
getResources
().
getDisplayMetrics
();
int
w
=
Float
.
valueOf
(
renderData
.
width
.
floatValue
()
*
dm
.
density
).
intValue
();
int
h
=
Float
.
valueOf
(
renderData
.
height
.
floatValue
()
*
dm
.
density
).
intValue
();
int
w
=
renderData
.
width
;
int
h
=
renderData
.
height
;
for
(
GLRenderData
child:
renderData
.
contextChildren
)
recRender
(
child
);
...
...
@@ -751,4 +761,16 @@ public class GLCanvas extends GLSurfaceView
d
.
removeAll
(
b
);
return
d
;
}
public
void
setPixelRatio
(
float
pixelRatio
)
{
this
.
pixelRatio
=
pixelRatio
;
syncSize
(
this
.
getWidth
(),
this
.
getHeight
(),
pixelRatio
);
}
private
void
syncSize
(
int
w
,
int
h
,
float
pixelRatio
)
{
int
width
=
(
int
)
(
w
*
pixelRatio
/
displayDensity
);
int
height
=
(
int
)
(
h
*
pixelRatio
/
displayDensity
);
getHolder
().
setFixedSize
(
width
,
height
);
}
}
android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java
View file @
8acaae75
...
...
@@ -27,6 +27,11 @@ public class GLCanvasManager extends SimpleViewManager<GLCanvas> {
private
ExecutorSupplier
executorSupplier
;
@ReactProp
(
name
=
"pixelRatio"
)
public
void
setPixelRatio
(
GLCanvas
view
,
float
pixelRatio
)
{
view
.
setPixelRatio
(
pixelRatio
);
}
@ReactProp
(
name
=
"nbContentTextures"
)
public
void
setNbContentTextures
(
GLCanvas
view
,
int
nbContentTextures
)
{
view
.
setNbContentTextures
(
nbContentTextures
);
...
...
android/src/main/java/com/projectseptember/RNGL/GLData.java
View file @
8acaae75
...
...
@@ -10,17 +10,19 @@ public class GLData {
final
Integer
shader
;
final
ReadableMap
uniforms
;
final
Integer
width
;
final
Integer
height
;
final
Double
width
;
final
Double
height
;
final
Double
pixelRatio
;
final
Integer
fboId
;
final
List
<
GLData
>
contextChildren
;
final
List
<
GLData
>
children
;
public
GLData
(
Integer
shader
,
ReadableMap
uniforms
,
Integer
width
,
Integer
height
,
Integer
fboId
,
List
<
GLData
>
contextChildren
,
List
<
GLData
>
children
)
{
public
GLData
(
Integer
shader
,
ReadableMap
uniforms
,
Double
width
,
Double
height
,
Double
pixelRatio
,
Integer
fboId
,
List
<
GLData
>
contextChildren
,
List
<
GLData
>
children
)
{
this
.
shader
=
shader
;
this
.
uniforms
=
uniforms
;
this
.
width
=
width
;
this
.
height
=
height
;
this
.
pixelRatio
=
pixelRatio
;
this
.
fboId
=
fboId
;
this
.
contextChildren
=
contextChildren
;
this
.
children
=
children
;
...
...
@@ -37,11 +39,12 @@ public class GLData {
public
static
GLData
fromMap
(
ReadableMap
map
)
{
Integer
shader
=
map
.
getInt
(
"shader"
);
ReadableMap
uniforms
=
map
.
getMap
(
"uniforms"
);
Integer
width
=
(
int
)
map
.
getDouble
(
"width"
);
Integer
height
=
(
int
)
map
.
getDouble
(
"height"
);
Double
width
=
map
.
getDouble
(
"width"
);
Double
height
=
map
.
getDouble
(
"height"
);
Double
pixelRatio
=
map
.
getDouble
(
"pixelRatio"
);
Integer
fboId
=
map
.
getInt
(
"fboId"
);
List
<
GLData
>
children
=
fromArray
(
map
.
getArray
(
"children"
));
List
<
GLData
>
contextChildren
=
fromArray
(
map
.
getArray
(
"contextChildren"
));
return
new
GLData
(
shader
,
uniforms
,
width
,
height
,
fboId
,
contextChildren
,
children
);
return
new
GLData
(
shader
,
uniforms
,
width
,
height
,
pixelRatio
,
fboId
,
contextChildren
,
children
);
}
}
ios/GLCanvas.m
View file @
8acaae75
...
...
@@ -178,6 +178,7 @@ RCT_NOT_IMPLEMENTED(-init)
weak_traverseTree
=
traverseTree
=
^
GLRenderData
*
(
GLData
*
data
)
{
NSNumber
*
width
=
data
.
width
;
NSNumber
*
height
=
data
.
height
;
NSNumber
*
pixelRatio
=
data
.
pixelRatio
;
int
fboId
=
[
data
.
fboId
intValue
];
NSMutableArray
*
contextChildren
=
[[
NSMutableArray
alloc
]
init
];
...
...
@@ -275,8 +276,8 @@ RCT_NOT_IMPLEMENTED(-init)
initWithShader:
shader
withUniforms:
uniforms
withTextures:
textures
withWidth:
width
withHeight:
height
withWidth:
(
int
)([
width
floatValue
]
*
[
pixelRatio
floatValue
])
withHeight:
(
int
)([
height
floatValue
]
*
[
pixelRatio
floatValue
])
withFboId:
fboId
withContextChildren:
contextChildren
withChildren:
children
];
...
...
@@ -404,16 +405,14 @@ RCT_NOT_IMPLEMENTED(-init)
GLRenderData
*
rd
=
_renderData
;
if
(
!
rd
)
return
;
RCT_PROFILE_BEGIN_EVENT
(
0
,
@"GLCanvas render"
,
nil
);
CGFloat
scale
=
self
.
contentScaleFactor
;
@autoreleasepool
{
CGFloat
scale
=
RCTScreenScale
();
void
(
^
recDraw
)
(
GLRenderData
*
renderData
);
__block
__weak
void
(
^
weak_recDraw
)
(
GLRenderData
*
renderData
);
weak_recDraw
=
recDraw
=
^
void
(
GLRenderData
*
renderData
)
{
float
w
=
[
renderData
.
width
floatValue
]
*
scale
;
float
h
=
[
renderData
.
height
floatValue
]
*
scale
;
int
w
=
renderData
.
width
;
int
h
=
renderData
.
height
;
for
(
GLRenderData
*
child
in
renderData
.
contextChildren
)
weak_recDraw
(
child
);
...
...
ios/GLData.h
View file @
8acaae75
...
...
@@ -8,6 +8,7 @@
@property
(
nonatomic
)
NSDictionary
*
uniforms
;
@property
(
nonatomic
)
NSNumber
*
width
;
@property
(
nonatomic
)
NSNumber
*
height
;
@property
(
nonatomic
)
NSNumber
*
pixelRatio
;
@property
(
nonatomic
)
NSNumber
*
fboId
;
@property
(
nonatomic
)
NSArray
*
contextChildren
;
@property
(
nonatomic
)
NSArray
*
children
;
...
...
@@ -16,6 +17,7 @@
withUniforms
:
(
NSDictionary
*
)
uniforms
withWidth
:
(
NSNumber
*
)
width
withHeight
:
(
NSNumber
*
)
height
withPixelRatio
:
(
NSNumber
*
)
pixelRatio
withFboId
:
(
NSNumber
*
)
fboId
withContextChildren
:
(
NSArray
*
)
contextChildren
withChildren
:
(
NSArray
*
)
children
;
...
...
ios/GLData.m
View file @
8acaae75
...
...
@@ -6,6 +6,7 @@
withUniforms
:
(
NSDictionary
*
)
uniforms
withWidth
:
(
NSNumber
*
)
width
withHeight
:
(
NSNumber
*
)
height
withPixelRatio
:
(
NSNumber
*
)
pixelRatio
withFboId
:
(
NSNumber
*
)
fboId
withContextChildren
:
(
NSArray
*
)
contextChildren
withChildren
:
(
NSArray
*
)
children
...
...
@@ -15,6 +16,7 @@
self
.
uniforms
=
uniforms
;
self
.
width
=
width
;
self
.
height
=
height
;
self
.
pixelRatio
=
pixelRatio
;
self
.
fboId
=
fboId
;
self
.
contextChildren
=
contextChildren
;
self
.
children
=
children
;
...
...
ios/GLRenderData.h
View file @
8acaae75
...
...
@@ -7,8 +7,8 @@
@property
(
nonatomic
)
GLShader
*
shader
;
@property
(
nonatomic
)
NSDictionary
*
uniforms
;
@property
(
nonatomic
)
NSDictionary
*
textures
;
@property
(
nonatomic
)
NSNumber
*
width
;
@property
(
nonatomic
)
NSNumber
*
height
;
@property
(
nonatomic
)
int
width
;
@property
(
nonatomic
)
int
height
;
@property
(
nonatomic
)
int
fboId
;
@property
(
nonatomic
)
NSArray
*
contextChildren
;
@property
(
nonatomic
)
NSArray
*
children
;
...
...
@@ -16,8 +16,8 @@
-
(
instancetype
)
initWithShader
:
(
GLShader
*
)
shader
withUniforms
:(
NSDictionary
*
)
uniforms
withTextures
:
(
NSDictionary
*
)
textures
withWidth
:
(
NSNumber
*
)
width
withHeight
:
(
NSNumber
*
)
height
withWidth
:
(
int
)
width
withHeight
:
(
int
)
height
withFboId
:
(
int
)
fboId
withContextChildren
:
(
NSArray
*
)
contextChildren
withChildren
:
(
NSArray
*
)
children
;
...
...
ios/GLRenderData.m
View file @
8acaae75
...
...
@@ -6,8 +6,8 @@
-
(
instancetype
)
initWithShader
:
(
GLShader
*
)
shader
withUniforms
:(
NSDictionary
*
)
uniforms
withTextures
:
(
NSDictionary
*
)
textures
withWidth
:
(
NSNumber
*
)
width
withHeight
:
(
NSNumber
*
)
height
withWidth
:
(
int
)
width
withHeight
:
(
int
)
height
withFboId
:
(
int
)
fboId
withContextChildren
:
(
NSArray
*
)
contextChildren
withChildren
:
(
NSArray
*
)
children
...
...
ios/RCTConvert+GLData.m
View file @
8acaae75
...
...
@@ -10,6 +10,7 @@
NSDictionary
*
uniforms
=
[
self
NSDictionary
:
json
[
@"uniforms"
]];
NSNumber
*
width
=
[
self
NSNumber
:
json
[
@"width"
]];
NSNumber
*
height
=
[
self
NSNumber
:
json
[
@"height"
]];
NSNumber
*
pixelRatio
=
[
self
NSNumber
:
json
[
@"pixelRatio"
]];
NSNumber
*
fboId
=
[
self
NSNumber
:
json
[
@"fboId"
]];
NSArray
*
contextChildrenJSON
=
[
self
NSArray
:
json
[
@"contextChildren"
]];
NSArray
*
childrenJSON
=
[
self
NSArray
:
json
[
@"children"
]];
...
...
@@ -30,6 +31,7 @@
withUniforms:
uniforms
withWidth:
width
withHeight:
height
withPixelRatio:
pixelRatio
withFboId:
fboId
withContextChildren:
contextChildren
withChildren:
children
];
...
...
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