summaryrefslogtreecommitdiffstats
path: root/graphics/java/android/renderscript/Program.java
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/java/android/renderscript/Program.java')
-rw-r--r--graphics/java/android/renderscript/Program.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 1628a97..c6ed72a 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -17,6 +17,11 @@
package android.renderscript;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+
+import android.content.res.Resources;
import android.util.Config;
import android.util.Log;
@@ -95,6 +100,44 @@ public class Program extends BaseObj {
return this;
}
+ public BaseProgramBuilder setShader(Resources resources, int resourceID) {
+ byte[] str;
+ int strLength;
+ InputStream is = resources.openRawResource(resourceID);
+ try {
+ try {
+ str = new byte[1024];
+ strLength = 0;
+ while(true) {
+ int bytesLeft = str.length - strLength;
+ if (bytesLeft == 0) {
+ byte[] buf2 = new byte[str.length * 2];
+ System.arraycopy(str, 0, buf2, 0, str.length);
+ str = buf2;
+ bytesLeft = str.length - strLength;
+ }
+ int bytesRead = is.read(str, strLength, bytesLeft);
+ if (bytesRead <= 0) {
+ break;
+ }
+ strLength += bytesRead;
+ }
+ } finally {
+ is.close();
+ }
+ } catch(IOException e) {
+ throw new Resources.NotFoundException();
+ }
+
+ try {
+ mShader = new String(str, 0, strLength, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ Log.e("Renderscript shader creation", "Could not decode shader string");
+ }
+
+ return this;
+ }
+
public void addInput(Element e) throws IllegalStateException {
// Should check for consistant and non-conflicting names...
if(mInputCount >= MAX_INPUT) {