Revision 7845dc66
Added by Leszek Koltunski over 9 years ago
| src/main/java/org/distorted/library/Distorted.java | ||
|---|---|---|
| 5 | 5 |
import java.io.InputStream; |
| 6 | 6 |
import java.io.InputStreamReader; |
| 7 | 7 |
|
| 8 |
import android.opengl.GLSurfaceView;
|
|
| 8 |
import android.content.Context;
|
|
| 9 | 9 |
import android.opengl.GLES20; |
| 10 | 10 |
import android.os.Build; |
| 11 | 11 |
import android.util.Log; |
| 12 | 12 |
|
| 13 |
import org.distorted.library.R; |
|
| 14 | 13 |
import org.distorted.library.exception.*; |
| 15 | 14 |
|
| 16 | 15 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 237 | 236 |
|
| 238 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 239 | 238 |
|
| 240 |
private static String readTextFileFromRawResource(final GLSurfaceView v, final int resourceId)
|
|
| 239 |
private static String readTextFileFromRawResource(final Context c, final int resourceId)
|
|
| 241 | 240 |
{
|
| 242 |
final InputStream inputStream = v.getContext().getResources().openRawResource(resourceId);
|
|
| 241 |
final InputStream inputStream = c.getResources().openRawResource(resourceId);
|
|
| 243 | 242 |
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); |
| 244 | 243 |
final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
| 245 | 244 |
|
| ... | ... | |
| 264 | 263 |
|
| 265 | 264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 266 | 265 |
|
| 267 |
private static String getVertexShader(final GLSurfaceView v)
|
|
| 266 |
private static String getVertexShader(final Context c)
|
|
| 268 | 267 |
{
|
| 269 |
return readTextFileFromRawResource( v, R.raw.main_vertex_shader);
|
|
| 268 |
return readTextFileFromRawResource( c, R.raw.main_vertex_shader);
|
|
| 270 | 269 |
} |
| 271 | 270 |
|
| 272 | 271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 273 | 272 |
|
| 274 |
private static String getFragmentShader(final GLSurfaceView v)
|
|
| 273 |
private static String getFragmentShader(final Context c)
|
|
| 275 | 274 |
{
|
| 276 |
return readTextFileFromRawResource( v, R.raw.main_fragment_shader);
|
|
| 275 |
return readTextFileFromRawResource( c, R.raw.main_fragment_shader);
|
|
| 277 | 276 |
} |
| 278 | 277 |
|
| 279 | 278 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 302 | 301 |
* Compiles the vertex and fragment shaders, establishes the addresses of all uniforms, and initialises all Bitmaps that have already |
| 303 | 302 |
* been created. |
| 304 | 303 |
* |
| 305 |
* @param v The Surface that just got created.
|
|
| 304 |
* @param context Context of the APpp using the library - used to open up Resources and read Shader code.
|
|
| 306 | 305 |
* @throws FragmentCompilationException |
| 307 | 306 |
* @throws VertexCompilationException |
| 308 | 307 |
* @throws VertexUniformsException |
| 309 | 308 |
* @throws FragmentUniformsException |
| 310 | 309 |
* @throws LinkingException |
| 311 | 310 |
*/ |
| 312 |
public static void onSurfaceCreated(GLSurfaceView v) throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
|
| 311 |
public static void onSurfaceCreated(final Context context) throws FragmentCompilationException,VertexCompilationException,VertexUniformsException,FragmentUniformsException,LinkingException
|
|
| 313 | 312 |
{
|
| 314 | 313 |
mInitialized = true; |
| 315 | 314 |
|
| 316 | 315 |
// String ver; |
| 317 | 316 |
|
| 318 |
final String vertexShader = Distorted.getVertexShader(v);
|
|
| 319 |
final String fragmentShader = Distorted.getFragmentShader(v);
|
|
| 317 |
final String vertexShader = Distorted.getVertexShader(context);
|
|
| 318 |
final String fragmentShader = Distorted.getFragmentShader(context);
|
|
| 320 | 319 |
/* |
| 321 | 320 |
ver = GLES20.glGetString(GLES20.GL_SHADING_LANGUAGE_VERSION); |
| 322 | 321 |
Log.d(TAG, "GLSL version: "+(ver==null ? "null" : ver) ); |
Also available in: Unified diff
convert Distorted.java from GLSurfaceView to Context.