Example #1
0
  public static int loadTexture2(final Bitmap bitmap) {
    final int[] textureHandle = new int[1];

    glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      // Bind to the texture in OpenGL
      glBindTexture(GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

      // Load the bitmap into the bound texture.
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);

      //			Buffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
      //			bitmap.copyPixelsToBuffer(byteBuffer);
      //			glTexImage2D(GL_TEXTURE_2D, 0, GLES20.GL_RGB, bitmap.getWidth(), bitmap.getHeight(),
      //					0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, byteBuffer);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    } else {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Example #2
0
  /**
   * Creates a texture from raw data.
   *
   * @param data Image data, in a "direct" ByteBuffer.
   * @param width Texture width, in pixels (not bytes).
   * @param height Texture height, in pixels.
   * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA).
   * @return Handle to texture.
   */
  public static int createImageTexture(ByteBuffer data, int width, int height, int format) {
    int[] textureHandles = new int[1];
    int textureHandle;

    GLES20.glGenTextures(1, textureHandles, 0);
    textureHandle = textureHandles[0];
    GlUtil.checkGlError("glGenTextures");

    // Bind the texture handle to the 2D texture target.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);

    // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering
    // is smaller or larger than the source image.
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GlUtil.checkGlError("loadImageTexture");

    // Load the data from the buffer into the texture handle.
    GLES20.glTexImage2D(
        GLES20.GL_TEXTURE_2D, /*level*/
        0,
        format,
        width,
        height, /*border*/
        0,
        format,
        GLES20.GL_UNSIGNED_BYTE,
        data);
    GlUtil.checkGlError("loadImageTexture");

    return textureHandle;
  }
  protected SurfaceTexture createSurfaceTexture() {
    int tex[] = new int[1];
    GLES20.glGenTextures(1, tex, 0);
    //		GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex[0]);
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    textureName = tex[0];
    Log.d("OESTexture", "createSurfaceTexture textureName:" + textureName);
    final SurfaceTexture t = new SurfaceTexture(tex[0]);
    t.setOnFrameAvailableListener(
        new SurfaceTexture.OnFrameAvailableListener() {

          @Override
          public void onFrameAvailable(SurfaceTexture surfaceTexture) {
            textureUpdated = true;
            // Log.d("OESTexture", "onFrameAvailable textureName:" + textureName);
          }
        });
    return t;
  }
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Example #5
0
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false;

      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Example #6
0
 private void makeTexture() {
   int[] handleArr = new int[1];
   glGenTextures(1, handleArr, 0);
   handle = handleArr[0];
   glBindTexture(GL_TEXTURE_2D, handle);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 }
Example #7
0
 public static void a(int i, int j, IntBuffer intbuffer) {
   intbuffer.position(0);
   GLES20.glGenTextures(1, intbuffer);
   GLES20.glBindTexture(3553, intbuffer.get(0));
   GLES20.glTexParameteri(3553, 10241, 9729);
   GLES20.glTexParameteri(3553, 10240, 9729);
   GLES20.glTexParameteri(3553, 10242, 33071);
   GLES20.glTexParameteri(3553, 10243, 33071);
   GLES20.glTexImage2D(3553, 0, 6408, i, j, 0, 6408, 5121, null);
   GLES20.glFramebufferTexture2D(36160, 36064, 3553, intbuffer.get(0), 0);
 }
Example #8
0
  private static int createTexture() {
    int[] texture = new int[1];

    GLES20.glGenTextures(1, texture, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture[0]);
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    return texture[0];
  }
Example #9
0
  /** The Surface is created/init() */
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.i("Almalence", "GLLayer.onSurfaceCreated()");

    PluginManager.getInstance().onGLSurfaceCreated(gl, config);

    if (PluginManager.getInstance().shouldPreviewToGPU()) {
      final int[] tex = new int[1];
      GLES20.glGenTextures(1, tex, 0);
      this.texture_preview = tex[0];

      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, this.texture_preview);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);

      this.surfaceTexture = new SurfaceTexture(this.texture_preview);
      this.surfaceTexture.setOnFrameAvailableListener(
          new OnFrameAvailableListener() {
            @Override
            public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
              PluginManager.getInstance().onFrameAvailable();
            }
          });

      final Camera camera = CameraController.getCamera();
      if (camera == null) {
        return;
      }

      try {
        camera.setDisplayOrientation(90);
      } catch (RuntimeException e) {
        e.printStackTrace();
      }

      try {
        camera.setPreviewTexture(this.surfaceTexture);
      } catch (final IOException e) {
        e.printStackTrace();
      }

      camera.startPreview();
    }
  }
  private int loadTexture(String path) {
    String fullPath = "gfx";
    fullPath += path;
    Bitmap bitmap = null;
    try { // Get reference to AssetManager

      AssetManager mngr = _context.getAssets();
      // Create an input stream to read from the asset folder
      InputStream ins = mngr.open(fullPath);
      // Convert the input stream into a bitmap
      bitmap = BitmapFactory.decodeStream(ins);
    } catch (final IOException e) {
      e.printStackTrace();
      Toast.makeText(_context, "couldn't set image to background", Toast.LENGTH_LONG).show();
    }

    int h = firstBigger2power((float) bitmap.getHeight() / Utils.scaleFactrWidth);
    int w = firstBigger2power((float) bitmap.getWidth() / Utils.scaleFactrWidth);

    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, Bitmap.createScaledBitmap(bitmap, w, h, true), 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Example #11
0
 /**
  * create external texture
  *
  * @return texture ID
  */
 public static int initTex() {
   if (DEBUG) Log.v(TAG, "initTex:");
   final int[] tex = new int[1];
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
   GLES20.glGenTextures(1, tex, 0);
   GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
   return tex[0];
 }
  /** Sets up texturing for the object */
  private void setupTextures(Object3D ob) {
    // create new texture ids if object has them
    if (ob.hasTexture()) {
      // number of textures
      int[] texIDs = ob.get_texID();
      int[] textures = new int[texIDs.length];
      _texIDs = new int[texIDs.length];
      // texture file ids
      int[] texFiles = ob.getTexFile();

      Log.d("TEXFILES LENGTH: ", texFiles.length + "");
      GLES20.glGenTextures(texIDs.length, textures, 0);

      for (int i = 0; i < texIDs.length; i++) {
        texIDs[i] = textures[i];

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);

        // parameters
        GLES20.glTexParameterf(
            GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameterf(
            GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);

        InputStream is = mContext.getResources().openRawResource(texFiles[i]);
        Bitmap bitmap;
        try {
          bitmap = BitmapFactory.decodeStream(is);
        } finally {
          try {
            is.close();
          } catch (IOException e) {
            // Ignore.
          }
        }

        // create it
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();

        Log.d("ATTACHING TEXTURES: ", "Attached " + i);
      }
    }
  }
  public static int loadTexture(Bitmap bitmap) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Example #14
0
  public Texture(boolean shouldInterpolate, boolean shouldRepeat) {

    this.mInterpolate = shouldInterpolate;
    this.mRepeat = shouldRepeat;

    GLES20.glGenTextures(1, mTexId, 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTextureId());

    int repeatStrategy = mRepeat ? GLES20.GL_REPEAT : GLES20.GL_CLAMP_TO_EDGE;
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, repeatStrategy);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, repeatStrategy);

    // if you want that to be smoothly interpolated change GL_NEAREST to GL_LINEAR
    int interpStrategy = this.mInterpolate ? GLES20.GL_LINEAR : GLES20.GL_NEAREST;

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, interpStrategy);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, interpStrategy);
  }
 private int createTexture(
     final int width, final int height, final int textureFormat, final int textureType) {
   final int[] textureIds = {0};
   GLES20.glGenTextures(1, textureIds, 0);
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureIds[0]);
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
   GLES20.glTexImage2D(
       GLES20.GL_TEXTURE_2D,
       0,
       textureFormat,
       width,
       height,
       0,
       textureFormat,
       textureType,
       (Buffer) null);
   return textureIds[0];
 }
Example #16
0
 /** Initializes GL state. Call this after the EGL surface has been created and made current. */
 public void surfaceCreated() {
   mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER);
   if (mProgram == 0) {
     throw new RuntimeException("failed creating program");
   }
   maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
   checkGlError("glGetAttribLocation aPosition");
   if (maPositionHandle == -1) {
     throw new RuntimeException("Could not get attrib location for aPosition");
   }
   maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
   checkGlError("glGetAttribLocation aTextureCoord");
   if (maTextureHandle == -1) {
     throw new RuntimeException("Could not get attrib location for aTextureCoord");
   }
   muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
   checkGlError("glGetUniformLocation uMVPMatrix");
   if (muMVPMatrixHandle == -1) {
     throw new RuntimeException("Could not get attrib location for uMVPMatrix");
   }
   muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix");
   checkGlError("glGetUniformLocation uSTMatrix");
   if (muSTMatrixHandle == -1) {
     throw new RuntimeException("Could not get attrib location for uSTMatrix");
   }
   int[] textures = new int[1];
   GLES20.glGenTextures(1, textures, 0);
   mTextureID = textures[0];
   GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
   checkGlError("glBindTexture mTextureID");
   GLES20.glTexParameterf(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
   GLES20.glTexParameterf(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
   checkGlError("glTexParameter");
 }
  private void genFBO(GL10 glUnused) {
    fboWidth = camera.getViewport().getWidth();
    fboHeight = camera.getViewport().getHeight();

    GLES20.glGenFramebuffers(1, fb, 0);
    GLES20.glGenRenderbuffers(1, depthRb, 0);
    GLES20.glGenTextures(1, renderTex, 0);

    // generate texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTex[0]);

    // parameters - we have to make sure we clamp the textures to the edges
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    // create it
    // create an empty intbuffer first
    int[] buf = new int[fboWidth * fboHeight];
    IntBuffer texBuffer =
        ByteBuffer.allocateDirect(buf.length * 4).order(ByteOrder.nativeOrder()).asIntBuffer();

    // generate the textures
    GLES20.glTexImage2D(
        GLES20.GL_TEXTURE_2D,
        0,
        GLES20.GL_RGB,
        fboWidth,
        fboHeight,
        0,
        GLES20.GL_RGB,
        GLES20.GL_UNSIGNED_BYTE,
        texBuffer);

    // create render buffer and bind 16-bit depth buffer
    GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRb[0]);
    GLES20.glRenderbufferStorage(
        GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, fboWidth, fboHeight);
  }
Example #18
0
  public Texture(Context context, int idpicture) {

    int[] names = new int[1];
    GLES20.glGenTextures(1, names, 0);
    name = names[0];
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, name);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), idpicture);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  }
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glDisable(GLES20.GL_DEPTH_TEST);
      GLES20.glDisable(GLES20.GL_DITHER);
      GLES20.glDisable(GLES20.GL_STENCIL_TEST);
      GLES20.glDisable(GL10.GL_DITHER);

      String extensions = GLES20.glGetString(GL10.GL_EXTENSIONS);
      Log.d(TAG, "OpenGL extensions=" + extensions);

      // Ignore the passed-in GL10 interface, and use the GLES20
      // class's static methods instead.
      mProgram = createProgram(VERTEX_SHADER_SOURCE, FRAGMENT_SHADER_SOURCE);
      if (mProgram == 0) {
        return;
      }
      maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
      checkGlError("glGetAttribLocation aPosition");
      if (maPositionHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aPosition");
      }
      maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord");
      checkGlError("glGetAttribLocation aTextureCoord");
      if (maTextureHandle == -1) {
        throw new RuntimeException("Could not get attrib location for aTextureCoord");
      }

      muSamplerYHandle = GLES20.glGetUniformLocation(mProgram, "SamplerY");
      if (muSamplerYHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerY");
      }
      muSamplerUHandle = GLES20.glGetUniformLocation(mProgram, "SamplerU");
      if (muSamplerUHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerU");
      }
      muSamplerVHandle = GLES20.glGetUniformLocation(mProgram, "SamplerV");
      if (muSamplerVHandle == -1) {
        throw new RuntimeException("Could not get uniform location for SamplerV");
      }

      mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
      GLES20.glVertexAttribPointer(
          maPositionHandle,
          3,
          GLES20.GL_FLOAT,
          false,
          TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
          mTriangleVertices);
      checkGlError("glVertexAttribPointer maPosition");

      mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
      GLES20.glEnableVertexAttribArray(maPositionHandle);
      checkGlError("glEnableVertexAttribArray maPositionHandle");
      GLES20.glVertexAttribPointer(
          maTextureHandle,
          2,
          GLES20.GL_FLOAT,
          false,
          TRIANGLE_VERTICES_DATA_STRIDE_BYTES,
          mTriangleVertices);
      checkGlError("glVertexAttribPointer maTextureHandle");
      GLES20.glEnableVertexAttribArray(maTextureHandle);
      checkGlError("glEnableVertexAttribArray maTextureHandle");

      GLES20.glGenTextures(1, mTextureY, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureY[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      GLES20.glGenTextures(1, mTextureU, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureU[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      GLES20.glGenTextures(1, mTextureV, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureV[0]);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

      mSurfaceCreated = true;
    }
  // Returns true on success, false otherwise.
  @CalledByNative
  public boolean allocate(int width, int height, int frameRate) {
    Log.d(TAG, "allocate: requested (" + width + "x" + height + ")@" + frameRate + "fps");
    try {
      mCamera = Camera.open(mId);
    } catch (RuntimeException ex) {
      Log.e(TAG, "allocate: Camera.open: " + ex);
      return false;
    }

    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    Camera.getCameraInfo(mId, cameraInfo);
    mCameraOrientation = cameraInfo.orientation;
    mCameraFacing = cameraInfo.facing;
    mDeviceOrientation = getDeviceOrientation();
    Log.d(
        TAG,
        "allocate: orientation dev="
            + mDeviceOrientation
            + ", cam="
            + mCameraOrientation
            + ", facing="
            + mCameraFacing);

    Camera.Parameters parameters = mCamera.getParameters();

    // getSupportedPreviewFpsRange() returns a List with at least one
    // element, but when camera is in bad state, it can return null pointer.
    List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange();
    if (listFpsRange == null || listFpsRange.size() == 0) {
      Log.e(TAG, "allocate: no fps range found");
      return false;
    }
    int frameRateInMs = frameRate * 1000;
    // Use the first range as default.
    int[] fpsMinMax = listFpsRange.get(0);
    int newFrameRate = (fpsMinMax[0] + 999) / 1000;
    for (int[] fpsRange : listFpsRange) {
      if (fpsRange[0] <= frameRateInMs && frameRateInMs <= fpsRange[1]) {
        fpsMinMax = fpsRange;
        newFrameRate = frameRate;
        break;
      }
    }
    frameRate = newFrameRate;
    Log.d(TAG, "allocate: fps set to " + frameRate);

    // Calculate size.
    List<Camera.Size> listCameraSize = parameters.getSupportedPreviewSizes();
    int minDiff = Integer.MAX_VALUE;
    int matchedWidth = width;
    int matchedHeight = height;
    for (Camera.Size size : listCameraSize) {
      int diff = Math.abs(size.width - width) + Math.abs(size.height - height);
      Log.d(TAG, "allocate: supported (" + size.width + ", " + size.height + "), diff=" + diff);
      // TODO(wjia): Remove this hack (forcing width to be multiple
      // of 32) by supporting stride in video frame buffer.
      // Right now, VideoCaptureController requires compact YV12
      // (i.e., with no padding).
      if (diff < minDiff && (size.width % 32 == 0)) {
        minDiff = diff;
        matchedWidth = size.width;
        matchedHeight = size.height;
      }
    }
    if (minDiff == Integer.MAX_VALUE) {
      Log.e(TAG, "allocate: can not find a multiple-of-32 resolution");
      return false;
    }

    mCaptureFormat =
        new CaptureFormat(matchedWidth, matchedHeight, frameRate, BuggyDeviceHack.getImageFormat());
    // Hack to avoid certain capture resolutions under a minimum one,
    // see http://crbug.com/305294
    BuggyDeviceHack.applyMinDimensions(mCaptureFormat);
    Log.d(TAG, "allocate: matched (" + mCaptureFormat.mWidth + "x" + mCaptureFormat.mHeight + ")");

    if (parameters.isVideoStabilizationSupported()) {
      Log.d(
          TAG,
          "Image stabilization supported, currently: "
              + parameters.getVideoStabilization()
              + ", setting it.");
      parameters.setVideoStabilization(true);
    } else {
      Log.d(TAG, "Image stabilization not supported.");
    }
    parameters.setPreviewSize(mCaptureFormat.mWidth, mCaptureFormat.mHeight);
    parameters.setPreviewFormat(mCaptureFormat.mPixelFormat);
    parameters.setPreviewFpsRange(fpsMinMax[0], fpsMinMax[1]);
    mCamera.setParameters(parameters);

    // Set SurfaceTexture. Android Capture needs a SurfaceTexture even if
    // it is not going to be used.
    mGlTextures = new int[1];
    // Generate one texture pointer and bind it as an external texture.
    GLES20.glGenTextures(1, mGlTextures, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mGlTextures[0]);
    // No mip-mapping with camera source.
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    // Clamp to edge is only option.
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

    mSurfaceTexture = new SurfaceTexture(mGlTextures[0]);
    mSurfaceTexture.setOnFrameAvailableListener(null);

    try {
      mCamera.setPreviewTexture(mSurfaceTexture);
    } catch (IOException ex) {
      Log.e(TAG, "allocate: " + ex);
      return false;
    }

    int bufSize =
        mCaptureFormat.mWidth
            * mCaptureFormat.mHeight
            * ImageFormat.getBitsPerPixel(mCaptureFormat.mPixelFormat)
            / 8;
    for (int i = 0; i < NUM_CAPTURE_BUFFERS; i++) {
      byte[] buffer = new byte[bufSize];
      mCamera.addCallbackBuffer(buffer);
    }
    mExpectedFrameSize = bufSize;

    return true;
  }
Example #21
0
 void SetTextureWRAP_T(int value) {
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, value);
 }
Example #22
0
 void SetTextureWRAP_MIN_FILTER(int value) {
   GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, value);
 }
Example #23
0
 @Override
 public void glTexParameteri(int target, int pname, int param) {
   GLES20.glTexParameteri(target, pname, param);
 }
Example #24
0
 @Override
 public void texParameteri(final int target, final int par, final int v) {
   checkOpenGLThread();
   GLES20.glTexParameteri(target, par, v);
 }