wglMakeCurrent

wglMakeCurrent

wglMakeCurrent 函数设定OpenGL当前线程的渲染环境。以后这个线程所有的OpenGL调用都是在这个hdc标识的设备上绘制。你也可以使用wglMakeCurrent 函数来改变调用线程的当前渲染环境,使之不再是当前的渲染环境。

 

BOOL wglMakeCurrent(
  HDC  hdc,      // device context of device that OpenGL calls are
                 // to be drawn on
  HGLRC  hglrc   // OpenGL rendering context to be made the calling
                 // thread's current rendering context
);

 

参数:

hdc

设备环境的句柄。调用这个函数的线程接下来的所有OpenGL调用都将在这个hdc所标识的设备上绘制。

hglrc

函数设定的OpenGL渲染环境的句柄,作为当前线程的渲染环境。

如果hglrc为NULL,函数将使调用线程的当前渲染环境不再作为当前的渲染环境,并释放这个渲染环境所使用的设备环境。这种情况下hdc参数将被忽略。

 

返回值:

当wglMakeCurrent 函数调用成功,将返回TRUE,否则返回FALSE,要想得到更多的信息,请调用

GetLastError。

 

注意:

hdc参数的绘制表面必须是支持OpenGL的。它不需是wglCreateContext 创建hglrc时所传进来的hdc,但它必须是相同的设备并具有相同的像素格式。GDI转换的hdc将不被渲染环境所支持。当前的渲染环境将一直使用hdc设备环境直到它不再是当前渲染环境。


在切换到新的渲染环境之前,OpenGL将冲刷掉当前调用线程之前的所有渲染环境。

 

一个线程可以有一个渲染环境。所以一个多线程进程可以有多个渲染环境。一个线程在调用任何OpenGL函数之前必须设置一个当前渲染环境。否则所有OpenGL调用都将忽略。

 

在某一时刻渲染环境只能属于一个线程,你不能使一个渲染环境同时属于多个线程。

 

一个应用程序可以通过不同线程中的不同的当前渲染环境产生多个绘图,它支持各个线程都拥有自己的渲染环境的设备环境。

 

如果有错误发生,wglMakeCurrent 函数在返回之前将使渲染环境不作为线程当前的渲染环境。

 

MSDN原文:

wglMakeCurrent

The wglMakeCurrent function makes a specified OpenGL rendering context the calling thread's current rendering context. All subsequent OpenGL calls made by the thread are drawn on the device identified by hdc. You can also use wglMakeCurrent to change the calling thread's current rendering context so it's no longer current.

BOOL wglMakeCurrent(
  HDC  hdc,      // device context of device that OpenGL calls are 
                 // to be drawn on
  HGLRC  hglrc   // OpenGL rendering context to be made the calling 
                 // thread's current rendering context
);

Parameters

hdc
Handle to a device context. Subsequent OpenGL calls made by the calling thread are drawn on the device identified by hdc.
hglrc
Handle to an OpenGL rendering context that the function sets as the calling thread's rendering context.

If hglrc is NULL, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, hdc is ignored.

Return Values

When the wglMakeCurrent function succeeds, the return value is TRUE; otherwise the return value is FALSE. To get extended error information, call GetLastError.

Remarks

The hdc parameter must refer to a drawing surface supported by OpenGL. It need not be the same hdc that was passed to wglCreateContext when hglrc was created, but it must be on the same device and have the same pixel format. GDI transformation and clipping in hdc are not supported by the rendering context. The current rendering context uses the hdc device context until the rendering context is no longer current.

Before switching to the new rendering context, OpenGL flushes any previous rendering context that was current to the calling thread.

A thread can have one current rendering context. A process can have multiple rendering contexts by means of multithreading. A thread must set a current rendering context before calling any OpenGL functions. Otherwise, all OpenGL calls are ignored.

A rendering context can be current to only one thread at a time. You cannot make a rendering context current to multiple threads.

An application can perform multithread drawing by making different rendering contexts current to different threads, supplying each thread with its own rendering context and device context.

If an error occurs, the wglMakeCurrent function makes the thread's current rendering context not current before returning.

你可能感兴趣的:(thread,多线程,function,null,application,transformation)