Skip to content

Commit

Permalink
gl20 opt
Browse files Browse the repository at this point in the history
  • Loading branch information
godrin committed Oct 4, 2012
1 parent 1ad4317 commit 431d8fd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 68 deletions.
2 changes: 1 addition & 1 deletion defend/src/com/cdm/view/CoordSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void apply() {
Gdx.gl10.glTranslatef(x, y, 0);
Gdx.gl10.glLineWidth(scale * 0.04f);
} else {
Gdx.gl20.glLineWidth(scale * 0.04f);
//Gdx.gl20.glLineWidth(scale * 0.04f);
Renderer.scaleMatrix(scale,scale,scale);
Renderer.translateMatrix(x,y,0);
}
Expand Down
125 changes: 58 additions & 67 deletions defend/src/com/cdm/view/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@ public void drawLines(Position pos, List<Vector3> lines, float angle,
} else {
initGlSettings();

Gdx.gl20.glLineWidth(pos.getSystem().getScale() * 0.04f);
Matrix4 p = new Matrix4();
Matrix4 s = new Matrix4();
Matrix4 x = new Matrix4(projMatrix);
s.setToScaling(size, size, size);
p.setToRotation(Vector3.Z, angle);
p.trn(pos.x, pos.y, 0);
x.mul(p);
x.mul(s);
setGL20LineWidth(pos);
Matrix4 x = computeMVProjMatrix(pos, angle, size);
renderer20.begin(x, GL10.GL_LINES);
for (int i = 0; i < lines.size(); i++) {
Vector3 v = lines.get(i);
Expand Down Expand Up @@ -131,40 +124,33 @@ public void drawPoly(Position pos, List<Vector3> lines, float angle,

Gdx.gl10.glPopMatrix();
} else {
Gdx.gl20.glLineWidth(pos.getSystem().getScale() * 0.04f);
Matrix4 p = new Matrix4();
Matrix4 s = new Matrix4();
Matrix4 x = new Matrix4(projMatrix);
s.setToScaling(size, size, size);
p.setToRotation(Vector3.Z, angle);
p.trn(pos.x, pos.y, 0);
x.mul(p);
x.mul(s);
setGL20LineWidth(pos);
Matrix4 mvProj = computeMVProjMatrix(pos, angle, size);
if (true) {
renderer20.begin(x, GL20.GL_TRIANGLES);
float r = color.r;
float g = color.g;
float b = color.b;
float a = color.a;
if (r > 1)
r = 1;
if (r < 0)
r = 0;
if (g > 1)
g = 1;
if (g < 0)
g = 0;
if (b > 1)
b = 1;
if (b < 0)
b = 0;
if (a > 1)
a = 1;
if (a < 0)
a = 0;

renderer20.begin(mvProj, GL20.GL_TRIANGLES);
for (int i = 0; i < lines.size(); i++) {
Vector3 v = lines.get(i);
// FIXME: ensure from outside !
float r = color.r;
float g = color.g;
float b = color.b;
float a = color.a;
if (r > 1)
r = 1;
if (r < 0)
r = 0;
if (g > 1)
g = 1;
if (g < 0)
g = 0;
if (b > 1)
b = 1;
if (b < 0)
b = 0;
if (a > 1)
a = 1;
if (a < 0)
a = 0;
renderer20.color(r, g, b, a);
renderer20.vertex(v.x, v.y, v.z);
}
Expand All @@ -175,6 +161,22 @@ public void drawPoly(Position pos, List<Vector3> lines, float angle,

}

private static Matrix4 p = new Matrix4();
private static Matrix4 s = new Matrix4();
private static Matrix4 x = new Matrix4();

private Matrix4 computeMVProjMatrix(Position pos, float angle, float size) {
p.idt();
s.idt();
x.set(projMatrix);
s.setToScaling(size, size, size);
p.setToRotation(Vector3.Z, angle);
p.trn(pos.x, pos.y, 0);
x.mul(p);
x.mul(s);
return x;
}

@Override
public void drawRect(float x0, float y0, float x1, float y1, Color c) {
if (renderer != null) {
Expand Down Expand Up @@ -307,49 +309,38 @@ public void render(PolySprite sprite, Position pos, float size,
Gdx.gl10.glPopMatrix();
} else {
initGlSettings();
// FIXME: new
Matrix4 p = new Matrix4();
Matrix4 s = new Matrix4();
Matrix4 x = new Matrix4(projMatrix);

s.setToScaling(size, size, size);
p.setToRotation(Vector3.Z, angle);
p.trn(pos.x, pos.y, 0);
x.mul(p);
x.mul(s);

// Gdx.gl20.glBlendColor(color.r, color.g, color.b, color.a);
// Gdx.gl20.glScalef(size, size, size);
Gdx.gl20.glLineWidth(pos.getSystem().getScale() * 0.04f);
// x=new Matrix4();
Matrix4 x = computeMVProjMatrix(pos, angle, size);

setGL20LineWidth(pos);

sprite.render(x, renderMode);
}
}

public void render(WorldCallback callback, Position pos, float size,
float angle) {
if(Gdx.gl20==null)
if (Gdx.gl20 == null)
return;
initGlSettings();
// FIXME: new
Matrix4 p = new Matrix4();
Matrix4 s = new Matrix4();
Matrix4 x = new Matrix4(projMatrix);

s.setToScaling(size, size, size);
p.setToRotation(Vector3.Z, angle);
p.trn(pos.x, pos.y, 0);
x.mul(p);
x.mul(s);
Matrix4 x = computeMVProjMatrix(pos, angle, size);

// Gdx.gl20.glBlendColor(color.r, color.g, color.b, color.a);
// Gdx.gl20.glScalef(size, size, size);
Gdx.gl20.glLineWidth(pos.getSystem().getScale() * 0.04f);
setGL20LineWidth(pos);
// x=new Matrix4();
callback.callback(x);
}

private static float lineWidth = -1;

private void setGL20LineWidth(Position pos) {
float lw = pos.getSystem().getScale() * 0.04f;
if (lw != lineWidth) {
Gdx.gl20.glLineWidth(lw);
lineWidth = lw;
}
}

public static void pushMatrix() {
// FIXME: new
matrixStack.add(new Matrix4(projMatrix));
Expand Down

0 comments on commit 431d8fd

Please sign in to comment.