From 591ae03667c6a61c5fd215e10ccb5e2e4a7ce7c0 Mon Sep 17 00:00:00 2001 From: Emux Date: Tue, 6 Dec 2016 20:46:39 +0200 Subject: [PATCH] GL shader version, closes #265 --- vtm/src/org/oscim/renderer/GLShader.java | 41 ++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/vtm/src/org/oscim/renderer/GLShader.java b/vtm/src/org/oscim/renderer/GLShader.java index a4331e10..d9c06c48 100644 --- a/vtm/src/org/oscim/renderer/GLShader.java +++ b/vtm/src/org/oscim/renderer/GLShader.java @@ -1,3 +1,20 @@ +/* + * Copyright 2013 Hannes Janetzek + * Copyright 2016 devemux86 + * + * 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 . + */ package org.oscim.renderer; import org.oscim.backend.AssetAdapter; @@ -16,12 +33,20 @@ public abstract class GLShader { public int program; protected boolean create(String vertexSource, String fragmentSource) { - program = createProgram(vertexSource, fragmentSource); + return createVersioned(vertexSource, fragmentSource, null); + } + + protected boolean createVersioned(String vertexSource, String fragmentSource, String version) { + program = createProgramVersioned(vertexSource, fragmentSource, version); return program != 0; } protected boolean create(String fileName) { - program = loadShader(fileName); + return createVersioned(fileName, null); + } + + protected boolean createVersioned(String fileName, String version) { + program = loadShaderVersioned(fileName, version); return program != 0; } @@ -44,6 +69,10 @@ public abstract class GLShader { } public static int loadShader(String file) { + return loadShaderVersioned(file, null); + } + + public static int loadShaderVersioned(String file, String version) { String path = "shaders/" + file + ".glsl"; String vs = AssetAdapter.readTextFile(path); @@ -58,7 +87,7 @@ public abstract class GLShader { String fs = vs.substring(fsStart + 2); vs = vs.substring(0, fsStart); - int shader = createProgram(vs, fs); + int shader = createProgramVersioned(vs, fs, version); if (shader == 0) { System.out.println(vs + " \n\n" + fs); } @@ -86,7 +115,13 @@ public abstract class GLShader { } public static int createProgram(String vertexSource, String fragmentSource) { + return createProgramVersioned(vertexSource, fragmentSource, null); + } + + public static int createProgramVersioned(String vertexSource, String fragmentSource, String version) { String defs = ""; + if (version != null) + defs += "#version " + version + "\n"; if (GLAdapter.GDX_DESKTOP_QUIRKS) defs += "#define DESKTOP_QUIRKS 1\n"; else