android.opengl.GLES30 Java Examples

The following examples show how to use android.opengl.GLES30. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GLSurface.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * Bitmapから画像をテクスチャに読み込む
 * @param bitmap
 */
@Override
public void loadBitmap(@NonNull final Bitmap bitmap) {
	final int width = bitmap.getWidth();
	final int height = bitmap.getHeight();
	if ((width > mTexWidth) || (height > mTexHeight)) {
		mWidth = width;
		mHeight = height;
		releaseFrameBuffer();
		createFrameBuffer(width, height);
	}
	GLES30.glActiveTexture(TEX_UNIT);
	GLES30.glBindTexture(TEX_TARGET, mFBOTexId);
	GLUtils.texImage2D(TEX_TARGET, 0, bitmap, 0);
	GLES30.glBindTexture(TEX_TARGET, 0);
	// initialize texture matrix
	Matrix.setIdentityM(mTexMatrix, 0);
	mTexMatrix[0] = width / (float)mTexWidth;
	mTexMatrix[5] = height / (float)mTexHeight;
}
 
Example #2
Source File: GlUtil.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #3
Source File: GlUtil.java    From grafika with Apache License 2.0 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #4
Source File: GLSurface.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * オフスクリーンフレームバッファを破棄
 */
@Override
protected void releaseFrameBuffer() {
	final int[] names = new int[1];
	// デプスバッファがある時はデプスバッファを破棄
	if (mDepthBufferObj >= 0) {
		names[0] = mDepthBufferObj;
		GLES30.glDeleteRenderbuffers(1, names, 0);
		mDepthBufferObj = -1;
	}
	// オフスクリーンのカラーバッファ用のテクスチャを破棄
	if (mFBOTexId >= 0) {
		names[0] = mFBOTexId;
		GLES30.glDeleteTextures(1, names, 0);
		mFBOTexId = -1;
	}
	// オフスクリーンのフレームバッファーオブジェクトを破棄
	if (mFrameBufferObj >= 0) {
		names[0] = mFrameBufferObj;
		GLES30.glDeleteFramebuffers(1, names, 0);
		mFrameBufferObj = -1;
	}
}
 
Example #5
Source File: GlUtil.java    From ShapesInOpenGLES2.0 with MIT License 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #6
Source File: GLSurface.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 既存のテクスチャ(GL_TEXTURE_2D)をwrapするためのインスタンス生成のヘルパーメソッド
 * @param isGLES3
 * @param tex_unit
 * @param tex_id
 * @param width
 * @param height
 * @param use_depth_buffer
 */
@SuppressLint("NewApi")
public static GLSurface newInstance(final boolean isGLES3,
	final int tex_unit, final int tex_id,
	final int width, final int height, final boolean use_depth_buffer) {

	if (isGLES3 && BuildCheck.isAndroid4_3()) {
		return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, tex_id,
			width, height,
			use_depth_buffer, DEFAULT_ADJUST_POWER2);
	} else {
		return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, tex_id,
			width, height,
			use_depth_buffer, DEFAULT_ADJUST_POWER2);
	}
}
 
Example #7
Source File: GLSurface.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 既存のテクスチャ(GL_TEXTURE_2D)をwrapするためのインスタンス生成のヘルパーメソッド, デプスバッファなし
 * @param isGLES3
 * @param tex_id
 * @param tex_unit
 * @param width
 * @param height
 */
@SuppressLint("NewApi")
public static GLSurface newInstance(final boolean isGLES3,
	final int tex_unit, final int tex_id,
	final int width, final int height) {

	if (isGLES3 && BuildCheck.isAndroid4_3()) {
		return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, tex_id,
			width, height,
			false, DEFAULT_ADJUST_POWER2);
	} else {
		return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, tex_id,
			width, height,
			false, DEFAULT_ADJUST_POWER2);
	}
}
 
Example #8
Source File: OverlayRendererHolder.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * internalOnStartの下請け、GLES3用
 */
@WorkerThread
private void internalOnStartES3() {
	if (DEBUG) Log.v(TAG, String.format("internalOnStartES3:init overlay texture(%dx%d)",
		width(), height()));
	if (DEBUG) Log.v(TAG, "internalOnStartES3:shader=" + MY_FRAGMENT_SHADER_EXT_ES3);

	mDrawer.updateShader(MY_FRAGMENT_SHADER_EXT_ES3);
	final int uTex1 = mDrawer.glGetUniformLocation("sTexture");
	GLES30.glUniform1i(uTex1, 0);
	if (DEBUG) Log.v(TAG, "internalOnStart:uTex1=" + uTex1);

	final int uTex2 = mDrawer.glGetUniformLocation("sTexture2");
	mOverlayTexId = GLHelper.initTex(
		GL_TEXTURE_EXTERNAL_OES,
		GLES30.GL_TEXTURE1,
		GLES30.GL_LINEAR, GLES30.GL_LINEAR,
		GLES30.GL_CLAMP_TO_EDGE);
	mOverlayTexture = new SurfaceTexture(mOverlayTexId);
	mOverlayTexture.setDefaultBufferSize(width(), height());
	mOverlaySurface = new Surface(mOverlayTexture);
	GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
	GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId);
	GLES30.glUniform1i(uTex2, 1);
	if (DEBUG) Log.v(TAG, "internalOnStart:uTex2=" + uTex2);
}
 
Example #9
Source File: GLUtil.java    From VideoRecorder with Apache License 2.0 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #10
Source File: GLSurface.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * インスタンス生成のヘルパーメソッド(GL_TEXTURE_2D), デプスバッファ無し
 * テクスチャユニットはGL_TEXTURE0
 * @param isGLES3
 * @param tex_unit
 * @param width
 * @param height
 */
@SuppressLint("NewApi")
public static GLSurface newInstance(final boolean isGLES3,
	final int tex_unit,
	final int width, final int height) {

	if (isGLES3 && BuildCheck.isAndroid4_3()) {
		return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, -1,
			width, height,
			false, DEFAULT_ADJUST_POWER2);
	} else {
		return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, -1,
			width, height,
			false, DEFAULT_ADJUST_POWER2);
	}
}
 
Example #11
Source File: Utils.java    From alynx-live-wallpaper with Apache License 2.0 6 votes vote down vote up
static int linkProgramGLES30(
    final int vertShader,
    final int fragShader
) throws RuntimeException {
    int program = GLES30.glCreateProgram();
    if (program == 0) {
        throw new RuntimeException("Failed to create program");
    }
    GLES30.glAttachShader(program, vertShader);
    GLES30.glAttachShader(program, fragShader);
    GLES30.glLinkProgram(program);
    final int[] status = new int[1];
    GLES30.glGetProgramiv(program, GLES30.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        final String log = GLES30.glGetProgramInfoLog(program);
        GLES30.glDeleteProgram(program);
        throw new RuntimeException(log);
    }
    return program;
}
 
Example #12
Source File: GlUtil.java    From VIA-AI with MIT License 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #13
Source File: GlUtil.java    From AndroidPlayground with MIT License 6 votes vote down vote up
/**
 * Writes GL version info to the log.
 */
public static void logVersionInfo() {
    Log.i(TAG, "vendor  : " + GLES20.glGetString(GLES20.GL_VENDOR));
    Log.i(TAG, "renderer: " + GLES20.glGetString(GLES20.GL_RENDERER));
    Log.i(TAG, "version : " + GLES20.glGetString(GLES20.GL_VERSION));

    if (false) {
        int[] values = new int[1];
        GLES30.glGetIntegerv(GLES30.GL_MAJOR_VERSION, values, 0);
        int majorVersion = values[0];
        GLES30.glGetIntegerv(GLES30.GL_MINOR_VERSION, values, 0);
        int minorVersion = values[0];
        if (GLES30.glGetError() == GLES30.GL_NO_ERROR) {
            Log.i(TAG, "iversion: " + majorVersion + "." + minorVersion);
        }
    }
}
 
Example #14
Source File: SurfaceDrawable.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 映像入力用SurfaceTexture/Surfaceを再生成する
 */
@SuppressLint("NewApi")
@WorkerThread
protected void handleReCreateInputSurface() {
	if (DEBUG) Log.v(TAG, "handleReCreateInputSurface:");
	synchronized (mSync) {
		mEglTask.makeCurrent();
		handleReleaseInputSurface();
		mEglTask.makeCurrent();
		if (isOES3()) {
			mTexId = com.serenegiant.glutils.es3.GLHelper.initTex(
				GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE0, GLES30.GL_NEAREST);
		} else {
			mTexId = com.serenegiant.glutils.es2.GLHelper.initTex(
				GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE0, GLES20.GL_NEAREST);
		}
		mInputTexture = new SurfaceTexture(mTexId);
		mInputSurface = new Surface(mInputTexture);
		if (BuildCheck.isAndroid4_1()) {
			// XXX getIntrinsicWidth/getIntrinsicHeightの代わりにmImageWidth/mImageHeightを使うべきかも?
			mInputTexture.setDefaultBufferSize(getIntrinsicWidth(), getIntrinsicHeight());
		}
		mInputTexture.setOnFrameAvailableListener(mOnFrameAvailableListener);
	}
	onCreateSurface(mInputSurface);
}
 
Example #15
Source File: OverlayRendererHolder.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@WorkerThread
private void handleUpdateOverlay(final int targetId, @NonNull final Bitmap overlay) {
	if (DEBUG) Log.v(TAG, "handleUpdateOverlay:" + overlay);

	if (isGLES3()) {
		GLES30.glActiveTexture(GLES30.GL_TEXTURE1);
		GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId);
	} else {
		GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
		GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId);
	}
	try {
		final Canvas canvas = mOverlaySurface.lockCanvas(null);
		try {
			if (overlay != null) {
				canvas.drawBitmap(overlay, 0, 0, null);
			} else if (DEBUG) {
				// DEBUGフラグtrueでオーバーレイ映像が設定されていないときは全面を薄赤色にする
				canvas.drawColor(0x7fff0000);	// ARGB
			} else {
				// DEBUGフラグfalseでオーバーレイ映像が設定されていなければ全面透過
				canvas.drawColor(0x00000000);	// ARGB
			}
		} finally {
			mOverlaySurface.unlockCanvasAndPost(canvas);
		}
	} catch (final Exception e) {
		Log.w(TAG, e);
	}
	requestFrame();
}
 
Example #16
Source File: GLUtils.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 対応しているGL|ESのバージョンを取得
 * XXX GLES30はAPI>=18以降なんだけどAPI=18でもGLコンテキスト生成に失敗する端末があるのでAP1>=21に変更
 * API>=21でGL_OES_EGL_image_external_essl3に対応していれば3, そうでなければ2を返す
 * @return
 */
public static int getSupportedGLVersion() {
	if (sSupportedGLVersion < 1) {
		// 一度も実行されていない時
		final AtomicInteger result = new AtomicInteger(1);
		final Semaphore sync = new Semaphore(0);
		final GLContext context = new GLContext(3, null, 0);
		// ダミースレッド上でEGL/GLコンテキストを生成してエクステンション文字列をチェックする
		new Thread(new Runnable() {
			@Override
			public void run() {
				context.initialize();
				String extensions = GLES20.glGetString(GLES20.GL_EXTENSIONS); // API >= 8
				if (DEBUG) Log.i(TAG, "getSupportedGLVersion:" + extensions);
				if ((extensions == null) || !extensions.contains("GL_OES_EGL_image_external")) {
					result.set(1);
				} else if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) && context.isGLES3()) {
					extensions = GLES30.glGetString(GLES30.GL_EXTENSIONS); 	// API >= 18
					result.set((extensions != null) && extensions.contains("GL_OES_EGL_image_external_essl3")
						? 3 : 2);
				} else {
					result.set(2);
				}
				context.release();
				sync.release();
			}
		}).start();
		try {
			sync.tryAcquire(500, TimeUnit.MILLISECONDS);
			sSupportedGLVersion = result.get();
		} catch (final InterruptedException e) {
			// ignore
		}
	}
	if (DEBUG) Log.i(TAG, "getSupportedGLVersion:" + sSupportedGLVersion);
	return sSupportedGLVersion;
}
 
Example #17
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    mWidth = width;
    mHeight = height;
    // Set the viewport
    GLES30.glViewport(0, 0, mWidth, mHeight);
    float aspect = (float) width / height;

    // this projection matrix is applied to object coordinates
    //no idea why 53.13f, it was used in another example and it worked.
    Matrix.perspectiveM(mProjectionMatrix, 0, 53.13f, aspect, Z_NEAR, Z_FAR);
}
 
Example #18
Source File: GLHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
	 * OpenGL|ESのエラーをチェックしてlogCatに出力する
	 * @param op
	 */
    public static void checkGlError(final String op) {
        final int error = GLES30.glGetError();
        if (error != GLES30.GL_NO_ERROR) {
            final String msg = op + ": glError 0x" + Integer.toHexString(error);
			Log.e(TAG, msg);
			Stacktrace.print();
//         	if (DEBUG) {
//	            throw new RuntimeException(msg);
//       	}
        }
    }
 
Example #19
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public static int LoadShader(int type, String shaderSrc) {
    int shader;
    int[] compiled = new int[1];

    // Create the shader object
    shader = GLES30.glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    // Load the shader source
    GLES30.glShaderSource(shader, shaderSrc);

    // Compile the shader
    GLES30.glCompileShader(shader);

    // Check the compile status
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);

    if (compiled[0] == 0) {
        Log.e(TAG, "Erorr!!!!");
        Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
        GLES30.glDeleteShader(shader);
        return 0;
    }

    return shader;
}
 
Example #20
Source File: AndroidGL30.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void texImage3D(int target, int level, int internalformat, int width, int height, int depth, int border, int format,
                       int type, java.nio.Buffer pixels) {
    if (pixels == null)
        GLES30.glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, 0);
    else
        GLES30.glTexImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
}
 
Example #21
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    mWidth = width;
    mHeight = height;
    // Set the viewport
    GLES30.glViewport(0, 0, mWidth, mHeight);
    float aspect = (float) width / height;

    // this projection matrix is applied to object coordinates
    //no idea why 53.13f, it was used in another example and it worked.
    Matrix.perspectiveM(mProjectionMatrix, 0, 53.13f, aspect, Z_NEAR, Z_FAR);
}
 
Example #22
Source File: LessonOneRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) 
{
	GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);			        
               
       // Do a complete rotation every 10 seconds.
       long time = SystemClock.uptimeMillis() % 10000L;
       float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
       
       // Draw the triangle facing straight on.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle1Vertices);
       
       // Draw one translated a bit down and rotated to be flat on the ground.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle2Vertices);
       
       // Draw one translated a bit to the right and rotated to be facing to the left.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
       drawTriangle(mTriangle3Vertices);
}
 
Example #23
Source File: GLHelper.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * テクスチャ名を生成(GL_TEXTURE0のみ)
 * @param texTarget テクスチャのタイプ, GL_TEXTURE_EXTERNAL_OESかGL_TEXTURE_2D
 * @param texUnit テクスチャユニット, GL_TEXTURE0...GL_TEXTURE31
 * @param minFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST
 * @param magFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST
 * @param wrap テクスチャのクランプ方法, GL_CLAMP_TO_EDGE等
 * @return
 */
public static int initTex(final int texTarget, final int texUnit,
	final int minFilter, final int magFilter, final int wrap) {

	if (DEBUG) Log.v(TAG, "initTex:target=" + texTarget);
	final int[] tex = new int[1];
	GLES30.glActiveTexture(texUnit);
	GLES30.glGenTextures(1, tex, 0);
	GLES30.glBindTexture(texTarget, tex[0]);
	GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_WRAP_S, wrap);
	GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_WRAP_T, wrap);
	GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_MIN_FILTER, minFilter);
	GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_MAG_FILTER, magFilter);
	return tex[0];
}
 
Example #24
Source File: Square.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up the drawing object data for use in an OpenGL ES context.
 */
public Square() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
    // (# of coordinate values * 4 bytes per float)
            squareCoords.length * 4);
    bb.order(ByteOrder.nativeOrder());
    vertexBuffer = bb.asFloatBuffer();
    vertexBuffer.put(squareCoords);
    vertexBuffer.position(0);

    // initialize byte buffer for the draw list
    ByteBuffer dlb = ByteBuffer.allocateDirect(
            // (# of coordinate values * 2 bytes per short)
            drawOrder.length * 2);
    dlb.order(ByteOrder.nativeOrder());
    drawListBuffer = dlb.asShortBuffer();
    drawListBuffer.put(drawOrder);
    drawListBuffer.position(0);

    // prepare shaders and OpenGL program
    int vertexShader = MyGLRenderer.loadShader(
            GLES30.GL_VERTEX_SHADER,
            vertexShaderCode);
    int fragmentShader = MyGLRenderer.loadShader(
            GLES30.GL_FRAGMENT_SHADER,
            fragmentShaderCode);

    mProgram = GLES30.glCreateProgram();             // create empty OpenGL Program
    GLES30.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES30.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES30.glLinkProgram(mProgram);                  // create OpenGL program executables
}
 
Example #25
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    //set the clear buffer color to light gray.
    //GLES30.glClearColor(0.9f, .9f, 0.9f, 0.9f);
    //set the clear buffer color to a dark gray
    GLES30.glClearColor(0.1f, .1f, 0.1f, 1.0f);
    //initialize the cube code for drawing.
    mPyramid = new Pyramid();
    //if we had other objects setup them up here as well.
}
 
Example #26
Source File: LessonOneRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) 
{
	GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT | GLES30.GL_COLOR_BUFFER_BIT);			        
               
       // Do a complete rotation every 10 seconds.
       long time = SystemClock.uptimeMillis() % 10000L;
       float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
       
       // Draw the triangle facing straight on.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle1Vertices);
       
       // Draw one translated a bit down and rotated to be flat on the ground.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);        
       drawTriangle(mTriangle2Vertices);
       
       // Draw one translated a bit to the right and rotated to be facing to the left.
       Matrix.setIdentityM(mModelMatrix, 0);
       Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
       Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
       drawTriangle(mTriangle3Vertices);
}
 
Example #27
Source File: GLES20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
GeometryHandle allocateVBO(EGeometryFormatType type) {
	GeometryHandle geometry =  super.allocateVBO(type);
	if (gles3 && type.isSingleBuffer()) {
		int[] vaos = new int[] {0};
		GLES30.glGenVertexArrays(1, vaos, 0);
		geometry.setInternalFormatId(vaos[0]);
		bindFormat(vaos[0]);

		specifyFormat(type);
	}

	return geometry;
}
 
Example #28
Source File: EffectDrawer2D.java    From libcommon with Apache License 2.0 5 votes vote down vote up
private void updateParams() {
	if (DEBUG) Log.v(TAG, "MyRendererTask#updateParams:");
	final int n = Math.min(mCurrentParams != null
		? mCurrentParams.length : 0, MAX_PARAM_NUM);
	if ((muParamsLoc >= 0) && (n > 0)) {
		if (mDrawer != null) {
			mDrawer.glUseProgram();
		} else if (DEBUG) Log.d(TAG, "handleChangeEffect: mDrawer is null");
		if (mDrawer.isGLES3) {
			GLES30.glUniform1fv(muParamsLoc, n, mCurrentParams, 0);
		} else {
			GLES20.glUniform1fv(muParamsLoc, n, mCurrentParams, 0);
		}
	}
}
 
Example #29
Source File: Triangle.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Encapsulates the OpenGL ES instructions for drawing this shape.
 *
 * @param mvpMatrix - The Model View Project matrix in which to draw
 * this shape.
 */
public void draw(float[] mvpMatrix) {
    // Add program to OpenGL environment
    GLES30.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES30.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES30.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES30.glVertexAttribPointer(
            mPositionHandle, COORDS_PER_VERTEX,
            GLES30.GL_FLOAT, false,
            vertexStride, vertexBuffer);

    // get handle to fragment shader's vColor member
    mColorHandle = GLES30.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES30.glUniform4fv(mColorHandle, 1, color, 0);

    // get handle to shape's transformation matrix
    mMVPMatrixHandle = GLES30.glGetUniformLocation(mProgram, "uMVPMatrix");
    MyGLRenderer.checkGlError("glGetUniformLocation");

    // Apply the projection and view transformation
    GLES30.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0);
    MyGLRenderer.checkGlError("glUniformMatrix4fv");

    // Draw the triangle
    GLES30.glDrawArrays(GLES30.GL_TRIANGLES, 0, vertexCount);

    // Disable vertex array
    GLES30.glDisableVertexAttribArray(mPositionHandle);
}
 
Example #30
Source File: GLTexture.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
	 * コンストラクタ
	 * @param texTarget GL_TEXTURE_EXTERNAL_OESはだめ
	 * @param texUnit
	 * @param width テクスチャサイズ
	 * @param height テクスチャサイズ
	 * @param filter_param	テクスチャの補間方法を指定 GL_LINEARとかGL_NEAREST
	 */
	public GLTexture(final int texTarget, final int texUnit,
					 final int width, final int height, final int filter_param) {
//		if (DEBUG) Log.v(TAG, String.format("コンストラクタ(%d,%d)", width, height));
		mTextureTarget = texTarget;
		mTextureUnit = texUnit;
		// テクスチャに使うビットマップは縦横サイズが2の乗数でないとダメ。
		// 更に、ミップマップするなら正方形でないとダメ
		// 指定したwidth/heightと同じか大きい2の乗数にする
		int w = 32;
		for (; w < width; w <<= 1);
		int h = 32;
		for (; h < height; h <<= 1);
		if (mTexWidth != w || mTexHeight != h) {
			mTexWidth = w;
			mTexHeight = h;
		}
		mImageWidth = mTexWidth;
		mImageHeight = mTexHeight;
//		if (DEBUG) Log.v(TAG, String.format("texSize(%d,%d)", mTexWidth, mTexHeight));
		mTextureId = GLHelper.initTex(mTextureTarget, texUnit, filter_param);
		// テクスチャのメモリ領域を確保する
		GLES30.glTexImage2D(mTextureTarget,
			0,					// ミップマップレベル0(ミップマップしない)
			GLES30.GL_RGBA,				// 内部フォーマット
			mTexWidth, mTexHeight,		// サイズ
			0,					// 境界幅
			GLES30.GL_RGBA,				// 引き渡すデータのフォーマット
			GLES30.GL_UNSIGNED_BYTE,	// データの型
			null);				// ピクセルデータ無し
		// テクスチャ変換行列を初期化
		Matrix.setIdentityM(mTexMatrix, 0);
		mTexMatrix[0] = width / (float)mTexWidth;
		mTexMatrix[5] = height / (float)mTexHeight;
		setViewPort(0, 0, mImageWidth, mImageHeight);
//		if (DEBUG) Log.v(TAG, "GLTexture:id=" + mTextureId);
	}