void GL_APIENTRY _mesa_TexEnvxv(GLenum target, GLenum pname, const GLfixed *params) { switch(target) { case GL_POINT_SPRITE: case GL_TEXTURE_FILTER_CONTROL_EXT: case GL_TEXTURE_ENV: break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexEnvxv(target=0x%x)", target); return; } switch(pname) { case GL_COORD_REPLACE: case GL_TEXTURE_ENV_MODE: case GL_COMBINE_RGB: case GL_COMBINE_ALPHA: case GL_SRC0_RGB: case GL_SRC1_RGB: case GL_SRC2_RGB: case GL_SRC0_ALPHA: case GL_SRC1_ALPHA: case GL_SRC2_ALPHA: case GL_OPERAND0_RGB: case GL_OPERAND1_RGB: case GL_OPERAND2_RGB: case GL_OPERAND0_ALPHA: case GL_OPERAND1_ALPHA: case GL_OPERAND2_ALPHA: _mesa_TexEnvf(target, pname, (GLfloat) params[0]); break; case GL_TEXTURE_LOD_BIAS_EXT: case GL_RGB_SCALE: case GL_ALPHA_SCALE: _mesa_TexEnvf(target, pname, (GLfloat) (params[0] / 65536.0f)); break; case GL_TEXTURE_ENV_COLOR: { unsigned int i; GLfloat converted_params[4]; for (i = 0; i < ARRAY_SIZE(converted_params); i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } _mesa_TexEnvfv(target, pname, converted_params); break; } default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexEnvxv(pname=0x%x)", pname); return; } }
void GL_APIENTRY _mesa_TexParameterxv(GLenum target, GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; bool convert_params_value = true; switch(target) { case GL_TEXTURE_2D: case GL_TEXTURE_CUBE_MAP: case GL_TEXTURE_EXTERNAL_OES: break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexParameterxv(target=0x%x)", target); return; } switch(pname) { case GL_TEXTURE_WRAP_S: case GL_TEXTURE_WRAP_T: convert_params_value = false; n_params = 1; break; case GL_TEXTURE_MIN_FILTER: case GL_TEXTURE_MAG_FILTER: case GL_GENERATE_MIPMAP: convert_params_value = false; n_params = 1; break; case GL_TEXTURE_MAX_ANISOTROPY_EXT: n_params = 1; break; case GL_TEXTURE_CROP_RECT_OES: n_params = 4; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexParameterxv(pname=0x%x)", pname); return; } if (convert_params_value) { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } } else { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) params[i]; } } _mesa_TexParameterfv(target, pname, converted_params); }
void GL_APIENTRY _mesa_LightModelxv(GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; bool convert_params_value = true; switch(pname) { case GL_LIGHT_MODEL_AMBIENT: n_params = 4; break; case GL_LIGHT_MODEL_TWO_SIDE: convert_params_value = false; n_params = 1; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glLightModelxv(pname=0x%x)", pname); return; } if (convert_params_value) { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } } else { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) params[i]; } } _mesa_LightModelfv(pname, converted_params); }
void GL_APIENTRY _mesa_PointParameterxv(GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 3; GLfloat converted_params[3]; switch(pname) { case GL_POINT_SIZE_MIN: case GL_POINT_SIZE_MAX: case GL_POINT_FADE_THRESHOLD_SIZE: n_params = 1; break; case GL_POINT_DISTANCE_ATTENUATION: n_params = 3; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glPointParameterxv(pname=0x%x)", pname); return; } for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } _mesa_PointParameterfv(pname, converted_params); }
void GL_APIENTRY _mesa_Materialx(GLenum face, GLenum pname, GLfixed param) { if (face != GL_FRONT_AND_BACK) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glMaterialx(face=0x%x)", face); return; } if (pname != GL_SHININESS) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glMaterialx(pname=0x%x)", pname); return; } _es_Materialf(face, pname, (GLfloat) (param / 65536.0f)); }
GLAPI OSMesaContext GLAPIENTRY OSMesaGetCurrentContext( void ) { struct gl_context *ctx = _mesa_get_current_context(); if (ctx) return (OSMesaContext) ctx; else return NULL; }
void GL_APIENTRY _mesa_TexEnvx(GLenum target, GLenum pname, GLfixed param) { switch(target) { case GL_POINT_SPRITE: case GL_TEXTURE_FILTER_CONTROL_EXT: case GL_TEXTURE_ENV: break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexEnvx(target=0x%x)", target); return; } switch(pname) { case GL_COORD_REPLACE: case GL_TEXTURE_ENV_MODE: case GL_COMBINE_RGB: case GL_COMBINE_ALPHA: case GL_SRC0_RGB: case GL_SRC1_RGB: case GL_SRC2_RGB: case GL_SRC0_ALPHA: case GL_SRC1_ALPHA: case GL_SRC2_ALPHA: case GL_OPERAND0_RGB: case GL_OPERAND1_RGB: case GL_OPERAND2_RGB: case GL_OPERAND0_ALPHA: case GL_OPERAND1_ALPHA: case GL_OPERAND2_ALPHA: _mesa_TexEnvf(target, pname, (GLfloat) param); break; case GL_TEXTURE_LOD_BIAS_EXT: case GL_RGB_SCALE: case GL_ALPHA_SCALE: _mesa_TexEnvf(target, pname, (GLfloat) (param / 65536.0f)); break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glTexEnvx(pname=0x%x)", pname); return; } }
static int changed(ggi_visual_t vis, int whatchanged) { GLcontext *ctx; ctx = _mesa_get_current_context(); GGIMESADPRINT_CORE("changed() called\n"); switch (whatchanged) { case GGI_CHG_APILIST: { char api[GGI_MAX_APILEN]; char args[GGI_MAX_APILEN]; int i; const char *fname; ggi_dlhandle *lib; GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual); GLframebuffer *gl_fb = &(LIBGGI_MESAEXT(vis)->mesa_buffer); /* Initialize the framebuffer to provide all necessary buffers in software. The target libraries that are loaded next are free to modify this according to their capabilities. */ /* FIXME: if the target changes capabilities we'll leak swrast's memory !!! Need to deallocate first */ _mesa_initialize_framebuffer(gl_fb, gl_vis, gl_vis->depthBits > 0, gl_vis->stencilBits > 0, gl_vis->accumRedBits > 0, gl_vis->alphaBits > 0); for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++) { strcat(api, "-mesa"); GGIMESADPRINT_CORE("GGIMesa: looking for" "a sublib named %s\n", api); fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL); if (fname == NULL) { /* No special implementation for this sublib */ continue; } lib = ggiExtensionLoadDL(vis, fname, args, NULL, SUBLIB_PREFIX); } /* The targets have cleared everything they can do from the framebuffer structure so we provide the rest in sw */ /*_swrast_alloc_buffers(gl_fb);*/ break; } } return 0; }
void GL_APIENTRY _mesa_Lightxv(GLenum light, GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; if (light < GL_LIGHT0 || light > GL_LIGHT7) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glLightxv(light=0x%x)", light); return; } switch(pname) { case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_POSITION: n_params = 4; break; case GL_SPOT_DIRECTION: n_params = 3; break; case GL_SPOT_EXPONENT: case GL_SPOT_CUTOFF: case GL_CONSTANT_ATTENUATION: case GL_LINEAR_ATTENUATION: case GL_QUADRATIC_ATTENUATION: n_params = 1; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glLightxv(pname=0x%x)", pname); return; } for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } _mesa_Lightfv(light, pname, converted_params); }
/* * Bind buffer b to context c and make c the current rendering context. */ PUBLIC GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, XMesaBuffer readBuffer ) { if (c) { if (!drawBuffer || !readBuffer) return GL_FALSE; /* must specify buffers! */ if (&(c->mesa) == _mesa_get_current_context() && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer && c->mesa.ReadBuffer == &readBuffer->mesa_buffer && XMESA_BUFFER(c->mesa.DrawBuffer)->wasCurrent) { /* same context and buffer, do nothing */ return GL_TRUE; } c->xm_buffer = drawBuffer; /* Call this periodically to detect when the user has begun using * GL rendering from multiple threads. */ _glapi_check_multithread(); xmesa_check_and_update_buffer_size(c, drawBuffer); if (readBuffer != drawBuffer) xmesa_check_and_update_buffer_size(c, readBuffer); _mesa_make_current(&(c->mesa), &drawBuffer->mesa_buffer, &readBuffer->mesa_buffer); /* * Must recompute and set these pixel values because colormap * can be different for different windows. */ c->clearpixel = xmesa_color_to_pixel( &c->mesa, c->clearcolor[0], c->clearcolor[1], c->clearcolor[2], c->clearcolor[3], c->xm_visual->undithered_pf); XMesaSetForeground(c->display, drawBuffer->cleargc, c->clearpixel); /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ drawBuffer->wasCurrent = GL_TRUE; } else { /* Detach */ _mesa_make_current( NULL, NULL, NULL ); } return GL_TRUE; }
static void gl_ggiGetSize(GLframebuffer *fb, GLuint *width, GLuint *height) { /* FIXME: this is a hack to work around the new interface */ GLcontext *ctx; ggi_mesa_context_t ggi_ctx; ctx = _mesa_get_current_context(); ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiGetSize() called\n"); *width = LIBGGI_VIRTX(ggi_ctx->ggi_visual); *height = LIBGGI_VIRTY(ggi_ctx->ggi_visual); printf("returning %d, %d\n", *width, *height); }
void GL_APIENTRY _mesa_GetMaterialxv(GLenum face, GLenum pname, GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; switch(face) { case GL_FRONT: case GL_BACK: break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetMaterialxv(face=0x%x)", face); return; } switch(pname) { case GL_SHININESS: n_params = 1; break; case GL_AMBIENT: case GL_DIFFUSE: case GL_SPECULAR: case GL_EMISSION: n_params = 4; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetMaterialxv(pname=0x%x)", pname); return; } _mesa_GetMaterialfv(face, pname, converted_params); for (i = 0; i < n_params; i++) { params[i] = (GLint) (converted_params[i] * 65536); } }
void GL_APIENTRY _es_Materialxv(GLenum face, GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; if (face != GL_FRONT_AND_BACK) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glMaterialxv(face=0x%x)", face); return; } switch(pname) { case GL_AMBIENT: case GL_DIFFUSE: case GL_AMBIENT_AND_DIFFUSE: case GL_SPECULAR: case GL_EMISSION: n_params = 4; break; case GL_SHININESS: n_params = 1; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glMaterialxv(pname=0x%x)", pname); return; } for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } _es_Materialfv(face, pname, converted_params); }
/* * XXX move somewhere else someday? */ void _mesa_SampleCoverageARB(GLclampf value, GLboolean invert) { GLcontext *ctx = _mesa_get_current_context(); if (!ctx->Extensions.ARB_multisample) { _mesa_error(ctx, GL_INVALID_OPERATION, "glSampleCoverageARB"); return; } ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx ); ctx->Multisample.SampleCoverageValue = (GLfloat) CLAMP(value, 0.0, 1.0); ctx->Multisample.SampleCoverageInvert = invert; ctx->NewState |= _NEW_MULTISAMPLE; }
/* * GL_MESA_resize_buffers extension * When this function is called, we'll ask the window system how large * the current window is. If it's not what we expect, we'll have to * resize/reallocate the software accum/stencil/depth/alpha buffers. */ void _mesa_ResizeBuffersMESA( void ) { GLcontext *ctx = _mesa_get_current_context(); if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(ctx, "glResizeBuffersMESA\n"); if (ctx) { ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH( ctx ); if (ctx->DrawBuffer) { GLuint buf_width, buf_height; GLframebuffer *buffer = ctx->DrawBuffer; /* ask device driver for size of output buffer */ (*ctx->Driver.GetBufferSize)( buffer, &buf_width, &buf_height ); /* see if size of device driver's color buffer (window) has changed */ if (buffer->Width == buf_width && buffer->Height == buf_height) return; /* size is as expected */ buffer->Width = buf_width; buffer->Height = buf_height; ctx->Driver.ResizeBuffers( buffer ); } if (ctx->ReadBuffer && ctx->ReadBuffer != ctx->DrawBuffer) { GLuint buf_width, buf_height; GLframebuffer *buffer = ctx->ReadBuffer; /* ask device driver for size of read buffer */ (*ctx->Driver.GetBufferSize)( buffer, &buf_width, &buf_height ); /* see if size of device driver's color buffer (window) has changed */ if (buffer->Width == buf_width && buffer->Height == buf_height) return; /* size is as expected */ buffer->Width = buf_width; buffer->Height = buf_height; ctx->Driver.ResizeBuffers( buffer ); } ctx->NewState |= _NEW_BUFFERS; /* to update scissor / window bounds */ } }
static GLboolean dri_make_current(__DRIcontext * cPriv, __DRIdrawable * driDrawPriv, __DRIdrawable * driReadPriv) { struct gl_context *mesaCtx; struct gl_framebuffer *mesaDraw; struct gl_framebuffer *mesaRead; TRACE; if (cPriv) { struct dri_context *ctx = dri_context(cPriv); struct dri_drawable *draw; struct dri_drawable *read; if (!driDrawPriv || !driReadPriv) return GL_FALSE; draw = dri_drawable(driDrawPriv); read = dri_drawable(driReadPriv); mesaCtx = &ctx->Base; mesaDraw = &draw->Base; mesaRead = &read->Base; /* check for same context and buffer */ if (mesaCtx == _mesa_get_current_context() && mesaCtx->DrawBuffer == mesaDraw && mesaCtx->ReadBuffer == mesaRead) { return GL_TRUE; } _glapi_check_multithread(); swrast_check_and_update_window_size(mesaCtx, mesaDraw); if (mesaRead != mesaDraw) swrast_check_and_update_window_size(mesaCtx, mesaRead); _mesa_make_current( mesaCtx, mesaDraw, mesaRead ); } else { /* unbind */ _mesa_make_current( NULL, NULL, NULL ); } return GL_TRUE; }
/* * Make the specified FX/Mesa context the current one. */ void GLAPIENTRY fxMesaMakeCurrent(fxMesaContext fxMesa) { if (!fxMesa) { _mesa_make_current(NULL, NULL, NULL); fxMesaCurrentCtx = NULL; if (TDFX_DEBUG & VERBOSE_DRIVER) { fprintf(stderr, "fxMesaMakeCurrent(NULL)\n"); } return; } /* if this context is already the current one, we can return early */ if (fxMesaCurrentCtx == fxMesa && fxMesaCurrentCtx->glCtx == _mesa_get_current_context()) { if (TDFX_DEBUG & VERBOSE_DRIVER) { fprintf(stderr, "fxMesaMakeCurrent(NOP)\n"); } return; } if (TDFX_DEBUG & VERBOSE_DRIVER) { fprintf(stderr, "fxMesaMakeCurrent(...)\n"); } if (fxMesaCurrentCtx) grGlideGetState((GrState *) fxMesaCurrentCtx->state); fxMesaCurrentCtx = fxMesa; grSstSelect(fxMesa->board); grGlideSetState((GrState *) fxMesa->state); _mesa_make_current(fxMesa->glCtx, fxMesa->glBuffer, fxMesa->glBuffer); fxSetupDDPointers(fxMesa->glCtx); }
void GL_APIENTRY _mesa_Fogxv(GLenum pname, const GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; bool convert_params_value = true; switch(pname) { case GL_FOG_MODE: convert_params_value = false; n_params = 1; break; case GL_FOG_COLOR: n_params = 4; break; case GL_FOG_DENSITY: case GL_FOG_START: case GL_FOG_END: n_params = 1; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glFogxv(pname=0x%x)", pname); return; } if (convert_params_value) { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) (params[i] / 65536.0f); } } else { for (i = 0; i < n_params; i++) { converted_params[i] = (GLfloat) params[i]; } } _mesa_Fogfv(pname, converted_params); }
/* * Swap front/back buffers for current context if double buffered. */ void ggiMesaSwapBuffers(void) { GLcontext *ctx; ggi_mesa_context_t ggi_ctx; ctx = _mesa_get_current_context(); ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n"); _mesa_notifySwapBuffers(ctx); gl_ggiFlush(ctx); ggiSetDisplayFrame(ggi_ctx->ggi_visual, !ggiGetDisplayFrame(ggi_ctx->ggi_visual)); ggiSetWriteFrame(ggi_ctx->ggi_visual, !ggiGetWriteFrame(ggi_ctx->ggi_visual)); ggiSetReadFrame(ggi_ctx->ggi_visual, !ggiGetReadFrame(ggi_ctx->ggi_visual)); GGIMESADPRINT_CORE("swap disp: %d, write %d\n", ggiGetDisplayFrame(ggi_ctx->ggi_visual), ggiGetWriteFrame(ggi_ctx->ggi_visual)); }
/** * Free the data associated with the given context. * * But doesn't free the GLcontext struct itself. * * \sa _mesa_initialize_context() and init_attrib_groups(). */ void _mesa_free_context_data( GLcontext *ctx ) { GLint RefCount; if (!_mesa_get_current_context()){ /* No current context, but we may need one in order to delete * texture objs, etc. So temporarily bind the context now. */ _mesa_make_current(ctx, NULL, NULL); } /* unreference WinSysDraw/Read buffers */ _mesa_reference_framebuffer(&ctx->WinSysDrawBuffer, NULL); _mesa_reference_framebuffer(&ctx->WinSysReadBuffer, NULL); _mesa_reference_framebuffer(&ctx->DrawBuffer, NULL); _mesa_reference_framebuffer(&ctx->ReadBuffer, NULL); _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, NULL); _mesa_reference_vertprog(ctx, &ctx->VertexProgram._Current, NULL); _mesa_reference_vertprog(ctx, &ctx->VertexProgram._TnlProgram, NULL); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current, NULL); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._Current, NULL); _mesa_reference_fragprog(ctx, &ctx->FragmentProgram._TexEnvProgram, NULL); _mesa_free_attrib_data(ctx); _mesa_free_lighting_data( ctx ); _mesa_free_eval_data( ctx ); _mesa_free_texture_data( ctx ); _mesa_free_matrix_data( ctx ); _mesa_free_viewport_data( ctx ); _mesa_free_colortables_data( ctx ); _mesa_free_program_data(ctx); _mesa_free_shader_state(ctx); _mesa_free_queryobj_data(ctx); #if FEATURE_ARB_sync _mesa_free_sync_data(ctx); #endif _mesa_free_varray_data(ctx); _mesa_delete_array_object(ctx, ctx->Array.DefaultArrayObj); #if FEATURE_ARB_pixel_buffer_object _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj, NULL); _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj, NULL); #endif #if FEATURE_ARB_vertex_buffer_object _mesa_reference_buffer_object(ctx, &ctx->Array.ArrayBufferObj, NULL); _mesa_reference_buffer_object(ctx, &ctx->Array.ElementArrayBufferObj, NULL); #endif /* free dispatch tables */ _mesa_free(ctx->Exec); _mesa_free(ctx->Save); /* Shared context state (display lists, textures, etc) */ _glthread_LOCK_MUTEX(ctx->Shared->Mutex); RefCount = --ctx->Shared->RefCount; _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex); assert(RefCount >= 0); if (RefCount == 0) { /* free shared state */ _mesa_free_shared_state( ctx, ctx->Shared ); } /* needs to be after freeing shared state */ _mesa_free_display_list_data(ctx); if (ctx->Extensions.String) _mesa_free((void *) ctx->Extensions.String); /* unbind the context if it's currently bound */ if (ctx == _mesa_get_current_context()) { _mesa_make_current(NULL, NULL, NULL); } }
/** * Bind the given context to the given drawBuffer and readBuffer and * make it the current context for the calling thread. * We'll render into the drawBuffer and read pixels from the * readBuffer (i.e. glRead/CopyPixels, glCopyTexImage, etc). * * We check that the context's and framebuffer's visuals are compatible * and return immediately if they're not. * * \param newCtx the new GL context. If NULL then there will be no current GL * context. * \param drawBuffer the drawing framebuffer * \param readBuffer the reading framebuffer */ GLboolean _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer, GLframebuffer *readBuffer ) { if (MESA_VERBOSE & VERBOSE_API) _mesa_debug(newCtx, "_mesa_make_current()\n"); /* Check that the context's and framebuffer's visuals are compatible. */ if (newCtx && drawBuffer && newCtx->WinSysDrawBuffer != drawBuffer) { if (!check_compatible(newCtx, drawBuffer)) { _mesa_warning(newCtx, "MakeCurrent: incompatible visuals for context and drawbuffer"); return GL_FALSE; } } if (newCtx && readBuffer && newCtx->WinSysReadBuffer != readBuffer) { if (!check_compatible(newCtx, readBuffer)) { _mesa_warning(newCtx, "MakeCurrent: incompatible visuals for context and readbuffer"); return GL_FALSE; } } /* We used to call _glapi_check_multithread() here. Now do it in drivers */ _glapi_set_context((void *) newCtx); ASSERT(_mesa_get_current_context() == newCtx); if (!newCtx) { _glapi_set_dispatch(NULL); /* none current */ } else { _glapi_set_dispatch(newCtx->CurrentDispatch); if (drawBuffer && readBuffer) { /* TODO: check if newCtx and buffer's visual match??? */ ASSERT(drawBuffer->Name == 0); ASSERT(readBuffer->Name == 0); _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer); _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer); /* * Only set the context's Draw/ReadBuffer fields if they're NULL * or not bound to a user-created FBO. */ if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) { /* KW: merge conflict here, revisit. */ /* fix up the fb fields - these will end up wrong otherwise * if the DRIdrawable changes, and everything relies on them. * This is a bit messy (same as needed in _mesa_BindFramebufferEXT) */ unsigned int i; GLenum buffers[MAX_DRAW_BUFFERS]; _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer); for(i = 0; i < newCtx->Const.MaxDrawBuffers; i++) { buffers[i] = newCtx->Color.DrawBuffer[i]; } _mesa_drawbuffers(newCtx, newCtx->Const.MaxDrawBuffers, buffers, NULL); } if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) { _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer); } /* XXX only set this flag if we're really changing the draw/read * framebuffer bindings. */ newCtx->NewState |= _NEW_BUFFERS; #if 1 /* We want to get rid of these lines: */ #if _HAVE_FULL_GL if (!drawBuffer->Initialized) { initialize_framebuffer_size(newCtx, drawBuffer); } if (readBuffer != drawBuffer && !readBuffer->Initialized) { initialize_framebuffer_size(newCtx, readBuffer); } _mesa_resizebuffers(newCtx); #endif #else /* We want the drawBuffer and readBuffer to be initialized by * the driver. * This generally means the Width and Height match the actual * window size and the renderbuffers (both hardware and software * based) are allocated to match. The later can generally be * done with a call to _mesa_resize_framebuffer(). * * It's theoretically possible for a buffer to have zero width * or height, but for now, assert check that the driver did what's * expected of it. */ ASSERT(drawBuffer->Width > 0); ASSERT(drawBuffer->Height > 0); #endif if (drawBuffer) { _mesa_check_init_viewport(newCtx, drawBuffer->Width, drawBuffer->Height); } } if (newCtx->FirstTimeCurrent) { check_context_limits(newCtx); /* We can use this to help debug user's problems. Tell them to set * the MESA_INFO env variable before running their app. Then the * first time each context is made current we'll print some useful * information. */ if (_mesa_getenv("MESA_INFO")) { _mesa_print_info(); } newCtx->FirstTimeCurrent = GL_FALSE; } } return GL_TRUE; }
MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView* view, ulong options, BGLDispatcher* dispatcher) : BGLRenderer(view, options, dispatcher), fBitmap(NULL), fDirectModeEnabled(false), fInfo(NULL), fInfoLocker("info locker"), fContext(NULL), fVisual(NULL), fFrameBuffer(NULL), fFrontRenderBuffer(NULL), fBackRenderBuffer(NULL), fColorSpace(B_NO_COLOR_SPACE) { CALLED(); fClearColor[BE_RCOMP] = 0; fClearColor[BE_GCOMP] = 0; fClearColor[BE_BCOMP] = 0; fClearColor[BE_ACOMP] = 0; fClearIndex = 0; fColorSpace = BScreen(GLView()->Window()).ColorSpace(); // We force single buffering for the time being options &= ~BGL_DOUBLE; const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); const GLboolean stereoFlag = false; const GLint depth = (options & BGL_DEPTH) ? 16 : 0; const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; const GLint accum = (options & BGL_ACCUM) ? 16 : 0; const GLint red = rgbFlag ? 8 : 0; const GLint green = rgbFlag ? 8 : 0; const GLint blue = rgbFlag ? 8 : 0; const GLint alpha = alphaFlag ? 8 : 0; fOptions = options; // | BGL_INDIRECT; struct dd_function_table functions; fVisual = _mesa_create_visual(dblFlag, stereoFlag, red, green, blue, alpha, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1); // Initialize device driver function table _mesa_init_driver_functions(&functions); functions.GetString = _GetString; functions.UpdateState = _UpdateState; functions.GetBufferSize = NULL; functions.Error = _Error; functions.Viewport = _Viewport; functions.Flush = _Flush; // create core context #if HAIKU_MESA_VER <= 708 fContext = _mesa_create_context(fVisual, NULL, &functions, this); #else fContext = _mesa_create_context(API_OPENGL, fVisual, NULL, &functions, this); #endif if (!fContext) { ERROR("%s: Failed to create Mesa context!\n", __func__); _mesa_destroy_visual(fVisual); return; } /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext(fContext); _vbo_CreateContext(fContext); _tnl_CreateContext(fContext); _swsetup_CreateContext(fContext); _swsetup_Wakeup(fContext); // Use default TCL pipeline TNL_CONTEXT(fContext)->Driver.RunPipeline = _tnl_run_pipeline; _mesa_meta_init(fContext); _mesa_enable_sw_extensions(fContext); _mesa_enable_1_3_extensions(fContext); _mesa_enable_1_4_extensions(fContext); _mesa_enable_1_5_extensions(fContext); _mesa_enable_2_0_extensions(fContext); _mesa_enable_2_1_extensions(fContext); // create core framebuffer fFrameBuffer = (struct msr_framebuffer*)calloc(1, sizeof(*fFrameBuffer)); if (fFrameBuffer == NULL) { ERROR("%s: Unable to calloc GL FrameBuffer!\n", __func__); _mesa_destroy_visual(fVisual); return; } _mesa_initialize_window_framebuffer(&fFrameBuffer->base, fVisual); // Setup front render buffer fFrontRenderBuffer = _NewRenderBuffer(true); if (fFrontRenderBuffer == NULL) { ERROR("%s: FrontRenderBuffer is requested but unallocated!\n", __func__); _mesa_destroy_visual(fVisual); free(fFrameBuffer); return; } _mesa_add_renderbuffer(&fFrameBuffer->base, BUFFER_FRONT_LEFT, &fFrontRenderBuffer->base); // Setup back render buffer (if requested) if (fVisual->doubleBufferMode) { fBackRenderBuffer = _NewRenderBuffer(false); if (fBackRenderBuffer == NULL) { ERROR("%s: BackRenderBuffer is requested but unallocated!\n", __func__); _mesa_destroy_visual(fVisual); free(fFrameBuffer); return; } _mesa_add_renderbuffer(&fFrameBuffer->base, BUFFER_BACK_LEFT, &fBackRenderBuffer->base); } #if HAIKU_MESA_VER >= 709 // New Mesa _swrast_add_soft_renderbuffers(&fFrameBuffer->base, GL_FALSE, fVisual->haveDepthBuffer, fVisual->haveStencilBuffer, fVisual->haveAccumBuffer, alphaFlag, GL_FALSE); #else // Old Mesa _mesa_add_soft_renderbuffers(&fFrameBuffer->base, GL_FALSE, fVisual->haveDepthBuffer, fVisual->haveStencilBuffer, fVisual->haveAccumBuffer, alphaFlag, GL_FALSE); #endif BRect bounds = view->Bounds(); fWidth = fNewWidth = (GLint)bounds.Width(); fHeight = fNewHeight = (GLint)bounds.Height(); // some stupid applications (Quake2) don't even think about calling LockGL() // before using glGetString and its glGet*() friends... // so make sure there is at least a valid context. if (!_mesa_get_current_context()) { LockGL(); // not needed, we don't have a looper yet: UnlockLooper(); } }
// // Input: rect - initial rectangle // name - window name // resizingMode - example: B_FOLLOW_NONE // mode - usually 0 ? // options - Bitwise-OR of BGL_* tokens // BGLView::BGLView(BRect rect, char *name, ulong resizingMode, ulong mode, ulong options) : BView(rect, name, B_FOLLOW_ALL_SIDES, mode | B_WILL_DRAW | B_FRAME_EVENTS) // | B_FULL_UPDATE_ON_RESIZE) { // We don't support single buffering (yet): double buffering forced. options |= BGL_DOUBLE; const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); const GLboolean stereoFlag = false; const GLint depth = (options & BGL_DEPTH) ? 16 : 0; const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; const GLint accum = (options & BGL_ACCUM) ? 16 : 0; const GLint index = (options & BGL_INDEX) ? 32 : 0; const GLint red = rgbFlag ? 8 : 0; const GLint green = rgbFlag ? 8 : 0; const GLint blue = rgbFlag ? 8 : 0; const GLint alpha = alphaFlag ? 8 : 0; m_options = options | BGL_INDIRECT; struct dd_function_table functions; if (!rgbFlag) { fprintf(stderr, "Mesa Warning: color index mode not supported\n"); } // Allocate auxiliary data object MesaDriver * md = new MesaDriver(); // examine option flags and create gl_context struct GLvisual * visual = _mesa_create_visual( rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha, index, depth, stencil, accum, accum, accum, accum, 1 ); // Initialize device driver function table _mesa_init_driver_functions(&functions); functions.GetString = md->GetString; functions.UpdateState = md->UpdateState; functions.GetBufferSize = md->GetBufferSize; functions.Clear = md->Clear; functions.ClearIndex = md->ClearIndex; functions.ClearColor = md->ClearColor; functions.Error = md->Error; functions.Viewport = md->Viewport; // create core context GLcontext *ctx = _mesa_create_context(visual, NULL, &functions, md); if (! ctx) { _mesa_destroy_visual(visual); delete md; return; } _mesa_enable_sw_extensions(ctx); _mesa_enable_1_3_extensions(ctx); _mesa_enable_1_4_extensions(ctx); _mesa_enable_1_5_extensions(ctx); // create core framebuffer GLframebuffer * buffer = _mesa_create_framebuffer(visual, depth > 0 ? GL_TRUE : GL_FALSE, stencil > 0 ? GL_TRUE: GL_FALSE, accum > 0 ? GL_TRUE : GL_FALSE, alphaFlag ); /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext(ctx); _vbo_CreateContext(ctx); _tnl_CreateContext(ctx); _swsetup_CreateContext(ctx); _swsetup_Wakeup(ctx); md->Init(this, ctx, visual, buffer ); // Hook aux data into BGLView object m_gc = md; // some stupid applications (Quake2) don't even think about calling LockGL() // before using glGetString and friends... so make sure there is at least a // valid context. if (!_mesa_get_current_context()) { LockGL(); // not needed, we don't have a looper yet: UnlockLooper(); } }
MesaSoftwareRenderer::MesaSoftwareRenderer(BGLView* view, ulong options, BGLDispatcher* dispatcher) : BGLRenderer(view, options, dispatcher), fBitmap(NULL), fDirectModeEnabled(false), fInfo(NULL), fInfoLocker("info locker"), fContext(NULL), fVisual(NULL), fFrameBuffer(NULL), fFrontRenderBuffer(NULL), fBackRenderBuffer(NULL), fColorSpace(B_NO_COLOR_SPACE) { CALLED(); fClearColor[BE_RCOMP] = 0; fClearColor[BE_GCOMP] = 0; fClearColor[BE_BCOMP] = 0; fClearColor[BE_ACOMP] = 0; fClearIndex = 0; fColorSpace = BScreen(GLView()->Window()).ColorSpace(); // We force single buffering for the time being //options &= !BGL_DOUBLE; const GLboolean rgbFlag = ((options & BGL_INDEX) == 0); const GLboolean alphaFlag = ((options & BGL_ALPHA) == BGL_ALPHA); const GLboolean dblFlag = ((options & BGL_DOUBLE) == BGL_DOUBLE); const GLboolean stereoFlag = false; const GLint depth = (options & BGL_DEPTH) ? 16 : 0; const GLint stencil = (options & BGL_STENCIL) ? 8 : 0; const GLint accum = (options & BGL_ACCUM) ? 16 : 0; const GLint index = (options & BGL_INDEX) ? 32 : 0; const GLint red = rgbFlag ? 8 : 0; const GLint green = rgbFlag ? 8 : 0; const GLint blue = rgbFlag ? 8 : 0; const GLint alpha = alphaFlag ? 8 : 0; fOptions = options; // | BGL_INDIRECT; struct dd_function_table functions; fVisual = _mesa_create_visual(rgbFlag, dblFlag, stereoFlag, red, green, blue, alpha, index, depth, stencil, accum, accum, accum, alpha ? accum : 0, 1); // Initialize device driver function table _mesa_init_driver_functions(&functions); functions.GetString = _GetString; functions.UpdateState = _UpdateState; functions.GetBufferSize = NULL; functions.Error = _Error; functions.Viewport = _Viewport; functions.Flush = _Flush; // create core context fContext = _mesa_create_context(fVisual, NULL, &functions, this); if (!fContext) { _mesa_destroy_visual(fVisual); return; } /* Initialize the software rasterizer and helper modules. */ _swrast_CreateContext(fContext); _vbo_CreateContext(fContext); _tnl_CreateContext(fContext); _swsetup_CreateContext(fContext); _swsetup_Wakeup(fContext); // Use default TCL pipeline TNL_CONTEXT(fContext)->Driver.RunPipeline = _tnl_run_pipeline; _mesa_enable_sw_extensions(fContext); _mesa_enable_1_3_extensions(fContext); _mesa_enable_1_4_extensions(fContext); _mesa_enable_1_5_extensions(fContext); _mesa_enable_2_0_extensions(fContext); _mesa_enable_2_1_extensions(fContext); // create core framebuffer fFrameBuffer = (struct msr_framebuffer*)_mesa_calloc( sizeof(*fFrameBuffer)); _mesa_initialize_framebuffer(&fFrameBuffer->Base, fVisual); fFrontRenderBuffer = (struct msr_renderbuffer*)_mesa_calloc( sizeof(*fFrontRenderBuffer)); _mesa_init_renderbuffer(&fFrontRenderBuffer->Base, 0); fFrontRenderBuffer->Base.AllocStorage = _FrontRenderbufferStorage; fFrontRenderBuffer->Base.Data = NULL; fFrontRenderBuffer->Base.InternalFormat = GL_RGBA; fFrontRenderBuffer->Base._BaseFormat = GL_RGBA; fFrontRenderBuffer->Base.DataType = GL_UNSIGNED_BYTE; fFrontRenderBuffer->Base.RedBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.GreenBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.BlueBits = 8 * sizeof(GLubyte); fFrontRenderBuffer->Base.AlphaBits = 8 * sizeof(GLubyte); _SetSpanFuncs(fFrontRenderBuffer, fColorSpace); _mesa_add_renderbuffer(&fFrameBuffer->Base, BUFFER_FRONT_LEFT, &fFrontRenderBuffer->Base); if (dblFlag) { fBackRenderBuffer = (struct msr_renderbuffer*)_mesa_calloc( sizeof(*fBackRenderBuffer)); _mesa_init_renderbuffer(&fBackRenderBuffer->Base, 0); fBackRenderBuffer->Base.AllocStorage = _BackRenderbufferStorage; fBackRenderBuffer->Base.Data = NULL; fBackRenderBuffer->Base.Delete = _DeleteBackBuffer; fBackRenderBuffer->Base.InternalFormat = GL_RGBA; fBackRenderBuffer->Base._BaseFormat = GL_RGBA; fBackRenderBuffer->Base.DataType = GL_UNSIGNED_BYTE; fBackRenderBuffer->Base.RedBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.GreenBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.BlueBits = 8 * sizeof(GLubyte); fBackRenderBuffer->Base.AlphaBits = 8 * sizeof(GLubyte); _SetSpanFuncs(fBackRenderBuffer, fColorSpace); _mesa_add_renderbuffer(&fFrameBuffer->Base, BUFFER_BACK_LEFT, &fBackRenderBuffer->Base); } _mesa_add_soft_renderbuffers(&fFrameBuffer->Base, GL_FALSE, fVisual->haveDepthBuffer, fVisual->haveStencilBuffer, fVisual->haveAccumBuffer, alphaFlag, GL_FALSE); BRect bounds = view->Bounds(); fWidth = fNewWidth = (GLint)bounds.Width(); fHeight = fNewHeight = (GLint)bounds.Height(); // some stupid applications (Quake2) don't even think about calling LockGL() // before using glGetString and its glGet*() friends... // so make sure there is at least a valid context. if (!_mesa_get_current_context()) { LockGL(); // not needed, we don't have a looper yet: UnlockLooper(); } }
void GL_APIENTRY _mesa_GetTexEnvxv(GLenum target, GLenum pname, GLfixed *params) { unsigned int i; unsigned int n_params = 4; GLfloat converted_params[4]; bool convert_params_value = true; switch(target) { case GL_POINT_SPRITE: if (pname != GL_COORD_REPLACE) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetTexEnvxv(target=0x%x)", target); return; } break; case GL_TEXTURE_FILTER_CONTROL_EXT: if (pname != GL_TEXTURE_LOD_BIAS_EXT) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetTexEnvxv(target=0x%x)", target); return; } break; case GL_TEXTURE_ENV: if (pname != GL_TEXTURE_ENV_COLOR && pname != GL_RGB_SCALE && pname != GL_ALPHA_SCALE && pname != GL_TEXTURE_ENV_MODE && pname != GL_COMBINE_RGB && pname != GL_COMBINE_ALPHA && pname != GL_SRC0_RGB && pname != GL_SRC1_RGB && pname != GL_SRC2_RGB && pname != GL_SRC0_ALPHA && pname != GL_SRC1_ALPHA && pname != GL_SRC2_ALPHA && pname != GL_OPERAND0_RGB && pname != GL_OPERAND1_RGB && pname != GL_OPERAND2_RGB && pname != GL_OPERAND0_ALPHA && pname != GL_OPERAND1_ALPHA && pname != GL_OPERAND2_ALPHA) { _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetTexEnvxv(target=0x%x)", target); return; } break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetTexEnvxv(target=0x%x)", target); return; } switch(pname) { case GL_COORD_REPLACE: convert_params_value = false; n_params = 1; break; case GL_TEXTURE_LOD_BIAS_EXT: n_params = 1; break; case GL_TEXTURE_ENV_COLOR: n_params = 4; break; case GL_RGB_SCALE: case GL_ALPHA_SCALE: n_params = 1; break; case GL_TEXTURE_ENV_MODE: case GL_COMBINE_RGB: case GL_COMBINE_ALPHA: case GL_SRC0_RGB: case GL_SRC1_RGB: case GL_SRC2_RGB: case GL_SRC0_ALPHA: case GL_SRC1_ALPHA: case GL_SRC2_ALPHA: case GL_OPERAND0_RGB: case GL_OPERAND1_RGB: case GL_OPERAND2_RGB: case GL_OPERAND0_ALPHA: case GL_OPERAND1_ALPHA: case GL_OPERAND2_ALPHA: convert_params_value = false; n_params = 1; break; default: _mesa_error(_mesa_get_current_context(), GL_INVALID_ENUM, "glGetTexEnvxv(pname=0x%x)", pname); return; } _mesa_GetTexEnvfv(target, pname, converted_params); if (convert_params_value) { for (i = 0; i < n_params; i++) { params[i] = (GLint) (converted_params[i] * 65536); } } else { for (i = 0; i < n_params; i++) { params[i] = (GLfixed) converted_params[i]; } } }