GLUtils: generate / draw buffers, set color (#666)
This commit is contained in:
parent
915cdae09c
commit
46349724a8
@ -32,6 +32,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.oscim.backend.GLAdapter.gl;
|
||||
import static org.oscim.backend.GLAdapter.gl30;
|
||||
|
||||
/**
|
||||
* Utility functions
|
||||
@ -39,6 +40,17 @@ import static org.oscim.backend.GLAdapter.gl;
|
||||
public class GLUtils {
|
||||
static final Logger log = LoggerFactory.getLogger(GLUtils.class);
|
||||
|
||||
/**
|
||||
* Set int color argb to uniform wxyz.
|
||||
*/
|
||||
public static void setColor(int location, int color) {
|
||||
gl.uniform4f(location,
|
||||
((color >>> 16) & 0xff) / 255f,
|
||||
((color >>> 8) & 0xff) / 255f,
|
||||
((color >>> 0) & 0xff) / 255f,
|
||||
((color >>> 24) & 0xff) / 255f);
|
||||
}
|
||||
|
||||
public static void setColor(int location, int color, float alpha) {
|
||||
if (alpha >= 1)
|
||||
alpha = ((color >>> 24) & 0xff) / 255f;
|
||||
@ -316,6 +328,44 @@ public class GLUtils {
|
||||
gl.deleteBuffers(num, buf);
|
||||
}
|
||||
|
||||
public static int[] glGenFrameBuffers(int num) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
gl.genFramebuffers(num, buf);
|
||||
int[] ret = new int[num];
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
buf.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void glDeleteFrameBuffers(int num, int[] ids) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
buf.flip();
|
||||
gl.deleteFramebuffers(num, buf);
|
||||
}
|
||||
|
||||
public static int[] glGenRenderBuffers(int num) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
gl.genRenderbuffers(num, buf);
|
||||
int[] ret = new int[num];
|
||||
buf.position(0);
|
||||
buf.limit(num);
|
||||
buf.get(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void glDeleteRenderBuffers(int num, int[] ids) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||
buf.put(ids, 0, num);
|
||||
buf.flip();
|
||||
gl.deleteRenderbuffers(num, buf);
|
||||
}
|
||||
|
||||
public static int[] glGenTextures(int num) {
|
||||
if (num <= 0)
|
||||
return null;
|
||||
@ -350,4 +400,19 @@ public class GLUtils {
|
||||
buf.flip();
|
||||
gl.deleteTextures(num, buf);
|
||||
}
|
||||
|
||||
/*========== GL30 ==========*/
|
||||
|
||||
/**
|
||||
* Specifies a list of color buffers to be drawn into.
|
||||
*
|
||||
* @param num Specifies the number of buffers in bufs.
|
||||
* @param glEnum Points to an array of symbolic constants specifying the buffers into which fragment colors or data values will be written.
|
||||
*/
|
||||
public static void glDrawBuffers(int num, int[] glEnum) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(num);
|
||||
buf.put(glEnum, 0, num);
|
||||
buf.flip();
|
||||
gl30.drawBuffers(num, buf);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,26 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
* Copyright 2019 Gustl22
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.renderer;
|
||||
|
||||
import org.oscim.backend.GL;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
import static org.oscim.backend.GLAdapter.gl;
|
||||
|
||||
public class OffscreenRenderer extends LayerRenderer {
|
||||
@ -54,17 +69,11 @@ public class OffscreenRenderer extends LayerRenderer {
|
||||
}
|
||||
|
||||
protected boolean setupFBO(GLViewport viewport) {
|
||||
IntBuffer buf = MapRenderer.getIntBuffer(1);
|
||||
|
||||
texW = (int) viewport.getWidth();
|
||||
texH = (int) viewport.getHeight();
|
||||
|
||||
gl.genFramebuffers(1, buf);
|
||||
fb = buf.get(0);
|
||||
|
||||
buf.clear();
|
||||
gl.genTextures(1, buf);
|
||||
renderTex = buf.get(0);
|
||||
fb = GLUtils.glGenFrameBuffers(1)[0];
|
||||
renderTex = GLUtils.glGenTextures(1)[0];
|
||||
|
||||
GLUtils.checkGlError(getClass().getName() + ": 0");
|
||||
|
||||
@ -92,9 +101,7 @@ public class OffscreenRenderer extends LayerRenderer {
|
||||
GLUtils.checkGlError(getClass().getName() + ": 1");
|
||||
|
||||
if (useDepthTexture) {
|
||||
buf.clear();
|
||||
gl.genTextures(1, buf);
|
||||
renderDepth = buf.get(0);
|
||||
renderDepth = GLUtils.glGenTextures(1)[0];
|
||||
gl.bindTexture(GL.TEXTURE_2D, renderDepth);
|
||||
GLUtils.setTextureParameter(GL.NEAREST,
|
||||
GL.NEAREST,
|
||||
@ -112,9 +119,7 @@ public class OffscreenRenderer extends LayerRenderer {
|
||||
GL.TEXTURE_2D,
|
||||
renderDepth, 0);
|
||||
} else {
|
||||
buf.clear();
|
||||
gl.genRenderbuffers(1, buf);
|
||||
int depthRenderbuffer = buf.get(0);
|
||||
int depthRenderbuffer = GLUtils.glGenRenderBuffers(1)[0];
|
||||
|
||||
gl.bindRenderbuffer(GL.RENDERBUFFER, depthRenderbuffer);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user