add and use utility to set Int color as uniform

This commit is contained in:
Hannes Janetzek
2013-03-16 01:35:41 +01:00
parent f262efee7f
commit 3e6ac7d5d4
6 changed files with 67 additions and 55 deletions

View File

@@ -167,12 +167,8 @@ public class LineTexRenderer {
LineTexLayer ll = (LineTexLayer) l;
Line line = ll.line;
if (line.stippleColor == null)
GLES20.glUniform4f(hTexColor, 1.0f, 1.0f, 1.0f, 1.0f);
else
GLES20.glUniform4fv(hTexColor, 1, line.stippleColor, 0);
GLES20.glUniform4fv(hBgColor, 1, line.color, 0);
GlUtils.setColor(hTexColor, line.stippleColor, 1);
GlUtils.setColor(hBgColor, line.color, 1);
float ps = FastMath.clamp((int) (s+0.5f), 1, 3);
GLES20.glUniform1f(hPatternScale, (GLRenderer.COORD_SCALE * line.stipple) / ps);

View File

@@ -113,13 +113,13 @@ public final class PolygonRenderer {
GLState.blend(false);
if (a.blend == zoom)
GlUtils.setBlendColors(hPolygonColor,
GlUtils.setColorBlend(hPolygonColor,
a.color, a.blendColor, scale - 1.0f);
else
GlUtils.setColor(hPolygonColor, a.blendColor, 1);
} else {
if (a.color[3] != 1)
if (a.color < 0xff000000)
GLState.blend(true);
else
GLState.blend(false);

View File

@@ -17,7 +17,6 @@ package org.oscim.theme.renderinstruction;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.oscim.utils.GlUtils;
import org.xml.sax.Attributes;
import android.graphics.Color;
@@ -85,11 +84,11 @@ public final class Area extends RenderInstruction {
this.level = 0;
this.style = "";
this.fade = -1;
blendColor = null;
blendColor = 0;
blend = -1;
strokeWidth = 0;
color = GlUtils.colorToFloatP(fill);
color = fill;
}
/**
@@ -126,12 +125,8 @@ public final class Area extends RenderInstruction {
// paintFill.setShader(shader);
// }
color = GlUtils.colorToFloatP(fill);
if (blend > 0)
blendColor = GlUtils.colorToFloatP(blendFill);
else
blendColor = null;
color = fill; //GlUtils.colorToFloatP(fill);
blendColor = blendFill; //GlUtils.colorToFloatP(blendFill);
this.blend = blend;
this.strokeWidth = strokeWidth;
@@ -144,18 +139,11 @@ public final class Area extends RenderInstruction {
renderCallback.renderArea(this, this.level);
}
// @Override
// public void scaleStrokeWidth(float scaleFactor) {
// // if (paintOutline != null) {
// // paintOutline.setStrokeWidth(strokeWidth * scaleFactor);
// // }
// }
public String style;
private final int level;
public final float strokeWidth;
public final float color[];
public final int color;
public final int fade;
public final float blendColor[];
public final int blendColor;
public final int blend;
}

View File

@@ -20,7 +20,6 @@ import java.util.regex.Pattern;
import org.oscim.core.Tag;
import org.oscim.theme.IRenderCallback;
import org.oscim.theme.RenderThemeHandler;
import org.oscim.utils.GlUtils;
import org.xml.sax.Attributes;
import android.graphics.Color;
@@ -66,8 +65,9 @@ public final class Line extends RenderInstruction {
int stipple = 0;
float stippleWidth = 0;
float[] color = null;
float[] stippleColor = null;
int color = Color.RED;
int stippleColor = Color.BLACK;
if (line != null) {
color = line.color;
@@ -90,8 +90,7 @@ public final class Line extends RenderInstruction {
else if ("src".equals(name)) {
//src = value;
} else if ("stroke".equals(name)) {
int stroke = Color.parseColor(value);
color = GlUtils.colorToFloatP(stroke);
color = Color.parseColor(value);
} else if ("width".equals(name)) {
width = Float.parseFloat(value);
} else if ("cap".equals(name)) {
@@ -101,8 +100,7 @@ public final class Line extends RenderInstruction {
} else if ("stipple".equals(name)) {
stipple = Integer.parseInt(value);
} else if ("stipple-stroke".equals(name)) {
int stroke = Color.parseColor(value);
stippleColor = GlUtils.colorToFloatP(stroke);
stippleColor = Color.parseColor(value);
} else if ("stipple-width".equals(name)) {
stippleWidth = Float.parseFloat(value);
} else if ("fade".equals(name)) {
@@ -117,13 +115,6 @@ public final class Line extends RenderInstruction {
}
}
// hint that sth is missing
if (color == null)
color = GlUtils.colorToFloatP(Color.RED);
if (stipple != 0 && stippleColor == null)
stippleColor = GlUtils.colorToFloatP(Color.GREEN);
// inherit properties from 'line'
if (line != null) {
// use stroke width relative to 'line'
@@ -160,7 +151,7 @@ public final class Line extends RenderInstruction {
public final String style;
public final float width;
public final float[] color;
public final int color;
public final Cap cap;
public final boolean outline;
public final boolean fixed;
@@ -169,14 +160,14 @@ public final class Line extends RenderInstruction {
public final float min;
public final int stipple;
public final float[] stippleColor;
public final int stippleColor;
public final float stippleWidth;
private Line(int level, String style, float[] color, float width,
private Line(int level, String style, int color, float width,
Cap cap, boolean fixed,
int stipple, float[] stippleColor, float stippleWidth,
int stipple, int stippleColor, float stippleWidth,
int fade, float blur, boolean isOutline, float min) {
this.level = level;
@@ -222,10 +213,10 @@ public final class Line extends RenderInstruction {
this.fixed = true;
this.fade = -1;
this.stipple = 0;
this.stippleColor = null;
this.stippleColor = Color.BLACK;
this.stippleWidth = 0;
this.min = 0;
this.color = GlUtils.colorToFloatP(stroke);
this.color = stroke; //GlUtils.colorToFloatP(stroke);
}
public Line(int stroke, float width, int stipple) {
@@ -238,10 +229,10 @@ public final class Line extends RenderInstruction {
this.fixed = true;
this.fade = -1;
this.stipple = stipple;
this.stippleColor = null;
this.stippleColor = Color.BLACK;
this.stippleWidth = 0.6f;
this.min = 0;
color = GlUtils.colorToFloatP(stroke);
color = stroke; //GlUtils.colorToFloatP(stroke);
}
@Override

View File

@@ -26,6 +26,10 @@ import android.util.Log;
* Utility functions
*/
public class GlUtils {
public static native void setColor(int location, int color, float alpha);
public static native void setColorBlend(int location, int color1, int color2, float mix);
private static String TAG = "GlUtils";
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
@@ -202,6 +206,7 @@ public class GlUtils {
return oom;
}
public static void setBlendColors(int handle, float[] c1, float[] c2, float mix) {
if (mix <= 0f)
GLES20.glUniform4fv(handle, 1, c1, 0);