Android Open Source - glestest G L E S Test






From Project

Back to project page glestest.

License

The source code is released under:

GNU General Public License

If you think the Android project glestest listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *    GLESTest.java : Main class.//from  w  ww  .j a  va2s .c  o m
 *    (C)2013 Marisa Kirisame, UnSX Team.
 *
 *    This file is part of GLEStest.
 *
 *    GLEStest is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    GLEStest is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with GLEStest.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sayachan.glestest;

import android.app.Activity;
import android.app.ActionBar;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.os.Handler;
import android.opengl.GLSurfaceView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import java.io.InputStream;
import java.io.IOException;
import java.util.Scanner;

import org.sayachan.glestest.R;

/* clase principal de la aplicacin */
public class GLESTest extends Activity
{
  private GLSurfaceView glesView = null;
  private Handler gstart = new Handler();

  /* opciones de figura, textura y shader de pantalla */
  public static byte fig = 0, tex = 0, sha = 0;
  /* shaders */
  public static String[][] bSha, sSha;

  protected String stringStream( InputStream is )
  {
    Scanner s = new Scanner(is,"UTF-8").useDelimiter("\\A");
    return s.hasNext()?s.next():"";
  }

  protected String[] readShader( String f, String s ) throws IOException
  {
    AssetManager am = getAssets();
    String[] sources = new String[2];
    InputStream frag = am.open(f+"/frag/"+s,
      AssetManager.ACCESS_STREAMING);
    sources[0] = stringStream(frag);
    frag.close();
    InputStream vert = am.open(f+"/common.glslv",
      AssetManager.ACCESS_STREAMING);
    sources[1] = stringStream(vert);
    vert.close();
    return sources;
  }

  protected String[] listShaders( String f ) throws IOException
  {
    AssetManager am = getAssets();
    String[] flist = am.list(f+"/frag");
    return flist;
  }

  protected void readAllShaders()
  {
    try
    {
      int i;
      String[] ct;
      /* base */
      ct = listShaders("base");
      bSha = new String[ct.length][];
      for ( i=0; i<ct.length; i++ )
        bSha[i] = readShader("base",ct[i]);
      /* screen */
      ct = listShaders("screen");
      sSha = new String[ct.length][];
      for ( i=0; i<ct.length; i++ )
        sSha[i] = readShader("screen",ct[i]);
    }
    catch ( IOException ioe )
    {
    }
  }

  protected void startup()
  {
    glesView = new GLESTestView(this);
    setContentView(glesView);
  }

  @Override public boolean onCreateOptionsMenu( Menu menu )
  {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main,menu);
    return super.onCreateOptionsMenu(menu);
  }

  @Override public boolean onOptionsItemSelected( MenuItem item )
  {
    switch ( item.getItemId() )
    {
    case R.id.sel_obj:
      GLESTest.fig += 1;
      if ( GLESTest.fig >= 5 )
        GLESTest.fig = 0;
      return true;
    case R.id.sel_tex:
      GLESTest.tex += 1;
      if ( GLESTest.tex >= 6 )
        GLESTest.tex = 0;
      return true;
    case R.id.sel_sha:
      GLESTest.sha += 1;
      if ( GLESTest.sha >= 7 )
        GLESTest.sha = 0;
      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }

  @Override public void onCreate( Bundle svIState )
  {
    super.onCreate(svIState);
    setContentView(R.layout.main);
    final GLESTest me = this;
    new Thread(new Runnable()
      {public void run(){readAllShaders();gstart.post(
      new Runnable(){public void run(){me.startup();}});}})
      .start();
  }
  @Override protected void onPause()
  {
    super.onPause();
    if ( glesView != null )
      glesView.onPause();
  }
  @Override protected void onResume()
  {
    super.onResume();
    if ( glesView != null )
      glesView.onResume();
  }
}




Java Source Code List

org.sayachan.glestest.GLESTestGeometry.java
org.sayachan.glestest.GLESTestRender.java
org.sayachan.glestest.GLESTestShaders.java
org.sayachan.glestest.GLESTest.java