From 479bfb4f81ea161833d94d8fbc6b5a64fe616e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Renaudeau?= Date: Mon, 16 Nov 2015 18:43:37 +0100 Subject: [PATCH] wip --- .../com/projectseptember/RNGL/GLCanvas.java | 72 +++++++++++-------- .../RNGL/GLCanvasManager.java | 2 - .../java/com/projectseptember/RNGL/GLFBO.java | 39 ++-------- .../com/projectseptember/RNGL/GLImage.java | 28 ++------ .../projectseptember/RNGL/RNGLContext.java | 2 + 5 files changed, 54 insertions(+), 89 deletions(-) diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java index 9a5815d..b432e7e 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvas.java @@ -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 I guess? probably Uri should be resolved in advance. not in GLImage + private List imagesToPreload; + private List preloaded; - List preloaded; // TODO List - - private Map images = new HashMap<>(); + private Map images = new HashMap<>(); private List contentTextures = new ArrayList<>(); private List 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 imagesToPreload = new ArrayList<>(); + for (int i=0; i images) { - Map prevImages = this.images; + public GLRenderData recSyncData (GLData data, HashMap images) { + Map prevImages = this.images; GLShader shader = rnglContext.getShader(data.shader); Map 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 images = new HashMap<>(); + HashMap 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 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); diff --git a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java index 2134691..7c16e55 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLCanvasManager.java @@ -1,7 +1,6 @@ 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 { @Override public GLCanvas createViewInstance (ThemedReactContext context) { - Log.i("GLCanvas", "createViewInstance..."); return new GLCanvas(context); } } diff --git a/android/src/main/java/com/projectseptember/RNGL/GLFBO.java b/android/src/main/java/com/projectseptember/RNGL/GLFBO.java index b5f6009..006fdb5 100644 --- a/android/src/main/java/com/projectseptember/RNGL/GLFBO.java +++ b/android/src/main/java/com/projectseptember/RNGL/GLFBO.java @@ -1,7 +1,5 @@ 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 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; } - private static @Nullable Uri getResourceDrawableUri(Context context, @Nullable String name) { + public static @Nullable Uri getResourceDrawableUri(Context context, @Nullable String name) { if (name == null || name.isEmpty()) { return null; } diff --git a/android/src/main/java/com/projectseptember/RNGL/RNGLContext.java b/android/src/main/java/com/projectseptember/RNGL/RNGLContext.java index 6e9233c..4eb4814 100644 --- a/android/src/main/java/com/projectseptember/RNGL/RNGLContext.java +++ b/android/src/main/java/com/projectseptember/RNGL/RNGLContext.java @@ -1,5 +1,7 @@ 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; -- 2.26.2