コード例 #1
0
ファイル: EGLContext.java プロジェクト: davidcl/jogl
 @Override
 protected void resetStates() {
   eglQueryStringInitialized = false;
   eglQueryStringAvailable = false;
   eglExtProcAddressTable = null;
   // no inner state _eglExt = null;
   super.resetStates();
 }
コード例 #2
0
    @Override
    public SharedResourceRunner.Resource createSharedResource(String connection) {
      final X11GraphicsDevice sharedDevice =
          new X11GraphicsDevice(
              X11Util.openDisplay(connection),
              AbstractGraphicsDevice.DEFAULT_UNIT,
              true /* owner */);
      sharedDevice.lock();
      try {
        final X11GraphicsScreen sharedScreen =
            new X11GraphicsScreen(sharedDevice, sharedDevice.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(sharedDevice);
        final String glXServerVendorName =
            GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(sharedDevice.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp =
            GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + sharedDevice);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl sharedDrawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(sharedDevice, false, caps, caps, null, 64, 64));
        sharedDrawable.setRealized(true);
        final X11GLCapabilities chosenCaps =
            (X11GLCapabilities) sharedDrawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(sharedDevice);
        }
        final GLContextImpl sharedContext = (GLContextImpl) sharedDrawable.createContext(null);
        if (null == sharedContext) {
          throw new GLException("Couldn't create shared context for drawable: " + sharedDrawable);
        }

        boolean madeCurrent = false;
        sharedContext.makeCurrent();
        try {
          madeCurrent = sharedContext.isCurrent();
        } finally {
          sharedContext.release();
        }
        if (sharedContext.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG) {
          System.err.println("SharedDevice:  " + sharedDevice);
          System.err.println("SharedScreen:  " + sharedScreen);
          System.err.println("SharedContext: " + sharedContext + ", madeCurrent " + madeCurrent);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            sharedDevice,
            sharedScreen,
            sharedDrawable,
            sharedContext,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + connection, t);
      } finally {
        sharedDevice.unlock();
      }
    }
コード例 #3
0
 @Override
 public GLRendererQuirks getRendererQuirks() {
   return null != context ? context.getRendererQuirks() : null;
 }
コード例 #4
0
ファイル: EGLContext.java プロジェクト: davidcl/jogl
  @Override
  protected boolean createImpl(GLContextImpl shareWith) throws GLException {
    final EGLGraphicsConfiguration config =
        (EGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration();
    final long eglDisplay = config.getScreen().getDevice().getHandle();
    final GLProfile glProfile = drawable.getGLProfile();
    final long eglConfig = config.getNativeConfig();
    long shareWithHandle = EGL.EGL_NO_CONTEXT;

    if (0 == eglDisplay) {
      throw new GLException(
          "Error: attempted to create an OpenGL context without a display connection");
    }
    if (0 == eglConfig) {
      throw new GLException(
          "Error: attempted to create an OpenGL context without a graphics configuration");
    }

    try {
      // might be unavailable on EGL < 1.2
      if (!EGL.eglBindAPI(EGL.EGL_OPENGL_ES_API)) {
        throw new GLException(
            "Catched: eglBindAPI to ES failed , error 0x" + Integer.toHexString(EGL.eglGetError()));
      }
    } catch (GLException glex) {
      if (DEBUG) {
        glex.printStackTrace();
      }
    }

    if (shareWith != null) {
      shareWithHandle = shareWith.getHandle();
      if (shareWithHandle == 0) {
        throw new GLException("GLContextShareSet returned an invalid OpenGL context");
      }
    }

    final IntBuffer contextAttrsNIO;
    {
      final int[] contextAttrs = new int[] {EGL.EGL_CONTEXT_CLIENT_VERSION, -1, EGL.EGL_NONE};
      if (glProfile.usesNativeGLES2()) {
        contextAttrs[1] = 2;
      } else if (glProfile.usesNativeGLES1()) {
        contextAttrs[1] = 1;
      } else {
        throw new GLException("Error creating OpenGL context - invalid GLProfile: " + glProfile);
      }
      contextAttrsNIO = Buffers.newDirectIntBuffer(contextAttrs);
    }
    contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWithHandle, contextAttrsNIO);
    if (contextHandle == 0) {
      throw new GLException(
          "Error creating OpenGL context: eglDisplay "
              + toHexString(eglDisplay)
              + ", eglConfig "
              + config
              + ", "
              + glProfile
              + ", shareWith "
              + toHexString(shareWithHandle)
              + ", error "
              + toHexString(EGL.eglGetError()));
    }
    if (DEBUG) {
      System.err.println(
          getThreadName()
              + ": Created OpenGL context 0x"
              + Long.toHexString(contextHandle)
              + ",\n\twrite surface 0x"
              + Long.toHexString(drawable.getHandle())
              + ",\n\tread  surface 0x"
              + Long.toHexString(drawableRead.getHandle())
              + ",\n\t"
              + this
              + ",\n\tsharing with 0x"
              + Long.toHexString(shareWithHandle));
    }
    if (!EGL.eglMakeCurrent(
        eglDisplay, drawable.getHandle(), drawableRead.getHandle(), contextHandle)) {
      throw new GLException(
          "Error making context "
              + toHexString(contextHandle)
              + " current: error code "
              + toHexString(EGL.eglGetError()));
    }
    setGLFunctionAvailability(true, glProfile.usesNativeGLES2() ? 2 : 1, 0, CTX_PROFILE_ES);
    return true;
  }
コード例 #5
0
    @Override
    public SharedResourceRunner.Resource createSharedResource(
        final AbstractGraphicsDevice adevice) {
      final X11GraphicsDevice device =
          new X11GraphicsDevice(
              X11Util.openDisplay(adevice.getConnection()), adevice.getUnitID(), true /* owner */);
      GLContextImpl context = null;
      boolean contextIsCurrent = false;
      device.lock();
      try {
        final X11GraphicsScreen screen = new X11GraphicsScreen(device, device.getDefaultScreen());

        GLXUtil.initGLXClientDataSingleton(device);
        final String glXServerVendorName =
            GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_VENDOR);
        final boolean glXServerMultisampleAvailable =
            GLXUtil.isMultisampleAvailable(
                GLX.glXQueryServerString(device.getHandle(), 0, GLX.GLX_EXTENSIONS));

        final GLProfile glp = GLProfile.get(device, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false);
        if (null == glp) {
          throw new GLException("Couldn't get default GLProfile for device: " + device);
        }

        final GLCapabilitiesImmutable caps = new GLCapabilities(glp);
        final GLDrawableImpl drawable =
            createOnscreenDrawableImpl(
                createDummySurfaceImpl(device, false, caps, caps, null, 64, 64));
        drawable.setRealized(true);
        final X11GLCapabilities chosenCaps = (X11GLCapabilities) drawable.getChosenGLCapabilities();
        final boolean glxForcedOneOne = !chosenCaps.hasFBConfig();
        final VersionNumber glXServerVersion;
        if (glxForcedOneOne) {
          glXServerVersion = versionOneOne;
        } else {
          glXServerVersion = GLXUtil.getGLXServerVersionNumber(device);
        }
        context = (GLContextImpl) drawable.createContext(null);
        if (null == context) {
          throw new GLException("Couldn't create shared context for drawable: " + drawable);
        }
        contextIsCurrent = GLContext.CONTEXT_NOT_CURRENT != context.makeCurrent();

        final boolean allowsSurfacelessCtx;
        if (contextIsCurrent && context.getGLVersionNumber().compareTo(GLContext.Version3_0) >= 0) {
          allowsSurfacelessCtx = probeSurfacelessCtx(context, true /* restoreDrawable */);
        } else {
          setNoSurfacelessCtxQuirk(context);
          allowsSurfacelessCtx = false;
        }

        if (context.hasRendererQuirk(GLRendererQuirks.DontCloseX11Display)) {
          X11Util.markAllDisplaysUnclosable();
        }
        if (DEBUG_SHAREDCTX) {
          System.err.println("SharedDevice:  " + device);
          System.err.println("SharedScreen:  " + screen);
          System.err.println("SharedContext: " + context + ", madeCurrent " + contextIsCurrent);
          System.err.println("  allowsSurfacelessCtx " + allowsSurfacelessCtx);
          System.err.println("GLX Server Vendor:      " + glXServerVendorName);
          System.err.println(
              "GLX Server Version:     " + glXServerVersion + ", forced " + glxForcedOneOne);
          System.err.println("GLX Server Multisample: " + glXServerMultisampleAvailable);
          System.err.println("GLX Client Vendor:      " + GLXUtil.getClientVendorName());
          System.err.println("GLX Client Version:     " + GLXUtil.getClientVersionNumber());
          System.err.println("GLX Client Multisample: " + GLXUtil.isClientMultisampleAvailable());
        }
        return new SharedResource(
            device,
            screen,
            drawable,
            context,
            glXServerVersion,
            glXServerVendorName,
            glXServerMultisampleAvailable && GLXUtil.isClientMultisampleAvailable());
      } catch (final Throwable t) {
        throw new GLException(
            "X11GLXDrawableFactory - Could not initialize shared resources for " + adevice, t);
      } finally {
        if (contextIsCurrent) {
          context.release();
        }
        device.unlock();
      }
    }
コード例 #6
0
 @Override
 public GLRendererQuirks getRendererQuirks(final GLProfile glp) {
   return null != context ? context.getRendererQuirks() : null;
 }