aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-jogl/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ardor3d-jogl/src/main')
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java11
-rw-r--r--ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java78
2 files changed, 83 insertions, 6 deletions
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
index b4bb91a..dab4d58 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/renderer/jogl/JoglContextCapabilities.java
@@ -3,7 +3,7 @@
*
* This file is part of Ardor3D.
*
- * Ardor3D is free software: you can redistribute it and/or modify it
+ * Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
@@ -13,6 +13,8 @@ package com.ardor3d.renderer.jogl;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
+import com.ardor3d.renderer.ContextCapabilities;
+import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2ES1;
@@ -20,9 +22,6 @@ import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GL2ES3;
import com.jogamp.opengl.GLAutoDrawable;
-import com.ardor3d.renderer.ContextCapabilities;
-import com.ardor3d.util.geom.jogl.DirectNioBuffersSet;
-
public class JoglContextCapabilities extends ContextCapabilities {
public JoglContextCapabilities(final GLAutoDrawable autodrawable, final DirectNioBuffersSet directNioBuffersSet) {
@@ -83,6 +82,8 @@ public class JoglContextCapabilities extends ContextCapabilities {
_tessellationShadersSupported = gl.isExtensionAvailable("GL_ARB_tessellation_shader") && _glslSupported;
+ _computeShaderSupported = gl.isExtensionAvailable("GL_ARB_compute_shader") && _glslSupported;
+
if (_glslSupported) {
if (gl.isGL2()) {
gl.glGetIntegerv(GL2.GL_MAX_VERTEX_ATTRIBS_ARB, buf);
@@ -112,7 +113,7 @@ public class JoglContextCapabilities extends ContextCapabilities {
// Max multisample samples.
if (gl.isExtensionAvailable("GL_EXT_framebuffer_multisample")
&& gl.isExtensionAvailable("GL_EXT_framebuffer_blit") && gl.isGL2ES3()) {
- gl.glGetIntegerv(GL2ES3.GL_MAX_SAMPLES, buf);
+ gl.glGetIntegerv(GL.GL_MAX_SAMPLES, buf);
_maxFBOSamples = buf.get(0);
} else {
_maxFBOSamples = 0;
diff --git a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
index 97bbc52..44e9b80 100644
--- a/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
+++ b/ardor3d-jogl/src/main/java/com/ardor3d/scene/state/jogl/JoglShaderObjectsStateUtil.java
@@ -31,6 +31,7 @@ import com.jogamp.opengl.GL;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GL2ES2;
import com.jogamp.opengl.GL3;
+import com.jogamp.opengl.GL3ES3;
import com.jogamp.opengl.GLContext;
public abstract class JoglShaderObjectsStateUtil {
@@ -312,7 +313,7 @@ public abstract class JoglShaderObjectsStateUtil {
}
}
- // Compile the tessellation control shader
+ // Compile the tessellation evaluation shader
final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
compiled.clear();
@@ -344,6 +345,64 @@ public abstract class JoglShaderObjectsStateUtil {
}
}
+ if (caps.isComputeShaderSupported()) {
+ if (state.getComputeShader() != null) {
+ if (state._computeShaderID != -1) {
+ removeCompShader(state);
+ }
+ if (gl.isGL2()) {
+ state._computeShaderID = (int) gl.getGL2().glCreateShaderObjectARB(GL3ES3.GL_COMPUTE_SHADER);
+ } else {
+ if (gl.isGL2ES2()) {
+ state._computeShaderID = gl.getGL2ES2().glCreateShader(GL3ES3.GL_COMPUTE_SHADER);
+ }
+ }
+
+ // Create the sources
+ final byte array[] = new byte[state.getComputeShader().limit()];
+ state.getComputeShader().rewind();
+ state.getComputeShader().get(array);
+ if (gl.isGL2()) {
+ gl.getGL2().glShaderSourceARB(state._computeShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glShaderSource(state._computeShaderID, 1, new String[] { new String(array) },
+ new int[] { array.length }, 0);
+ }
+ }
+
+ // Compile the compute shader
+ final JoglRenderContext context = (JoglRenderContext) ContextManager.getCurrentContext();
+ final IntBuffer compiled = context.getDirectNioBuffersSet().getSingleIntBuffer();
+ compiled.clear();
+ if (gl.isGL2()) {
+ gl.getGL2().glCompileShaderARB(state._computeShaderID);
+ gl.getGL2().glGetObjectParameterivARB(state._computeShaderID, GL2.GL_OBJECT_COMPILE_STATUS_ARB,
+ compiled);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glCompileShader(state._computeShaderID);
+ gl.getGL2ES2().glGetShaderiv(state._computeShaderID, GL2ES2.GL_COMPILE_STATUS, compiled);
+ }
+ }
+ checkShaderError(compiled.get(0), state._computeShaderID, state._computeShaderName);
+
+ // Attach the program
+ if (gl.isGL2()) {
+ gl.getGL2().glAttachObjectARB(state._programID, state._computeShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glAttachShader(state._programID, state._computeShaderID);
+ }
+ }
+
+ } else if (state._computeShaderID != -1) {
+ removeCompShader(state);
+ state._computeShaderID = -1;
+ }
+ }
+
if (gl.isGL2()) {
gl.getGL2().glLinkProgramARB(state._programID);
} else {
@@ -492,6 +551,23 @@ public abstract class JoglShaderObjectsStateUtil {
}
}
+ /** Removes the compute shader */
+ private static void removeCompShader(final GLSLShaderObjectsState state) {
+ final GL gl = GLContext.getCurrentGL();
+
+ if (state._computeShaderID != -1) {
+ if (gl.isGL2()) {
+ gl.getGL2().glDetachObjectARB(state._programID, state._computeShaderID);
+ gl.getGL2().glDeleteObjectARB(state._computeShaderID);
+ } else {
+ if (gl.isGL2ES2()) {
+ gl.getGL2ES2().glDetachShader(state._programID, state._computeShaderID);
+ gl.getGL2ES2().glDeleteShader(state._computeShaderID);
+ }
+ }
+ }
+ }
+
/**
* Check for shader errors. If an error is detected, program exits.
*