• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Main repository of MikuMikuStudio


コミットメタ情報

リビジョン2289ac83038140baeef31155d98bcea7324bd033 (tree)
日時2013-07-06 10:37:54
作者Kazuhiko Kobayashi <chototsu_moushinp@yaho...>
コミッターkobayasi

ログメッセージ

Support Adreno320, Intel GPU

変更サマリ

差分

--- a/engine/lib/lwjgl/lwjgl_hidden_switches.text
+++ /dev/null
@@ -1,25 +0,0 @@
1-LWJGL "Hidden" switches:
2-
3-org.lwjgl.opengl.Display.noinput
4-Do not initialize any controls when creating the display
5-
6-org.lwjgl.opengl.Display.nomouse
7-Do not create the mouse when creating the display
8-
9-org.lwjgl.opengl.Display.nokeyboard
10-Do not create the keyboard when creating the display
11-
12-org.lwjgl.util.Debug
13-Whether to output debug info
14-
15-org.lwjgl.util.NoChecks
16-Whether to disable runtime function/buffer checks and state tracking.
17-
18-org.lwjgl.opengl.Display.allowSoftwareOpenGL
19-Whether to allow creation of a software only opengl context
20-
21-org.lwjgl.opengl.Window.undecorated
22-Whether to create an undecorated window (no title bar)
23-
24-org.lwjgl.input.Mouse.allowNegativeMouseCoords
25-Usually mouse is clamped to 0,0 - setting this to true will cause you to get negative values if dragging outside and below or left of window
\ No newline at end of file
--- a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
+++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java
@@ -176,7 +176,7 @@ public final class OGLESShaderRenderer implements Renderer {
176176 // + "renderer!");
177177 versionStr = "";
178178 }
179- logger.info("GLES20.GL_SHADING_LANGUAGE_VERSION = "+versionStr);
179+ logger.info("GLES20.GL_SHADING_LANGUAGE_VERSION = " + versionStr);
180180
181181 // Fix issue in TestRenderToMemory when GL_FRONT is the main
182182 // buffer being used.
@@ -192,7 +192,7 @@ public final class OGLESShaderRenderer implements Renderer {
192192 float version = 1;
193193 try {
194194 version = Float.parseFloat(versionStr);
195- } catch(Exception ex) {
195+ } catch (Exception ex) {
196196 }
197197 glslVer = (int) (version * 100);
198198
@@ -271,7 +271,7 @@ public final class OGLESShaderRenderer implements Renderer {
271271 */
272272 GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, intBuf16);
273273 maxTexSize = intBuf16.get(0);
274- logger.log(Level.INFO, "Maximum Texture Resolution: {0}"+ maxTexSize);
274+ logger.log(Level.INFO, "Maximum Texture Resolution: {0}" + maxTexSize);
275275
276276 GLES20.glGetIntegerv(GLES20.GL_MAX_CUBE_MAP_TEXTURE_SIZE, intBuf16);
277277 maxCubeTexSize = intBuf16.get(0);
@@ -406,15 +406,15 @@ public final class OGLESShaderRenderer implements Renderer {
406406 // checkGLError();
407407
408408 useVBO = false;
409-
409+
410410 // NOTE: SDK_INT is only available since 1.6,
411411 // but for jME3 it doesn't matter since android versions 1.5 and below
412412 // are not supported.
413- if (Build.VERSION.SDK_INT >= 9){
413+ if (Build.VERSION.SDK_INT >= 9) {
414414 useVBO = true;
415415 }
416416 // chekc Adreno200,205,220 bug
417- if (GLES20.glGetString(GLES20.GL_RENDERER).indexOf("Adreno") >=0) {
417+ if (GLES20.glGetString(GLES20.GL_RENDERER).indexOf("Adreno") >= 0) {
418418 adreno_finish_bug = true;
419419 }
420420 logger.log(Level.INFO, "Caps: {0}", caps);
@@ -734,7 +734,7 @@ public final class OGLESShaderRenderer implements Renderer {
734734 public void setClipRect(int x, int y, int width, int height) {
735735 if (!context.clipRectEnabled) {
736736 // if (verboseLogging) {
737- logger.info("GLES20.glEnable(GLES20.GL_SCISSOR_TEST)");
737+ logger.info("GLES20.glEnable(GLES20.GL_SCISSOR_TEST)");
738738 // }
739739 GLES20.glEnable(GLES20.GL_SCISSOR_TEST);
740740 checkGLError();
@@ -1035,10 +1035,10 @@ public final class OGLESShaderRenderer implements Renderer {
10351035 logger.info("GLES20.glShaderSource(" + id + ")");
10361036 }
10371037 if (source.getType().equals(ShaderType.Vertex)
1038- && GLES20.glGetString(GLES20.GL_RENDERER).indexOf("PowerVR")>=0) {
1038+ && GLES20.glGetString(GLES20.GL_RENDERER).indexOf("PowerVR") >= 0) {
10391039 GLES20.glShaderSource(
10401040 id,
1041- source.getDefines()
1041+ source.getDefines()
10421042 + source.getSource());
10431043 } else {
10441044 GLES20.glShaderSource(
@@ -1090,7 +1090,7 @@ public final class OGLESShaderRenderer implements Renderer {
10901090 logger.log(Level.FINE, "compile success: " + source.getName());
10911091 }
10921092 } else {
1093- logger.log(Level.WARNING, "Bad compile of:\n{0}{1}",
1093+ logger.log(Level.WARNING, "Bad compile of:\n{0}{1}",
10941094 new Object[]{source.getDefines(), source.getSource()});
10951095 if (infoLog != null) {
10961096 throw new RendererException("compile error in:" + source + " error:" + infoLog);
@@ -1297,6 +1297,79 @@ public final class OGLESShaderRenderer implements Renderer {
12971297 }
12981298 }
12991299
1300+ public void setShaderWithoutUpdateUniforms(Shader shader) {
1301+ if (verboseLogging) {
1302+ logger.info("setShader(" + shader + ")");
1303+ }
1304+
1305+ if (shader == null) {
1306+ if (context.boundShaderProgram > 0) {
1307+
1308+ if (verboseLogging) {
1309+ logger.info("GLES20.glUseProgram(0)");
1310+ }
1311+
1312+ GLES20.glUseProgram(0);
1313+
1314+ statistics.onShaderUse(null, true);
1315+ context.boundShaderProgram = 0;
1316+ boundShader = null;
1317+ }
1318+ } else {
1319+ if (shader.isUpdateNeeded()) {
1320+ updateShaderData(shader);
1321+ }
1322+
1323+ // NOTE: might want to check if any of the
1324+ // sources need an update?
1325+
1326+ if (!shader.isUsable()) {
1327+ logger.warning("shader is not usable.");
1328+ return;
1329+ }
1330+
1331+ assert shader.getId() > 0;
1332+
1333+ if (context.boundShaderProgram != shader.getId()) {
1334+ if (VALIDATE_SHADER) {
1335+ // check if shader can be used
1336+ // with current state
1337+ if (verboseLogging) {
1338+ logger.info("GLES20.glValidateProgram(" + shader.getId() + ")");
1339+ }
1340+
1341+ GLES20.glValidateProgram(shader.getId());
1342+
1343+ if (verboseLogging) {
1344+ logger.info("GLES20.glGetProgramiv(" + shader.getId() + ", GLES20.GL_VALIDATE_STATUS, buffer)");
1345+ }
1346+
1347+ GLES20.glGetProgramiv(shader.getId(), GLES20.GL_VALIDATE_STATUS, intBuf1);
1348+
1349+ boolean validateOK = intBuf1.get(0) == GLES20.GL_TRUE;
1350+
1351+ if (validateOK) {
1352+ logger.fine("shader validate success");
1353+ } else {
1354+ logger.warning("shader validate failure");
1355+ }
1356+ }
1357+
1358+ if (verboseLogging) {
1359+ logger.info("GLES20.glUseProgram(" + shader.getId() + ")");
1360+ }
1361+
1362+ GLES20.glUseProgram(shader.getId());
1363+
1364+ statistics.onShaderUse(shader, true);
1365+ context.boundShaderProgram = shader.getId();
1366+ boundShader = shader;
1367+ } else {
1368+ statistics.onShaderUse(shader, false);
1369+ }
1370+ }
1371+ }
1372+
13001373 public void deleteShaderSource(ShaderSource source) {
13011374 if (source.getId() < 0) {
13021375 logger.warning("Shader source is not uploaded to GPU, cannot delete.");
@@ -1577,9 +1650,9 @@ public final class OGLESShaderRenderer implements Renderer {
15771650 }
15781651 */
15791652
1580- public void setMainFrameBufferOverride(FrameBuffer fb){
1653+ public void setMainFrameBufferOverride(FrameBuffer fb) {
15811654 }
1582-
1655+
15831656 public void setFrameBuffer(FrameBuffer fb) {
15841657 if (verboseLogging) {
15851658 logger.warning("setFrameBuffer is not supported.");
@@ -1716,6 +1789,8 @@ public final class OGLESShaderRenderer implements Renderer {
17161789
17171790 private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
17181791 logger.warning("deleteRenderBuffer is not supported.");
1792+ intBuf1.put(0, rb.getId());
1793+ GLES20.glDeleteRenderbuffers(1, intBuf1);
17191794 }
17201795 /*
17211796 private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb){
@@ -1726,6 +1801,25 @@ public final class OGLESShaderRenderer implements Renderer {
17261801
17271802 public void deleteFrameBuffer(FrameBuffer fb) {
17281803 logger.warning("deleteFrameBuffer is not supported.");
1804+ if (fb.getId() != -1) {
1805+ if (context.boundFBO == fb.getId()) {
1806+ GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
1807+ context.boundFBO = 0;
1808+ }
1809+
1810+ if (fb.getDepthBuffer() != null) {
1811+ deleteRenderBuffer(fb, fb.getDepthBuffer());
1812+ }
1813+ if (fb.getColorBuffer() != null) {
1814+ deleteRenderBuffer(fb, fb.getColorBuffer());
1815+ }
1816+
1817+ intBuf1.put(0, fb.getId());
1818+ GLES20.glDeleteFramebuffers(1, intBuf1);
1819+ fb.resetObject();
1820+
1821+ statistics.onDeleteFrameBuffer();
1822+ }
17291823 }
17301824 /*
17311825 public void deleteFrameBuffer(FrameBuffer fb) {
@@ -1917,14 +2011,14 @@ public final class OGLESShaderRenderer implements Renderer {
19172011
19182012 // bind texture
19192013 int target = convertTextureType(type);
1920- if (context.boundTextureUnit != 0) {
1921- if (verboseLogging) {
1922- logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0)");
1923- }
1924-
1925- GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
1926- context.boundTextureUnit = 0;
2014+ if (context.boundTextureUnit != 0) {
2015+ if (verboseLogging) {
2016+ logger.info("GLES20.glActiveTexture(GLES20.GL_TEXTURE0)");
19272017 }
2018+
2019+ GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
2020+ context.boundTextureUnit = 0;
2021+ }
19282022 if (context.boundTextures[0] != img) {
19292023
19302024 if (verboseLogging) {
@@ -2454,11 +2548,11 @@ public final class OGLESShaderRenderer implements Renderer {
24542548 }
24552549
24562550 Android22Workaround.glVertexAttribPointer(loc,
2457- vb.getNumComponents(),
2458- convertFormat(vb.getFormat()),
2459- vb.isNormalized(),
2460- vb.getStride(),
2461- vb.getOffset());
2551+ vb.getNumComponents(),
2552+ convertFormat(vb.getFormat()),
2553+ vb.isNormalized(),
2554+ vb.getStride(),
2555+ vb.getOffset());
24622556
24632557 attribs[loc] = vb;
24642558 }
@@ -2646,9 +2740,9 @@ public final class OGLESShaderRenderer implements Renderer {
26462740 }
26472741
26482742 ArrayList<VertexBuffer> buffersList = mesh.getBufferList();
2649- for (int i = 0; i < buffersList.size(); i++){
2743+ for (int i = 0; i < buffersList.size(); i++) {
26502744 VertexBuffer vb = buffersList.get(i);
2651-
2745+
26522746 if (vb.getBufferType() == Type.InterleavedData
26532747 || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
26542748 || vb.getBufferType() == Type.Index) {
@@ -2676,7 +2770,7 @@ public final class OGLESShaderRenderer implements Renderer {
26762770 logger.info("renderMeshVertexArray");
26772771 }
26782772
2679- // IntMap<VertexBuffer> buffers = mesh.getBuffers();
2773+ // IntMap<VertexBuffer> buffers = mesh.getBuffers();
26802774 IntMap<VertexBuffer> buffers = mesh.getBuffers();
26812775 IntMap.Entry<VertexBuffer> table[] = buffers.getTable();
26822776 for (IntMap.Entry<VertexBuffer> entry : table) {
@@ -2713,7 +2807,7 @@ public final class OGLESShaderRenderer implements Renderer {
27132807 drawTriangleList_Array(indices, mesh, count);
27142808 } else {
27152809 if (verboseLogging) {
2716- logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
2810+ logger.log(Level.INFO, "GLES20.glDrawArrays({0}, {1}, {2})",
27172811 new Object[]{mesh.getMode(), 0, mesh.getVertexCount()});
27182812 }
27192813
@@ -2723,7 +2817,7 @@ public final class OGLESShaderRenderer implements Renderer {
27232817
27242818 private void renderMeshDefault(Mesh mesh, int lod, int count) {
27252819 if (verboseLogging) {
2726- logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
2820+ logger.log(Level.INFO, "renderMeshDefault({0}, {1}, {2})",
27272821 new Object[]{mesh, lod, count});
27282822 }
27292823 VertexBuffer indices = null;
@@ -2740,9 +2834,9 @@ public final class OGLESShaderRenderer implements Renderer {
27402834 indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
27412835 }
27422836 ArrayList<VertexBuffer> buffersList = mesh.getBufferList();
2743- for (int i = 0; i < buffersList.size(); i++){
2837+ for (int i = 0; i < buffersList.size(); i++) {
27442838 VertexBuffer vb = buffersList.get(i);
2745-
2839+
27462840 if (vb.getBufferType() == Type.InterleavedData
27472841 || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
27482842 || vb.getBufferType() == Type.Index) {
@@ -2764,7 +2858,7 @@ public final class OGLESShaderRenderer implements Renderer {
27642858 } else {
27652859 // throw new UnsupportedOperationException("Cannot render without index buffer");
27662860 if (verboseLogging) {
2767- logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
2861+ logger.log(Level.INFO, "GLES20.glDrawArrays({0}, 0, {1})",
27682862 new Object[]{convertElementMode(mesh.getMode()), mesh.getVertexCount()});
27692863 }
27702864
@@ -2815,8 +2909,8 @@ public final class OGLESShaderRenderer implements Renderer {
28152909 }
28162910
28172911 private void checkGLError() {
2818-
28192912 }
2913+
28202914 private void checkGLError2() {
28212915 int error;
28222916 while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
@@ -2950,18 +3044,18 @@ public final class OGLESShaderRenderer implements Renderer {
29503044
29513045 if (verboseLogging) {
29523046 logger.log(Level.INFO,
2953- "GLES20.glVertexAttribPointer(" +
2954- "location={0}, " +
2955- "numComponents={1}, " +
2956- "format={2}, " +
2957- "isNormalized={3}, " +
2958- "stride={4}, " +
2959- "data.capacity={5})",
2960- new Object[]{loc, vb.getNumComponents(),
2961- vb.getFormat(),
2962- vb.isNormalized(),
2963- vb.getStride(),
2964- avb.getData().capacity()});
3047+ "GLES20.glVertexAttribPointer("
3048+ + "location={0}, "
3049+ + "numComponents={1}, "
3050+ + "format={2}, "
3051+ + "isNormalized={3}, "
3052+ + "stride={4}, "
3053+ + "data.capacity={5})",
3054+ new Object[]{loc, vb.getNumComponents(),
3055+ vb.getFormat(),
3056+ vb.isNormalized(),
3057+ vb.getStride(),
3058+ avb.getData().capacity()});
29653059 }
29663060
29673061
@@ -3005,6 +3099,7 @@ public final class OGLESShaderRenderer implements Renderer {
30053099 boundShader = null;
30063100 lastFb = null;
30073101 }
3102+
30083103 public void resetBoundsTexture() {
30093104 context.boundTextures[0] = null;
30103105 if (context.boundTextureUnit != 0) {
@@ -3012,8 +3107,8 @@ public final class OGLESShaderRenderer implements Renderer {
30123107 context.boundTextureUnit = 0;
30133108 }
30143109 // GLES20.glDisable(GLES20.GL_TEXTURE_2D);
3015- GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
3016- // context.boundTextureUnit = -2;
3110+ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
3111+ // context.boundTextureUnit = -2;
30173112 // context.boundElementArrayVBO = -2;
30183113 // context.boundShaderProgram = -1;
30193114 // context.boundArrayVBO = -1;
--- /dev/null
+++ b/engine/src/bullet/native/com_jme3_bullet_PhysicsSpace_BroadphaseType.h
@@ -0,0 +1,13 @@
1+/* DO NOT EDIT THIS FILE - it is machine generated */
2+#include <jni.h>
3+/* Header for class com_jme3_bullet_PhysicsSpace_BroadphaseType */
4+
5+#ifndef _Included_com_jme3_bullet_PhysicsSpace_BroadphaseType
6+#define _Included_com_jme3_bullet_PhysicsSpace_BroadphaseType
7+#ifdef __cplusplus
8+extern "C" {
9+#endif
10+#ifdef __cplusplus
11+}
12+#endif
13+#endif
--- a/engine/src/core-data/Common/MatDefs/Water/simple_water.frag
+++ b/engine/src/core-data/Common/MatDefs/Water/simple_water.frag
@@ -102,7 +102,8 @@ void main(void)
102102 vec4 E=normalize(viewCamDir);
103103 vec4 vRef = normalize(reflect(-L,vNorm));
104104 float stemp =max(0.0, dot( vRef,E) );
105- vec4 specular;
105+ //initializing to 0 to avoid artifacts on old intel cards
106+ vec4 specular = vec4(0.0,0.0,0.0,0.0);
106107 if(stemp>0.0){
107108 stemp = pow(stemp, exponent);
108109 specular = vec4(stemp);
--- a/engine/src/core/com/jme3/material/MatParam.java
+++ b/engine/src/core/com/jme3/material/MatParam.java
@@ -44,7 +44,6 @@ import com.jme3.math.Quaternion;
4444 import com.jme3.math.Vector2f;
4545 import com.jme3.math.Vector3f;
4646 import com.jme3.math.Vector4f;
47-import com.jme3.renderer.GL1Renderer;
4847 import com.jme3.renderer.Renderer;
4948 import com.jme3.shader.VarType;
5049 import com.jme3.texture.Texture;
@@ -279,9 +278,6 @@ public class MatParam implements Savable, Cloneable {
279278 }
280279 technique.updateUniformParam(getPrefixedName(), getVarType(), value, true);
281280 }
282- if (ffBinding != null && r instanceof GL1Renderer) {
283- ((GL1Renderer) r).setFixedFuncBinding(ffBinding, getValue());
284- }
285281 }
286282 void apply(Renderer r, Technique technique, int paramIndex) {
287283 TechniqueDef techDef = technique.getDef();
@@ -295,9 +291,6 @@ public class MatParam implements Savable, Cloneable {
295291 }
296292 technique.updateUniformParam(paramIndex, getVarType(), value, true);
297293 }
298- if (ffBinding != null && r instanceof GL1Renderer) {
299- ((GL1Renderer) r).setFixedFuncBinding(ffBinding, getValue());
300- }
301294 }
302295
303296 /**
--- a/engine/src/core/com/jme3/material/Material.java
+++ b/engine/src/core/com/jme3/material/Material.java
@@ -1034,7 +1034,7 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
10341034 Renderer r = rm.getRenderer();
10351035
10361036 TechniqueDef techDef = technique.getDef();
1037-
1037+ r.setShaderWithoutUpdateUniforms(technique.getShader());
10381038 if (techDef.getLightMode() == LightMode.MultiPass
10391039 && geom.getWorldLightList().size() == 0) {
10401040 return;
--- a/engine/src/core/com/jme3/renderer/Renderer.java
+++ b/engine/src/core/com/jme3/renderer/Renderer.java
@@ -175,6 +175,7 @@ public interface Renderer {
175175 * @param shader The shader to use for rendering.
176176 */
177177 public void setShader(Shader shader);
178+ public void setShaderWithoutUpdateUniforms(Shader shader);
178179
179180 /**
180181 * Deletes a shader. This method also deletes
--- a/engine/src/core/com/jme3/system/NullRenderer.java
+++ b/engine/src/core/com/jme3/system/NullRenderer.java
@@ -149,4 +149,7 @@ public class NullRenderer implements Renderer {
149149 public void setAlphaToCoverage(boolean value) {
150150 }
151151
152+ public void setShaderWithoutUpdateUniforms(Shader shader) {
153+ }
154+
152155 }
--- a/engine/src/desktop/com/jme3/system/Natives.java
+++ b/engine/src/desktop/com/jme3/system/Natives.java
@@ -172,7 +172,7 @@ public class Natives {
172172 if (needLWJGL) {
173173 logger.log(Level.INFO, "Extraction Directory #1: {0}", getExtractionDir());
174174 logger.log(Level.INFO, "Extraction Directory #2: {0}", workingDir.toString());
175- logger.log(Level.INFO, "Extraction Directory #3: {0}", System.getProperty("user.dir"));
175+// logger.log(Level.INFO, "Extraction Directory #3: {0}", System.getProperty("user.dir"));
176176 // LWJGL supports this feature where
177177 // it can load libraries from this path.
178178 // This is a fallback method in case the OS doesn't load
--- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglGL1Renderer.java
+++ /dev/null
@@ -1,1178 +0,0 @@
1-package com.jme3.renderer.lwjgl;
2-
3-import com.jme3.light.SpotLight;
4-import java.util.ArrayList;
5-import com.jme3.light.PointLight;
6-import com.jme3.math.Vector3f;
7-import com.jme3.light.DirectionalLight;
8-import com.jme3.light.Light;
9-import org.lwjgl.opengl.GL14;
10-import com.jme3.math.FastMath;
11-import com.jme3.renderer.GL1Renderer;
12-import com.jme3.shader.Shader;
13-import com.jme3.shader.Shader.ShaderSource;
14-import com.jme3.texture.FrameBuffer;
15-import java.nio.ShortBuffer;
16-import java.nio.Buffer;
17-import com.jme3.scene.Mesh.Mode;
18-import com.jme3.scene.VertexBuffer.Usage;
19-import com.jme3.scene.VertexBuffer.Type;
20-import com.jme3.util.IntMap.Entry;
21-import com.jme3.util.IntMap;
22-import com.jme3.scene.Mesh;
23-import com.jme3.scene.VertexBuffer;
24-import com.jme3.texture.Image;
25-import com.jme3.texture.Texture.WrapAxis;
26-import com.jme3.texture.Texture;
27-import com.jme3.light.LightList;
28-import com.jme3.material.FixedFuncBinding;
29-import java.nio.FloatBuffer;
30-import com.jme3.math.Matrix4f;
31-import java.util.logging.Level;
32-import com.jme3.material.RenderState;
33-import com.jme3.math.ColorRGBA;
34-import com.jme3.renderer.Caps;
35-import com.jme3.util.NativeObjectManager;
36-import com.jme3.renderer.RenderContext;
37-import com.jme3.renderer.Statistics;
38-import com.jme3.util.BufferUtils;
39-import java.nio.ByteBuffer;
40-import java.nio.IntBuffer;
41-import java.util.EnumSet;
42-import java.util.logging.Logger;
43-import jme3tools.converters.MipMapGenerator;
44-import org.lwjgl.opengl.GL12;
45-import org.lwjgl.opengl.GLContext;
46-
47-import static org.lwjgl.opengl.GL11.*;
48-
49-public class LwjglGL1Renderer implements GL1Renderer {
50-
51- private static final Logger logger = Logger.getLogger(LwjglRenderer.class.getName());
52- private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250);
53- private final StringBuilder stringBuf = new StringBuilder(250);
54- private final IntBuffer ib1 = BufferUtils.createIntBuffer(1);
55- private final IntBuffer intBuf16 = BufferUtils.createIntBuffer(16);
56- private final FloatBuffer fb16 = BufferUtils.createFloatBuffer(16);
57- private final FloatBuffer fb4Null = BufferUtils.createFloatBuffer(4);
58- private final RenderContext context = new RenderContext();
59- private final NativeObjectManager objManager = new NativeObjectManager();
60- private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
61- private int maxTexSize;
62- private int maxCubeTexSize;
63- private int maxVertCount;
64- private int maxTriCount;
65- private int maxLights;
66- private boolean gl12 = false;
67- private final Statistics statistics = new Statistics();
68- private int vpX, vpY, vpW, vpH;
69- private int clipX, clipY, clipW, clipH;
70-
71- private Matrix4f worldMatrix = new Matrix4f();
72- private Matrix4f viewMatrix = new Matrix4f();
73-
74- private ArrayList<Light> lightList = new ArrayList<Light>(8);
75- private ColorRGBA materialAmbientColor = new ColorRGBA();
76- private Vector3f tempVec = new Vector3f();
77-
78- protected void updateNameBuffer() {
79- int len = stringBuf.length();
80-
81- nameBuf.position(0);
82- nameBuf.limit(len);
83- for (int i = 0; i < len; i++) {
84- nameBuf.put((byte) stringBuf.charAt(i));
85- }
86-
87- nameBuf.rewind();
88- }
89-
90- public Statistics getStatistics() {
91- return statistics;
92- }
93-
94- public EnumSet<Caps> getCaps() {
95- return caps;
96- }
97-
98- public void initialize() {
99- if (GLContext.getCapabilities().OpenGL12){
100- gl12 = true;
101- }
102-
103- // Default values for certain GL state.
104- glShadeModel(GL_SMOOTH);
105- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
106- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
107-
108- // Enable rescaling/normaling of normal vectors.
109- // Fixes lighting issues with scaled models.
110- if (gl12){
111- glEnable(GL12.GL_RESCALE_NORMAL);
112- }else{
113- glEnable(GL_NORMALIZE);
114- }
115-
116- if (GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
117- caps.add(Caps.NonPowerOfTwoTextures);
118- } else {
119- logger.log(Level.WARNING, "Your graphics card does not "
120- + "support non-power-of-2 textures. "
121- + "Some features might not work.");
122- }
123-
124- maxLights = glGetInteger(GL_MAX_LIGHTS);
125-
126- }
127-
128- public void invalidateState() {
129- context.reset();
130- }
131-
132- public void resetGLObjects() {
133- logger.log(Level.INFO, "Reseting objects and invalidating state");
134- objManager.resetObjects();
135- statistics.clearMemory();
136- invalidateState();
137- }
138-
139- public void cleanup() {
140- logger.log(Level.INFO, "Deleting objects and invalidating state");
141- objManager.deleteAllObjects(this);
142- statistics.clearMemory();
143- invalidateState();
144- }
145-
146- public void setDepthRange(float start, float end) {
147- glDepthRange(start, end);
148- }
149-
150- public void clearBuffers(boolean color, boolean depth, boolean stencil) {
151- int bits = 0;
152- if (color) {
153- //See explanations of the depth below, we must enable color write to be able to clear the color buffer
154- if (context.colorWriteEnabled == false) {
155- glColorMask(true, true, true, true);
156- context.colorWriteEnabled = true;
157- }
158- bits = GL_COLOR_BUFFER_BIT;
159- }
160- if (depth) {
161-
162- //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false
163- //here s some link on openl board
164- //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223
165- //if depth clear is requested, we enable the depthMask
166- if (context.depthWriteEnabled == false) {
167- glDepthMask(true);
168- context.depthWriteEnabled = true;
169- }
170- bits |= GL_DEPTH_BUFFER_BIT;
171- }
172- if (stencil) {
173- bits |= GL_STENCIL_BUFFER_BIT;
174- }
175- if (bits != 0) {
176- glClear(bits);
177- }
178- }
179-
180- public void setBackgroundColor(ColorRGBA color) {
181- glClearColor(color.r, color.g, color.b, color.a);
182- }
183-
184- private void setMaterialColor(int type, ColorRGBA color, ColorRGBA defaultColor) {
185- if (color != null){
186- fb16.put(color.r).put(color.g).put(color.b).put(color.a).flip();
187- }else{
188- fb16.put(defaultColor.r).put(defaultColor.g).put(defaultColor.b).put(defaultColor.a).flip();
189- }
190- glMaterial(GL_FRONT_AND_BACK, type, fb16);
191- }
192-
193- /**
194- * Applies fixed function bindings from the context to OpenGL
195- */
196- private void applyFixedFuncBindings(boolean forLighting){
197- if (forLighting){
198- glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, context.shininess);
199- setMaterialColor(GL_AMBIENT, context.ambient, ColorRGBA.DarkGray);
200- setMaterialColor(GL_DIFFUSE, context.diffuse, ColorRGBA.White);
201- setMaterialColor(GL_SPECULAR, context.specular, ColorRGBA.Black);
202-
203- if (context.useVertexColor){
204- glEnable(GL_COLOR_MATERIAL);
205- }else{
206- glDisable(GL_COLOR_MATERIAL);
207- }
208- }else{
209- // Ignore other values as they have no effect when
210- // GL_LIGHTING is disabled.
211- ColorRGBA color = context.color;
212- if (color != null){
213- glColor4f(color.r, color.g, color.b, color.a);
214- }else{
215- glColor4f(1,1,1,1);
216- }
217- }
218- }
219-
220- /**
221- * Reset fixed function bindings to default values.
222- */
223- private void resetFixedFuncBindings(){
224- context.color = null;
225- context.ambient = null;
226- context.diffuse = null;
227- context.specular = null;
228- context.shininess = 0;
229- context.useVertexColor = false;
230- }
231-
232- public void setFixedFuncBinding(FixedFuncBinding ffBinding, Object val) {
233- switch (ffBinding) {
234- case Color:
235- context.color = (ColorRGBA) val;
236- break;
237- case MaterialAmbient:
238- context.ambient = (ColorRGBA) val;
239- break;
240- case MaterialDiffuse:
241- context.diffuse = (ColorRGBA) val;
242- break;
243- case MaterialSpecular:
244- context.specular = (ColorRGBA) val;
245- break;
246- case MaterialShininess:
247- context.shininess = (Float) val;
248- break;
249- case UseVertexColor:
250- context.useVertexColor = (Boolean) val;
251- break;
252- }
253- }
254-
255- public void applyRenderState(RenderState state) {
256- if (state.isWireframe() && !context.wireframe) {
257- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
258- context.wireframe = true;
259- } else if (!state.isWireframe() && context.wireframe) {
260- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
261- context.wireframe = false;
262- }
263-
264- if (state.isDepthTest() && !context.depthTestEnabled) {
265- glEnable(GL_DEPTH_TEST);
266- glDepthFunc(GL_LEQUAL);
267- context.depthTestEnabled = true;
268- } else if (!state.isDepthTest() && context.depthTestEnabled) {
269- glDisable(GL_DEPTH_TEST);
270- context.depthTestEnabled = false;
271- }
272-
273- if (state.isAlphaTest() && !context.alphaTestEnabled) {
274- glEnable(GL_ALPHA_TEST);
275- glAlphaFunc(GL_GREATER, state.getAlphaFallOff());
276- context.alphaTestEnabled = true;
277- } else if (!state.isAlphaTest() && context.alphaTestEnabled) {
278- glDisable(GL_ALPHA_TEST);
279- context.alphaTestEnabled = false;
280- }
281-
282- if (state.isDepthWrite() && !context.depthWriteEnabled) {
283- glDepthMask(true);
284- context.depthWriteEnabled = true;
285- } else if (!state.isDepthWrite() && context.depthWriteEnabled) {
286- glDepthMask(false);
287- context.depthWriteEnabled = false;
288- }
289-
290- if (state.isColorWrite() && !context.colorWriteEnabled) {
291- glColorMask(true, true, true, true);
292- context.colorWriteEnabled = true;
293- } else if (!state.isColorWrite() && context.colorWriteEnabled) {
294- glColorMask(false, false, false, false);
295- context.colorWriteEnabled = false;
296- }
297-
298- if (state.isPointSprite()) {
299- logger.log(Level.WARNING, "Point Sprite unsupported!");
300- }
301-
302- if (state.isPolyOffset()) {
303- if (!context.polyOffsetEnabled) {
304- glEnable(GL_POLYGON_OFFSET_FILL);
305- glPolygonOffset(state.getPolyOffsetFactor(),
306- state.getPolyOffsetUnits());
307- context.polyOffsetEnabled = true;
308- context.polyOffsetFactor = state.getPolyOffsetFactor();
309- context.polyOffsetUnits = state.getPolyOffsetUnits();
310- } else {
311- if (state.getPolyOffsetFactor() != context.polyOffsetFactor
312- || state.getPolyOffsetUnits() != context.polyOffsetUnits) {
313- glPolygonOffset(state.getPolyOffsetFactor(),
314- state.getPolyOffsetUnits());
315- context.polyOffsetFactor = state.getPolyOffsetFactor();
316- context.polyOffsetUnits = state.getPolyOffsetUnits();
317- }
318- }
319- } else {
320- if (context.polyOffsetEnabled) {
321- glDisable(GL_POLYGON_OFFSET_FILL);
322- context.polyOffsetEnabled = false;
323- context.polyOffsetFactor = 0;
324- context.polyOffsetUnits = 0;
325- }
326- }
327- if (state.getFaceCullMode() != context.cullMode) {
328- if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) {
329- glDisable(GL_CULL_FACE);
330- } else {
331- glEnable(GL_CULL_FACE);
332- }
333-
334- switch (state.getFaceCullMode()) {
335- case Off:
336- break;
337- case Back:
338- glCullFace(GL_BACK);
339- break;
340- case Front:
341- glCullFace(GL_FRONT);
342- break;
343- case FrontAndBack:
344- glCullFace(GL_FRONT_AND_BACK);
345- break;
346- default:
347- throw new UnsupportedOperationException("Unrecognized face cull mode: "
348- + state.getFaceCullMode());
349- }
350-
351- context.cullMode = state.getFaceCullMode();
352- }
353-
354- if (state.getBlendMode() != context.blendMode) {
355- if (state.getBlendMode() == RenderState.BlendMode.Off) {
356- glDisable(GL_BLEND);
357- } else {
358- glEnable(GL_BLEND);
359- switch (state.getBlendMode()) {
360- case Off:
361- break;
362- case Additive:
363- glBlendFunc(GL_ONE, GL_ONE);
364- break;
365- case AlphaAdditive:
366- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
367- break;
368- case Color:
369- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
370- break;
371- case Alpha:
372- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
373- break;
374- case PremultAlpha:
375- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
376- break;
377- case Modulate:
378- glBlendFunc(GL_DST_COLOR, GL_ZERO);
379- break;
380- case ModulateX2:
381- glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
382- break;
383- default:
384- throw new UnsupportedOperationException("Unrecognized blend mode: "
385- + state.getBlendMode());
386- }
387- }
388-
389- context.blendMode = state.getBlendMode();
390- }
391-
392- if (state.isStencilTest()) {
393- throw new UnsupportedOperationException("OpenGL 1.1 doesn't support two sided stencil operations.");
394- }
395-
396- }
397-
398- public void setViewPort(int x, int y, int w, int h) {
399- if (x != vpX || vpY != y || vpW != w || vpH != h) {
400- glViewport(x, y, w, h);
401- vpX = x;
402- vpY = y;
403- vpW = w;
404- vpH = h;
405- }
406- }
407-
408- public void setClipRect(int x, int y, int width, int height) {
409- if (!context.clipRectEnabled) {
410- glEnable(GL_SCISSOR_TEST);
411- context.clipRectEnabled = true;
412- }
413- if (clipX != x || clipY != y || clipW != width || clipH != height) {
414- glScissor(x, y, width, height);
415- clipX = x;
416- clipY = y;
417- clipW = width;
418- clipH = height;
419- }
420- }
421-
422- public void clearClipRect() {
423- if (context.clipRectEnabled) {
424- glDisable(GL_SCISSOR_TEST);
425- context.clipRectEnabled = false;
426-
427- clipX = 0;
428- clipY = 0;
429- clipW = 0;
430- clipH = 0;
431- }
432- }
433-
434- public void onFrame() {
435- objManager.deleteUnused(this);
436-// statistics.clearFrame();
437- }
438-
439- private FloatBuffer storeMatrix(Matrix4f matrix, FloatBuffer store) {
440- store.clear();
441- matrix.fillFloatBuffer(store, true);
442- store.clear();
443- return store;
444- }
445-
446- private void setModelView(Matrix4f modelMatrix, Matrix4f viewMatrix){
447- if (context.matrixMode != GL_MODELVIEW) {
448- glMatrixMode(GL_MODELVIEW);
449- context.matrixMode = GL_MODELVIEW;
450- }
451-
452- glLoadMatrix(storeMatrix(viewMatrix, fb16));
453- glMultMatrix(storeMatrix(modelMatrix, fb16));
454- }
455-
456- private void setProjection(Matrix4f projMatrix){
457- if (context.matrixMode != GL_PROJECTION) {
458- glMatrixMode(GL_PROJECTION);
459- context.matrixMode = GL_PROJECTION;
460- }
461-
462- glLoadMatrix(storeMatrix(projMatrix, fb16));
463- }
464-
465- public void setWorldMatrix(Matrix4f worldMatrix) {
466- this.worldMatrix.set(worldMatrix);
467- }
468-
469- public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix) {
470- this.viewMatrix.set(viewMatrix);
471- setProjection(projMatrix);
472- }
473-
474- public void setLighting(LightList list) {
475- // XXX: This is abuse of setLighting() to
476- // apply fixed function bindings
477- // and do other book keeping.
478- if (list == null || list.size() == 0){
479- glDisable(GL_LIGHTING);
480- applyFixedFuncBindings(false);
481- setModelView(worldMatrix, viewMatrix);
482- return;
483- }
484-
485- // Number of lights set previously
486- int numLightsSetPrev = lightList.size();
487-
488- // If more than maxLights are defined, they will be ignored.
489- // The GL1 renderer is not permitted to crash due to a
490- // GL1 limitation. It must render anything that the GL2 renderer
491- // can render (even incorrectly).
492- lightList.clear();
493- materialAmbientColor.set(0, 0, 0, 0);
494-
495- for (int i = 0; i < list.size(); i++){
496- Light l = list.get(i);
497- if (l.getType() == Light.Type.Ambient){
498- // Gather
499- materialAmbientColor.addLocal(l.getColor());
500- }else{
501- // Add to list
502- lightList.add(l);
503-
504- // Once maximum lights reached, exit loop.
505- if (lightList.size() >= maxLights){
506- break;
507- }
508- }
509- }
510-
511- applyFixedFuncBindings(true);
512-
513- glEnable(GL_LIGHTING);
514-
515- fb16.clear();
516- fb16.put(materialAmbientColor.r)
517- .put(materialAmbientColor.g)
518- .put(materialAmbientColor.b)
519- .put(1).flip();
520-
521- glLightModel(GL_LIGHT_MODEL_AMBIENT, fb16);
522-
523- if (context.matrixMode != GL_MODELVIEW) {
524- glMatrixMode(GL_MODELVIEW);
525- context.matrixMode = GL_MODELVIEW;
526- }
527- // Lights are already in world space, so just convert
528- // them to view space.
529- glLoadMatrix(storeMatrix(viewMatrix, fb16));
530-
531- for (int i = 0; i < lightList.size(); i++){
532- int glLightIndex = GL_LIGHT0 + i;
533- Light light = lightList.get(i);
534- Light.Type lightType = light.getType();
535- ColorRGBA col = light.getColor();
536- Vector3f pos;
537-
538- // Enable the light
539- glEnable(glLightIndex);
540-
541- // OGL spec states default value for light ambient is black
542- switch (lightType){
543- case Directional:
544- DirectionalLight dLight = (DirectionalLight) light;
545-
546- fb16.clear();
547- fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
548- glLight(glLightIndex, GL_DIFFUSE, fb16);
549- glLight(glLightIndex, GL_SPECULAR, fb16);
550-
551- pos = tempVec.set(dLight.getDirection()).negateLocal().normalizeLocal();
552- fb16.clear();
553- fb16.put(pos.x).put(pos.y).put(pos.z).put(0.0f).flip();
554- glLight(glLightIndex, GL_POSITION, fb16);
555- glLightf(glLightIndex, GL_SPOT_CUTOFF, 180);
556- break;
557- case Point:
558- PointLight pLight = (PointLight) light;
559-
560- fb16.clear();
561- fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
562- glLight(glLightIndex, GL_DIFFUSE, fb16);
563- glLight(glLightIndex, GL_SPECULAR, fb16);
564-
565- pos = pLight.getPosition();
566- fb16.clear();
567- fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
568- glLight(glLightIndex, GL_POSITION, fb16);
569- glLightf(glLightIndex, GL_SPOT_CUTOFF, 180);
570-
571- if (pLight.getRadius() > 0) {
572- // Note: this doesn't follow the same attenuation model
573- // as the one used in the lighting shader.
574- glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1);
575- glLightf(glLightIndex, GL_LINEAR_ATTENUATION, pLight.getInvRadius() * 2);
576- glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, pLight.getInvRadius() * pLight.getInvRadius());
577- }else{
578- glLightf(glLightIndex, GL_CONSTANT_ATTENUATION, 1);
579- glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0);
580- glLightf(glLightIndex, GL_QUADRATIC_ATTENUATION, 0);
581- }
582-
583- break;
584- case Spot:
585- SpotLight sLight = (SpotLight) light;
586-
587- fb16.clear();
588- fb16.put(col.r).put(col.g).put(col.b).put(col.a).flip();
589- glLight(glLightIndex, GL_DIFFUSE, fb16);
590- glLight(glLightIndex, GL_SPECULAR, fb16);
591-
592- pos = sLight.getPosition();
593- fb16.clear();
594- fb16.put(pos.x).put(pos.y).put(pos.z).put(1.0f).flip();
595- glLight(glLightIndex, GL_POSITION, fb16);
596-
597- Vector3f dir = sLight.getDirection();
598- fb16.clear();
599- fb16.put(dir.x).put(dir.y).put(dir.z).put(1.0f).flip();
600- glLight(glLightIndex, GL_SPOT_DIRECTION, fb16);
601-
602- float outerAngleRad = sLight.getSpotOuterAngle();
603- float innerAngleRad = sLight.getSpotInnerAngle();
604- float spotCut = outerAngleRad * FastMath.RAD_TO_DEG;
605- float spotExpo = 0.0f;
606- if (outerAngleRad > 0) {
607- spotExpo = (1.0f - (innerAngleRad / outerAngleRad)) * 128.0f;
608- }
609-
610- glLightf(glLightIndex, GL_SPOT_CUTOFF, spotCut);
611- glLightf(glLightIndex, GL_SPOT_EXPONENT, spotExpo);
612-
613- if (sLight.getSpotRange() > 0) {
614- glLightf(glLightIndex, GL_LINEAR_ATTENUATION, sLight.getInvSpotRange());
615- }else{
616- glLightf(glLightIndex, GL_LINEAR_ATTENUATION, 0);
617- }
618-
619- break;
620- default:
621- throw new UnsupportedOperationException(
622- "Unrecognized light type: " + lightType);
623- }
624- }
625-
626- // Disable lights after the index
627- for (int i = lightList.size(); i < numLightsSetPrev; i++){
628- glDisable(GL_LIGHT0 + i);
629- }
630-
631- // This will set view matrix as well.
632- setModelView(worldMatrix, viewMatrix);
633- }
634-
635- private int convertTextureType(Texture.Type type) {
636- switch (type) {
637- case TwoDimensional:
638- return GL_TEXTURE_2D;
639-// case ThreeDimensional:
640-// return GL_TEXTURE_3D;
641-// case CubeMap:
642-// return GL_TEXTURE_CUBE_MAP;
643- default:
644- throw new UnsupportedOperationException("Unknown texture type: " + type);
645- }
646- }
647-
648- private int convertMagFilter(Texture.MagFilter filter) {
649- switch (filter) {
650- case Bilinear:
651- return GL_LINEAR;
652- case Nearest:
653- return GL_NEAREST;
654- default:
655- throw new UnsupportedOperationException("Unknown mag filter: " + filter);
656- }
657- }
658-
659- private int convertMinFilter(Texture.MinFilter filter) {
660- switch (filter) {
661- case Trilinear:
662- return GL_LINEAR_MIPMAP_LINEAR;
663- case BilinearNearestMipMap:
664- return GL_LINEAR_MIPMAP_NEAREST;
665- case NearestLinearMipMap:
666- return GL_NEAREST_MIPMAP_LINEAR;
667- case NearestNearestMipMap:
668- return GL_NEAREST_MIPMAP_NEAREST;
669- case BilinearNoMipMaps:
670- return GL_LINEAR;
671- case NearestNoMipMaps:
672- return GL_NEAREST;
673- default:
674- throw new UnsupportedOperationException("Unknown min filter: " + filter);
675- }
676- }
677-
678- private int convertWrapMode(Texture.WrapMode mode) {
679- switch (mode) {
680- case EdgeClamp:
681- case Clamp:
682- case BorderClamp:
683- return GL_CLAMP;
684- case Repeat:
685- return GL_REPEAT;
686- default:
687- throw new UnsupportedOperationException("Unknown wrap mode: " + mode);
688- }
689- }
690-
691- private void setupTextureParams(Texture tex) {
692- int target = convertTextureType(tex.getType());
693-
694- // filter things
695- int minFilter = convertMinFilter(tex.getMinFilter());
696- int magFilter = convertMagFilter(tex.getMagFilter());
697- glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
698- glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);
699-
700- // repeat modes
701- switch (tex.getType()) {
702-// case ThreeDimensional:
703-// case CubeMap:
704-// glTexParameteri(target, GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
705- case TwoDimensional:
706- glTexParameteri(target, GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
707- // fall down here is intentional..
708-// case OneDimensional:
709- glTexParameteri(target, GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
710- break;
711- default:
712- throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
713- }
714- }
715-
716- public void updateTexImageData(Image img, Texture.Type type, boolean mips, int unit) {
717- int texId = img.getId();
718- if (texId == -1) {
719- // create texture
720- glGenTextures(ib1);
721- texId = ib1.get(0);
722- img.setId(texId);
723- objManager.registerForCleanup(img);
724-
725- statistics.onNewTexture();
726- }
727-
728- // bind texture
729- int target = convertTextureType(type);
730-// if (context.boundTextureUnit != unit) {
731-// glActiveTexture(GL_TEXTURE0 + unit);
732-// context.boundTextureUnit = unit;
733-// }
734- if (context.boundTextures[unit] != img) {
735- glEnable(target);
736- glBindTexture(target, texId);
737- context.boundTextures[unit] = img;
738-
739- statistics.onTextureUse(img, true);
740- }
741-
742- // Check sizes if graphics card doesn't support NPOT
743- if (!GLContext.getCapabilities().GL_ARB_texture_non_power_of_two) {
744- if (img.getWidth() != 0 && img.getHeight() != 0) {
745- if (!FastMath.isPowerOfTwo(img.getWidth())
746- || !FastMath.isPowerOfTwo(img.getHeight())) {
747-
748- // Resize texture to Power-of-2 size
749- MipMapGenerator.resizeToPowerOf2(img);
750-
751- }
752- }
753- }
754-
755- if (!img.hasMipmaps() && mips) {
756- // No pregenerated mips available,
757- // generate from base level if required
758-
759- // Check if hardware mips are supported
760- if (GLContext.getCapabilities().OpenGL14) {
761- glTexParameteri(target, GL14.GL_GENERATE_MIPMAP, GL_TRUE);
762- } else {
763- MipMapGenerator.generateMipMaps(img);
764- }
765- } else {
766- }
767-
768- /*
769- if (target == GL_TEXTURE_CUBE_MAP) {
770- List<ByteBuffer> data = img.getData();
771- if (data.size() != 6) {
772- logger.log(Level.WARNING, "Invalid texture: {0}\n"
773- + "Cubemap textures must contain 6 data units.", img);
774- return;
775- }
776- for (int i = 0; i < 6; i++) {
777- TextureUtil.uploadTexture(img, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, 0, tdc);
778- }
779- } else if (target == EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT) {
780- List<ByteBuffer> data = img.getData();
781- // -1 index specifies prepare data for 2D Array
782- TextureUtil.uploadTexture(img, target, -1, 0, tdc);
783- for (int i = 0; i < data.size(); i++) {
784- // upload each slice of 2D array in turn
785- // this time with the appropriate index
786- TextureUtil.uploadTexture(img, target, i, 0, tdc);
787- }
788- } else {*/
789- TextureUtil.uploadTexture(img, target, 0, 0, false);
790- //}
791-
792- img.clearUpdateNeeded();
793- }
794-
795- public void setTexture(int unit, Texture tex) {
796- if (unit != 0 || tex.getType() != Texture.Type.TwoDimensional) {
797- //throw new UnsupportedOperationException();
798- return;
799- }
800-
801- Image image = tex.getImage();
802- if (image.isUpdateNeeded()) {
803- updateTexImageData(image, tex.getType(), tex.getMinFilter().usesMipMapLevels(), unit);
804- }
805-
806- int texId = image.getId();
807- assert texId != -1;
808-
809- Image[] textures = context.boundTextures;
810-
811- int type = convertTextureType(tex.getType());
812-// if (!context.textureIndexList.moveToNew(unit)) {
813-// if (context.boundTextureUnit != unit){
814-// glActiveTexture(GL_TEXTURE0 + unit);
815-// context.boundTextureUnit = unit;
816-// }
817-// glEnable(type);
818-// }
819-
820-// if (context.boundTextureUnit != unit) {
821-// glActiveTexture(GL_TEXTURE0 + unit);
822-// context.boundTextureUnit = unit;
823-// }
824-
825- if (textures[unit] != image) {
826- glEnable(type);
827- glBindTexture(type, texId);
828- textures[unit] = image;
829-
830- statistics.onTextureUse(image, true);
831- } else {
832- statistics.onTextureUse(image, false);
833- }
834-
835- setupTextureParams(tex);
836- }
837-
838- private void clearTextureUnits() {
839- Image[] textures = context.boundTextures;
840- if (textures[0] != null) {
841- glDisable(GL_TEXTURE_2D);
842- textures[0] = null;
843- }
844- }
845-
846- public void deleteImage(Image image) {
847- int texId = image.getId();
848- if (texId != -1) {
849- ib1.put(0, texId);
850- ib1.position(0).limit(1);
851- glDeleteTextures(ib1);
852- image.resetObject();
853- }
854- }
855-
856- private int convertArrayType(VertexBuffer.Type type) {
857- switch (type) {
858- case Position:
859- return GL_VERTEX_ARRAY;
860- case Normal:
861- return GL_NORMAL_ARRAY;
862- case TexCoord:
863- return GL_TEXTURE_COORD_ARRAY;
864- case Color:
865- return GL_COLOR_ARRAY;
866- default:
867- return -1; // unsupported
868- }
869- }
870-
871- private int convertVertexFormat(VertexBuffer.Format fmt) {
872- switch (fmt) {
873- case Byte:
874- return GL_BYTE;
875- case Float:
876- return GL_FLOAT;
877- case Int:
878- return GL_INT;
879- case Short:
880- return GL_SHORT;
881- case UnsignedByte:
882- return GL_UNSIGNED_BYTE;
883- case UnsignedInt:
884- return GL_UNSIGNED_INT;
885- case UnsignedShort:
886- return GL_UNSIGNED_SHORT;
887- default:
888- throw new UnsupportedOperationException("Unrecognized vertex format: " + fmt);
889- }
890- }
891-
892- private int convertElementMode(Mesh.Mode mode) {
893- switch (mode) {
894- case Points:
895- return GL_POINTS;
896- case Lines:
897- return GL_LINES;
898- case LineLoop:
899- return GL_LINE_LOOP;
900- case LineStrip:
901- return GL_LINE_STRIP;
902- case Triangles:
903- return GL_TRIANGLES;
904- case TriangleFan:
905- return GL_TRIANGLE_FAN;
906- case TriangleStrip:
907- return GL_TRIANGLE_STRIP;
908- default:
909- throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
910- }
911- }
912-
913- public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) {
914- if (count > 1) {
915- throw new UnsupportedOperationException();
916- }
917-
918- glDrawArrays(convertElementMode(mode), 0, vertCount);
919- }
920-
921- public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
922- int arrayType = convertArrayType(vb.getBufferType());
923- if (arrayType == -1) {
924- return; // unsupported
925- }
926- glEnableClientState(arrayType);
927- context.boundAttribs[vb.getBufferType().ordinal()] = vb;
928-
929- if (vb.getBufferType() == Type.Normal) {
930- // normalize if requested
931- if (vb.isNormalized() && !context.normalizeEnabled) {
932- glEnable(GL_NORMALIZE);
933- context.normalizeEnabled = true;
934- } else if (!vb.isNormalized() && context.normalizeEnabled) {
935- glDisable(GL_NORMALIZE);
936- context.normalizeEnabled = false;
937- }
938- }
939-
940- // NOTE: Use data from interleaved buffer if specified
941- Buffer data = idb != null ? idb.getData() : vb.getData();
942- int comps = vb.getNumComponents();
943- int type = convertVertexFormat(vb.getFormat());
944-
945- data.rewind();
946-
947- switch (vb.getBufferType()) {
948- case Position:
949- if (!(data instanceof FloatBuffer)) {
950- throw new UnsupportedOperationException();
951- }
952-
953- glVertexPointer(comps, vb.getStride(), (FloatBuffer) data);
954- break;
955- case Normal:
956- if (!(data instanceof FloatBuffer)) {
957- throw new UnsupportedOperationException();
958- }
959-
960- glNormalPointer(vb.getStride(), (FloatBuffer) data);
961- break;
962- case Color:
963- if (data instanceof FloatBuffer) {
964- glColorPointer(comps, vb.getStride(), (FloatBuffer) data);
965- } else if (data instanceof ByteBuffer) {
966- glColorPointer(comps, true, vb.getStride(), (ByteBuffer) data);
967- } else {
968- throw new UnsupportedOperationException();
969- }
970- break;
971- case TexCoord:
972- if (!(data instanceof FloatBuffer)) {
973- throw new UnsupportedOperationException();
974- }
975-
976- glTexCoordPointer(comps, vb.getStride(), (FloatBuffer) data);
977- break;
978- default:
979- // Ignore, this is an unsupported attribute for OpenGL1.
980- break;
981- }
982- }
983-
984- public void setVertexAttrib(VertexBuffer vb) {
985- setVertexAttrib(vb, null);
986- }
987-
988- private void drawElements(int mode, int format, Buffer data) {
989- switch (format) {
990- case GL_UNSIGNED_BYTE:
991- glDrawElements(mode, (ByteBuffer) data);
992- break;
993- case GL_UNSIGNED_SHORT:
994- glDrawElements(mode, (ShortBuffer) data);
995- break;
996- case GL_UNSIGNED_INT:
997- glDrawElements(mode, (IntBuffer) data);
998- break;
999- default:
1000- throw new UnsupportedOperationException();
1001- }
1002- }
1003-
1004- public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) {
1005- Mesh.Mode mode = mesh.getMode();
1006-
1007- Buffer indexData = indexBuf.getData();
1008- indexData.rewind();
1009-
1010- if (mesh.getMode() == Mode.Hybrid) {
1011- throw new UnsupportedOperationException();
1012- /*
1013- int[] modeStart = mesh.getModeStart();
1014- int[] elementLengths = mesh.getElementLengths();
1015-
1016- int elMode = convertElementMode(Mode.Triangles);
1017- int fmt = convertVertexFormat(indexBuf.getFormat());
1018- // int elSize = indexBuf.getFormat().getComponentSize();
1019- // int listStart = modeStart[0];
1020- int stripStart = modeStart[1];
1021- int fanStart = modeStart[2];
1022- int curOffset = 0;
1023- for (int i = 0; i < elementLengths.length; i++) {
1024- if (i == stripStart) {
1025- elMode = convertElementMode(Mode.TriangleStrip);
1026- } else if (i == fanStart) {
1027- elMode = convertElementMode(Mode.TriangleStrip);
1028- }
1029- int elementLength = elementLengths[i];
1030- indexData.position(curOffset);
1031-
1032- drawElements(elMode,
1033- fmt,
1034- indexData);
1035-
1036- curOffset += elementLength;
1037- }*/
1038- } else {
1039- drawElements(convertElementMode(mode),
1040- convertVertexFormat(indexBuf.getFormat()),
1041- indexData);
1042- }
1043- }
1044-
1045- public void clearVertexAttribs() {
1046- for (int i = 0; i < 16; i++) {
1047- VertexBuffer vb = context.boundAttribs[i];
1048- if (vb != null) {
1049- int arrayType = convertArrayType(vb.getBufferType());
1050- glDisableClientState(arrayType);
1051- context.boundAttribs[vb.getBufferType().ordinal()] = null;
1052- }
1053- }
1054- }
1055-
1056- private void renderMeshDefault(Mesh mesh, int lod, int count) {
1057- VertexBuffer indices = null;
1058-
1059- VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
1060- if (interleavedData != null && interleavedData.isUpdateNeeded()) {
1061- updateBufferData(interleavedData);
1062- }
1063-
1064- IntMap<VertexBuffer> buffers = mesh.getBuffers();
1065- if (mesh.getNumLodLevels() > 0) {
1066- indices = mesh.getLodLevel(lod);
1067- } else {
1068- indices = buffers.get(Type.Index.ordinal());
1069- }
1070- for (Entry<VertexBuffer> entry : buffers) {
1071- VertexBuffer vb = entry.getValue();
1072-
1073- if (vb.getBufferType() == Type.InterleavedData
1074- || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
1075- || vb.getBufferType() == Type.Index) {
1076- continue;
1077- }
1078-
1079- if (vb.getStride() == 0) {
1080- // not interleaved
1081- setVertexAttrib(vb);
1082- } else {
1083- // interleaved
1084- setVertexAttrib(vb, interleavedData);
1085- }
1086- }
1087-
1088- if (indices != null) {
1089- drawTriangleList(indices, mesh, count);
1090- } else {
1091- glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
1092- }
1093-
1094- // TODO: Fix these to use IDList??
1095- clearVertexAttribs();
1096- clearTextureUnits();
1097- resetFixedFuncBindings();
1098- }
1099-
1100- public void renderMesh(Mesh mesh, int lod, int count) {
1101- if (mesh.getVertexCount() == 0) {
1102- return;
1103- }
1104-
1105- if (context.pointSize != mesh.getPointSize()) {
1106- glPointSize(mesh.getPointSize());
1107- context.pointSize = mesh.getPointSize();
1108- }
1109- if (context.lineWidth != mesh.getLineWidth()) {
1110- glLineWidth(mesh.getLineWidth());
1111- context.lineWidth = mesh.getLineWidth();
1112- }
1113-
1114- boolean dynamic = false;
1115- if (mesh.getBuffer(Type.InterleavedData) != null) {
1116- throw new UnsupportedOperationException("Interleaved meshes are not supported");
1117- }
1118-
1119- if (mesh.getNumLodLevels() == 0) {
1120- IntMap<VertexBuffer> bufs = mesh.getBuffers();
1121- for (Entry<VertexBuffer> entry : bufs) {
1122- if (entry.getValue().getUsage() != VertexBuffer.Usage.Static) {
1123- dynamic = true;
1124- break;
1125- }
1126- }
1127- } else {
1128- dynamic = true;
1129- }
1130-
1131- statistics.onMeshDrawn(mesh, lod);
1132-
1133-// if (!dynamic) {
1134- // dealing with a static object, generate display list
1135-// renderMeshDisplayList(mesh);
1136-// } else {
1137- renderMeshDefault(mesh, lod, count);
1138-// }
1139-
1140-
1141- }
1142-
1143- public void setAlphaToCoverage(boolean value) {
1144- }
1145-
1146- public void setShader(Shader shader) {
1147- }
1148-
1149- public void deleteShader(Shader shader) {
1150- }
1151-
1152- public void deleteShaderSource(ShaderSource source) {
1153- }
1154-
1155- public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) {
1156- }
1157-
1158- public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) {
1159- }
1160-
1161- public void setMainFrameBufferOverride(FrameBuffer fb){
1162- }
1163-
1164- public void setFrameBuffer(FrameBuffer fb) {
1165- }
1166-
1167- public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
1168- }
1169-
1170- public void deleteFrameBuffer(FrameBuffer fb) {
1171- }
1172-
1173- public void updateBufferData(VertexBuffer vb) {
1174- }
1175-
1176- public void deleteBuffer(VertexBuffer vb) {
1177- }
1178-}
--- a/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java
+++ b/engine/src/lwjgl-ogl/com/jme3/renderer/lwjgl/LwjglRenderer.java
@@ -1187,6 +1187,54 @@ public class LwjglRenderer implements Renderer {
11871187 }
11881188 }
11891189
1190+ public void setShaderWithoutUpdateUniforms(Shader shader) {
1191+ if (shader == null) {
1192+ throw new IllegalArgumentException("shader cannot be null");
1193+// if (context.boundShaderProgram > 0) {
1194+// glUseProgram(0);
1195+// statistics.onShaderUse(null, true);
1196+// context.boundShaderProgram = 0;
1197+// boundShader = null;
1198+// }
1199+ } else {
1200+ if (shader.isUpdateNeeded()) {
1201+ updateShaderData(shader);
1202+ }
1203+
1204+ // NOTE: might want to check if any of the
1205+ // sources need an update?
1206+
1207+ if (!shader.isUsable()) {
1208+ return;
1209+ }
1210+
1211+ assert shader.getId() > 0;
1212+
1213+// updateShaderUniforms(shader);
1214+ if (context.boundShaderProgram != shader.getId()) {
1215+ if (VALIDATE_SHADER) {
1216+ // check if shader can be used
1217+ // with current state
1218+ glValidateProgram(shader.getId());
1219+ glGetProgram(shader.getId(), GL_VALIDATE_STATUS, intBuf1);
1220+ boolean validateOK = intBuf1.get(0) == GL_TRUE;
1221+ if (validateOK) {
1222+ logger.fine("shader validate success");
1223+ } else {
1224+ logger.warning("shader validate failure");
1225+ }
1226+ }
1227+
1228+ glUseProgram(shader.getId());
1229+ statistics.onShaderUse(shader, true);
1230+ context.boundShaderProgram = shader.getId();
1231+ boundShader = shader;
1232+ } else {
1233+ statistics.onShaderUse(shader, false);
1234+ }
1235+ }
1236+ }
1237+
11901238 public void deleteShaderSource(ShaderSource source) {
11911239 if (source.getId() < 0) {
11921240 logger.warning("Shader source is not uploaded to GPU, cannot delete.");
--- a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglContext.java
+++ b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglContext.java
@@ -36,7 +36,6 @@ import com.jme3.input.lwjgl.JInputJoyInput;
3636 import com.jme3.input.lwjgl.LwjglKeyInput;
3737 import com.jme3.input.lwjgl.LwjglMouseInput;
3838 import com.jme3.renderer.Renderer;
39-import com.jme3.renderer.lwjgl.LwjglGL1Renderer;
4039 import com.jme3.renderer.lwjgl.LwjglRenderer;
4140 import com.jme3.system.AppSettings;
4241 import com.jme3.system.SystemListener;
@@ -118,14 +117,10 @@ public abstract class LwjglContext implements JmeContext {
118117 if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL2)
119118 || settings.getRenderer().equals(AppSettings.LWJGL_OPENGL3)){
120119 renderer = new LwjglRenderer();
121- }else if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL1)){
122- renderer = new LwjglGL1Renderer();
123120 }else if (settings.getRenderer().equals(AppSettings.LWJGL_OPENGL_ANY)){
124121 // Choose an appropriate renderer based on capabilities
125122 if (GLContext.getCapabilities().OpenGL20){
126123 renderer = new LwjglRenderer();
127- }else{
128- renderer = new LwjglGL1Renderer();
129124 }
130125 }else{
131126 throw new UnsupportedOperationException("Unsupported renderer: " + settings.getRenderer());
@@ -134,8 +129,6 @@ public abstract class LwjglContext implements JmeContext {
134129 // Init renderer
135130 if (renderer instanceof LwjglRenderer){
136131 ((LwjglRenderer)renderer).initialize();
137- }else if (renderer instanceof LwjglGL1Renderer){
138- ((LwjglGL1Renderer)renderer).initialize();
139132 }else{
140133 assert false;
141134 }