Ejemplo n.º 1
0
    bool
    create(WglDrawable *wglDrawable) {
        if (!hglrc) {
            HDC hDC = wglDrawable->hDC;

            hglrc = wglCreateContext(hDC);
            if (!hglrc) {
                std::cerr << "error: wglCreateContext failed\n";
                exit(1);
            }

            if (shareContext) {
                shareContext->create(wglDrawable);
            }

            if (!createARB(hDC)) {
                if (shareContext) {
                    BOOL bRet;
                    bRet = wglShareLists(shareContext->hglrc,
                                         hglrc);
                    if (!bRet) {
                        std::cerr
                            << "warning: wglShareLists failed: "
                            << std::hex << GetLastError() << std::dec
                            << "\n";
                    }
                }
            }
        }

        return true;
    }
Ejemplo n.º 2
0
COffscreenGLContext::COffscreenGLContext()
{
	//! this creates a 2nd OpenGL context on the >onscreen< window/HDC
	//! so don't render to the the default framebuffer (always bind FBOs,DLs,...) !!!

	//! get the main (onscreen) GL context
	HGLRC mainRC = wglGetCurrentContext();
	hdc = wglGetCurrentDC();
	if (!hdc || !mainRC) {
		throw opengl_error("Couldn't create an offscreen GL context: wglGetCurrentDC failed!");
	}


	//! create a 2nd GL context
	offscreenRC = wglCreateContext(hdc);
	if (!offscreenRC) {
		throw opengl_error("Couldn't create an offscreen GL context: wglCreateContext failed!");
	}


	//! share the GL resources (textures,DLists,shaders,...)
	if(!wglMakeCurrent(NULL, NULL))
		throw opengl_error("Could not deactivate rendering context");
	int status = wglShareLists(mainRC, offscreenRC);
	if(!wglMakeCurrent(hdc, mainRC))
		throw opengl_error("Could not activate rendering context");

	if (!status) {
		DWORD err = GetLastError();
		char msg[256];
		SNPRINTF(msg, 255, "Couldn't create an offscreen GL context: wglShareLists failed (error: %i)!", (int)err);
		throw opengl_error(msg);
	}
}
Ejemplo n.º 3
0
	Context::Context(Context *shared)
		: ContextSysBase()
	{
		assert( Context::current() == shared );

		mTarget = nullptr;
		mGLFormat = shared->mGLFormat;
		GPU::RenderTargetWin* previousSharedTarget = shared->mTarget;
		
		init();

		if ( shared->mGLFormat.versionMajor >= 3 )
		{
			initNewContext(shared->mHGLRC);
		}
		else
		{
			initOldContext();
			wglShareLists(shared->mHGLRC, mHGLRC);
		}

		shared->doneCurrent();

		makeCurrent();
		{
			GLenum wglewInitResult = wglewInit();
			GLenum glewInitResult = glewInit();
			assert(GLEW_OK == wglewInitResult && GLEW_OK == glewInitResult);
		}
		doneCurrent();

		shared->makeCurrent(previousSharedTarget);
	}
Ejemplo n.º 4
0
SDL_Thread* SDL_GL_CreateThread(int (*fn)(void *), void *data) {

  SDL_SysWMinfo info;
  SDL_VERSION(&info.version);
  if (SDL_GetWMInfo(&info) == -1) {
    // Could not get SDL version info.
    return NULL;
  }
  
  gl_thread_device = GetDC(info.window);

  gl_thread_context = wglCreateContext(gl_thread_device);
  if (gl_thread_context == NULL) {
    // Could not create new OpenGL context
    return NULL;
  }
  
  BOOL err = wglShareLists(info.hglrc, gl_thread_context);
  if (err == 0) {
    int code = GetLastError();
    //Could not get OpenGL share lists: %i
    return NULL;
  }
  
  gl_thread_func = fn;
  gl_thread_data = data;
  
  return SDL_CreateThread(gl_thread_create, NULL);

}
Ejemplo n.º 5
0
bool
makeCurrent(Drawable *drawable, Context *context)
{
    if (!drawable || !context) {
        return wglMakeCurrent(NULL, NULL);
    } else {
        WglDrawable *wglDrawable = static_cast<WglDrawable *>(drawable);
        WglContext *wglContext = static_cast<WglContext *>(context);

        if (!wglContext->hglrc) {
            wglContext->hglrc = wglCreateContext(wglDrawable->hDC);
            if (!wglContext->hglrc) {
                std::cerr << "error: wglCreateContext failed\n";
                exit(1);
                return false;
            }
            if (wglContext->shareContext) {
                BOOL bRet;
                bRet = wglShareLists(wglContext->shareContext->hglrc,
                                     wglContext->hglrc);
                if (!bRet) {
                    std::cerr << "warning: wglShareLists failed\n";
                }
            }
        }

        return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc);
    }
}
Ejemplo n.º 6
0
    WindowedGLContext (Component* const component_,
                       HGLRC contextToShareWith,
                       const OpenGLPixelFormat& pixelFormat)
        : renderContext (0),
          component (component_),
          dc (0)
    {
        initialiseGLExtensions();
        jassert (component != nullptr);
        createNativeWindow();

        PIXELFORMATDESCRIPTOR pfd;
        initialisePixelFormatDescriptor (pfd, pixelFormat);

        const int format = ChoosePixelFormat (dc, &pfd);

        if (format != 0)
            SetPixelFormat (dc, format, &pfd);

        renderContext = wglCreateContext (dc);

        if (renderContext != 0)
        {
            makeActive();
            initialiseGLExtensions();
            extensions.initialise();
            setPixelFormat (pixelFormat);

            if (contextToShareWith != 0)
                wglShareLists (contextToShareWith, renderContext);
        }
    }
Ejemplo n.º 7
0
int SDL_WM_CreateTempContext() {
  
  SDL_SysWMinfo info;
  SDL_VERSION(&info.version);
  if (SDL_GetWMInfo(&info) == -1) {
    // Could not get SDL version info.
    return 1;
  }
  
  temp_device = GetDC(info.window);

  temp_context = wglCreateContext(temp_device);
  if (temp_context == NULL) {
    // Could not create OpenGL context
    return 2;
  }

  if (!wglShareLists(info.hglrc, temp_context)) {
    // Could not share lists with temp context.
    return 3;
  }
  
  return 0;
  
}
Ejemplo n.º 8
0
static void create_opengl_context (struct claw_window *window) {
	window->device_context = GetDC (window->hwnd);
	PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_GENERIC_ACCELERATED|PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		32,
		0, 0, 0, 0, 0, 0, 0, 0,
		0, // accumulation buffer
		0, 0, 0, 0,
		0, // depth buffer
		0, // stencil buffer
		0, // aux buffers
		0, 0, 0, 0, 0
	};
	int pixel_format = ChoosePixelFormat (window->device_context, &pfd);
	SetPixelFormat (window->device_context, pixel_format, &pfd);
	window->opengl_context = wglCreateContext (window->device_context);
	if (first_context)
		wglShareLists (first_context, window->opengl_context);
	else
		first_context = window->opengl_context;
	wglMakeCurrent (window->device_context, window->opengl_context);
}
Ejemplo n.º 9
0
static int
assignToVideoContext(HGLRC hRC)
{
    // Traverse existing Video Contexts to see if we can share gfx resources with any of them
    video_contexts_t::iterator it = video_contexts.begin();
    int i = 0;
	int iempty = -1;
    for ( ; it != video_contexts.end(); it ++, i++) 
    {
		if (!it->empty()) {
			// Try to share resource lists with first Context in the group
			if (wglShareLists(it->front(), hRC) == TRUE) {
				// Succeeded, so add the new Rendering Context to this Video Context
				it->push_back(hRC);
				// We're done, this is the Video Context we were looking for
				return 1 + i;
			}
		}
		else if (iempty < 0) {
			iempty = i; // remember this Video Context as available
		}
    }
    // Could not share with any Video Context, so create and add new Video Context (or reuse an empty one)
	if (iempty < 0) {
		video_context_t vctx;
		vctx.push_back(hRC);
		video_contexts.push_back(vctx);
	    return 1 + i; // add 1 to reserve 0 = unassigned
	}
	else {
		video_contexts[iempty].push_back(hRC);
		return 1 + iempty;
	}
}
Ejemplo n.º 10
0
void CIrrWindow::createIrrDevice()
{
	// create irr device
	SIrrlichtCreationParameters param;
	param.WindowId = (void*)getHandle();
	param.ZBufferBits = 32;
	param.DriverType = video::EDT_OPENGL;	

	m_device	= createDeviceEx(param);
	m_driver	= m_device->getVideoDriver();
	m_smgr		= m_device->getSceneManager();
	
	// init opengl
	HDC HDc = GetDC( getHandle() );
	PIXELFORMATDESCRIPTOR pfd={0};
	pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
	int pf = GetPixelFormat(HDc);	
	DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);	
	pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
	pfd.cDepthBits=16;
	pf = ChoosePixelFormat(HDc, &pfd);	
	SetPixelFormat(HDc, pf, &pfd);
	
	// share video data
	m_videoData.OpenGLWin32.HWnd = NULL;
	m_videoData.OpenGLWin32.HDc = HDc;
	m_videoData.OpenGLWin32.HRc = wglCreateContext(HDc);

	// share for multithread
	wglShareLists((HGLRC)m_driver->getExposedVideoData().OpenGLWin32.HRc, (HGLRC)m_videoData.OpenGLWin32.HRc);
	
	g_irrView = this;
	initScene();
}
Ejemplo n.º 11
0
HGLRC CL_GL1CreationHelper::create_opengl2_context(HGLRC share_context)
{
	HGLRC opengl2_context = wglCreateContext(hdc);
	if (opengl2_context)
		wglShareLists(share_context, opengl2_context);
	return opengl2_context;
}
Ejemplo n.º 12
0
void WGLRenderer::init(Device *device, Renderer *other) {
	WGLDevice *wglDevice = static_cast<WGLDevice *>(device);

	if (m_session == NULL) {
		Log(EDebug, "Using an existing WGL context");
		m_context = wglGetCurrentContext();
		if (m_context == NULL)
			Log(EError, "Unable to retrieve the current WGL context!");
		m_borrowed = true;
	} else {
		/* Create a GL context */
		Log(EDebug, "Initializing WGL renderer");
		m_context = wglCreateContext(wglDevice->getDeviceContext());

		if (other != NULL) {
			Assert(other->getClass() == m_theClass);
			if (wglShareLists(m_context,
				static_cast<WGLRenderer *>(other)->m_context) != TRUE)
				Log(EError, "Unable to set up context sharing: %s",
					lastErrorText().c_str());
		}

		device->makeCurrent(this);
		m_borrowed = false;
	}

	GLRenderer::init(device);

	m_initialized = true;
}
	GLContext* Win32Context::clone() const
	{
		// Create new context based on own HDC
		HGLRC newCtx = wglCreateContext(mHDC);
		
		if (!newCtx)
		{
			OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, 
				"Error calling wglCreateContext", "Win32Context::clone");
		}

		HGLRC oldrc = wglGetCurrentContext();
		HDC oldhdc = wglGetCurrentDC();
		wglMakeCurrent(NULL, NULL);
		// Share lists with old context
	    if (!wglShareLists(mGlrc, newCtx))
		{
			String errorMsg = translateWGLError();
			wglDeleteContext(newCtx);
			OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, String("wglShareLists() failed: ") + errorMsg, "Win32Context::clone");
		}
		// restore old context
		wglMakeCurrent(oldhdc, oldrc);
		

		return new Win32Context(mHDC, newCtx);
	}
Ejemplo n.º 14
0
/// Create a GL rendering context
///
/// @return NULL if failed
glContext::renderingContext *
glContext::createRenderingContext()
{
	glContext::renderingContext *rc;

	rc = new renderingContext();

	rc->_hDC = GetDC(window::getInstance().hWnd());
	rc->_hGLRC = wglCreateContext(rc->_hDC);
//   HGLRC mainhGLRC = _mainRC ? _mainRC->_hGLRC : 0; //todo for ARB_CREATE_CONTEXT
    //rc->_hGLRC = wglCreateContextAttribsARB(rc->_hDC, mainhGLRC, contextAttribs); //TODO for ARB_CREAE_CONTEXT, contextAttribs = NULL if no debug required

	if (_mainRC) //main context already created, share withi these contexts
		wglShareLists(_mainRC->_hGLRC,rc->_hGLRC);
	if(rc->_hGLRC == 0)
	{
		window::getInstance().messageBoxWithLastError("wglCreateContext");
		return false;
	}

	//TODO debug - makecurrent(rc) to set the debug callbak here
   // makeCurrent(rc);

    //GLExtensionFunctions::getInstance().resolve();
   // if(_options._verbose && GLExtensionFunctions::getInstance()._has_GL_ARB_debug_output) {
     //   glDebugMessageCallbackARB(debugMessageCallback, NULL);
    //}
//    makeUnCurrent();
	return rc;
}
Ejemplo n.º 15
0
GLXContext
glXCreateContext(Display * display, XVisualInfo * visinfo,
  GLXContext share, Bool direct)
{
  /* KLUDGE: GLX really expects a display pointer to be passed
     in as the first parameter, but Win32 needs an HDC instead,
     so BE SURE that the global XHDC is set before calling this
     routine. */
  HGLRC context;

  context = wglCreateContext(XHDC);

#if 0
  /* XXX GLUT doesn't support it now, so don't worry about display list
     and texture object sharing. */
  if (share) {
    wglShareLists(share, context);
  }
#endif

  /* Since direct rendering is implicit, the direct flag is
     ignored. */

  return context;
}
Ejemplo n.º 16
0
/*< private >*/
GdkGLContextImpl *
_gdk_win32_gl_context_impl_new (GdkGLContext  *glcontext,
                                GdkGLDrawable *gldrawable,
                                GdkGLContext  *share_list,
                                gboolean       direct,
                                int            render_type)
{
  GdkGLConfig *glconfig;
  HDC hdc;
  HGLRC hglrc;
  GdkGLContextImplWin32 *share_impl = NULL;

  GDK_GL_NOTE_FUNC_PRIVATE ();

  /*
   * Create an OpenGL rendering context.
   */

  glconfig = gdk_gl_drawable_get_gl_config (gldrawable);

  /* Get DC. */
  hdc = gdk_win32_gl_window_get_hdc (GDK_GL_WINDOW (gldrawable));
  if (hdc == NULL)
    return NULL;

  GDK_GL_NOTE_FUNC_IMPL ("wglCreateContext");

  hglrc = wglCreateContext (hdc);

  /* Release DC. */
  gdk_win32_gl_window_release_hdc (GDK_GL_WINDOW (gldrawable));

  if (hglrc == NULL)
    return NULL;

  if (share_list != NULL && GDK_IS_GL_CONTEXT (share_list))
    {
      GDK_GL_NOTE_FUNC_IMPL ("wglShareLists");

      share_impl = GDK_GL_CONTEXT_IMPL_WIN32 (share_list);
      if (!wglShareLists (share_impl->hglrc, hglrc))
        {
          wglDeleteContext (hglrc);
          return NULL;
        }
    }

  /*
   * Instantiate the GdkGLContextImplWin32 object.
   */

  return gdk_win32_gl_context_impl_new_common (glcontext,
                                               glconfig,
                                               share_list,
                                               render_type,
                                               hglrc,
                                               FALSE);
}
Ejemplo n.º 17
0
JNIEXPORT jboolean JNICALL WGL_NATIVE(wglShareLists)
	(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1)
{
	jboolean rc = 0;
	WGL_NATIVE_ENTER(env, that, wglShareLists_FUNC);
	rc = (jboolean)wglShareLists((HGLRC)arg0, (HGLRC)arg1);
	WGL_NATIVE_EXIT(env, that, wglShareLists_FUNC);
	return rc;
}
Ejemplo n.º 18
0
bool OglContext::createPBuffer(ms_uint32 width, ms_uint32 height)
{
  HPBUFFERARB hPBuffer = NULL;
  hPBufferDC = NULL;
  hPBufferRC = NULL;

  int pixelFormat;
  int valid = false;
  UINT numFormats = 0;
  float fAttributes[] = {0,0};
  int samples = MAX_MULTISAMPLE_SAMPLES;

  while ((!valid || numFormats == 0) && samples >= 0) {
    int iAttributes[] = {
      WGL_SAMPLES_ARB,samples,
      WGL_DRAW_TO_PBUFFER_ARB,GL_TRUE,
      WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
      WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
      WGL_COLOR_BITS_ARB,24,
      WGL_ALPHA_BITS_ARB,8,
      WGL_DEPTH_BITS_ARB,16,
      WGL_STENCIL_BITS_ARB,0,
      WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,
      WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
      0,0
    };

    valid = wglChoosePixelFormatARB(window,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
    if (!valid || numFormats == 0) samples -= 2;
  }

  if(numFormats == 0) {
    msSetError(MS_OGLERR, "P-buffer Error: Unable to find an acceptable pixel format.", "OglContext::createPBuffer()");
    return FALSE;
  }

  if (!(hPBuffer = wglCreatePbufferARB(window, pixelFormat, width, height, 0))) {
    msSetError(MS_OGLERR, "P-buffer Error: Unable to create P-buffer. glError: %d", "OglContext::createPBuffer()", glGetError());
    return FALSE;
  }
  if (!(hPBufferDC = wglGetPbufferDCARB(hPBuffer))) {
    msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
    return FALSE;
  }
  if (!(hPBufferRC = wglCreateContext(hPBufferDC))) {
    msSetError(MS_OGLERR, "P-buffer Error: Unable to get P-buffer DC. glError: %d", "OglContext::createPBuffer()", glGetError());
    return FALSE;
  }

  if (wglShareLists(sharingContext,hPBufferRC) == FALSE) {
    msSetError(MS_OGLERR, "P-buffer Error: Unable to share display lists. glError: %d", "OglContext::createPBuffer()", glGetError());
    return FALSE;
  }

  return TRUE;
}
Ejemplo n.º 19
0
static gboolean
gst_gl_context_wgl_create_context (GstGLContext * context,
    GstGLAPI gl_api, GstGLContext * other_context, GError ** error)
{
  GstGLWindow *window;
  GstGLContextWGL *context_wgl;
  GstGLContextWGL *other_wgl = NULL;
  HDC device;

  context_wgl = GST_GL_CONTEXT_WGL (context);
  window = gst_gl_context_get_window (context);
  device = (HDC) gst_gl_window_get_display (window);

  if (other_context) {
    if (!GST_GL_IS_CONTEXT_WGL (other_context)) {
      g_set_error (error, GST_GL_CONTEXT_ERROR,
          GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
          "Cannot share context with a non-WGL context");
      goto failure;
    }
    other_wgl = (GstGLContextWGL *) other_context;
  }

  context_wgl->wgl_context = wglCreateContext (device);
  if (context_wgl->wgl_context)
    GST_DEBUG ("gl context created: %" G_GUINTPTR_FORMAT,
        (guintptr) context_wgl->wgl_context);
  else {
    g_set_error (error, GST_GL_CONTEXT_ERROR,
        GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "failed to create glcontext:0x%x",
        (unsigned int) GetLastError ());
    goto failure;
  }
  g_assert (context_wgl->wgl_context);

  GST_LOG ("gl context id: %" G_GUINTPTR_FORMAT,
      (guintptr) context_wgl->wgl_context);

  if (other_wgl) {
    if (!wglShareLists (other_wgl->wgl_context, context_wgl->wgl_context)) {
      g_set_error (error, GST_GL_CONTEXT_ERROR,
          GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "failed to share contexts 0x%x",
          (unsigned int) GetLastError ());
      goto failure;
    }
  }

  gst_object_unref (window);

  return TRUE;

failure:
  gst_object_unref (window);

  return FALSE;
}
Ejemplo n.º 20
0
void PBuffer_GL1_Impl::create(OpenGLWindowProvider &window_provider, const Size &size)
{
	reset();

	OpenGL::set_active(gc_provider);

	if (glWglCreatePbufferARB == 0)
	{
		throw Exception("WGL_ARB_pbuffer OpenGL extension not supported by this card");
	}

	int attribList[1] = { 0 };

	PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd 
		1,                              // version number
		// PFD_DRAW_TO_WINDOW |            // support window
		PFD_SUPPORT_OPENGL //|            // support OpenGL
		//PFD_DOUBLEBUFFER |              // double buffered
		//PFD_DEPTH_DONTCARE
		,             // do you care about a zbuffer?
		PFD_TYPE_RGBA,                  // RGBA type
		24,                             // 24-bit color depth
		0, 0, 0, 0, 0, 0,               // color bits ignored
		8,                              // alpha buffer
		0,                              // shift bit ignored
		0,                              // no accumulation buffer
		0, 0, 0, 0,                     // accum bits ignored
		0,                              // z-buffer
		0,                              // no stencil buffer
		0,                              // no auxiliary buffer
		PFD_MAIN_PLANE,                 // main layer
		0,                              // reserved
		0, 0, 0                         // layer masks ignored
	};

	int pixelformat = ChoosePixelFormat(wglGetCurrentDC(), &pfd);

	pbuffer = glWglCreatePbufferARB(
		wglGetCurrentDC(),
		pixelformat,
		size.width,
		size.height,
		attribList);
	pbuffer_dc = glWglGetPbufferDCARB(pbuffer);
	pbuffer_context = wglCreateContext(pbuffer_dc);

	HGLRC share_context = window_provider.get_share_context();
	if (share_context == 0)
		throw Exception("Shared OpenGL Context is not valid");

	wglShareLists(share_context, pbuffer_context);

	pbuffer_size = size;
}
Ejemplo n.º 21
0
void *
MSWinSurface::createExtraContext()
{
	assert(hGLRC != 0);
	HDC hDC = GetDC(hWnd);
	HGLRC hRC = wglCreateContext(hDC);
	if (hRC == 0) throw EMSWinError(GetLastError(), "wglCreateContext() (extra context)");
    if (! wglShareLists(hGLRC, hRC)) throw EMSWinError(GetLastError(), "wglShareLists() (extra context)");
	return hRC;
}
Ejemplo n.º 22
0
// Spout OpenGL initialization function
bool SpoutSenderPlugin::InitOpenGL()
{
	char windowtitle[512];

	// We only need an OpenGL context with no window
	m_hwnd = GetForegroundWindow(); // Any window will do - we don't render to it
	if(!m_hwnd) { printf("InitOpenGL error 1\n"); MessageBoxA(NULL, "Error 1\n", "InitOpenGL", MB_OK); return false; }
	m_hdc = GetDC(m_hwnd);
	if(!m_hdc) { printf("InitOpenGL error 2\n"); MessageBoxA(NULL, "Error 2\n", "InitOpenGL", MB_OK); return false; }
	GetWindowTextA(m_hwnd, windowtitle, 256); // debug

	PIXELFORMATDESCRIPTOR pfd;
	ZeroMemory( &pfd, sizeof( pfd ) );
	pfd.nSize = sizeof( pfd );
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 32;
	pfd.cDepthBits = 24; // LJ DEBUG - was 16;
	pfd.cStencilBits = 8; // LJ DEBUG -added
	pfd.iLayerType = PFD_MAIN_PLANE;

	int iFormat = ChoosePixelFormat(m_hdc, &pfd);
	if(!iFormat) { printf("InitOpenGL error 3\n"); MessageBoxA(NULL, "Error 3\n", "InitOpenGL", MB_OK); return false; }

	if(!SetPixelFormat(m_hdc, iFormat, &pfd)) { printf("InitOpenGL error 4\n"); MessageBoxA(NULL, "Error 4\n", "InitOpenGL", MB_OK); return false; }

	m_hRC = wglCreateContext(m_hdc);
	if(!m_hRC) { printf("InitOpenGL error 5\n"); MessageBoxA(NULL, "Error 5\n", "InitOpenGL", MB_OK); return false; }

	wglMakeCurrent(m_hdc, m_hRC);
	if(wglGetCurrentContext() == NULL) { printf("InitOpenGL error 6\n"); MessageBoxA(NULL, "Error 6\n", "InitOpenGL", MB_OK); return false; }

	// Set up a shared context
	if(!m_hSharedRC) m_hSharedRC = wglCreateContext(m_hdc);
	if(!m_hSharedRC) { printf("InitOpenGL shared context not created\n"); }
	if(!wglShareLists(m_hSharedRC, m_hRC)) { printf("wglShareLists failed\n"); }

	// Drop through to return true
	/*
	SendMessageTimeoutA(m_hwnd, WM_GETTEXT, 256, (LPARAM)windowtitle, SMTO_ABORTIFHUNG, 128, NULL);
	printf("InitOpenGL : hwnd = %x (%s), hdc = %x, context = %x\n", m_hwnd, windowtitle, m_hdc, m_hRC);
	int nTotalAvailMemoryInKB = 0;
	int nCurAvailMemoryInKB = 0;
	// GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
	// GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
	glGetIntegerv(0x9048, &nTotalAvailMemoryInKB);
	glGetIntegerv(0x9049, &nCurAvailMemoryInKB);
	printf("Memory : Total [%i], Available [%i]\n", nTotalAvailMemoryInKB, nCurAvailMemoryInKB);
	*/

	return true;

}
Ejemplo n.º 23
0
wxGLContext::wxGLContext(wxGLCanvas *win, const wxGLContext* other)
{
    m_glContext = wglCreateContext(win->GetHDC());
    wxCHECK_RET( m_glContext, wxT("Couldn't create OpenGL context") );

    if ( other )
    {
        if ( !wglShareLists(other->m_glContext, m_glContext) )
            wxLogLastError(_T("wglShareLists"));
    }
}
Ejemplo n.º 24
0
int Server::initGLContexts()
{
	diplayWindow = wglGetCurrentDC();
	primaryContext = wglGetCurrentContext();
	loadingThreadContext = wglCreateContext(diplayWindow);
	wglMakeCurrent(NULL, NULL);
	BOOL error = wglShareLists(primaryContext, loadingThreadContext);
	wglMakeCurrent(diplayWindow, primaryContext);

	return 0;
}
Ejemplo n.º 25
0
static inline HGLRC createContext(HDC hdc, HGLRC shared)
{
    HGLRC result = wglCreateContext(hdc);
    if (!result) {
        qErrnoWarning("%s: wglCreateContext failed.", __FUNCTION__);
        return 0;
    }
    if (shared && !wglShareLists(shared, result))
        qErrnoWarning("%s: wglShareLists() failed.", __FUNCTION__);
    return result;
}
Ejemplo n.º 26
0
BBGLContext *bbGLGraphicsAttachGraphics( HWND hwnd,int flags ){
	BBGLContext *context;
	
	HDC hdc;
	HGLRC hglrc;
	
	long pf;
	PIXELFORMATDESCRIPTOR pfd;
	RECT rect;
	
	_initWndClass();
	
	hdc=GetDC( hwnd );
	if( !hdc ) return 0;
	
	_initPfd( &pfd,flags );

	int multisample = 0;
	if (_MULTISAMPLE2X & flags) multisample = 2;
	else if (_MULTISAMPLE4X & flags) multisample = 4;
	else if (_MULTISAMPLE8X & flags) multisample = 8;
	else if (_MULTISAMPLE16X & flags) multisample = 16;
	if (multisample>0){
		pf=MyChoosePixelFormat( hdc,flags );
	}else{
		pf=ChoosePixelFormat( hdc,&pfd );
	}
	if( !pf ) return 0;
	SetPixelFormat( hdc,pf,&pfd );
	hglrc=wglCreateContext( hdc );
	
	if( _sharedContext ) wglShareLists( _sharedContext->hglrc,hglrc );
	
	GetClientRect( hwnd,&rect );
	
	context=(BBGLContext*)malloc( sizeof(BBGLContext) );
	memset( context,0,sizeof(*context) );
	
	context->mode=MODE_WIDGET;
	context->width=rect.right;
	context->height=rect.bottom;
	context->flags=flags;
	
	context->hdc=hdc;
	context->hwnd=hwnd;
	context->hglrc=hglrc;
	
	context->succ=_contexts;
	_contexts=context;
	
	return context;
}
Ejemplo n.º 27
0
void ParticleShaderVoronoi::setupBuffers(int width, int height)
{
	hdc = wglGetCurrentDC();
	hglrc = wglGetCurrentContext();

	pbufferOne = new nv_pbuffer(width, height, 1);

	pbufferOne->wglGetLastError();	

	// If we're sharing contexts, don't need to share lists
	if (pbufferOne->onecontext == false) 
		wglShareLists(pbufferOne->hglrc, hglrc);
	
}
Ejemplo n.º 28
0
    KT_API WinOGL3Context::WinOGL3Context( Window* window,
                                                    WinOGL3Context* sharedWith,
                                                    unsigned redBits,
                                                    unsigned greenBits,
                                                    unsigned blueBits,
                                                    unsigned alphaBits,
                                                    unsigned depth,
                                                    unsigned stencil )
    {
        myWindow = window ? window : new Window();

        myDC = GetDC( myWindow->GetWindowHandle() );

        if( !myDC )
            kTLaunchException( Exception, "Can't retrieve the DC to create a OGL context" );

        PIXELFORMATDESCRIPTOR pfd = {0};

        pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
        pfd.nVersion = 1;
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.iLayerType = PFD_MAIN_PLANE;
        pfd.cColorBits = redBits + greenBits + blueBits + alphaBits;
        pfd.cRedBits = redBits;
        pfd.cGreenBits = greenBits;
        pfd.cBlueBits = blueBits;
        pfd.cAlphaBits = alphaBits;
        pfd.cDepthBits = depth;
        pfd.cStencilBits = stencil;

        int pixelFormat = ChoosePixelFormat( myDC, &pfd );

        if( !pixelFormat )
            kTLaunchException( Exception, "Can't find a matching pixel format" );

        if( SetPixelFormat( myDC, pixelFormat, &pfd ) == FALSE )
            kTLaunchException( Exception, "Can't set the pixel format" );

        myOGLContext = wglCreateContext( myDC );

        if( !myOGLContext )
            kTLaunchException( Exception, "Can't create the context" );

        if( sharedWith )
        {
            if( wglShareLists( sharedWith->GetHandle(), myOGLContext ) == FALSE )
                kTLaunchException( Exception, "Can't share the context" );
        }
    }
//----------------------------------------------------------------------------//
void OpenGLWGLPBTextureTarget::initialisePBuffer()
{
    int creation_attrs[] =
    {
        WGL_PBUFFER_LARGEST_ARB, true,
        0
    };

    releasePBuffer();

    HDC hdc = wglGetCurrentDC();
    d_pbuffer = wglCreatePbufferARB(hdc, d_pixfmt, 
                                    static_cast<int>(d_area.getWidth()),
                                    static_cast<int>(d_area.getHeight()),
                                    creation_attrs);

    if (!d_pbuffer)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglCreatePbufferARB() call failed."));

    d_hdc = wglGetPbufferDCARB(d_pbuffer);

    if (!d_hdc)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglGetPbufferDCARB() call failed."));

    d_context= wglCreateContext(d_hdc);

    if (!d_hdc)
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglCreateContext() call failed."));

    if(!wglShareLists(wglGetCurrentContext(), d_context))
        CEGUI_THROW(RendererException(
            "OpenGLWGLPBTextureTarget::initialisePBuffer - "
            "pbuffer creation failure, wglShareLists() call failed."));

    // extract the actual size of the created bufer
    int actual_width, actual_height;
    wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_WIDTH_ARB, &actual_width);
    wglQueryPbufferARB(d_pbuffer, WGL_PBUFFER_HEIGHT_ARB, &actual_height);
    d_area.setSize(Size(static_cast<float>(actual_width),
                        static_cast<float>(actual_height)));

    // ensure CEGUI::Texture is wrapping real GL texture and has correct size
    d_CEGUITexture->setOpenGLTexture(d_texture, d_area.getSize());
}
Ejemplo n.º 30
0
GHOST_TSuccess GHOST_WindowWin32::installDrawingContext(GHOST_TDrawingContextType type)
{
	GHOST_TSuccess success;
	switch (type) {
	case GHOST_kDrawingContextTypeOpenGL:
		{
		if(m_stereoVisual)
			sPreferredFormat.dwFlags |= PFD_STEREO;

		// Attempt to match device context pixel format to the preferred format
		int iPixelFormat = EnumPixelFormats(m_hDC);
		if (iPixelFormat == 0) {
			success = GHOST_kFailure;
			break;
		}
		if (::SetPixelFormat(m_hDC, iPixelFormat, &sPreferredFormat) == FALSE) {
			success = GHOST_kFailure;
			break;
		}
		// For debugging only: retrieve the pixel format chosen
		PIXELFORMATDESCRIPTOR preferredFormat;
		::DescribePixelFormat(m_hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &preferredFormat);
		// Create the context
		m_hGlRc = ::wglCreateContext(m_hDC);
		if (m_hGlRc) {
			if (s_firsthGLRc) {
				wglShareLists(s_firsthGLRc, m_hGlRc);
			} else {
				s_firsthGLRc = m_hGlRc;
			}

			success = ::wglMakeCurrent(m_hDC, m_hGlRc) == TRUE ? GHOST_kSuccess : GHOST_kFailure;
		}
		else {
			success = GHOST_kFailure;
		}
		}
		break;

	case GHOST_kDrawingContextTypeNone:
		success = GHOST_kSuccess;
		break;

	default:
		success = GHOST_kFailure;
	}
	return success;
}