示例#1
0
  public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glRasterPos2i(1, 1);
    gl.glDrawPixels(
        dim.width,
        dim.height, //
        GL.GL_RGB,
        GL.GL_UNSIGNED_BYTE,
        pixels);

    gl.glFlush();
  }
示例#2
0
  static GL15 create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("OpenGL15")) return null;

    GL15 funcs = new GL15(provider);

    boolean supported =
        checkFunctions(
            funcs.BindBuffer,
            funcs.DeleteBuffers,
            funcs.GenBuffers,
            funcs.IsBuffer,
            funcs.BufferData,
            funcs.BufferSubData,
            funcs.GetBufferSubData,
            funcs.MapBuffer,
            funcs.UnmapBuffer,
            funcs.GetBufferParameteriv,
            funcs.GetBufferPointerv,
            funcs.GenQueries,
            funcs.DeleteQueries,
            funcs.IsQuery,
            funcs.BeginQuery,
            funcs.EndQuery,
            funcs.GetQueryiv,
            funcs.GetQueryObjectiv,
            funcs.GetQueryObjectuiv);

    return GL.checkExtension("OpenGL15", funcs, supported);
  }
示例#3
0
 /** Returns true if a hader compiler is available, otherwise false. */
 public static boolean isShaderCompilerAvailable(final GL _gl) {
   final GL2ES2 gl = _gl.getGL2ES2();
   final ProfileInformation info = getProfileInformation(gl);
   if (null == info.shaderCompilerAvailable) {
     if (gl.isGLES2()) {
       boolean queryOK = false;
       try {
         final byte[] param = new byte[1];
         gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0);
         final int err = gl.glGetError();
         boolean v = GL.GL_NO_ERROR == err && param[0] != (byte) 0x00;
         if (!v) {
           final Set<Integer> bfs = getShaderBinaryFormats(gl);
           if (bfs.size() == 0) {
             // no supported binary formats, hence a compiler must be available!
             v = true;
           }
         }
         info.shaderCompilerAvailable = Boolean.valueOf(v);
         queryOK = true;
       } catch (final GLException gle) {
         System.err.println("Caught exception on thread " + Thread.currentThread().getName());
         gle.printStackTrace();
       }
       if (!queryOK) {
         info.shaderCompilerAvailable = Boolean.valueOf(true);
       }
     } else if (gl.isGL2ES2()) {
       info.shaderCompilerAvailable = new Boolean(true);
     } else {
       throw new GLException("Invalid OpenGL profile");
     }
   }
   return info.shaderCompilerAvailable.booleanValue();
 }
示例#4
0
 /**
  * If supported, queries the natively supported shader binary formats using {@link
  * GL2ES2#GL_NUM_SHADER_BINARY_FORMATS} and {@link GL2ES2#GL_SHADER_BINARY_FORMATS} via {@link
  * GL2ES2#glGetIntegerv(int, int[], int)}.
  */
 public static Set<Integer> getShaderBinaryFormats(final GL _gl) {
   final GL2ES2 gl = _gl.getGL2ES2();
   final ProfileInformation info = getProfileInformation(gl);
   if (null == info.shaderBinaryFormats) {
     info.shaderBinaryFormats = new HashSet<Integer>();
     if (gl.isGLES2Compatible()) {
       try {
         final int[] param = new int[1];
         gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0);
         final int err = gl.glGetError();
         final int numFormats = GL.GL_NO_ERROR == err ? param[0] : 0;
         if (numFormats > 0) {
           final int[] formats = new int[numFormats];
           gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0);
           for (int i = 0; i < numFormats; i++) {
             info.shaderBinaryFormats.add(Integer.valueOf(formats[i]));
           }
         }
       } catch (final GLException gle) {
         System.err.println("Caught exception on thread " + Thread.currentThread().getName());
         gle.printStackTrace();
       }
     }
   }
   return info.shaderBinaryFormats;
 }
示例#5
0
  public static boolean createAndLoadShader(
      final GL _gl,
      final IntBuffer shader,
      final int shaderType,
      final int binFormat,
      final java.nio.Buffer bin,
      final PrintStream verboseOut) {
    final GL2ES2 gl = _gl.getGL2ES2();
    int err = gl.glGetError(); // flush previous errors ..
    if (err != GL.GL_NO_ERROR && null != verboseOut) {
      verboseOut.println("createAndLoadShader: Pre GL Error: 0x" + Integer.toHexString(err));
    }

    createShader(gl, shaderType, shader);
    err = gl.glGetError();
    if (err != GL.GL_NO_ERROR) {
      throw new GLException(
          "createAndLoadShader: CreateShader failed, GL Error: 0x" + Integer.toHexString(err));
    }

    shaderBinary(gl, shader, binFormat, bin);

    err = gl.glGetError();
    if (err != GL.GL_NO_ERROR && null != verboseOut) {
      verboseOut.println(
          "createAndLoadShader: ShaderBinary failed, GL Error: 0x" + Integer.toHexString(err));
    }
    return err == GL.GL_NO_ERROR;
  }
示例#6
0
文件: Main.java 项目: Osoldier/Vox
 private void InitGL() {
   GL.createCapabilities();
   System.out.println("OpenGL: " + glGetString(GL_VERSION));
   glEnable(GL13.GL_MULTISAMPLE);
   glEnable(GL_DEPTH_TEST);
   glViewport(0, 0, pix_width, pix_height);
 }
示例#7
0
  public static boolean isProgramStatusValid(final GL _gl, final int programObj, final int name) {
    final GL2ES2 gl = _gl.getGL2ES2();
    final int[] ires = new int[1];
    gl.glGetProgramiv(programObj, name, ires, 0);

    return ires[0] == 1;
  }
示例#8
0
  public static void shaderSource(final GL _gl, final int shader, final CharSequence[] source) {
    final GL2ES2 gl = _gl.getGL2ES2();
    if (!isShaderCompilerAvailable(_gl)) {
      throw new GLException("No compiler is available");
    }

    final int count = (null != source) ? source.length : 0;
    if (count == 0) {
      throw new GLException("No sources specified");
    }

    final IntBuffer lengths = Buffers.newDirectIntBuffer(count);
    for (int i = 0; i < count; i++) {
      lengths.put(i, source[i].length());
    }
    if (source instanceof String[]) {
      // rare case ..
      gl.glShaderSource(shader, count, (String[]) source, lengths);
    } else {
      final String[] tmp = new String[source.length];
      for (int i = source.length - 1; i >= 0; i--) {
        final CharSequence csq = source[i];
        if (csq instanceof String) {
          // if ShaderCode.create(.. mutableStringBuilder == false )
          tmp[i] = (String) csq;
        } else {
          // if ShaderCode.create(.. mutableStringBuilder == true )
          tmp[i] = source[i].toString();
        }
      }
      gl.glShaderSource(shader, count, tmp, lengths);
    }
  }
示例#9
0
 /** Array version of: {@link #glVertexAttribI2uivEXT VertexAttribI2uivEXT} */
 public static void glVertexAttribI2uivEXT(int index, int[] v) {
   long __functionAddress = GL.getCapabilities().glVertexAttribI2uivEXT;
   if (CHECKS) {
     checkFunctionAddress(__functionAddress);
     checkBuffer(v, 2);
   }
   callPV(__functionAddress, index, v);
 }
示例#10
0
 /** Array version of: {@link #glGetUniformuivEXT GetUniformuivEXT} */
 public static void glGetUniformuivEXT(int program, int location, int[] params) {
   long __functionAddress = GL.getCapabilities().glGetUniformuivEXT;
   if (CHECKS) {
     checkFunctionAddress(__functionAddress);
     checkBuffer(params, 1);
   }
   callPV(__functionAddress, program, location, params);
 }
示例#11
0
 /** Array version of: {@link #glGetVertexAttribIuivEXT GetVertexAttribIuivEXT} */
 public static void glGetVertexAttribIuivEXT(int index, int pname, int[] params) {
   long __functionAddress = GL.getCapabilities().glGetVertexAttribIuivEXT;
   if (CHECKS) {
     checkFunctionAddress(__functionAddress);
     checkBuffer(params, 4);
   }
   callPV(__functionAddress, index, pname, params);
 }
示例#12
0
 /** Array version of: {@link #glWindowPos3dvARB WindowPos3dvARB} */
 public static void glWindowPos3dvARB(double[] p) {
   long __functionAddress = GL.getCapabilities().glWindowPos3dvARB;
   if (CHECKS) {
     checkFunctionAddress(__functionAddress);
     checkBuffer(p, 3);
   }
   callPV(__functionAddress, p);
 }
示例#13
0
 /** int[] version of: {@link #glVertexAttribIPointerEXT VertexAttribIPointerEXT} */
 public static void glVertexAttribIPointerEXT(
     int index, int size, int type, int stride, int[] pointer) {
   long __functionAddress = GL.getCapabilities().glVertexAttribIPointerEXT;
   if (CHECKS) {
     checkFunctionAddress(__functionAddress);
     GLChecks.ensureBufferObject(GL15.GL_ARRAY_BUFFER_BINDING, false);
   }
   callPV(__functionAddress, index, size, type, stride, pointer);
 }
示例#14
0
  static NVPixelDataRange create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GL_NV_pixel_data_range")) return null;

    NVPixelDataRange funcs = new NVPixelDataRange(provider);

    boolean supported = checkFunctions(funcs.PixelDataRangeNV, funcs.FlushPixelDataRangeNV);

    return GL.checkExtension("GL_NV_pixel_data_range", funcs, supported);
  }
示例#15
0
  static GLX11 create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GLX_11")) return null;

    GLX11 funcs = new GLX11(provider);

    boolean supported =
        checkFunctions(funcs.QueryExtensionsString, funcs.GetClientString, funcs.QueryServerString);

    return GL.checkExtension("GLX_11", funcs, supported);
  }
示例#16
0
 private static ProfileInformation getProfileInformation(final GL gl) {
   final GLContext context = gl.getContext();
   context.validateCurrent();
   ProfileInformation data = (ProfileInformation) context.getAttachedObject(implObjectKey);
   if (data == null) {
     data = new ProfileInformation();
     context.attachObject(implObjectKey, data);
   }
   return data;
 }
 private void checkCompressedTextureExtensions(TextureData data) {
   GL gl = GLU.getCurrentGL();
   if (data.isDataCompressed()) {
     switch (data.getInternalFormat()) {
       case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
       case GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
         if (!gl.isExtensionAvailable("GL_EXT_texture_compression_s3tc")
             && !gl.isExtensionAvailable("GL_NV_texture_compression_vtc")) {
           throw new GLException("DXTn compressed textures not supported by this graphics card");
         }
         break;
       default:
         // FIXME: should test availability of more texture
         // compression extensions here
         break;
     }
   }
 }
示例#18
0
  public static boolean isShaderStatusValid(
      final GL _gl, final int shaderObj, final int name, final PrintStream verboseOut) {
    final GL2ES2 gl = _gl.getGL2ES2();
    final int[] ires = new int[1];
    gl.glGetShaderiv(shaderObj, name, ires, 0);

    final boolean res = ires[0] == 1;
    if (!res && null != verboseOut) {
      verboseOut.println("Shader status invalid: " + getShaderInfoLog(gl, shaderObj));
    }
    return res;
  }
  static NVBindlessMultiDrawIndirectCount create(
      java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GL_NV_bindless_multi_draw_indirect_count")) return null;

    NVBindlessMultiDrawIndirectCount funcs = new NVBindlessMultiDrawIndirectCount(provider);

    boolean supported =
        checkFunctions(
            funcs.MultiDrawArraysIndirectBindlessCountNV,
            funcs.MultiDrawElementsIndirectBindlessCountNV);

    return GL.checkExtension("GL_NV_bindless_multi_draw_indirect_count", funcs, supported);
  }
示例#20
0
  static GL12 create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("OpenGL12")) return null;

    GL12 funcs = new GL12(provider);

    boolean supported =
        checkFunctions(
            funcs.TexImage3D,
            funcs.TexSubImage3D,
            funcs.CopyTexSubImage3D,
            funcs.DrawRangeElements);

    return GL.checkExtension("OpenGL12", funcs, supported);
  }
示例#21
0
  public static String getProgramInfoLog(final GL _gl, final int programObj) {
    final GL2ES2 gl = _gl.getGL2ES2();
    final int[] infoLogLength = new int[1];
    gl.glGetProgramiv(programObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);

    if (infoLogLength[0] == 0) {
      return "(no info log)";
    }
    final int[] charsWritten = new int[1];
    final byte[] infoLogBytes = new byte[infoLogLength[0]];
    gl.glGetProgramInfoLog(programObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0);

    return new String(infoLogBytes, 0, charsWritten[0]);
  }
示例#22
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
    GL gl = drawable.getGL();

    gl.glViewport(0, 0, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, w, 0, h, -1.0, 1.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
示例#23
0
  static WGLNVGPUAffinity create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("WGL_NV_gpu_affinity")) return null;

    WGLNVGPUAffinity funcs = new WGLNVGPUAffinity(provider);

    boolean supported =
        checkFunctions(
            funcs.EnumGpusNV,
            funcs.EnumGpuDevicesNV,
            funcs.CreateAffinityDCNV,
            funcs.EnumGpusFromAffinityDCNV,
            funcs.DeleteDCNV);

    return GL.checkExtension("WGL_NV_gpu_affinity", funcs, supported);
  }
  static GLXEXTImportContext create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GLX_EXT_import_context")) return null;

    GLXEXTImportContext funcs = new GLXEXTImportContext(provider);

    boolean supported =
        checkFunctions(
            funcs.GetCurrentDisplayEXT,
            funcs.QueryContextInfoEXT,
            funcs.GetContextIDEXT,
            funcs.ImportContextEXT,
            funcs.FreeContextEXT);

    return GL.checkExtension("GLX_EXT_import_context", funcs, supported);
  }
  static EXTTextureInteger create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GL_EXT_texture_integer")) return null;

    EXTTextureInteger funcs = new EXTTextureInteger(provider);

    boolean supported =
        checkFunctions(
            funcs.ClearColorIiEXT,
            funcs.ClearColorIuiEXT,
            funcs.TexParameterIivEXT,
            funcs.TexParameterIuivEXT,
            funcs.GetTexParameterIivEXT,
            funcs.GetTexParameterIuivEXT);

    return GL.checkExtension("GL_EXT_texture_integer", funcs, supported);
  }
示例#26
0
 /**
  * Performs {@link GL2ES2#glValidateProgram(int)}
  *
  * <p>One shall only call this method while debugging and only if all required resources by the
  * shader are set.
  *
  * <p>Note: It is possible that a working shader program will fail validation. This has been
  * experienced on NVidia APX2500 and Tegra2.
  *
  * @see GL2ES2#glValidateProgram(int)
  */
 public static boolean isProgramExecStatusValid(
     final GL _gl, final int programObj, final PrintStream verboseOut) {
   final GL2ES2 gl = _gl.getGL2ES2();
   gl.glValidateProgram(programObj);
   if (!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) {
     if (null != verboseOut) {
       verboseOut.println(
           "Program validation failed: "
               + programObj
               + "\n\t"
               + getProgramInfoLog(gl, programObj));
     }
     return false;
   }
   return true;
 }
  static ARBShaderSubroutine create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GL_ARB_shader_subroutine")) return null;

    ARBShaderSubroutine funcs = new ARBShaderSubroutine(provider);

    boolean supported =
        checkFunctions(
            funcs.GetSubroutineUniformLocation,
            funcs.GetSubroutineIndex,
            funcs.GetActiveSubroutineUniformiv,
            funcs.GetActiveSubroutineUniformName,
            funcs.GetActiveSubroutineName,
            funcs.UniformSubroutinesuiv,
            funcs.GetUniformSubroutineuiv,
            funcs.GetProgramStageiv);

    return GL.checkExtension("GL_ARB_shader_subroutine", funcs, supported);
  }
示例#28
0
  static WGLNVDXInterop create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("WGL_NV_DX_interop")) return null;

    WGLNVDXInterop funcs = new WGLNVDXInterop(provider);

    boolean supported =
        checkFunctions(
            funcs.DXSetResourceShareHandleNV,
            funcs.DXOpenDeviceNV,
            funcs.DXCloseDeviceNV,
            funcs.DXRegisterObjectNV,
            funcs.DXUnregisterObjectNV,
            funcs.DXObjectAccessNV,
            funcs.DXLockObjectsNV,
            funcs.DXUnlockObjectsNV);

    return GL.checkExtension("WGL_NV_DX_interop", funcs, supported);
  }
示例#29
0
 public static boolean isProgramLinkStatusValid(
     final GL _gl, final int programObj, final PrintStream verboseOut) {
   final GL2ES2 gl = _gl.getGL2ES2();
   if (!gl.glIsProgram(programObj)) {
     if (null != verboseOut) {
       verboseOut.println("Program name invalid: " + programObj);
     }
     return false;
   }
   if (!isProgramStatusValid(gl, programObj, GL2ES2.GL_LINK_STATUS)) {
     if (null != verboseOut) {
       verboseOut.println(
           "Program link failed: " + programObj + "\n\t" + getProgramInfoLog(gl, programObj));
     }
     return false;
   }
   return true;
 }
  static GLXAMDGPUAssociation create(java.util.Set<String> ext, FunctionProvider provider) {
    if (!ext.contains("GLX_AMD_gpu_association")) return null;

    GLXAMDGPUAssociation funcs = new GLXAMDGPUAssociation(provider);

    boolean supported =
        checkFunctions(
            funcs.BlitContextFramebufferAMD,
            funcs.CreateAssociatedContextAMD,
            funcs.CreateAssociatedContextAttribsAMD,
            funcs.DeleteAssociatedContextAMD,
            funcs.GetContextGPUIDAMD,
            funcs.GetCurrentAssociatedContextAMD,
            funcs.GetGPUIDsAMD,
            funcs.GetGPUInfoAMD,
            funcs.MakeAssociatedContextCurrentAMD);

    return GL.checkExtension("GLX_AMD_gpu_association", funcs, supported);
  }