Advertisement
Guest User

JME3 geom, tess shaders support

a guest
May 20th, 2012
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 17.56 KB | None | 0 0
  1. --- com/jme3/material/Technique.java    Mon Jan 19 23:26:36 1970
  2. +++ com/jme3/material/Technique.java    Mon Jan 19 23:26:36 1970
  3. @@ -213,6 +213,9 @@
  4.  
  5.          ShaderKey key = new ShaderKey(def.getVertexShaderName(),
  6.                  def.getFragmentShaderName(),
  7. +                def.getGeometryShaderName(),
  8. +                def.getTessControlShaderName(),
  9. +                def.getTessEvaluationShaderName(),
  10.                  allDefines,
  11.                  def.getShaderLanguage());
  12.          shader = manager.loadShader(key);
  13. --- com/jme3/material/plugins/J3MLoader.java    Mon Jan 19 23:26:36 1970
  14. +++ com/jme3/material/plugins/J3MLoader.java    Mon Jan 19 23:26:36 1970
  15. @@ -69,6 +69,9 @@
  16.      private String shaderLang;
  17.      private String vertName;
  18.      private String fragName;
  19. +    private String geomName;
  20. +    private String tcName;
  21. +    private String teName;
  22.      
  23.      private static final String whitespacePattern = "\\p{javaWhitespace}+";
  24.  
  25. @@ -96,8 +99,14 @@
  26.          shaderLang = typeAndLang[1];
  27.          if (typeAndLang[0].equals("VertexShader")){
  28.              vertName = split[1].trim();
  29. -        }else if (typeAndLang[0].equals("FragmentShader")){
  30. +        } else if (typeAndLang[0].equals("FragmentShader")){
  31.              fragName = split[1].trim();
  32. +        } else if (typeAndLang[0].equals("GeometryShader")){
  33. +            geomName = split[1].trim();
  34. +        } else if (typeAndLang[0].equals("TessControlShader")){
  35. +            tcName = split[1].trim();
  36. +        } else if (typeAndLang[0].equals("TessEvaluationShader")){
  37. +            teName = split[1].trim();
  38.          }
  39.      }
  40.  
  41. @@ -372,7 +381,10 @@
  42.      private void readTechniqueStatement(Statement statement) throws IOException{
  43.          String[] split = statement.getLine().split("[ \\{]");
  44.          if (split[0].equals("VertexShader") ||
  45. -            split[0].equals("FragmentShader")){
  46. +                split[0].equals("FragmentShader") ||
  47. +                split[0].equals("GeometryShader") ||
  48. +                split[0].equals("TessControlShader") ||
  49. +                split[0].equals("TessEvaluationShader")) {
  50.              readShaderStatement(statement.getLine());
  51.          }else if (split[0].equals("LightMode")){
  52.              readLightMode(statement.getLine());
  53. @@ -412,13 +424,16 @@
  54.          }
  55.  
  56.          if (vertName != null && fragName != null){
  57. -            technique.setShaderFile(vertName, fragName, shaderLang);
  58. +            technique.setShaderFile(vertName, fragName, geomName, tcName, teName, shaderLang);
  59.          }
  60.          
  61.          materialDef.addTechniqueDef(technique);
  62.          technique = null;
  63.          vertName = null;
  64.          fragName = null;
  65. +        geomName = null;
  66. +        tcName = null;
  67. +        teName = null;
  68.          shaderLang = null;
  69.      }
  70.  
  71. --- com/jme3/shader/Shader.java Mon Jan 19 23:26:36 1970
  72. +++ com/jme3/shader/Shader.java Mon Jan 19 23:26:36 1970
  73. @@ -87,7 +87,17 @@
  74.          /**
  75.           * Control geometry assembly. (e.g compile a triangle list from input data)
  76.           */
  77. -        Geometry;
  78. +        Geometry,
  79. +
  80. +        /**
  81. +         * Control hardware tesselation per vertex. (e.g allow to output multiple vertices from a single input)
  82. +         */
  83. +        TesselationControl,
  84. +
  85. +        /**
  86. +         * Control tesseled vertices. (e.g allow to reshape tesseled vertices)
  87. +         */
  88. +        TesselationEvaluation;
  89.      }
  90.  
  91.      /**
  92. --- com/jme3/renderer/Caps.java Mon Jan 19 23:26:36 1970
  93. +++ com/jme3/renderer/Caps.java Mon Jan 19 23:26:36 1970
  94. @@ -107,6 +107,11 @@
  95.      OpenGL32,
  96.  
  97.      /**
  98. +     * Supports OpenGL 4.0
  99. +     */
  100. +    OpenGL40,
  101. +
  102. +    /**
  103.       * Supports OpenGL ARB program.
  104.       * <p>
  105.       * OpenGL: Renderer exposes ARB_vertex_program and ARB_fragment_program
  106. @@ -150,6 +155,11 @@
  107.      GLSL330,
  108.  
  109.      /**
  110. +     * Supports GLSL 4.0
  111. +     */
  112. +    GLSL400,
  113. +
  114. +    /**
  115.       * Supports reading from textures inside the vertex shader.
  116.       */
  117.      VertexTextureFetch,
  118. @@ -158,6 +168,12 @@
  119.       * Supports geometry shader.
  120.       */
  121.      GeometryShader,
  122. +
  123. +
  124. +    /**
  125. +     * Supports tesselation shader.
  126. +     */
  127. +    TesselationShader,
  128.  
  129.      /**
  130.       * Supports texture arrays
  131. --- com/jme3/asset/Desktop.cfg  Mon Jan 19 23:26:36 1970
  132. +++ com/jme3/asset/Desktop.cfg  Mon Jan 19 23:26:36 1970
  133. @@ -19,4 +19,4 @@
  134.  LOADER com.jme3.scene.plugins.ogre.MaterialLoader : material
  135.  LOADER com.jme3.scene.plugins.ogre.SceneLoader : scene
  136.  LOADER com.jme3.scene.plugins.blender.BlenderModelLoader : blend
  137. -LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, glsl, glsllib
  138. +LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, geom, tsctrl, tseval, glsl, glsllib
  139. --- com/jme3/asset/DesktopAssetManager.java Mon Jan 19 23:26:36 1970
  140. +++ com/jme3/asset/DesktopAssetManager.java Mon Jan 19 23:26:36 1970
  141. @@ -393,13 +393,27 @@
  142.          if (s == null){
  143.              String vertName = key.getVertName();
  144.              String fragName = key.getFragName();
  145. +           String geomName = key.getGeomName();
  146. +           String tcName = key.getTCName();
  147. +           String teName = key.getTEName();
  148.  
  149.              String vertSource = (String) loadAsset(new AssetKey(vertName));
  150.              String fragSource = (String) loadAsset(new AssetKey(fragName));
  151. +           String geomSource = geomName == null ? null : (String) loadAsset(new AssetKey(geomName));
  152. +           String tcSource = tcName == null ? null : (String) loadAsset(new AssetKey(tcName));
  153. +           String teSource = teName == null ? null : (String) loadAsset(new AssetKey(teName));
  154. +
  155.  
  156.              s = new Shader(key.getLanguage());
  157.              s.addSource(Shader.ShaderType.Vertex,   vertName, vertSource, key.getDefines().getCompiled());
  158.              s.addSource(Shader.ShaderType.Fragment, fragName, fragSource, key.getDefines().getCompiled());
  159. +           if (geomName != null)
  160. +               s.addSource(Shader.ShaderType.Geometry, geomName, geomSource, key.getDefines().getCompiled());
  161. +           if (tcName != null)
  162. +               s.addSource(Shader.ShaderType.TesselationControl, tcName, tcSource, key.getDefines().getCompiled());
  163. +           if (teName != null)
  164. +               s.addSource(Shader.ShaderType.TesselationEvaluation, teName, teSource, key.getDefines().getCompiled());
  165. +
  166.  
  167.              cache.addToCache(key, s);
  168.          }
  169. --- com/jme3/scene/Mesh.java    Mon Jan 19 23:26:36 1970
  170. +++ com/jme3/scene/Mesh.java    Mon Jan 19 23:26:36 1970
  171. @@ -135,7 +135,19 @@
  172.           * {@link Mesh#setElementLengths(int[]) element lengths} must
  173.           * be specified for this mode.
  174.           */
  175. -        Hybrid(false);
  176. +        Hybrid(false),
  177. +
  178. +       /**
  179. +        * A primitive is a patch. The number of vertices of a patches can be
  180. +        * set by the user. Used for tesselation process. This mode is only
  181. +        * compatible with OpenGL 4.0 and above so its better to avoid it if not
  182. +        * needed. Patches are intended to be used with tesselation shaders.
  183. +        *
  184. +        * To change the number of vertices of a patch, look at
  185. +        * {@link Mesh#setPatchVertices(int)} and
  186. +        * {@link Mesh#getPatchVertices()}.
  187. +        */
  188. +       Patches(true);
  189.          
  190.          private boolean listMode = false;
  191.          
  192. @@ -170,6 +182,7 @@
  193.      private VertexBuffer[] lodLevels;
  194.      private float pointSize = 1;
  195.      private float lineWidth = 1;
  196. +   private int patchVertices = 3;
  197.  
  198.      private transient int vertexArrayID = -1;
  199.  
  200. @@ -510,6 +523,28 @@
  201.      public void setPointSize(float pointSize) {
  202.          this.pointSize = pointSize;
  203.      }
  204. +    
  205. +    /**
  206. +    * Returns the number of vertices per patch. For meshes in Patch mode only.
  207. +    *
  208. +    * @return the number of vertices per patch.
  209. +    *
  210. +    * @see #setPatchVertices(int)
  211. +    */
  212. +   public int getPatchVertices() {
  213. +       return patchVertices;
  214. +   }
  215. +
  216. +   /**
  217. +    * Set the number of vertices per patch. For meshes in Patch mode only.
  218. +    *
  219. +    * @param patchVertices
  220. +    *            the number of vertices per patch.
  221. +     * @see #getPatchVertices()
  222. +    */
  223. +   public void setPatchVertices(int patchVertices) {
  224. +       this.patchVertices = patchVertices;
  225. +   }
  226.  
  227.      /**
  228.       * Returns the line width for line meshes.
  229. --- com/jme3/material/TechniqueDef.java Mon Jan 19 23:26:36 1970
  230. +++ com/jme3/material/TechniqueDef.java Mon Jan 19 23:26:36 1970
  231. @@ -101,6 +101,9 @@
  232.  
  233.      private String vertName;
  234.      private String fragName;
  235. +    private String geomName;
  236. +    private String tessControlName;
  237. +    private String tessEvalName;
  238.      private String shaderLang;
  239.      private DefineList presetDefines;
  240.      private boolean usesShaders;
  241. @@ -225,16 +228,28 @@
  242.       *
  243.       * @param vertexShader The name of the vertex shader
  244.       * @param fragmentShader The name of the fragment shader
  245. +     * @param geometryShader The name of the geometry shader
  246. +     * @param tessControlShader The name of the tesselation control shader
  247. +     * @param tessEvaluationShader The name of the tesselation evaluation shader
  248.       * @param shaderLanguage The shader language
  249.       */
  250. -    public void setShaderFile(String vertexShader, String fragmentShader, String shaderLanguage){
  251. +   public void setShaderFile(String vertexShader, String fragmentShader, String geometryShader,
  252. +           String tessControlShader, String tessEvaluationShader, String shaderLanguage) {
  253.          this.vertName = vertexShader;
  254.          this.fragName = fragmentShader;
  255. +        this.geomName = geometryShader;
  256. +        this.tessControlName = tessControlShader;
  257. +        this.tessEvalName = tessEvaluationShader;
  258.          this.shaderLang = shaderLanguage;
  259.  
  260.          Caps langCap = Caps.valueOf(shaderLanguage);
  261.          requiredCaps.add(langCap);
  262.  
  263. +        if(geomName != null)
  264. +           requiredCaps.add(Caps.GeometryShader);
  265. +        if(tessControlName != null || tessEvaluationShader != null)
  266. +           requiredCaps.add(Caps.TesselationShader);
  267. +        
  268.          usesShaders = true;
  269.      }
  270.  
  271. @@ -315,6 +330,39 @@
  272.  
  273.      
  274.      /**
  275. +     * Returns the name of the geometry shader used by the technique, or null
  276. +     * if no geometry shader is specified.
  277. +     *
  278. +     * @return the name of the geometry shader to be used.
  279. +     */
  280. +    public String getGeometryShaderName() {
  281. +        return geomName;
  282. +    }
  283. +
  284. +
  285. +    /**
  286. +     * Returns the name of the tessellation control shader used by the technique, or null
  287. +     * if no tessellation control shader is specified.
  288. +     *
  289. +     * @return the name of the tessellation control shader to be used.
  290. +     */
  291. +    public String getTessControlShaderName() {
  292. +        return tessControlName;
  293. +    }
  294. +
  295. +
  296. +    /**
  297. +     * Returns the name of the tessellation evaluation shader used by the technique, or null
  298. +     * if no tessellation evaluation shader is specified.
  299. +     *
  300. +     * @return the name of the tessellation evaluation shader to be used.
  301. +     */
  302. +    public String getTessEvaluationShaderName() {
  303. +        return tessEvalName;
  304. +    }
  305. +
  306. +    
  307. +    /**
  308.       * Returns the name of the vertex shader used by the technique, or null
  309.       * if no vertex shader is specified.
  310.       *
  311. @@ -368,6 +416,9 @@
  312.          oc.write(name, "name", null);
  313.          oc.write(vertName, "vertName", null);
  314.          oc.write(fragName, "fragName", null);
  315. +        oc.write(geomName, "geomName", null);
  316. +        oc.write(tessControlName, "tessControlName", null);
  317. +        oc.write(tessEvalName, "tessEvalName", null);
  318.          oc.write(shaderLang, "shaderLang", null);
  319.          oc.write(presetDefines, "presetDefines", null);
  320.          oc.write(lightMode, "lightMode", LightMode.Disable);
  321. @@ -385,6 +436,9 @@
  322.          name = ic.readString("name", null);
  323.          vertName = ic.readString("vertName", null);
  324.          fragName = ic.readString("fragName", null);
  325. +        geomName = ic.readString("geomName", null);
  326. +        tessControlName = ic.readString("tessControlName", null);
  327. +        tessEvalName = ic.readString("tessEvalName", null);
  328.          shaderLang = ic.readString("shaderLang", null);
  329.          presetDefines = (DefineList) ic.readSavable("presetDefines", null);
  330.          lightMode = ic.readEnum("lightMode", LightMode.class, LightMode.Disable);
  331. --- com/jme3/shader/ShaderKey.java  Mon Jan 19 23:26:36 1970
  332. +++ com/jme3/shader/ShaderKey.java  Mon Jan 19 23:26:36 1970
  333. @@ -42,22 +42,30 @@
  334.  public class ShaderKey extends AssetKey<Shader> {
  335.  
  336.      protected String fragName;
  337. +   protected String geomName;
  338. +   protected String tcName;
  339. +   protected String teName;
  340.      protected DefineList defines;
  341.      protected String language;
  342.  
  343.      public ShaderKey(){
  344.      }
  345.  
  346. -    public ShaderKey(String vertName, String fragName, DefineList defines, String lang){
  347. +    public ShaderKey(String vertName, String fragName, String geomName, String tcName, String teName, DefineList defines, String lang) {
  348.          super(vertName);
  349.          this.fragName = fragName;
  350. +       this.geomName = geomName;
  351. +       this.tcName = tcName;
  352. +       this.teName = teName;
  353.          this.defines = defines;
  354.          this.language = lang;
  355.      }
  356.  
  357.      @Override
  358.      public String toString(){
  359. -        return "V="+name + " F=" + fragName + (defines != null ? defines : "");
  360. +        return "V=" + name + " F=" + fragName + (geomName != null ? " G=" + geomName : "")
  361. +               + (tcName != null ? " TC=" + tcName : "") + (teName != null ? " TE=" + teName : "F")
  362. +               + (defines != null ? defines : "");
  363.      }
  364.  
  365.      @Override
  366. @@ -70,7 +78,10 @@
  367.          }
  368.  
  369.          final ShaderKey other = (ShaderKey) obj;
  370. -        if (name.equals(other.name) && fragName.equals(other.fragName)){
  371. +        if (name.equals(other.name) && fragName.equals(other.fragName)
  372. +               && (geomName == null ? other.geomName == null : geomName.equals(other.geomName))
  373. +               && (tcName == null ? other.tcName == null : tcName.equals(other.tcName))
  374. +               && (teName == null ? other.teName == null : teName.equals(other.teName))) {
  375.  //            return true;
  376.              if (defines != null && other.defines != null)
  377.                  return defines.getCompiled().equals(other.defines.getCompiled());
  378. @@ -103,6 +114,18 @@
  379.          return fragName;
  380.      }
  381.  
  382. +   public String getGeomName() {
  383. +       return geomName;
  384. +   }
  385. +
  386. +   public String getTCName() {
  387. +       return tcName;
  388. +   }
  389. +
  390. +   public String getTEName() {
  391. +       return teName;
  392. +   }
  393. +
  394.      public String getLanguage() {
  395.          return language;
  396.      }
  397. @@ -112,6 +135,9 @@
  398.          super.write(ex);
  399.          OutputCapsule oc = ex.getCapsule(this);
  400.          oc.write(fragName, "fragment_name", null);
  401. +       oc.write(geomName, "geometry_name", null);
  402. +       oc.write(tcName, "tess_control_name", null);
  403. +       oc.write(teName, "tess_eval_name", null);
  404.          oc.write(language, "language", null);
  405.      }
  406.  
  407. @@ -120,6 +146,9 @@
  408.          super.read(im);
  409.          InputCapsule ic = im.getCapsule(this);
  410.          fragName = ic.readString("fragment_name", null);
  411. +       geomName = ic.readString("geometry_name", null);
  412. +       tcName = ic.readString("tess_control_name", null);
  413. +       teName = ic.readString("tess_eval_name", null);
  414.          language = ic.readString("language", null);
  415.      }
  416.  
  417. --- com/jme3/renderer/lwjgl/LwjglRenderer.java  Mon Jan 19 23:26:36 1970
  418. +++ com/jme3/renderer/lwjgl/LwjglRenderer.java  Mon Jan 19 23:26:36 1970
  419. @@ -147,6 +147,11 @@
  420.                          caps.add(Caps.OpenGL31);
  421.                          if (ctxCaps.OpenGL32) {
  422.                              caps.add(Caps.OpenGL32);
  423. +                           caps.add(Caps.GeometryShader);
  424. +                           if (ctxCaps.OpenGL40) {
  425. +                               caps.add(Caps.OpenGL40);
  426. +                               caps.add(Caps.TesselationShader);
  427. +                           }
  428.                          }
  429.                      }
  430.                  }
  431. @@ -193,7 +198,9 @@
  432.  
  433.              // fall through intentional
  434.              case 400:
  435. +               caps.add(Caps.GLSL400);
  436.              case 330:
  437. +               caps.add(Caps.GLSL330);
  438.              case 150:
  439.                  caps.add(Caps.GLSL150);
  440.              case 140:
  441. @@ -921,8 +928,12 @@
  442.                  return GL_FRAGMENT_SHADER;
  443.              case Vertex:
  444.                  return GL_VERTEX_SHADER;
  445. -//            case Geometry:
  446. -//                return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB;
  447. +            case Geometry:
  448. +               return org.lwjgl.opengl.GL32.GL_GEOMETRY_SHADER;
  449. +           case TesselationControl:
  450. +               return org.lwjgl.opengl.GL40.GL_TESS_CONTROL_SHADER;
  451. +           case TesselationEvaluation:
  452. +               return org.lwjgl.opengl.GL40.GL_TESS_EVALUATION_SHADER;
  453.              default:
  454.                  throw new UnsupportedOperationException("Unrecognized shader type.");
  455.          }
  456. @@ -956,6 +967,12 @@
  457.                  }
  458.                  stringBuf.append("\n");
  459.              }
  460. +            
  461. +            if ((source.getType() == ShaderType.TesselationControl || source.getType() == ShaderType.TesselationEvaluation)
  462. +                   && version < 400)
  463. +               throw new RendererException("GLSL version for tessellation shaders must be 4.0 or above.");
  464. +           else if (source.getType() == ShaderType.Geometry && version < 150)
  465. +               throw new RendererException("GLSL version for geometry shader must be 1.5 or above.");
  466.          }
  467.          updateNameBuffer();
  468.  
  469. @@ -2353,6 +2370,8 @@
  470.                  return GL_TRIANGLE_FAN;
  471.              case TriangleStrip:
  472.                  return GL_TRIANGLE_STRIP;
  473. +            case Patches:
  474. +               return org.lwjgl.opengl.GL40.GL_PATCHES;
  475.              default:
  476.                  throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
  477.          }
  478. @@ -2492,6 +2511,10 @@
  479.              glLineWidth(mesh.getLineWidth());
  480.              context.lineWidth = mesh.getLineWidth();
  481.          }
  482. +       if (mesh.getMode() == Mode.Patches) {
  483. +           checkCap(Caps.OpenGL40);
  484. +           org.lwjgl.opengl.GL40.glPatchParameteri(org.lwjgl.opengl.GL40.GL_PATCH_VERTICES, mesh.getPatchVertices());
  485. +       }
  486.  
  487.          statistics.onMeshDrawn(mesh, lod);
  488.  //        if (GLContext.getCapabilities().GL_ARB_vertex_array_object){
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement