Commit c1623d4e authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: Use the context manager to prepare for drawing.

parent 380930dc
......@@ -12,6 +12,7 @@ C_SRCS = \
arb_program_shader.c \
baseshader.c \
basetexture.c \
context.c \
cubetexture.c \
device.c \
directx.c \
......
/*
* Context and render target management in wined3d
*
* Copyright 2007 Stefan Dösinger for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_FLOAT_H
# include <float.h>
#endif
#include "wined3d_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d);
/*****************************************************************************
* ActivateContext
*
* Finds a rendering context and drawable matching the device and render
* target for the current thread, activates them and puts them into the
* requested state.
*
* Params:
* This: Device to activate the context for
* target: Requested render target
* usage: Prepares the context for blitting, drawing or other actions
*
*****************************************************************************/
void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextUsage usage) {
DWORD tid = This->createParms.BehaviorFlags & D3DCREATE_MULTITHREADED ? GetCurrentThreadId() : 0;
int i;
DWORD dirtyState, idx;
BYTE shift;
WineD3DContext *context;
TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
/* TODO: Render target selection */
/* TODO: Thread selection */
/* TODO: Activate the opengl context */
context = &This->contexts[This->activeContext];
switch(usage) {
case CTXUSAGE_RESOURCELOAD:
/* This does not require any special states to be set up */
break;
case CTXUSAGE_DRAWPRIM:
/* This needs all dirty states applied */
for(i=0; i < context->numDirtyEntries; i++) {
dirtyState = context->dirtyArray[i];
idx = dirtyState >> 5;
shift = dirtyState & 0x1f;
context->isStateDirty[idx] &= ~(1 << shift);
StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
}
context->numDirtyEntries = 0; /* This makes the whole list clean */
break;
case CTXUSAGE_BLIT:
FIXME("Setting up for blitting not supported yet\n");
break;
default:
FIXME("Unexpected context usage requested\n");
}
}
......@@ -1178,10 +1178,7 @@ void drawPrimitive(IWineD3DDevice *iface,
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
IWineD3DSwapChainImpl *swapchain;
int i;
DWORD dirtyState, idx;
BYTE shift;
WineD3DContext *context;
int i;
/* Signals other modules that a drawing is in progress and the stateblock finalized */
This->isInDraw = TRUE;
......@@ -1198,18 +1195,7 @@ void drawPrimitive(IWineD3DDevice *iface,
/* Ok, we will be updating the screen from here onwards so grab the lock */
ENTER_GL();
/* TODO: Find the correct context for the render target / thread */
context = &This->contexts[This->activeContext];
/* Apply dirty states */
for(i=0; i < context->numDirtyEntries; i++) {
dirtyState = context->dirtyArray[i];
idx = dirtyState >> 5;
shift = dirtyState & 0x1f;
context->isStateDirty[idx] &= ~(1 << shift);
StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
}
context->numDirtyEntries = 0; /* This makes the whole list clean */
ActivateContext(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
if (TRACE_ON(d3d_draw) && wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
check_fbo_status(iface);
......
......@@ -290,6 +290,7 @@ do {
typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
typedef struct IWineD3DSurfaceImpl IWineD3DSurfaceImpl;
typedef struct IWineD3DPaletteImpl IWineD3DPaletteImpl;
typedef struct IWineD3DDeviceImpl IWineD3DDeviceImpl;
/* Tracking */
......@@ -478,6 +479,14 @@ struct WineD3DContext {
GLenum tracking_parm; /* Which source is tracking current colour */
};
typedef enum ContextUsage {
CTXUSAGE_RESOURCELOAD = 1, /* Only loads textures: No State is applied */
CTXUSAGE_DRAWPRIM = 2, /* OpenGL states are set up for blitting DirectDraw surfacs */
CTXUSAGE_BLIT = 3, /* OpenGL states are set up 3D drawing */
} ContextUsage;
void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
/* Routine to fill gl caps for swapchains and IWineD3D */
BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
......@@ -575,7 +584,7 @@ void dumpResources(ResourceList *resources);
/*****************************************************************************
* IWineD3DDevice implementation structure
*/
typedef struct IWineD3DDeviceImpl
struct IWineD3DDeviceImpl
{
/* IUnknown fields */
const IWineD3DDeviceVtbl *lpVtbl;
......@@ -688,7 +697,7 @@ typedef struct IWineD3DDeviceImpl
WineD3DContext contexts[1]; /* Dynamic array later */
UINT activeContext; /* Only 0 for now */
UINT numContexts; /* Always 1 for now */
} IWineD3DDeviceImpl;
};
extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment