Esempio n. 1
0
SpoutSenderSDK2::~SpoutSenderSDK2()
{
	// OpenGL context required
	if(wglGetCurrentContext()) {
		// ReleaseSender does nothing if there is no sender
		if(bInitialized) sender.ReleaseSender();
	}

}
Esempio n. 2
0
void DestroyContext (GLContext* ctx)
{
  if (NULL == ctx) return;
  if (NULL != ctx->rc) wglMakeCurrent(NULL, NULL);
  if (NULL != ctx->rc) wglDeleteContext(wglGetCurrentContext());
  if (NULL != ctx->wnd && NULL != ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
  if (NULL != ctx->wnd) DestroyWindow(ctx->wnd);
  UnregisterClass(L"GLEW", GetModuleHandle(NULL));
}
cl_context QHoneycombWidget::CreateContext()
{
  cl_int errNum;
  cl_uint numPlatforms;
  cl_platform_id firstPlatformId;
  cl_context context = NULL;

  // First, select an OpenCL platform to run on.  For this example, we
  // simply choose the first available platform.  Normally, you would
  // query for all available platforms and select the most appropriate one.
  errNum = clGetPlatformIDs(1, &firstPlatformId, &numPlatforms);
  if (errNum != CL_SUCCESS || numPlatforms <= 0)
  {
    std::cerr << "Failed to find any OpenCL platforms." << std::endl;
    return NULL;
  }

  // Next, create an OpenCL context on the platform.  Attempt to
  // create a GPU-based context, and if that fails, try to create
  // a CPU-based context.
  cl_context_properties contextProperties[] =
  {
#ifdef _WIN32
    CL_CONTEXT_PLATFORM,
    (cl_context_properties)firstPlatformId,
    CL_GL_CONTEXT_KHR,
    (cl_context_properties)wglGetCurrentContext(),
    CL_WGL_HDC_KHR,
    (cl_context_properties)wglGetCurrentDC(),
#elif defined( __GNUC__)
    CL_CONTEXT_PLATFORM, (cl_context_properties)clSelectedPlatformID,
    CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
    CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
#elif defined(__APPLE__) 
    //todo
#endif
    0



  };
  context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU,
    NULL, NULL, &errNum);
  if (errNum != CL_SUCCESS)
  {
    std::cout << "Could not create GPU context, trying CPU..." << std::endl;
    context = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU,
      NULL, NULL, &errNum);
    if (errNum != CL_SUCCESS)
    {
      std::cerr << "Failed to create an OpenCL GPU or CPU context." << std::endl;
      return NULL;
    }
  }

  return context;
}
Esempio n. 4
0
JNIEXPORT jintLong JNICALL WGL_NATIVE(wglGetCurrentContext)
	(JNIEnv *env, jclass that)
{
	jintLong rc = 0;
	WGL_NATIVE_ENTER(env, that, wglGetCurrentContext_FUNC);
	rc = (jintLong)wglGetCurrentContext();
	WGL_NATIVE_EXIT(env, that, wglGetCurrentContext_FUNC);
	return rc;
}
Esempio n. 5
0
	void OpenCL::setupFromOpenGL(int deviceNumber) {
		ofLog(OF_LOG_VERBOSE, "OpenCL::setupFromOpenGL ");

		if(isSetup) {
			ofLog(OF_LOG_VERBOSE, "... already setup. returning");
			return;
		}

		if(deviceInfo.size() == 0) getDeviceInfos(CL_DEVICE_TYPE_GPU);
		deviceNumber = (deviceNumber + getNumDevices()) % getNumDevices();
		clDevice = deviceInfo[deviceNumber].clDeviceId;
		cl_platform_id clPlatformID = deviceInfo[deviceNumber].clPlatformId;

		cl_int err;

#ifdef TARGET_OSX	
		CGLContextObj kCGLContext = CGLGetCurrentContext();
		CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
		cl_context_properties properties[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup, 0 };

		clContext = clCreateContext(properties, 0, 0, NULL, NULL, &err);
#elif defined _WIN32
		//aqcuire shared context on windows.
		{
			// TODO: we want to be more specific about the platform,
			// at the moment only the first successful platform is selected. 

			cl_context_properties properties[] = 
			{
				CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), 
				CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), 
				CL_CONTEXT_PLATFORM, (cl_context_properties)clPlatformID, 
				0
			};
			ofLogNotice() << "Using OpenCL Platform: 0x" << std::hex << clPlatformID;
			ofLogNotice() << "Using OpenCL Device: 0x" << std::hex << clDevice;

			clContext = clCreateContext(properties, 1, &clDevice, NULL, NULL, &err);
			ofLogNotice() <<  "Created OpenCL context: " << (err == CL_SUCCESS ? "SUCCESS" : "ERROR");
		}

#endif
		if(clContext == NULL) {
			ofLog(OF_LOG_ERROR, "Error creating clContext.");
			assert(err != CL_INVALID_PLATFORM);
			assert(err != CL_INVALID_VALUE);
			assert(err != CL_INVALID_DEVICE);
			assert(err != CL_INVALID_DEVICE_TYPE);
			assert(err != CL_DEVICE_NOT_AVAILABLE);
			assert(err != CL_DEVICE_NOT_FOUND);
			assert(err != CL_OUT_OF_HOST_MEMORY);
			assert(false);
		}

		createQueue();
	}	
bool eae6320::OpenGlExtensions::Load( std::string* o_errorMessage )
{
	// A current OpenGL context must exist before extensions can be loaded
	{
		const HGLRC currentContext = wglGetCurrentContext();
		if ( currentContext == NULL )
		{
			if ( o_errorMessage )
			{
				*o_errorMessage = "OpenGL extensions can't be loaded without a current OpenGL context";
			}
			return false;
		}
	}

#define EAE6320_LOADGLFUNCTION( i_functionName, i_functionType )														\
		i_functionName = reinterpret_cast<i_functionType>( GetGlFunctionAddress( #i_functionName, o_errorMessage ) );	\
		if ( !i_functionName )																							\
			return false;

	EAE6320_LOADGLFUNCTION( glActiveTexture, PFNGLACTIVETEXTUREPROC );
	EAE6320_LOADGLFUNCTION( glAttachShader, PFNGLATTACHSHADERPROC );
	EAE6320_LOADGLFUNCTION( glBindBuffer, PFNGLBINDBUFFERPROC );
	EAE6320_LOADGLFUNCTION( glBindVertexArray, PFNGLBINDVERTEXARRAYPROC );
	EAE6320_LOADGLFUNCTION( glBufferData, PFNGLBUFFERDATAPROC );
	EAE6320_LOADGLFUNCTION( glCompileShader, PFNGLCOMPILESHADERPROC );
	EAE6320_LOADGLFUNCTION( glCreateProgram, PFNGLCREATEPROGRAMPROC );
	EAE6320_LOADGLFUNCTION( glCreateShader, PFNGLCREATESHADERPROC );
	EAE6320_LOADGLFUNCTION( glDeleteBuffers, PFNGLDELETEBUFFERSPROC );
	EAE6320_LOADGLFUNCTION( glDeleteProgram, PFNGLDELETEPROGRAMPROC );
	EAE6320_LOADGLFUNCTION( glDeleteVertexArrays, PFNGLDELETEVERTEXARRAYSPROC );
	EAE6320_LOADGLFUNCTION( glDeleteShader, PFNGLDELETESHADERPROC );
	EAE6320_LOADGLFUNCTION( glEnableVertexAttribArray, PFNGLENABLEVERTEXATTRIBARRAYARBPROC );
	EAE6320_LOADGLFUNCTION( glGenBuffers, PFNGLGENBUFFERSPROC );
	EAE6320_LOADGLFUNCTION( glGenVertexArrays, PFNGLGENVERTEXARRAYSPROC );
	EAE6320_LOADGLFUNCTION( glGetProgramInfoLog, PFNGLGETPROGRAMINFOLOGPROC );
	EAE6320_LOADGLFUNCTION( glGetProgramiv, PFNGLGETPROGRAMIVPROC );
	EAE6320_LOADGLFUNCTION( glGetShaderInfoLog, PFNGLGETSHADERINFOLOGPROC );
	EAE6320_LOADGLFUNCTION( glGetShaderiv, PFNGLGETSHADERIVPROC );
	EAE6320_LOADGLFUNCTION( glGetUniformLocation, PFNGLGETUNIFORMLOCATIONPROC );
	EAE6320_LOADGLFUNCTION( glLinkProgram, PFNGLLINKPROGRAMPROC );
	EAE6320_LOADGLFUNCTION( glShaderSource, PFNGLSHADERSOURCEPROC );
	EAE6320_LOADGLFUNCTION( glUniform1fv, PFNGLUNIFORM1FVPROC );
	EAE6320_LOADGLFUNCTION( glUniform2fv, PFNGLUNIFORM2FVPROC );
	EAE6320_LOADGLFUNCTION( glUniform3fv, PFNGLUNIFORM3FVPROC );
	EAE6320_LOADGLFUNCTION( glUniform4fv, PFNGLUNIFORM4FVPROC );
	EAE6320_LOADGLFUNCTION( glUniformMatrix4fv, PFNGLUNIFORMMATRIX4FVPROC );
	EAE6320_LOADGLFUNCTION( glUseProgram, PFNGLUSEPROGRAMPROC );
	EAE6320_LOADGLFUNCTION( glVertexAttribPointer, PFNGLVERTEXATTRIBPOINTERPROC );
	EAE6320_LOADGLFUNCTION( glCompressedTexImage2D, PFNGLCOMPRESSEDTEXIMAGE2DPROC);
	EAE6320_LOADGLFUNCTION( glUniform1i, PFNGLUNIFORM1IPROC);

#undef EAE6320_LOADGLFUNCTION

	return true;
}
Esempio n. 7
0
//----------------------------------------------------------------------------//
void OpenGLWGLPBTextureTarget::enablePBuffer() const
{
    // store old details
    d_prevContext = wglGetCurrentContext();
    d_prevDC = wglGetCurrentDC();

    // switch to rendering to the pbuffer
    if (!wglMakeCurrent(d_hdc, d_context))
        std::cerr << "Failed to switch to pbuffer for rendering" << std::endl;
}
Esempio n. 8
0
void bbGLGraphicsSwapSharedContext(){

	if( wglGetCurrentContext()!=_sharedContext->hglrc ){
		wglMakeCurrent( _sharedContext->hdc,_sharedContext->hglrc );
	}else if( _currentContext ){
		wglMakeCurrent( _currentContext->hdc,_currentContext->hglrc );
	}else{
		wglMakeCurrent( 0,0 );
	}
}
Esempio n. 9
0
ExtensionManager::ExtensionManager( bool bInitAPI )
{
	if( !wglGetCurrentContext() ) 
		return;

	extensions = (char*) glGetString( GL_EXTENSIONS );

	if( bInitAPI )
		InitAPI();
}
Esempio n. 10
0
// Destroy the application window. Attempt to remove the rendering context and
// the device context as well.
void gs_display_dispose(long display)
{
    HWND hwnd = LongToHandle(display);
    HDC shell = GetDC(hwnd);
    HGLRC context = wglGetCurrentContext();
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(context);
    ReleaseDC(hwnd, shell);
    DestroyWindow(hwnd);
}
Esempio n. 11
0
QtRenderWindow::QtRenderWindow(QWidget* parent, QGLFormat format) : QGLWidget(format, parent)
{
	makeCurrent();
	deviceContext = wglGetCurrentDC();
	glContext = wglGetCurrentContext();
	onMakeCurrent();

	mRealtime = false;
	mNeedsUpdate = true;
}
Esempio n. 12
0
const bool gleIsOpenGLCurrent()
{
#ifdef WIN32
	return wglGetCurrentContext() != NULL;
#elif __MACOSX__
	#error "Not yet implemented"
#else // POSIX
	return glXGetCurrentContext() != NULL;
#endif
}
Esempio n. 13
0
DWORD SpoutSenderSDK2::DeInitGL()
{
	// OpenGL context required
	if(wglGetCurrentContext()) {
		if(bInitialized) sender.ReleaseSender();
	}
	bInitialized = false;

	return FF_SUCCESS;
}
Esempio n. 14
0
int IupGLIsCurrent (Ihandle* self)
{
  GLData* d = (GLData*)IupGetAttribute(self,"_IUPGL_DATA"); 
  if (d)
  {
    if (d->context == wglGetCurrentContext())
      return 1;
  }
  return 0;
}
Esempio n. 15
0
context::~context( void )
{
	if ( _hrc )
	{
		HGLRC oldCtxt = wglGetCurrentContext();
		if ( oldCtxt == _hrc )
			wglMakeCurrent( _hdc, NULL );
		wglDeleteContext( _hrc );
	}
}
Esempio n. 16
0
void cl_context::init()
{
    // OpenCL
    try
    {
        // Get available platforms
        vector<cl::Platform> platforms;
        cl::Platform::get(&platforms);
        LOG_INFO<<platforms.front().getInfo<CL_PLATFORM_VERSION>();

        // context sharing is OS specific
#if defined (__APPLE__) || defined(MACOSX)
        CGLContextObj curCGLContext = CGLGetCurrentContext();
        CGLShareGroupObj curCGLShareGroup = CGLGetShareGroup(curCGLContext);

        cl_context_properties properties[] =
        {
            CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
            (cl_context_properties)curCGLShareGroup,
            0
        };
#elif defined WIN32
        cl_context_properties properties[] =
        {
            CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
            CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(),
            0
        };
#else
        cl_context_properties properties[] =
        {
            CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
            CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(),
            0
        };
#endif

        m_context = cl::Context(CL_DEVICE_TYPE_GPU, properties);

        // Get a list of devices on this platform
        vector<cl::Device> devices = m_context.getInfo<CL_CONTEXT_DEVICES>();
        m_device = devices[0];

        // Create a command queue and use the first device
        m_queue = cl::CommandQueue(m_context, m_device);

    }
    catch(cl::Error &error)
    {
        LOG_ERROR << error.what() << "(" << oclErrorString(error.err()) << ")";
    }
}
Esempio n. 17
0
/***********************************************************************
 *              glGetString (OPENGL32.@)
 */
const GLubyte * WINAPI wine_glGetString( GLenum name )
{
  const GLubyte *ret;
  const char* GL_Extensions = NULL;

  /* this is for buggy nvidia driver, crashing if called from a different
     thread with no context */
  if(wglGetCurrentContext() == NULL)
    return NULL;

  if (GL_EXTENSIONS != name) {
    ENTER_GL();
    ret = glGetString(name);
    LEAVE_GL();
    return ret;
  }

  if (NULL == internal_gl_extensions) {
    ENTER_GL();
    GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);

    if (GL_Extensions)
    {
      size_t len = strlen(GL_Extensions);
      internal_gl_extensions = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len + 2);

      TRACE("GL_EXTENSIONS reported:\n");
      while (*GL_Extensions != 0x00) {
	const char* Start = GL_Extensions;
	char        ThisExtn[256];

	while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
	  GL_Extensions++;
	}
	memcpy(ThisExtn, Start, (GL_Extensions - Start));
        ThisExtn[GL_Extensions - Start] = 0;
	TRACE("- %s:", ThisExtn);
	
	/* test if supported API is disabled by config */
	if (!internal_gl_disabled_extensions || !strstr(internal_gl_disabled_extensions, ThisExtn)) {
	  strcat(internal_gl_extensions, " ");
	  strcat(internal_gl_extensions, ThisExtn);
	  TRACE(" active\n");
	} else {
	  TRACE(" deactived (by config)\n");
	}

	if (*GL_Extensions == ' ') GL_Extensions++;
      }
    }
    LEAVE_GL();
  }
  return (const GLubyte *) internal_gl_extensions;
}
Esempio n. 18
0
ARGS()
{
	//int pdata;
	HDC hDC;
	HGLRC gc;
	THIS_CLASS();

	//printf( "DOING USE\n" );
	gc = (HGLRC)GET_INT_FIELD("renderContext");
	//pdata = (int) GET_INT_FIELD("pData");
	if( gc == 0 )
	{
		printf( "gc = 0\n" );
		return 0;
	}

	hDC = (HDC)GET_INT_FIELD("display");
	//printf( "USE - hDC: %d\n", hDC);

	if( !hDC )
	{
		printf( "use - hdc 0" );
		return 0;
	}

	if( wglGetCurrentContext() == NULL )
	{
		printf( "ERROR WITH CONTEXT" );

		wglMakeCurrent( NULL, NULL );
		wglDeleteContext( (HGLRC)GET_INT_FIELD("renderContext") );

		SetDCPixelFormat(hDC);          
		// Create palette if needed
		GetOpenGLPalette(hDC);
		gc = wglCreateContext( hDC );
		wglMakeCurrent( hDC, gc );
		SET_INT_FIELD("renderContext", (long)gc );

		return 0;
	}
	
	if( !gc )
		return 0;
	
	if( !wglMakeCurrent( hDC, gc ) ) 
	{
		wglMakeCurrent( NULL, NULL );
		printf( "Error in wglMakeCurrent: %d", GetLastError() );
		return 0;

	}
	return 1;
}
Esempio n. 19
0
RenderContextOpenGLWin32::~RenderContextOpenGLWin32() {
	if (renderContext_) {
		if (wglGetCurrentContext() == renderContext_) {
			wglMakeCurrent(NULL, NULL);
		}

		wglDeleteContext(renderContext_);
	}

    ChangeDisplaySettings(NULL, 0);
}
bool CGraphicView::GetScreenPtFrom3DPoint( const CPoint3D& modelSpacePt, CPoint& screenPt )
{
	// this function works for any xyz point but usually we will just be returning the 
	// screen point for a grid point or node.
	GLint viewport[4];
	GLdouble mvMatrix[16], projMatrix[16];
	double winX = 0.0;
	double winY = 0.0;
	double winZ = 0.0; //depth value between 0 and 1 - for depth sorting
	bool bSuccess = false;

	HGLRC currentRC = wglGetCurrentContext();
	if( !currentRC )
	{
		TRACE( "CGraphicView::GetScreenPtFrom3DPoint Failed in GetCurrentContext\n" );
		return bSuccess;
	}
	HDC hDC = wglGetCurrentDC( );
	if( !hDC )
	{
		TRACE( "CGraphicView::GetScreenPtFrom3DPoint Failed in GetCurrentDC\n" );
		return bSuccess;
	}

	//if( !wglMakeCurrent( m_pDC->GetSafeHdc(), m_hDC ) )
	if( !wglMakeCurrent( hDC, currentRC ) )
	{
		TRACE( "CGraphicView::GetScreenPtFrom3DPoint Failed in MakeCurrent\n" );
		return bSuccess;
	}

	glGetIntegerv( GL_VIEWPORT, viewport );
	glGetDoublev( GL_MODELVIEW_MATRIX, mvMatrix );
	glGetDoublev( GL_PROJECTION_MATRIX, projMatrix );

	if( !gluProject( modelSpacePt.x, modelSpacePt.y, modelSpacePt.z, 
		             mvMatrix, projMatrix, viewport, 
				     &winX, &winY, &winZ ) )
	{
		//TRACE( "Failed in GetScreenPt #2\n" );
		//wglMakeCurrent( NULL, NULL );
		return bSuccess;
	}

	//openGL convention (origin at lower left)
	screenPt.x = int(winX);
	screenPt.y = int(winY);


	//windows convention (origin at upper left)
	screenPt.y = viewport[3] - viewport[1] - screenPt.y;
	bSuccess = true;
	return bSuccess;
}
Esempio n. 21
0
void CL::TinyCL::selectInteropDevice(DEVICE dev, bool profile) {
    try {
        //We assume only the first device and platform will be used
        //This is after all a lazy implementation
        cl::Platform::get(&mPlatforms);
        //Query the devices for the type desired
        mPlatforms.at(0).getDevices(static_cast<cl_device_type>(dev), &mDevices);
#ifdef _WIN32
        cl_context_properties properties[] = {
            CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
            CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(mPlatforms[0])(),
            0
        };
#elif defined(__linux__)
        cl_context_properties properties[] = {
            CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
            CL_WGL_HDC_KHR, (cl_context_properties)glXGetCurrentDisplay(),
            CL_CONTEXT_PLATFORM, (cl_context_properties)(mPlatforms[0])(),
            0
        };
#elif defined(__APPLE__)
        CGLContextObj glContext = CGLGetCurrentContext();
        CGLShareGroupObj shareGroup = CGLGetShareGroup(glContext);
        cl_context_properties properties[] = {
            CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
            (cl_context_properties)shareGroup,
        };
#endif

        mContext = cl::Context(mDevices, properties);
        //Grab the OpenGL device
        mDevices = mContext.getInfo<CL_CONTEXT_DEVICES>();
        if (profile)
            mQueue = cl::CommandQueue(mContext, mDevices.at(0), CL_QUEUE_PROFILING_ENABLE);
        else
            mQueue = cl::CommandQueue(mContext, mDevices.at(0));

        std::cout << "OpenCL Info:"
                  << "\nName: " << mDevices.at(0).getInfo<CL_DEVICE_NAME>()
                  << "\nVendor: " << mDevices.at(0).getInfo<CL_DEVICE_VENDOR>()
                  << "\nDriver Version: " << mDevices.at(0).getInfo<CL_DRIVER_VERSION>()
                  << "\nDevice Profile: " << mDevices.at(0).getInfo<CL_DEVICE_PROFILE>()
                  << "\nDevice Version: " << mDevices.at(0).getInfo<CL_DEVICE_VERSION>()
                  << "\nMax Work Group Size: " << mDevices.at(0).getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>()
                  << std::endl;
    }
    catch (const cl::Error &e) {
        std::cout << "Error selecting GL interop device: " << e.what()
                  << " code: " << e.err() << std::endl;
        throw e;
    }

}
Esempio n. 22
0
void COpenGL::FinitGL()
{
	if (wglGetCurrentContext())
		MakeGLContextNotCurrent();
	
	if (m_hGLContext)
	{
		wglDeleteContext(m_hGLContext);
		m_hGLContext = NULL;
	}
}
Esempio n. 23
0
static bool _begin()
{
	//wglMakeCurrent is slow in some environments. so, check if the desired context is already current
	if(wglGetCurrentContext() == main_hRC)
		return true;

	if(!wglMakeCurrent(main_hDC, main_hRC))
		return false;

	return true;
}
Esempio n. 24
0
SpoutReceiverSDK2::~SpoutReceiverSDK2()
{
	// OpenGL context required
	if(wglGetCurrentContext()) {
		// ReleaseReceiver does nothing if there is no receiver
		receiver.ReleaseReceiver();
		if(myTexture != 0) glDeleteTextures(1, &myTexture);
		myTexture = 0;
	}

}
Esempio n. 25
0
DWORD SpoutReceiverSDK2::DeInitGL()
{
	// OpenGL context required
	if(wglGetCurrentContext()) {
		// ReleaseReceiver does nothing if there is no receiver
		receiver.ReleaseReceiver();
		if(myTexture != 0) glDeleteTextures(1, &myTexture);
		myTexture = 0;
	}
	return FF_SUCCESS;
}
Esempio n. 26
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;

}
Esempio n. 27
0
int Server::initGLContexts()
{
	diplayWindow = wglGetCurrentDC();
	primaryContext = wglGetCurrentContext();
	loadingThreadContext = wglCreateContext(diplayWindow);
	wglMakeCurrent(NULL, NULL);
	BOOL error = wglShareLists(primaryContext, loadingThreadContext);
	wglMakeCurrent(diplayWindow, primaryContext);

	return 0;
}
Esempio n. 28
0
static HGLRC init_ogl_context_ex(HDC dc, bool fc, int major, int minor)
{
   HWND testwnd = NULL;
   HDC testdc   = NULL;
   HGLRC testrc = NULL;
   HGLRC old_rc = NULL;
   HDC old_dc   = NULL;
   HGLRC glrc   = NULL;

   testwnd = _al_win_create_hidden_window();
   if (!testwnd)
      return NULL;

   old_rc = wglGetCurrentContext();
   old_dc = wglGetCurrentDC();

   testdc = GetDC(testwnd);
   testrc = init_temp_context(testwnd);
   if (!testrc)
      goto bail;

   if (is_wgl_extension_supported("WGL_ARB_create_context", testdc)) {
      int attrib[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, major,
                      WGL_CONTEXT_MINOR_VERSION_ARB, minor,
                      WGL_CONTEXT_FLAGS_ARB, 0,
                      0};
      if (fc)
         attrib[5] = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
      if (!init_context_creation_extensions())
         goto bail;
      /* TODO: we could use the context sharing feature */
      glrc = _wglCreateContextAttribsARB(dc, 0, attrib);
   }
   else
      goto bail;

bail:
   wglMakeCurrent(NULL, NULL);
   if (testrc) {
      wglDeleteContext(testrc);
   }

   wglMakeCurrent(old_dc, old_rc);

   _wglCreateContextAttribsARB = NULL;

   if (testwnd) {
      ReleaseDC(testwnd, testdc);
      DestroyWindow(testwnd);
   }

   return glrc;
}
static void
_wgl_release (void *abstract_ctx)
{
    cairo_wgl_context_t *ctx = abstract_ctx;

    if (ctx->prev_dc != wglGetCurrentDC () ||
        ctx->prev_rc != wglGetCurrentContext ())
    {
        wglMakeCurrent (ctx->prev_dc,
                        ctx->prev_rc);
    }
}
CRect CGraphicsCamera::GetViewportRect( )
{
	GLint viewport[4];
	CRect r;
	HGLRC currentRC = wglGetCurrentContext();
	if( currentRC || wglMakeCurrent( m_hDC, m_hGLRC ) )
	{
		glGetIntegerv( GL_VIEWPORT, viewport );
		r = CRect( CPoint( viewport[0], viewport[1] ), CPoint( viewport[2], viewport[3] ) );
	}
	return r;
}