Skip to content

Commit

Permalink
fd
Browse files Browse the repository at this point in the history
  • Loading branch information
dingjikerbo committed Nov 27, 2018
1 parent 1b48d24 commit 0383402
Show file tree
Hide file tree
Showing 79 changed files with 2,165 additions and 1,032 deletions.
Binary file modified .DS_Store
Binary file not shown.
2,304 changes: 1,391 additions & 913 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -8,7 +8,7 @@
|--- |-------|-------|------|
|1|GLSurfacePreview|拿到相机输出的帧数据,直接绘制到屏幕|Done|
|2|GLSurfacePreview2|GLSurfaceView + OpenGL相机预览,先绘制到FBO的Texture上,再处理后(变红)绘制到Display Surface|Done|
|3|GLSurfacePreview3|GLSurfaceView + OpenGL相机预览,直接从相机的输出SurfaceTexture上复制数据到Display Surface|Pending|
|3|GLSurfacePreview3|GLSurfaceView + OpenGL相机预览,直接从相机的输出SurfaceTexture上复制数据到Display Surface|Done|
|4|SurfacePreview|SurfaceView + OpenGL + EGL相机预览,直接绘制到Display Surface|Done|
|5|SurfacePreview2|SurfaceView + OpenGL + EGL相机预览,先绘制到PBuffer,再Blit到Display Surface|Done|
|6|MultiSurfacePreview|相机预览到两个SurfaceView,共享EglContext,先绘制到Texture,再将Texture处理后Draw到另一个Surface|Done|
Expand Down
6 changes: 6 additions & 0 deletions build.gradle
Expand Up @@ -3,6 +3,9 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
Expand All @@ -16,6 +19,9 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}

Expand Down
Expand Up @@ -5,7 +5,7 @@
import android.hardware.Camera;
import android.opengl.GLSurfaceView;

import com.inuker.library.YUVProgram;
import com.inuker.library.program.YUVProgram;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down
Expand Up @@ -5,9 +5,8 @@
import android.hardware.Camera;
import android.opengl.GLSurfaceView;

import com.inuker.library.LogUtils;
import com.inuker.library.TextureProgram;
import com.inuker.library.YUVProgram;
import com.inuker.library.utils.LogUtils;
import com.inuker.library.program.YUVProgram;

import java.io.IOException;
import java.nio.ByteBuffer;
Expand Down
Expand Up @@ -2,8 +2,8 @@

import android.content.Context;

import com.inuker.library.GlUtil;
import com.inuker.library.ShaderProgram;
import com.inuker.library.utils.GlUtil;
import com.inuker.library.program.ShaderProgram;

import java.nio.FloatBuffer;

Expand Down
2 changes: 1 addition & 1 deletion glsurfacepreview3/src/main/AndroidManifest.xml
Expand Up @@ -10,7 +10,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity"
android:screenOrientation="landscape">
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
@@ -1,18 +1,13 @@
package com.example.dingjikerbo.glsurfacepreview3;

import android.graphics.ImageFormat;
import android.graphics.SurfaceTexture;
import android.hardware.Camera;
import android.opengl.GLSurfaceView;
import android.util.Log;

import com.inuker.library.LogUtils;
import com.inuker.library.TextureProgram;
import com.inuker.library.WindowSurface;
import com.inuker.library.YUVProgram;
import com.inuker.library.program.OESProgram;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
Expand All @@ -32,56 +27,69 @@ public class CameraSurfaceRender implements GLSurfaceView.Renderer, SurfaceTextu

private Camera mCamera;

private int mTextureId;
private int mSurfaceTextureId;
private SurfaceTexture mSurfaceTexture;

private TextureProgram mTextureProgram;
private float[] mTransformMatrix = new float[16];

private GLSurfaceView mGLSurfaceView;

private OESProgram mProgram;

public CameraSurfaceRender(GLSurfaceView glSurfaceView) {
mGLSurfaceView = glSurfaceView;
}

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
LogUtils.v("onSurfaceCreated");
Log.v("bush", String.format("onSurfaceCreated"));
mCamera = Camera.open(1);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
LogUtils.v(String.format("onSurfaceChanged width = %d, height = %d", width, height));
Log.v("bush", String.format("onSurfaceChanged"));

glViewport(0, 0, width, height);

int[] textures = new int[1];
glGenTextures(1, textures, 0);
mTextureId = textures[0];
mSurfaceTexture = new SurfaceTexture(mTextureId);
mSurfaceTextureId = textures[0];
mSurfaceTexture = new SurfaceTexture(mSurfaceTextureId);
mSurfaceTexture.setOnFrameAvailableListener(this);

mTextureProgram = new TextureProgram(mGLSurfaceView.getContext(), width, height);
mProgram = new OESProgram(mGLSurfaceView.getContext(), width, height);

try {
mCamera.setPreviewTexture(mSurfaceTexture);
mSurfaceTexture.setOnFrameAvailableListener(this);
} catch (IOException e) {
e.printStackTrace();
}

mCamera.startPreview();
}

@Override
public void onDrawFrame(GL10 gl) {
Log.v("bush", "onDrawFrame");

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1f, 1f, 1f, 1f);

mSurfaceTexture.updateTexImage();
mTextureProgram.draw(mTextureId);
mSurfaceTexture.getTransformMatrix(mTransformMatrix);

StringBuilder sb = new StringBuilder();
for (float f : mTransformMatrix) {
sb.append(String.format("%.2f, ", f));
}
Log.v("bush", String.format("%s", sb.toString()));

mProgram.draw(mSurfaceTextureId, mTransformMatrix);
}

@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
Log.v("bush", "onFrameAvailable");
mGLSurfaceView.requestRender();
}
}
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

Expand All @@ -15,6 +16,8 @@ protected void onCreate(Bundle savedInstanceState) {
mGLSurfaceView = new GLSurfaceView(this);
setContentView(mGLSurfaceView);

Log.v("bush", "hello world");

mGLSurfaceView.setEGLContextClientVersion(3);
mGLSurfaceView.setRenderer(new CameraSurfaceRender(mGLSurfaceView));
mGLSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
Expand Down
1 change: 1 addition & 0 deletions glsurfacepreview4/.gitignore
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions glsurfacepreview4/build.gradle
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion "26.0.3"


defaultConfig {
applicationId "com.example.inuker.glsurfacepreview4"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support.constraint:constraint-layout:1.1.3'
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(path: ':library')

}
21 changes: 21 additions & 0 deletions glsurfacepreview4/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
@@ -0,0 +1,26 @@
package com.example.inuker.glsurfacepreview4;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.example.inuker.glsurfacepreview4", appContext.getPackageName());
}
}
24 changes: 24 additions & 0 deletions glsurfacepreview4/src/main/AndroidManifest.xml
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.example.inuker.glsurfacepreview4"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>

0 comments on commit 0383402

Please sign in to comment.