entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
entry->render_targets = HeapAlloc(GetProcessHeap(), 0, gl_info->limits.buffers * sizeof(*entry->render_targets));
memcpy(entry->render_targets, device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
- entry->depth_stencil = (IWineD3DSurfaceImpl *)device->stencilBufferTarget;
+ entry->depth_stencil = device->depth_stencil;
entry->attached = FALSE;
entry->id = 0;
context_clean_fbo_attachments(gl_info);
memcpy(entry->render_targets, device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets));
- entry->depth_stencil = (IWineD3DSurfaceImpl *)device->stencilBufferTarget;
+ entry->depth_stencil = device->depth_stencil;
entry->attached = FALSE;
}
{
if (!memcmp(entry->render_targets,
device->render_targets, gl_info->limits.buffers * sizeof(*entry->render_targets))
- && entry->depth_stencil == (IWineD3DSurfaceImpl *)device->stencilBufferTarget)
+ && entry->depth_stencil == device->depth_stencil)
{
list_remove(&entry->entry);
list_add_head(&context->fbo_list, &entry->entry);
}
/* Apply depth targets */
- if (device->stencilBufferTarget)
+ if (device->depth_stencil)
{
- surface_set_compatible_renderbuffer((IWineD3DSurfaceImpl *)device->stencilBufferTarget,
+ surface_set_compatible_renderbuffer(device->depth_stencil,
device->render_targets[0]->pow2Width, device->render_targets[0]->pow2Height);
}
- context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, (IWineD3DSurfaceImpl *)device->stencilBufferTarget, TRUE);
+ context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, device->depth_stencil, TRUE);
entry->attached = TRUE;
}
if (device->render_targets[i])
context_apply_attachment_filter_states(device->render_targets[i]);
}
- if (device->stencilBufferTarget)
- context_apply_attachment_filter_states((IWineD3DSurfaceImpl *)device->stencilBufferTarget);
+ if (device->depth_stencil)
+ context_apply_attachment_filter_states(device->depth_stencil);
}
for (i = 0; i < gl_info->limits.buffers; ++i)
static void context_validate_onscreen_formats(IWineD3DDeviceImpl *device, struct wined3d_context *context)
{
/* Onscreen surfaces are always in a swapchain */
- IWineD3DSurfaceImpl *depth_stencil = (IWineD3DSurfaceImpl *) device->stencilBufferTarget;
- IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) ((IWineD3DSurfaceImpl *)context->current_rt)->container;
+ IWineD3DSurfaceImpl *depth_stencil = device->depth_stencil;
+ IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)((IWineD3DSurfaceImpl *)context->current_rt)->container;
if (!depth_stencil) return;
if (match_depth_stencil_format(swapchain->ds_format, depth_stencil->resource.format_desc)) return;
IWineD3DSurface_AddRef((IWineD3DSurface *)This->render_targets[0]);
/* Depth Stencil support */
- This->stencilBufferTarget = (IWineD3DSurface *)This->auto_depth_stencil;
- if (NULL != This->stencilBufferTarget) {
- IWineD3DSurface_AddRef(This->stencilBufferTarget);
- }
+ This->depth_stencil = This->auto_depth_stencil;
+ if (This->depth_stencil)
+ IWineD3DSurface_AddRef((IWineD3DSurface *)This->depth_stencil);
hr = This->shader_backend->shader_alloc_private(iface);
if(FAILED(hr)) {
This->shader_backend->shader_free_private(iface);
/* Release the buffers (with sanity checks)*/
- TRACE("Releasing the depth stencil buffer at %p\n", This->stencilBufferTarget);
- if (This->stencilBufferTarget != NULL && IWineD3DSurface_Release(This->stencilBufferTarget))
+ TRACE("Releasing the depth stencil buffer at %p\n", This->depth_stencil);
+ if (This->depth_stencil && IWineD3DSurface_Release((IWineD3DSurface *)This->depth_stencil))
{
- if (This->auto_depth_stencil != (IWineD3DSurfaceImpl *)This->stencilBufferTarget)
- FIXME("(%p) Something's still holding the stencilBufferTarget\n",This);
+ if (This->auto_depth_stencil != This->depth_stencil)
+ FIXME("(%p) Something is still holding the depth/stencil buffer.\n",This);
}
- This->stencilBufferTarget = NULL;
+ This->depth_stencil = NULL;
TRACE("Releasing the render target at %p\n", This->render_targets[0]);
IWineD3DSurface_Release((IWineD3DSurface *)This->render_targets[0]);
IWineD3DStateBlockImpl *stateblock = This->stateBlock;
const RECT *scissor_rect = stateblock->renderState[WINED3DRS_SCISSORTESTENABLE] ? &stateblock->scissorRect : NULL;
const WINED3DRECT *clear_rect = (Count > 0 && pRects) ? pRects : NULL;
+ IWineD3DSurfaceImpl *depth_stencil = This->depth_stencil;
const WINED3DVIEWPORT *vp = &stateblock->viewport;
GLbitfield glMask = 0;
unsigned int i;
WINED3DRECT curRect;
RECT vp_rect;
UINT drawable_width, drawable_height;
- IWineD3DSurfaceImpl *depth_stencil = (IWineD3DSurfaceImpl *) This->stencilBufferTarget;
struct wined3d_context *context;
/* When we're clearing parts of the drawable, make sure that the target surface is well up to date in the
TRACE("(%p) Count (%d), pRects (%p), Flags (%x), Color (0x%08x), Z (%f), Stencil (%d)\n", This,
Count, pRects, Flags, Color, Z, Stencil);
- if(Flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL) && This->stencilBufferTarget == NULL) {
+ if (Flags & (WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL) && !This->depth_stencil)
+ {
WARN("Clearing depth and/or stencil without a depth stencil buffer attached, returning WINED3DERR_INVALIDCALL\n");
/* TODO: What about depth stencil buffers without stencil bits? */
return WINED3DERR_INVALIDCALL;
static HRESULT WINAPI IWineD3DDeviceImpl_GetDepthStencilSurface(IWineD3DDevice* iface, IWineD3DSurface **ppZStencilSurface) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
- *ppZStencilSurface = This->stencilBufferTarget;
+ *ppZStencilSurface = (IWineD3DSurface *)This->depth_stencil;
TRACE("(%p) : zStencilSurface returning %p\n", This, *ppZStencilSurface);
if(*ppZStencilSurface != NULL) {
static HRESULT WINAPI IWineD3DDeviceImpl_SetDepthStencilSurface(IWineD3DDevice *iface, IWineD3DSurface *pNewZStencil) {
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
- HRESULT hr = WINED3D_OK;
- IWineD3DSurface *tmp;
+ IWineD3DSurfaceImpl *tmp;
+ HRESULT hr = WINED3D_OK;
- TRACE("(%p) Swapping z-buffer. Old = %p, new = %p\n",This, This->stencilBufferTarget, pNewZStencil);
+ TRACE("device %p, depth_stencil %p, old depth_stencil %p.\n", This, pNewZStencil, This->depth_stencil);
- if (pNewZStencil == This->stencilBufferTarget) {
- TRACE("Trying to do a NOP SetRenderTarget operation\n");
- } else {
- /** OpenGL doesn't support 'sharing' of the stencilBuffer so we may incur an extra memory overhead
- * depending on the renter target implementation being used.
- * A shared context implementation will share all buffers between all rendertargets (including swapchains),
- * implementations that use separate pbuffers for different swapchains or rendertargets will have to duplicate the
- * stencil buffer and incur an extra memory overhead
- ******************************************************/
-
- if (This->stencilBufferTarget) {
+ if (This->depth_stencil == (IWineD3DSurfaceImpl *)pNewZStencil)
+ {
+ TRACE("Trying to do a NOP SetRenderTarget operation.\n");
+ }
+ else
+ {
+ if (This->depth_stencil)
+ {
if (((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
- || ((IWineD3DSurfaceImpl *)This->stencilBufferTarget)->Flags & SFLAG_DISCARD) {
- surface_modify_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, SFLAG_DS_DISCARDED);
+ || This->depth_stencil->Flags & SFLAG_DISCARD)
+ {
+ surface_modify_ds_location(This->depth_stencil, SFLAG_DS_DISCARDED);
}
else
{
struct wined3d_context *context = context_acquire(This,
(IWineD3DSurface *)This->render_targets[0], CTXUSAGE_RESOURCELOAD);
- surface_load_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, context, SFLAG_DS_OFFSCREEN);
- surface_modify_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
+ surface_load_ds_location(This->depth_stencil, context, SFLAG_DS_OFFSCREEN);
+ surface_modify_ds_location(This->depth_stencil, SFLAG_DS_OFFSCREEN);
context_release(context);
}
}
- tmp = This->stencilBufferTarget;
- This->stencilBufferTarget = pNewZStencil;
- /* should we be calling the parent or the wined3d surface? */
- if (NULL != This->stencilBufferTarget) IWineD3DSurface_AddRef(This->stencilBufferTarget);
- if (NULL != tmp) IWineD3DSurface_Release(tmp);
+ tmp = This->depth_stencil;
+ This->depth_stencil = (IWineD3DSurfaceImpl *)pNewZStencil;
+ if (This->depth_stencil) IWineD3DSurface_AddRef((IWineD3DSurface *)This->depth_stencil);
+ if (tmp) IWineD3DSurface_Release((IWineD3DSurface *)tmp);
hr = WINED3D_OK;
if((!tmp && pNewZStencil) || (!pNewZStencil && tmp)) {
if (This->render_targets[i] == (IWineD3DSurfaceImpl *)resource)
This->render_targets[i] = NULL;
}
- if (This->stencilBufferTarget == (IWineD3DSurface *)resource) {
- This->stencilBufferTarget = NULL;
- }
+ if (This->depth_stencil == (IWineD3DSurfaceImpl *)resource)
+ This->depth_stencil = NULL;
}
break;
return;
}
- if (This->stencilBufferTarget) {
+ if (This->depth_stencil)
+ {
/* Note that this depends on the context_acquire() call above to set
* This->render_offscreen properly. We don't currently take the
* Z-compare function into account, but we could skip loading the
DWORD location = context->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN;
if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE]
|| This->stateBlock->renderState[WINED3DRS_ZENABLE])
- surface_load_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, context, location);
+ surface_load_ds_location(This->depth_stencil, context, location);
if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE])
- surface_modify_ds_location((IWineD3DSurfaceImpl *)This->stencilBufferTarget, location);
+ surface_modify_ds_location(This->depth_stencil, location);
}
/* Ok, we will be updating the screen from here onwards so grab the lock */
static void state_zenable(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
{
/* No z test without depth stencil buffers */
- if (!stateblock->device->stencilBufferTarget)
+ if (!stateblock->device->depth_stencil)
{
TRACE("No Z buffer - disabling depth test\n");
glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
GLint stencilPass_ccw = GL_KEEP;
/* No stencil test without a stencil buffer. */
- if (!stateblock->device->stencilBufferTarget)
+ if (!stateblock->device->depth_stencil)
{
glDisable(GL_STENCIL_TEST);
checkGLcall("glDisable GL_STENCIL_TEST");
static void state_stencilwrite2s(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
{
- DWORD mask = stateblock->device->stencilBufferTarget ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
+ DWORD mask = stateblock->device->depth_stencil ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
checkGLcall("glActiveStencilFaceEXT(GL_BACK)");
static void state_stencilwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
{
- DWORD mask = stateblock->device->stencilBufferTarget ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
+ DWORD mask = stateblock->device->depth_stencil ? stateblock->renderState[WINED3DRS_STENCILWRITEMASK] : 0;
glStencilMask(mask);
checkGLcall("glStencilMask");
This->dirtyRect.right = 0;
This->dirtyRect.bottom = 0;
}
- else if (iface == device->stencilBufferTarget)
+ else if (This == device->depth_stencil)
{
FIXME("Depth Stencil buffer locking is not implemented\n");
} else {
/* Accessing the depth stencil is supposed to fail between a BeginScene and EndScene pair,
* except depth blits, which seem to work
*/
- if (iface == device->stencilBufferTarget || (SrcSurface && SrcSurface == device->stencilBufferTarget))
+ if (This == device->depth_stencil || (Src && Src == device->depth_stencil))
{
if (device->inScene && !(Flags & WINEDDBLT_DEPTHFILL))
{
return WINEDDERR_SURFACEBUSY;
}
- if (device->inScene && (iface == device->stencilBufferTarget
- || (Source == device->stencilBufferTarget)))
+ if (device->inScene && (This == device->depth_stencil || srcImpl == device->depth_stencil))
{
TRACE("Attempt to access the depth stencil surface in a BeginScene / EndScene pair, returning WINED3DERR_INVALIDCALL\n");
return WINED3DERR_INVALIDCALL;
}
}
- if (This->device->stencilBufferTarget)
+ if (This->device->depth_stencil)
{
if (This->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
- || ((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget)->Flags & SFLAG_DISCARD)
+ || This->device->depth_stencil->Flags & SFLAG_DISCARD)
{
- surface_modify_ds_location((IWineD3DSurfaceImpl *)This->device->stencilBufferTarget, SFLAG_DS_DISCARDED);
+ surface_modify_ds_location(This->device->depth_stencil, SFLAG_DS_DISCARDED);
}
}
/* Render Target Support */
IWineD3DSurfaceImpl **render_targets;
IWineD3DSurfaceImpl *auto_depth_stencil;
- IWineD3DSurface *stencilBufferTarget;
+ IWineD3DSurfaceImpl *depth_stencil;
/* palettes texture management */
UINT NumberOfPalettes;