Extend GLState: viewport, texture, framebuffer (#667)

This commit is contained in:
Gustl22 2019-02-19 17:12:46 +01:00 committed by Emux
parent 46349724a8
commit f599a14506
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
5 changed files with 42 additions and 12 deletions

View File

@ -88,7 +88,7 @@ public class GdxSpriteBatchTest extends GdxMapApp {
GLState.enableVertexArrays(GLState.DISABLED, GLState.DISABLED);
gl.viewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
GLState.viewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
gl.frontFace(GL.CW);
mMapRenderer.onDrawFrame();

View File

@ -31,6 +31,7 @@ import org.oscim.layers.tile.buildings.BuildingLayer;
import org.oscim.layers.tile.vector.VectorTileLayer;
import org.oscim.layers.tile.vector.labeling.LabelLayer;
import org.oscim.map.Map;
import org.oscim.renderer.GLState;
import org.oscim.renderer.GLViewport;
import org.oscim.renderer.MapRenderer;
import org.oscim.scalebar.DefaultMapScaleBar;
@ -48,8 +49,6 @@ import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.oscim.backend.GLAdapter.gl;
public class MapApplicationAdapter extends ApplicationAdapter {
Logger log = LoggerFactory.getLogger(MapApplicationAdapter.class);
@ -164,7 +163,7 @@ public class MapApplicationAdapter extends ApplicationAdapter {
@Override
public void render() {
gl.viewport(0, 0, width, height);
GLState.viewport(width, height);
try {
mapRenderer.onDrawFrame();

View File

@ -1,7 +1,7 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2018 Gustl22
* Copyright 2018-2019 Gustl22
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -40,8 +40,12 @@ public class GLState {
private static int glVertexBuffer;
private static int glIndexBuffer;
private static int currentFramebufferId;
private static int currentTexId;
private static int viewportWidth;
private static int viewportHeight;
static void init() {
vertexArray[0] = false;
vertexArray[1] = false;
@ -151,6 +155,15 @@ public class GLState {
}
}
public static void bindFramebuffer(int id) {
gl.bindFramebuffer(GL.FRAMEBUFFER, id);
currentFramebufferId = id;
}
public static int getFramebuffer() {
return currentFramebufferId;
}
public static void bindTex2D(int id) {
if (id < 0) {
gl.bindTexture(GL.TEXTURE_2D, 0);
@ -161,6 +174,10 @@ public class GLState {
}
}
public static int getTexture() {
return currentTexId;
}
public static void setClearColor(float[] color) {
// Workaround for artifacts at canvas resize on desktop
if (!GLAdapter.GDX_DESKTOP_QUIRKS) {
@ -218,4 +235,18 @@ public class GLState {
gl.bindBuffer(GL.ARRAY_BUFFER, id);
}
public static void viewport(int width, int height) {
gl.viewport(0, 0, width, height);
viewportWidth = width;
viewportHeight = height;
}
public static int getViewportWidth() {
return viewportWidth;
}
public static int getViewportHeight() {
return viewportHeight;
}
}

View File

@ -172,7 +172,7 @@ public class MapRenderer {
if (width <= 0 || height <= 0)
return;
gl.viewport(0, 0, width, height);
GLState.viewport(width, height);
//GL.scissor(0, 0, width, height);
//GL.enable(GL20.SCISSOR_TEST);

View File

@ -144,13 +144,13 @@ public class OffscreenRenderer extends LayerRenderer {
public void enable(boolean on) {
if (on)
gl.bindFramebuffer(GL.FRAMEBUFFER, fb);
GLState.bindFramebuffer(fb);
else
gl.bindFramebuffer(GL.FRAMEBUFFER, 0);
GLState.bindFramebuffer(0);
}
public void begin() {
gl.bindFramebuffer(GL.FRAMEBUFFER, fb);
GLState.bindFramebuffer(fb);
gl.depthMask(true);
gl.clear(GL.DEPTH_BUFFER_BIT);
}
@ -192,15 +192,15 @@ public class OffscreenRenderer extends LayerRenderer {
@Override
public void render(GLViewport viewport) {
gl.bindFramebuffer(GL.FRAMEBUFFER, fb);
gl.viewport(0, 0, texW, texH);
GLState.bindFramebuffer(fb);
GLState.viewport(texW, texH);
gl.depthMask(true);
GLState.setClearColor(mClearColor);
gl.clear(GL.DEPTH_BUFFER_BIT | GL.COLOR_BUFFER_BIT);
mRenderer.render(viewport);
gl.bindFramebuffer(GL.FRAMEBUFFER, 0);
GLState.bindFramebuffer(0);
mShader.useProgram();