45 #ifndef QT_MAC_USE_COCOA 50 #include <private/qgl_p.h> 55 #ifndef GL_TEXTURE_RECTANGLE_EXT 56 #define GL_TEXTURE_RECTANGLE_EXT 0x84F5 62 for (
int s = 0; s < 32; ++s) {
63 if (((v>>s) & 1) == 1) {
75 #ifdef QT_MAC_USE_COCOA 82 share_ctx = shareWidget->
context()->d_func()->cx;
85 ctx = context.d_func()->cx;
86 context.d_func()->cx = 0;
89 [
static_cast<NSOpenGLContext *
>(
ctx) retain];
102 pbuf = [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:target
104 textureMaxMipMapLevel:0
105 pixelsWide:size.
width()
106 pixelsHigh:size.
height()];
108 qWarning(
"QGLPixelBuffer: Cannot create a pbuffer");
112 [
static_cast<NSOpenGLContext *
>(
ctx) setPixelBuffer:static_cast<NSOpenGLPixelBuffer *>(
pbuf)
115 currentVirtualScreen:0];
118 GLint attribs[40], i=0;
119 attribs[i++] = AGL_RGBA;
120 attribs[i++] = AGL_BUFFER_SIZE;
122 attribs[i++] = AGL_LEVEL;
123 attribs[i++] = f.
plane();
125 attribs[i++] = AGL_RED_SIZE;
129 attribs[i++] = AGL_GREEN_SIZE;
133 attribs[i++] = AGL_BLUE_SIZE;
137 attribs[i++] = AGL_STEREO;
139 attribs[i++] = AGL_ALPHA_SIZE;
143 attribs[i++] = AGL_STENCIL_SIZE;
147 attribs[i++] = AGL_DEPTH_SIZE;
151 attribs[i++] = AGL_ACCUM_RED_SIZE;
153 attribs[i++] = AGL_ACCUM_BLUE_SIZE;
155 attribs[i++] = AGL_ACCUM_GREEN_SIZE;
157 attribs[i++] = AGL_ACCUM_ALPHA_SIZE;
162 attribs[i++] = AGL_SAMPLE_BUFFERS_ARB;
164 attribs[i++] = AGL_SAMPLES_ARB;
167 attribs[i] = AGL_NONE;
169 AGLPixelFormat
format = aglChoosePixelFormat(0, 0, attribs);
171 qWarning(
"QGLPixelBuffer: Unable to find a pixel format (AGL error %d).",
172 (
int) aglGetError());
177 aglDescribePixelFormat(format, AGL_LEVEL, &res);
178 this->format.setPlane(res);
179 aglDescribePixelFormat(format, AGL_DOUBLEBUFFER, &res);
180 this->format.setDoubleBuffer(res);
181 aglDescribePixelFormat(format, AGL_DEPTH_SIZE, &res);
182 this->format.setDepth(res);
183 if (this->format.depth())
184 this->format.setDepthBufferSize(res);
185 aglDescribePixelFormat(format, AGL_RGBA, &res);
186 this->format.setRgba(res);
187 aglDescribePixelFormat(format, AGL_RED_SIZE, &res);
188 this->format.setRedBufferSize(res);
189 aglDescribePixelFormat(format, AGL_GREEN_SIZE, &res);
190 this->format.setGreenBufferSize(res);
191 aglDescribePixelFormat(format, AGL_BLUE_SIZE, &res);
192 this->format.setBlueBufferSize(res);
193 aglDescribePixelFormat(format, AGL_ALPHA_SIZE, &res);
194 this->format.setAlpha(res);
195 if (this->format.alpha())
196 this->format.setAlphaBufferSize(res);
197 aglDescribePixelFormat(format, AGL_ACCUM_RED_SIZE, &res);
198 this->format.setAccum(res);
199 if (this->format.accum())
200 this->format.setAccumBufferSize(res);
201 aglDescribePixelFormat(format, AGL_STENCIL_SIZE, &res);
202 this->format.setStencil(res);
203 if (this->format.stencil())
204 this->format.setStencilBufferSize(res);
205 aglDescribePixelFormat(format, AGL_STEREO, &res);
206 this->format.setStereo(res);
207 aglDescribePixelFormat(format, AGL_SAMPLE_BUFFERS_ARB, &res);
208 this->format.setSampleBuffers(res);
209 if (this->format.sampleBuffers()) {
210 aglDescribePixelFormat(format, AGL_SAMPLES_ARB, &res);
211 this->format.setSamples(res);
214 AGLContext share = 0;
216 share = share_ctx =
static_cast<AGLContext
>(shareWidget->d_func()->glcx->d_func()->cx);
217 ctx = aglCreateContext(format, share);
219 qWarning(
"QGLPixelBuffer: Unable to create a context (AGL error %d).",
220 (
int) aglGetError());
234 qWarning(
"QGLPixelBuffer: Unable to create a pbuffer (AGL error %d).",
235 (
int) aglGetError());
239 if (!aglSetPBuffer(
ctx,
pbuf, 0, 0, 0)) {
240 qWarning(
"QGLPixelBuffer: Unable to set pbuffer (AGL error %d).",
241 (
int) aglGetError());
245 aglDestroyPixelFormat(format);
253 #ifdef QT_MAC_USE_COCOA 254 [
static_cast<NSOpenGLPixelBuffer *
>(
pbuf) release];
256 [
static_cast<NSOpenGLContext *
>(
ctx) release];
259 aglDestroyPBuffer(
pbuf);
267 if (
d->invalid || !
d->share_ctx)
270 #ifdef QT_MAC_USE_COCOA 271 NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
272 if (
d->share_ctx != oldContext)
273 [
static_cast<NSOpenGLContext *
>(
d->share_ctx) makeCurrentContext];
275 [
static_cast<NSOpenGLContext *
>(
d->share_ctx)
276 setTextureImageToPixelBuffer:static_cast<NSOpenGLPixelBuffer *>(
d->pbuf)
278 if (oldContext && oldContext !=
d->share_ctx)
279 [oldContext makeCurrentContext];
282 aglSetCurrentContext(
d->share_ctx);
284 aglTexImagePBuffer(
d->share_ctx,
d->pbuf,
GL_FRONT);
289 #ifdef Q_MAC_COMPAT_GL_FUNCTIONS 292 return bindToDynamicTexture(GLuint(texture_id));
302 #ifdef QT_MAC_USE_COCOA 304 NSOpenGLContext *oldContext = [NSOpenGLContext currentContext];
305 if (
d->share_ctx != oldContext)
306 [
static_cast<NSOpenGLContext *
>(
d->share_ctx) makeCurrentContext];
308 glGenTextures(1, &texture);
313 if (oldContext && oldContext !=
d->share_ctx)
314 [oldContext makeCurrentContext];
318 glGenTextures(1, &texture);
#define GL_TEXTURE_MIN_FILTER
#define QT_END_NAMESPACE
This macro expands to.
static bool hasOpenGLPbuffers()
Returns true if the OpenGL pbuffer extension is present on this system; otherwise returns false...
int width() const
Returns the width.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QGLFormat format() const
Returns the frame buffer format that was obtained (this may be a subset of what was requested)...
virtual bool create(const QGLContext *shareContext=0)
Creates the GL context.
The QGLContext class encapsulates an OpenGL rendering context.
Q_CORE_EXPORT void qWarning(const char *,...)
The QGLPixelBuffer class encapsulates an OpenGL pbuffer.
bool bindToDynamicTexture(GLuint texture)
Generates and binds a 2D GL texture that is the same size as the pbuffer, and returns the texture's I...
bool isSharing() const
Returns true if this context is sharing its GL context with another QGLContext, otherwise false is re...
int height() const
Returns the height.
static Extensions glExtensions()
static int nearest_gl_texture_size(int v)
bool init(const QSize &size, const QGLFormat &f, QGLWidget *shareWidget)
#define GL_TEXTURE_RECTANGLE_EXT
GLuint generateDynamicTexture() const
The QSize class defines the size of a two-dimensional object using integer point precision.
#define GL_TEXTURE_MAG_FILTER
void releaseFromDynamicTexture()
Releases the pbuffer from any previously bound texture.