add and use utility to set Int color as uniform
This commit is contained in:
parent
f262efee7f
commit
3e6ac7d5d4
@ -7,20 +7,53 @@
|
|||||||
|
|
||||||
#define JNI(X) JNIEXPORT Java_org_oscim_utils_GlUtils_##X
|
#define JNI(X) JNIEXPORT Java_org_oscim_utils_GlUtils_##X
|
||||||
|
|
||||||
static const char TAG[] = "org.oscim.utils.GLUtils";
|
#define COLOR_R(C) (((C >> 16) & 0xff) / 255.0f)
|
||||||
|
#define COLOR_G(C) (((C >> 8) & 0xff) / 255.0f)
|
||||||
|
#define COLOR_B(C) (((C >> 0) & 0xff) / 255.0f)
|
||||||
|
#define COLOR_A(C) (((C >> 24) & 0xff) / 255.0f)
|
||||||
|
|
||||||
static void
|
void JNI(setColor)(JNIEnv *env, jclass* clazz, jint location, jint c, jfloat alpha)
|
||||||
nativeClassInit(JNIEnv *_env)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (alpha >= 1)
|
||||||
|
alpha = COLOR_A(c);
|
||||||
|
else if (alpha < 0)
|
||||||
|
alpha = 0;
|
||||||
|
else
|
||||||
|
alpha *= COLOR_A(c);
|
||||||
|
|
||||||
|
if (alpha == 1)
|
||||||
|
{
|
||||||
|
glUniform4f((GLint) location,
|
||||||
|
(GLfloat) COLOR_R(c),
|
||||||
|
(GLfloat) COLOR_G(c),
|
||||||
|
(GLfloat) COLOR_B(c),
|
||||||
|
(GLfloat) alpha);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glUniform4f((GLint) location,
|
||||||
|
(GLfloat) (COLOR_R(c) * alpha),
|
||||||
|
(GLfloat) (COLOR_G(c) * alpha),
|
||||||
|
(GLfloat) (COLOR_B(c) * alpha),
|
||||||
|
(GLfloat) alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JNI(init)(JNIEnv *env, jclass* clazz)
|
void JNI(setColorBlend)(JNIEnv *env, jclass* clazz, jint location, jint c1, jint c2, jfloat mix)
|
||||||
{
|
{
|
||||||
nativeClassInit(env);
|
float a1 = COLOR_A(c1) * (1 - mix);
|
||||||
__android_log_print(ANDROID_LOG_INFO, TAG, "all initialized");
|
float a2 = COLOR_A(c2) * mix;
|
||||||
|
|
||||||
|
glUniform4f((GLint) location,
|
||||||
|
(GLfloat) (COLOR_R(c1) * a1 + COLOR_R(c2) * a2),
|
||||||
|
(GLfloat) (COLOR_G(c1) * a1 + COLOR_G(c2) * a2),
|
||||||
|
(GLfloat) (COLOR_B(c1) * a1 + COLOR_B(c2) * a2),
|
||||||
|
(GLfloat) (a1 + a2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#undef JNI
|
#undef JNI
|
||||||
#define JNI(X) JNIEXPORT Java_org_oscim_utils_Matrix4_##X
|
#define JNI(X) JNIEXPORT Java_org_oscim_utils_Matrix4_##X
|
||||||
|
|
||||||
@ -42,7 +75,6 @@ transposeM(float* mTrans, int mTransOffset, float* m, int mOffset);
|
|||||||
static inline void
|
static inline void
|
||||||
matrix4_proj(float* mat, float* vec);
|
matrix4_proj(float* mat, float* vec);
|
||||||
|
|
||||||
|
|
||||||
jlong JNI(alloc)(JNIEnv *env, jclass* clazz)
|
jlong JNI(alloc)(JNIEnv *env, jclass* clazz)
|
||||||
{
|
{
|
||||||
return (long) calloc(16, sizeof(float));
|
return (long) calloc(16, sizeof(float));
|
||||||
|
@ -167,12 +167,8 @@ public class LineTexRenderer {
|
|||||||
LineTexLayer ll = (LineTexLayer) l;
|
LineTexLayer ll = (LineTexLayer) l;
|
||||||
Line line = ll.line;
|
Line line = ll.line;
|
||||||
|
|
||||||
if (line.stippleColor == null)
|
GlUtils.setColor(hTexColor, line.stippleColor, 1);
|
||||||
GLES20.glUniform4f(hTexColor, 1.0f, 1.0f, 1.0f, 1.0f);
|
GlUtils.setColor(hBgColor, line.color, 1);
|
||||||
else
|
|
||||||
GLES20.glUniform4fv(hTexColor, 1, line.stippleColor, 0);
|
|
||||||
|
|
||||||
GLES20.glUniform4fv(hBgColor, 1, line.color, 0);
|
|
||||||
|
|
||||||
float ps = FastMath.clamp((int) (s+0.5f), 1, 3);
|
float ps = FastMath.clamp((int) (s+0.5f), 1, 3);
|
||||||
GLES20.glUniform1f(hPatternScale, (GLRenderer.COORD_SCALE * line.stipple) / ps);
|
GLES20.glUniform1f(hPatternScale, (GLRenderer.COORD_SCALE * line.stipple) / ps);
|
||||||
|
@ -113,13 +113,13 @@ public final class PolygonRenderer {
|
|||||||
GLState.blend(false);
|
GLState.blend(false);
|
||||||
|
|
||||||
if (a.blend == zoom)
|
if (a.blend == zoom)
|
||||||
GlUtils.setBlendColors(hPolygonColor,
|
GlUtils.setColorBlend(hPolygonColor,
|
||||||
a.color, a.blendColor, scale - 1.0f);
|
a.color, a.blendColor, scale - 1.0f);
|
||||||
else
|
else
|
||||||
GlUtils.setColor(hPolygonColor, a.blendColor, 1);
|
GlUtils.setColor(hPolygonColor, a.blendColor, 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (a.color[3] != 1)
|
if (a.color < 0xff000000)
|
||||||
GLState.blend(true);
|
GLState.blend(true);
|
||||||
else
|
else
|
||||||
GLState.blend(false);
|
GLState.blend(false);
|
||||||
|
@ -17,7 +17,6 @@ package org.oscim.theme.renderinstruction;
|
|||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
import org.oscim.theme.RenderThemeHandler;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -85,11 +84,11 @@ public final class Area extends RenderInstruction {
|
|||||||
this.level = 0;
|
this.level = 0;
|
||||||
this.style = "";
|
this.style = "";
|
||||||
this.fade = -1;
|
this.fade = -1;
|
||||||
blendColor = null;
|
blendColor = 0;
|
||||||
blend = -1;
|
blend = -1;
|
||||||
strokeWidth = 0;
|
strokeWidth = 0;
|
||||||
|
|
||||||
color = GlUtils.colorToFloatP(fill);
|
color = fill;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,12 +125,8 @@ public final class Area extends RenderInstruction {
|
|||||||
// paintFill.setShader(shader);
|
// paintFill.setShader(shader);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
color = GlUtils.colorToFloatP(fill);
|
color = fill; //GlUtils.colorToFloatP(fill);
|
||||||
|
blendColor = blendFill; //GlUtils.colorToFloatP(blendFill);
|
||||||
if (blend > 0)
|
|
||||||
blendColor = GlUtils.colorToFloatP(blendFill);
|
|
||||||
else
|
|
||||||
blendColor = null;
|
|
||||||
|
|
||||||
this.blend = blend;
|
this.blend = blend;
|
||||||
this.strokeWidth = strokeWidth;
|
this.strokeWidth = strokeWidth;
|
||||||
@ -144,18 +139,11 @@ public final class Area extends RenderInstruction {
|
|||||||
renderCallback.renderArea(this, this.level);
|
renderCallback.renderArea(this, this.level);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void scaleStrokeWidth(float scaleFactor) {
|
|
||||||
// // if (paintOutline != null) {
|
|
||||||
// // paintOutline.setStrokeWidth(strokeWidth * scaleFactor);
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public String style;
|
public String style;
|
||||||
private final int level;
|
private final int level;
|
||||||
public final float strokeWidth;
|
public final float strokeWidth;
|
||||||
public final float color[];
|
public final int color;
|
||||||
public final int fade;
|
public final int fade;
|
||||||
public final float blendColor[];
|
public final int blendColor;
|
||||||
public final int blend;
|
public final int blend;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import java.util.regex.Pattern;
|
|||||||
import org.oscim.core.Tag;
|
import org.oscim.core.Tag;
|
||||||
import org.oscim.theme.IRenderCallback;
|
import org.oscim.theme.IRenderCallback;
|
||||||
import org.oscim.theme.RenderThemeHandler;
|
import org.oscim.theme.RenderThemeHandler;
|
||||||
import org.oscim.utils.GlUtils;
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
@ -66,8 +65,9 @@ public final class Line extends RenderInstruction {
|
|||||||
int stipple = 0;
|
int stipple = 0;
|
||||||
float stippleWidth = 0;
|
float stippleWidth = 0;
|
||||||
|
|
||||||
float[] color = null;
|
int color = Color.RED;
|
||||||
float[] stippleColor = null;
|
|
||||||
|
int stippleColor = Color.BLACK;
|
||||||
|
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
color = line.color;
|
color = line.color;
|
||||||
@ -90,8 +90,7 @@ public final class Line extends RenderInstruction {
|
|||||||
else if ("src".equals(name)) {
|
else if ("src".equals(name)) {
|
||||||
//src = value;
|
//src = value;
|
||||||
} else if ("stroke".equals(name)) {
|
} else if ("stroke".equals(name)) {
|
||||||
int stroke = Color.parseColor(value);
|
color = Color.parseColor(value);
|
||||||
color = GlUtils.colorToFloatP(stroke);
|
|
||||||
} else if ("width".equals(name)) {
|
} else if ("width".equals(name)) {
|
||||||
width = Float.parseFloat(value);
|
width = Float.parseFloat(value);
|
||||||
} else if ("cap".equals(name)) {
|
} else if ("cap".equals(name)) {
|
||||||
@ -101,8 +100,7 @@ public final class Line extends RenderInstruction {
|
|||||||
} else if ("stipple".equals(name)) {
|
} else if ("stipple".equals(name)) {
|
||||||
stipple = Integer.parseInt(value);
|
stipple = Integer.parseInt(value);
|
||||||
} else if ("stipple-stroke".equals(name)) {
|
} else if ("stipple-stroke".equals(name)) {
|
||||||
int stroke = Color.parseColor(value);
|
stippleColor = Color.parseColor(value);
|
||||||
stippleColor = GlUtils.colorToFloatP(stroke);
|
|
||||||
} else if ("stipple-width".equals(name)) {
|
} else if ("stipple-width".equals(name)) {
|
||||||
stippleWidth = Float.parseFloat(value);
|
stippleWidth = Float.parseFloat(value);
|
||||||
} else if ("fade".equals(name)) {
|
} 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'
|
// inherit properties from 'line'
|
||||||
if (line != null) {
|
if (line != null) {
|
||||||
// use stroke width relative to 'line'
|
// use stroke width relative to 'line'
|
||||||
@ -160,7 +151,7 @@ public final class Line extends RenderInstruction {
|
|||||||
|
|
||||||
public final String style;
|
public final String style;
|
||||||
public final float width;
|
public final float width;
|
||||||
public final float[] color;
|
public final int color;
|
||||||
public final Cap cap;
|
public final Cap cap;
|
||||||
public final boolean outline;
|
public final boolean outline;
|
||||||
public final boolean fixed;
|
public final boolean fixed;
|
||||||
@ -169,14 +160,14 @@ public final class Line extends RenderInstruction {
|
|||||||
public final float min;
|
public final float min;
|
||||||
|
|
||||||
public final int stipple;
|
public final int stipple;
|
||||||
public final float[] stippleColor;
|
public final int stippleColor;
|
||||||
public final float stippleWidth;
|
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,
|
Cap cap, boolean fixed,
|
||||||
int stipple, float[] stippleColor, float stippleWidth,
|
int stipple, int stippleColor, float stippleWidth,
|
||||||
int fade, float blur, boolean isOutline, float min) {
|
int fade, float blur, boolean isOutline, float min) {
|
||||||
|
|
||||||
this.level = level;
|
this.level = level;
|
||||||
@ -222,10 +213,10 @@ public final class Line extends RenderInstruction {
|
|||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.fade = -1;
|
this.fade = -1;
|
||||||
this.stipple = 0;
|
this.stipple = 0;
|
||||||
this.stippleColor = null;
|
this.stippleColor = Color.BLACK;
|
||||||
this.stippleWidth = 0;
|
this.stippleWidth = 0;
|
||||||
this.min = 0;
|
this.min = 0;
|
||||||
this.color = GlUtils.colorToFloatP(stroke);
|
this.color = stroke; //GlUtils.colorToFloatP(stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Line(int stroke, float width, int stipple) {
|
public Line(int stroke, float width, int stipple) {
|
||||||
@ -238,10 +229,10 @@ public final class Line extends RenderInstruction {
|
|||||||
this.fixed = true;
|
this.fixed = true;
|
||||||
this.fade = -1;
|
this.fade = -1;
|
||||||
this.stipple = stipple;
|
this.stipple = stipple;
|
||||||
this.stippleColor = null;
|
this.stippleColor = Color.BLACK;
|
||||||
this.stippleWidth = 0.6f;
|
this.stippleWidth = 0.6f;
|
||||||
this.min = 0;
|
this.min = 0;
|
||||||
color = GlUtils.colorToFloatP(stroke);
|
color = stroke; //GlUtils.colorToFloatP(stroke);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,6 +26,10 @@ import android.util.Log;
|
|||||||
* Utility functions
|
* Utility functions
|
||||||
*/
|
*/
|
||||||
public class GlUtils {
|
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";
|
private static String TAG = "GlUtils";
|
||||||
|
|
||||||
public static void setTextureParameter(int min_filter, int mag_filter, int wrap_s, int wrap_t) {
|
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;
|
return oom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setBlendColors(int handle, float[] c1, float[] c2, float mix) {
|
public static void setBlendColors(int handle, float[] c1, float[] c2, float mix) {
|
||||||
if (mix <= 0f)
|
if (mix <= 0f)
|
||||||
GLES20.glUniform4fv(handle, 1, c1, 0);
|
GLES20.glUniform4fv(handle, 1, c1, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user