来自JMonkey SimpleApplication的GLSL编译错误

时间:2014-06-03 15:22:41

标签: java opengl glsl jmonkeyengine

使用JMonkeyEngine,我创建了一个非常简单的SimpleApplication子类,但是我得到一个非常奇怪的错误,不知道是什么导致它。更重要的是,这曾经工作得很好,但似乎我的系统上发生了一些破坏它的事情。新工作区在同事的计算机上运行此代码就好了。

我收到一条'bad compile'消息,打印出Common / ShaderLib / Skinning.glsllib和Common / MatDefs / Misc / Unshaded.vert文件的串联。 (作为预处理器复制粘贴的结果)。

错误说我错过了文件顶部的'#version'。当然,我没有更改文件。我的理解是GLSL编译器应该将没有指定版本的文件解释为版本110。

第二个抱怨是关于“属性”第76行的语法错误。我没有看到任何错误。

我已尝试通过AppSettings指定要使用的OpenGL版本,但这似乎没有效果。

当我通过调试器运行代码时,我看到有一个字符串'language'设置为“GLSL100”,但是int'版本'设置为150.这是在LwjglRenderer中。

Jun 03, 2014 9:03:29 AM com.jme3.renderer.lwjgl.LwjglRenderer updateShaderSourceData
WARNING: Bad compile of:
1   #define HAS_COLOR 1
2   #ifdef NUM_BONES
3   
4   #if NUM_BONES < 1 || NUM_BONES > 255
5   #error NUM_BONES must be between 1 and 255.
6   #endif
7   
8   #define NUM_WEIGHTS_PER_VERT 4
9    
10  attribute vec4 inHWBoneWeight;
11  attribute vec4 inHWBoneIndex;
12  uniform mat4 m_BoneMatrices[NUM_BONES];
13  
14  void Skinning_Compute(inout vec4 position){
15      if (inHWBoneWeight.x != 0.0) {
16  #if NUM_WEIGHTS_PER_VERT == 1
17          position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
18  #else
19          mat4 mat = mat4(0.0);
20          mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
21          mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
22          mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
23          mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
24          position = mat * position;
25  #endif
26      }
27  }
28   
29  void Skinning_Compute(inout vec4 position, inout vec3 normal){
30      if (inHWBoneWeight.x != 0.0) {
31  #if NUM_WEIGHTS_PER_VERT == 1
32          position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
33          normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
34                         m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
35                         m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
36  #else
37          mat4 mat = mat4(0.0);
38          mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
39          mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
40          mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
41          mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
42          position = mat * position;
43  
44          mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
45          normal = rotMat * normal;
46  #endif
47      }
48  }
49   
50  void Skinning_Compute(inout vec4 position, inout vec3 tangent, inout vec3 normal){
51      if (inHWBoneWeight.x != 0.0) {
52  #if NUM_WEIGHTS_PER_VERT == 1
53          position = m_BoneMatrices[int(inHWBoneIndex.x)] * position;
54          tangent = m_BoneMatrices[int(inHWBoneIndex.x)] * tangent;
55          normal = (mat3(m_BoneMatrices[int(inHWBoneIndex.x)][0].xyz,
56                         m_BoneMatrices[int(inHWBoneIndex.x)][1].xyz,
57                         m_BoneMatrices[int(inHWBoneIndex.x)][2].xyz) * normal);
58  #else
59          mat4 mat = mat4(0.0);
60          mat += m_BoneMatrices[int(inHWBoneIndex.x)] * inHWBoneWeight.x;
61          mat += m_BoneMatrices[int(inHWBoneIndex.y)] * inHWBoneWeight.y;
62          mat += m_BoneMatrices[int(inHWBoneIndex.z)] * inHWBoneWeight.z;
63          mat += m_BoneMatrices[int(inHWBoneIndex.w)] * inHWBoneWeight.w;
64          position = mat * position;
65  
66          mat3 rotMat = mat3(mat[0].xyz, mat[1].xyz, mat[2].xyz);
67          tangent = rotMat * tangent;
68          normal = rotMat * normal;
69  #endif
70      }
71  }
72  
73  #endif
74  
75  uniform mat4 g_WorldViewProjectionMatrix;
76  attribute vec3 inPosition;
77  
78  #if defined(HAS_COLORMAP) || (defined(HAS_LIGHTMAP) && !defined(SEPARATE_TEXCOORD))
79      #define NEED_TEXCOORD1
80  #endif
81  
82  attribute vec2 inTexCoord;
83  attribute vec2 inTexCoord2;
84  attribute vec4 inColor;
85  
86  varying vec2 texCoord1;
87  varying vec2 texCoord2;
88  
89  varying vec4 vertColor;
90  
91  void main(){
92      #ifdef NEED_TEXCOORD1
93          texCoord1 = inTexCoord;
94      #endif
95  
96      #ifdef SEPARATE_TEXCOORD
97          texCoord2 = inTexCoord2;
98      #endif
99  
100     #ifdef HAS_VERTEXCOLOR
101         vertColor = inColor;
102     #endif
103 
104     vec4 modelSpacePos = vec4(inPosition, 1.0);
105     #ifdef NUM_BONES
106         Skinning_Compute(modelSpacePos);
107     #endif
108     gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
109 }

Jun 03, 2014 9:03:29 AM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.renderer.RendererException: compile error in:ShaderSource[name=Common/MatDefs/Misc/Unshaded.vert, defines, type=Vertex, language=GLSL100] error:ERROR: 0:1: '' :  #version required and missing.
ERROR: 0:76: 'attribute' : syntax error syntax error
�
    at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderSourceData(LwjglRenderer.java:1018)
    at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderData(LwjglRenderer.java:1041)
    at com.jme3.renderer.lwjgl.LwjglRenderer.setShader(LwjglRenderer.java:1107)
    at com.jme3.material.Material.render(Material.java:1116)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:523)
    at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:322)
    at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:371)
    at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:788)
    at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:719)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:983)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1035)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
    at java.lang.Thread.run(Thread.java:744)

这是我的代码:

import com.jme3.app.SimpleApplication;

public class VerySimpleApplication
    extends SimpleApplication
{

    @Override
    public void simpleInitApp()
    {
        // TODO Auto-generated method stub

    }

    public static void main(String[] args)
    {
        VerySimpleApplication app = new VerySimpleApplication();

        app.start();
    }

}

1 个答案:

答案 0 :(得分:0)

好的,问题是我需要使用OpenGL 2时默认使用OpenGL 3.

VerySimpleApplication app = new VerySimpleApplication();
AppSettings settings = new AppSettings(true);
settings.setRenderer(AppSettings.LWJGL_OPENGL2);
app.setSettings(settings);
app.start();

Answer to the question on JMonkey forum