Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Commit

Permalink
renderData set back to nil when data changes
Browse files Browse the repository at this point in the history
Attempt to fix #38
  • Loading branch information
gre committed Dec 28, 2015
1 parent b8c60b7 commit 38d4516
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 9 additions & 6 deletions android/src/main/java/com/projectseptember/RNGL/GLCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public void setAutoRedraw(boolean autoRedraw) {

public void setData (GLData data) {
this.data = data;
renderData = null;
if (!haveRemainingToPreload()) syncContentBitmaps();
requestSyncData();
}
Expand Down Expand Up @@ -586,13 +587,13 @@ private int arraySizeForType(int type) {

private boolean syncData () {
if (data == null) return true;
HashMap<Uri, GLImage> images = new HashMap<>();
GLRenderData node = recSyncData(data, images);
HashMap<Uri, GLImage> newImages = new HashMap<>();
GLRenderData node = recSyncData(data, newImages);
if (node == null) return false;
Set<Uri> imagesGone = diff(this.images.keySet(), images.keySet());
images = newImages;
preloaded.removeAll(imagesGone);
renderData = node;
this.images = images;
this.preloaded.removeAll(imagesGone);
return true;
}

Expand Down Expand Up @@ -647,16 +648,18 @@ private void recRender (GLRenderData renderData) {
}

private void render () {
if (renderData == null) return;
GLRenderData rd = renderData;
if (rd == null) return;
syncContentTextures();

int[] defaultFBOArr = new int[1];
glGetIntegerv(GL_FRAMEBUFFER_BINDING, defaultFBOArr, 0);
defaultFBO = defaultFBOArr[0];
glEnable(GL_BLEND);
recRender(renderData);
recRender(rd);
glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glBindBuffer(GL_ARRAY_BUFFER, 0);

if (dirtyOnLoad && !haveRemainingToPreload()) {
dirtyOnLoad = false;
Expand Down
9 changes: 6 additions & 3 deletions ios/GLCanvas.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ - (void)setPointerEvents:(RCTPointerEvents)pointerEvents
- (void)setData:(GLData *)data
{
_data = data;
_renderData = nil;
[self requestSyncData];
}

Expand Down Expand Up @@ -366,7 +367,7 @@ - (void)drawRect:(CGRect)rect
NSData *frameData = UIImagePNGRepresentation(frameImage);
NSString *frame =
[NSString stringWithFormat:@"data:image/png;base64,%@",
[frameData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]];
[frameData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]];
if (weakSelf.onGLCaptureFrame) weakSelf.onGLCaptureFrame(@{ @"frame": frame });
});
}
Expand All @@ -375,7 +376,8 @@ - (void)drawRect:(CGRect)rect

- (void)render
{
if (!_renderData) return;
GLRenderData *rd = _renderData;
if (!rd) return;

CGFloat scale = RCTScreenScale();

Expand Down Expand Up @@ -426,9 +428,10 @@ - (void)render

glGetIntegerv(GL_FRAMEBUFFER_BINDING, &defaultFBO);
glEnable(GL_BLEND);
recDraw(_renderData);
recDraw(rd);
glDisable(GL_BLEND);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
glBindBuffer(GL_ARRAY_BUFFER, 0);

if (_dirtyOnLoad && ![self haveRemainingToPreload]) {
_dirtyOnLoad = false;
Expand Down

0 comments on commit 38d4516

Please sign in to comment.