[PATCH 5/6] wined3d: Get rid of activeContext.
Henri Verbeet
hverbeet at codeweavers.com
Fri Jul 24 03:44:17 CDT 2009
---
dlls/wined3d/arb_program_shader.c | 42 ++++++++++++++++++------------------
dlls/wined3d/context.c | 7 ------
dlls/wined3d/device.c | 42 ++++++++++++++++++------------------
dlls/wined3d/drawprim.c | 10 +++++---
dlls/wined3d/surface.c | 10 ++++++--
dlls/wined3d/wined3d_private.h | 1 -
6 files changed, 55 insertions(+), 57 deletions(-)
diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index 2cea845..682624b 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -534,17 +534,15 @@ static void shader_arb_load_constants(
IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) device;
IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
- const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
+ const struct WineD3DContext *context = context_get_current();
+ const struct wined3d_gl_info *gl_info = context->gl_info;
if (useVertexShader) {
IWineD3DBaseShaderImpl* vshader = (IWineD3DBaseShaderImpl*) stateBlock->vertexShader;
/* Load DirectX 9 float constants for vertex shader */
- deviceImpl->highest_dirty_vs_const = shader_arb_load_constantsF(
- vshader, gl_info, GL_VERTEX_PROGRAM_ARB,
- deviceImpl->highest_dirty_vs_const,
- stateBlock->vertexShaderConstantF,
- deviceImpl->activeContext->vshader_const_dirty);
+ deviceImpl->highest_dirty_vs_const = shader_arb_load_constantsF(vshader, gl_info, GL_VERTEX_PROGRAM_ARB,
+ deviceImpl->highest_dirty_vs_const, stateBlock->vertexShaderConstantF, context->vshader_const_dirty);
shader_arb_vs_local_constants(deviceImpl);
}
@@ -553,11 +551,8 @@ static void shader_arb_load_constants(
IWineD3DBaseShaderImpl* pshader = (IWineD3DBaseShaderImpl*) stateBlock->pixelShader;
/* Load DirectX 9 float constants for pixel shader */
- deviceImpl->highest_dirty_ps_const = shader_arb_load_constantsF(
- pshader, gl_info, GL_FRAGMENT_PROGRAM_ARB,
- deviceImpl->highest_dirty_ps_const,
- stateBlock->pixelShaderConstantF,
- deviceImpl->activeContext->pshader_const_dirty);
+ deviceImpl->highest_dirty_ps_const = shader_arb_load_constantsF(pshader, gl_info, GL_FRAGMENT_PROGRAM_ARB,
+ deviceImpl->highest_dirty_ps_const, stateBlock->pixelShaderConstantF, context->pshader_const_dirty);
shader_arb_ps_local_constants(deviceImpl);
}
}
@@ -565,22 +560,26 @@ static void shader_arb_load_constants(
static void shader_arb_update_float_vertex_constants(IWineD3DDevice *iface, UINT start, UINT count)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+ struct WineD3DContext *context = context_get_current();
/* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
* context. On a context switch the old context will be fully dirtified */
- memset(This->activeContext->vshader_const_dirty + start, 1,
- sizeof(*This->activeContext->vshader_const_dirty) * count);
+ if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice != This) return;
+
+ memset(context->vshader_const_dirty + start, 1, sizeof(*context->vshader_const_dirty) * count);
This->highest_dirty_vs_const = max(This->highest_dirty_vs_const, start + count);
}
static void shader_arb_update_float_pixel_constants(IWineD3DDevice *iface, UINT start, UINT count)
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+ struct WineD3DContext *context = context_get_current();
/* We don't want shader constant dirtification to be an O(contexts), so just dirtify the active
* context. On a context switch the old context will be fully dirtified */
- memset(This->activeContext->pshader_const_dirty + start, 1,
- sizeof(*This->activeContext->pshader_const_dirty) * count);
+ if (!context || ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice != This) return;
+
+ memset(context->pshader_const_dirty + start, 1, sizeof(*context->pshader_const_dirty) * count);
This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, start + count);
}
@@ -4216,7 +4215,8 @@ static inline void find_arb_vs_compile_args(IWineD3DVertexShaderImpl *shader, IW
static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
struct shader_arb_priv *priv = This->shader_priv;
- const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
+ struct WineD3DContext *context = context_get_current();
+ const struct wined3d_gl_info *gl_info = context->gl_info;
int i;
/* Deal with pixel shaders first so the vertex shader arg function has the input signature ready */
@@ -4251,7 +4251,7 @@ static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, 8);
for(i = 0; i < 8; i++)
{
- This->activeContext->pshader_const_dirty[i] = 1;
+ context->pshader_const_dirty[i] = 1;
}
/* Also takes care of loading local constants */
shader_arb_load_constants(iface, TRUE, FALSE);
@@ -5172,7 +5172,7 @@ static void state_texfactor_arbfp(DWORD state, IWineD3DStateBlockImpl *statebloc
if (use_ps(stateblock)) return;
device = stateblock->wineD3DDevice;
- device->activeContext->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1;
+ context->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1;
device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_TFACTOR + 1);
}
@@ -5193,7 +5193,7 @@ static void state_arb_specularenable(DWORD state, IWineD3DStateBlockImpl *stateb
if (use_ps(stateblock)) return;
device = stateblock->wineD3DDevice;
- device->activeContext->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1;
+ context->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1;
device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1);
}
@@ -5231,7 +5231,7 @@ static void set_bumpmat_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, W
return;
}
} else if(device->shader_backend == &arb_program_shader_backend) {
- device->activeContext->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1;
+ context->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1;
device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_BUMPMAT(stage) + 1);
}
@@ -5266,7 +5266,7 @@ static void tex_bumpenvlum_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock
return;
}
} else if(device->shader_backend == &arb_program_shader_backend) {
- device->activeContext->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1;
+ context->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1;
device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_LUMINANCE(stage) + 1);
}
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 0109254..336c4d7 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1447,12 +1447,6 @@ void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context)
context_destroy_gl_resources(context);
destroy = TRUE;
- if (This->activeContext == context)
- {
- This->activeContext = NULL;
- TRACE("Destroying the active context.\n");
- }
-
if (!context_set_current(NULL))
{
ERR("Failed to clear current D3D context.\n");
@@ -2005,7 +1999,6 @@ struct WineD3DContext *ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface
This->highest_dirty_ps_const = GL_LIMITS(pshader_constantsF);
}
}
- This->activeContext = context;
switch (usage) {
case CTXUSAGE_CLEAR:
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 7e596b8..e62934c 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2145,7 +2145,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface,
This->render_targets[0] = swapchain->frontBuffer;
}
IWineD3DSurface_AddRef(This->render_targets[0]);
- This->activeContext = swapchain->context[0];
/* Depth Stencil support */
This->stencilBufferTarget = This->auto_depth_stencil_buffer;
@@ -2191,7 +2190,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface,
case ORM_BACKBUFFER:
{
- if(This->activeContext->aux_buffers > 0) {
+ if (context_get_current()->aux_buffers > 0)
+ {
TRACE("Using auxilliary buffer for offscreen rendering\n");
This->offscreenBuffer = GL_AUX0;
} else {
@@ -6011,6 +6011,7 @@ static void color_fill_fbo(IWineD3DDevice *iface, IWineD3DSurface *surface,
const WINED3DRECT *rect, const float color[4])
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+ struct WineD3DContext *context;
IWineD3DSwapChain *swapchain;
swapchain = get_swapchain(surface);
@@ -6019,20 +6020,20 @@ static void color_fill_fbo(IWineD3DDevice *iface, IWineD3DSurface *surface,
TRACE("Surface %p is onscreen\n", surface);
- ActivateContext(This, surface, CTXUSAGE_RESOURCELOAD);
+ context = ActivateContext(This, surface, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL);
+ context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
buffer = surface_get_gl_buffer(surface, swapchain);
glDrawBuffer(buffer);
checkGLcall("glDrawBuffer()");
} else {
TRACE("Surface %p is offscreen\n", surface);
- ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+ context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
- context_attach_surface_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, 0, surface);
- context_attach_depth_stencil_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL, FALSE);
+ context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
+ context_attach_surface_fbo(context, GL_FRAMEBUFFER_EXT, 0, surface);
+ context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, NULL, FALSE);
}
if (rect) {
@@ -6389,6 +6390,7 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
GLbitfield mask = GL_COLOR_BUFFER_BIT; /* TODO: Support blitting depth/stencil surfaces */
IWineD3DSwapChain *src_swapchain, *dst_swapchain;
+ struct WineD3DContext *context;
GLenum gl_filter;
POINT offset = {0, 0};
@@ -6414,9 +6416,9 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
src_swapchain = get_swapchain(src_surface);
dst_swapchain = get_swapchain(dst_surface);
- if (src_swapchain) ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
- else if (dst_swapchain) ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
- else ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+ if (src_swapchain) context = ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
+ else if (dst_swapchain) context = ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
+ else context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
if (src_swapchain) {
GLenum buffer = surface_get_gl_buffer(src_surface, src_swapchain);
@@ -6441,17 +6443,17 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
}
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, NULL);
+ context_bind_fbo(context, GL_READ_FRAMEBUFFER_EXT, NULL);
glReadBuffer(buffer);
checkGLcall("glReadBuffer()");
} else {
TRACE("Source surface %p is offscreen\n", src_surface);
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, &This->activeContext->src_fbo);
- context_attach_surface_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
+ context_bind_fbo(context, GL_READ_FRAMEBUFFER_EXT, &context->src_fbo);
+ context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
checkGLcall("glReadBuffer()");
- context_attach_depth_stencil_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, NULL, FALSE);
+ context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER_EXT, NULL, FALSE);
}
LEAVE_GL();
@@ -6480,18 +6482,18 @@ void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED
}
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, NULL);
+ context_bind_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, NULL);
glDrawBuffer(buffer);
checkGLcall("glDrawBuffer()");
} else {
TRACE("Destination surface %p is offscreen\n", dst_surface);
ENTER_GL();
- context_bind_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
- context_attach_surface_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
+ context_bind_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, &context->dst_fbo);
+ context_attach_surface_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
checkGLcall("glDrawBuffer()");
- context_attach_depth_stencil_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, NULL, FALSE);
+ context_attach_depth_stencil_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, NULL, FALSE);
}
glDisable(GL_SCISSOR_TEST);
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE));
@@ -6987,7 +6989,6 @@ void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain_
while(This->numContexts) {
DestroyContext(This, This->contexts[0]);
}
- This->activeContext = NULL;
HeapFree(GetProcessHeap(), 0, swapchain->context);
swapchain->context = NULL;
swapchain->num_contexts = 0;
@@ -7009,7 +7010,6 @@ HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *
swapchain->context[0] = CreateContext(This, target, swapchain->win_handle, FALSE,
&swapchain->presentParms);
swapchain->num_contexts = 1;
- This->activeContext = swapchain->context[0];
create_dummy_textures(This);
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 889ef6b..57f4227 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -73,6 +73,7 @@ static void drawStridedFast(IWineD3DDevice *iface, GLenum primitive_type,
static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_stream_info *si, UINT NumVertexes,
GLenum glPrimType, const void *idxData, UINT idxSize, UINT minIndex, UINT startIdx)
{
+ struct WineD3DContext *context = context_get_current();
unsigned int textureNo = 0;
const WORD *pIdxBufS = NULL;
const DWORD *pIdxBufL = NULL;
@@ -122,7 +123,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_stream_i
element = &si->elements[WINED3D_FFP_DIFFUSE];
if (element->data) diffuse = element->data + streamOffset[element->stream_idx];
else glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- num_untracked_materials = This->activeContext->num_untracked_materials;
+ num_untracked_materials = context->num_untracked_materials;
if (num_untracked_materials && element->format_desc->format != WINED3DFMT_A8R8G8B8)
FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format_desc->format));
@@ -261,7 +262,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_stream_i
for (i = 0; i < num_untracked_materials; ++i)
{
- glMaterialfv(GL_FRONT_AND_BACK, This->activeContext->untracked_materials[i], color);
+ glMaterialfv(GL_FRONT_AND_BACK, context->untracked_materials[i], color);
}
}
}
@@ -608,7 +609,7 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertice
if (!use_vs(This->stateBlock))
{
- if (!This->strided_streams.position_transformed && This->activeContext->num_untracked_materials
+ if (!This->strided_streams.position_transformed && context->num_untracked_materials
&& This->stateBlock->renderState[WINED3DRS_LIGHTING])
{
static BOOL warned;
@@ -620,7 +621,8 @@ void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertice
}
emulation = TRUE;
}
- else if(This->activeContext->fog_coord && This->stateBlock->renderState[WINED3DRS_FOGENABLE]) {
+ else if (context->fog_coord && This->stateBlock->renderState[WINED3DRS_FOGENABLE])
+ {
/* Either write a pipeline replacement shader or convert the specular alpha from unsigned byte
* to a float in the vertex buffer
*/
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index db33675..843247d 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3140,13 +3140,14 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
float left, right, top, bottom; /* Texture coordinates */
UINT fbwidth = Src->currentDesc.Width;
UINT fbheight = Src->currentDesc.Height;
+ struct WineD3DContext *context;
GLenum drawBuffer = GL_BACK;
GLenum texture_target;
BOOL noBackBufferBackup;
TRACE("Using hwstretch blit\n");
/* Activate the Proper context for reading from the source surface, set it up for blitting */
- ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
+ context = ActivateContext(myDevice, SrcSurface, CTXUSAGE_BLIT);
surface_internal_preload((IWineD3DSurface *) This, SRGB_RGB);
noBackBufferBackup = !swapchain && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
@@ -3160,10 +3161,13 @@ static inline void fb_copy_to_texture_hwstretch(IWineD3DSurfaceImpl *This, IWine
/* Try to use an aux buffer for drawing the rectangle. This way it doesn't need restoring.
* This way we don't have to wait for the 2nd readback to finish to leave this function.
*/
- if(myDevice->activeContext->aux_buffers >= 2) {
+ if (context->aux_buffers >= 2)
+ {
/* Got more than one aux buffer? Use the 2nd aux buffer */
drawBuffer = GL_AUX1;
- } else if((swapchain || myDevice->offscreenBuffer == GL_BACK) && myDevice->activeContext->aux_buffers >= 1) {
+ }
+ else if ((swapchain || myDevice->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1)
+ {
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
drawBuffer = GL_AUX0;
}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index f2b376a..00f311d 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1616,7 +1616,6 @@ struct IWineD3DDeviceImpl
/* Context management */
WineD3DContext **contexts; /* Dynamic array containing pointers to context structures */
- WineD3DContext *activeContext;
UINT numContexts;
WineD3DContext *pbufferContext; /* The context that has a pbuffer as drawable */
DWORD pbufferWidth, pbufferHeight; /* Size of the buffer drawable */
--
1.6.0.6
More information about the wine-patches
mailing list