Commit aba42d1f authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce a separate structure for framebuffer state.

parent 427803a9
......@@ -649,7 +649,7 @@ static void shader_arb_load_constants(const struct wined3d_context *context, cha
{
struct wined3d_shader *pshader = stateBlock->state.pixel_shader;
const struct arb_ps_compiled_shader *gl_shader = priv->compiled_fprog;
UINT rt_height = device->render_targets[0]->resource.height;
UINT rt_height = device->fb.render_targets[0]->resource.height;
/* Load DirectX 9 float constants for pixel shader */
device->highest_dirty_ps_const = shader_arb_load_constantsF(pshader, gl_info, GL_FRAGMENT_PROGRAM_ARB,
......@@ -4630,7 +4630,7 @@ static void shader_arb_select(const struct wined3d_context *context, BOOL usePS,
}
else
{
UINT rt_height = device->render_targets[0]->resource.height;
UINT rt_height = device->fb.render_targets[0]->resource.height;
shader_arb_ps_local_constants(compiled, context, state, rt_height);
}
......
......@@ -2224,10 +2224,11 @@ BOOL context_apply_clear_state(struct wined3d_context *context, struct wined3d_d
BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_device *device)
{
const struct StateEntry *state_table = device->StateTable;
const struct wined3d_fb_state *fb = &device->fb;
unsigned int i;
if (!context_validate_rt_config(context->gl_info->limits.buffers,
device->render_targets, device->depth_stencil))
fb->render_targets, fb->depth_stencil))
return FALSE;
/* Preload resources before FBO setup. Texture preload in particular may
......@@ -2240,7 +2241,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
{
context_validate_onscreen_formats(device, context, device->depth_stencil);
context_validate_onscreen_formats(device, context, fb->depth_stencil);
if (!context->render_offscreen)
{
......@@ -2251,8 +2252,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de
else
{
ENTER_GL();
context_apply_fbo_state(context, GL_FRAMEBUFFER, device->render_targets,
device->depth_stencil, SFLAG_INTEXTURE);
context_apply_fbo_state(context, GL_FRAMEBUFFER, fb->render_targets, fb->depth_stencil, SFLAG_INTEXTURE);
glReadBuffer(GL_NONE);
checkGLcall("glReadBuffer");
LEAVE_GL();
......@@ -2261,7 +2261,7 @@ BOOL context_apply_draw_state(struct wined3d_context *context, struct wined3d_de
if (context->draw_buffer_dirty)
{
context_apply_draw_buffers(context, context->gl_info->limits.buffers, device->render_targets);
context_apply_draw_buffers(context, context->gl_info->limits.buffers, fb->render_targets);
context->draw_buffer_dirty = FALSE;
}
......
......@@ -571,7 +571,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId
/* Invalidate the back buffer memory so LockRect will read it the next time */
for (i = 0; i < device->adapter->gl_info.limits.buffers; ++i)
{
struct wined3d_surface *target = device->render_targets[i];
struct wined3d_surface *target = device->fb.render_targets[i];
if (target)
{
surface_load_location(target, SFLAG_INDRAWABLE, NULL);
......@@ -583,7 +583,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId
/* Signals other modules that a drawing is in progress and the stateblock finalized */
device->isInDraw = TRUE;
context = context_acquire(device, device->render_targets[0]);
context = context_acquire(device, device->fb.render_targets[0]);
if (!context->valid)
{
context_release(context);
......@@ -598,7 +598,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId
return;
}
if (device->depth_stencil)
if (device->fb.depth_stencil)
{
/* Note that this depends on the context_acquire() call above to set
* context->render_offscreen properly. We don't currently take the
......@@ -608,7 +608,7 @@ void drawPrimitive(struct wined3d_device *device, UINT index_count, UINT StartId
DWORD location = context->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN;
if (state->render_states[WINED3DRS_ZWRITEENABLE] || state->render_states[WINED3DRS_ZENABLE])
{
struct wined3d_surface *ds = device->depth_stencil;
struct wined3d_surface *ds = device->fb.depth_stencil;
RECT current_rect, draw_rect, r;
if (location == SFLAG_DS_ONSCREEN && ds != device->onscreen_depth_stencil)
......
......@@ -918,10 +918,10 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
struct wined3d_shader_buffer *buffer, struct wined3d_shader *shader,
const struct wined3d_shader_reg_maps *reg_maps, struct shader_glsl_ctx_priv *ctx_priv)
{
struct wined3d_device *device = shader->device;
const struct wined3d_state *state = &device->stateBlock->state;
const struct wined3d_state *state = &shader->device->stateBlock->state;
const struct ps_compile_args *ps_args = ctx_priv->cur_ps_args;
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_fb_state *fb = &shader->device->fb;
unsigned int i, extra_constants_needed = 0;
const local_constant *lconst;
DWORD map;
......@@ -1050,7 +1050,7 @@ static void shader_generate_glsl_declarations(const struct wined3d_context *cont
*/
FIXME("Cannot find a free uniform for vpos correction params\n");
shader_addline(buffer, "const vec4 ycorrection = vec4(%f, %f, 0.0, 0.0);\n",
context->render_offscreen ? 0.0f : device->render_targets[0]->resource.height,
context->render_offscreen ? 0.0f : fb->render_targets[0]->resource.height,
context->render_offscreen ? 1.0f : -1.0f);
}
shader_addline(buffer, "vec4 vpos;\n");
......
......@@ -1874,7 +1874,7 @@ void find_ps_compile_args(const struct wined3d_state *state,
memset(args, 0, sizeof(*args)); /* FIXME: Make sure all bits are set. */
if (state->render_states[WINED3DRS_SRGBWRITEENABLE])
{
struct wined3d_surface *rt = device->render_targets[0];
struct wined3d_surface *rt = device->fb.render_targets[0];
if (rt->resource.format->flags & WINED3DFMT_FLAG_SRGB_WRITE) args->srgb_correction = 1;
}
......
......@@ -97,7 +97,7 @@ static void state_lighting(DWORD state, struct wined3d_stateblock *stateblock, s
static void state_zenable(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
/* No z test without depth stencil buffers */
if (!stateblock->device->depth_stencil)
if (!stateblock->device->fb.depth_stencil)
{
TRACE("No Z buffer - disabling depth test\n");
glDisable(GL_DEPTH_TEST); /* This also disables z writing in gl */
......@@ -284,7 +284,7 @@ static GLenum gl_blend_factor(WINED3DBLEND factor, const struct wined3d_format *
static void state_blend(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
struct wined3d_surface *target = stateblock->device->render_targets[0];
struct wined3d_surface *target = stateblock->device->fb.render_targets[0];
const struct wined3d_gl_info *gl_info = context->gl_info;
GLenum srcBlend, dstBlend;
WINED3DBLEND d3d_blend;
......@@ -794,7 +794,7 @@ static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, st
GLint stencilPass_ccw = GL_KEEP;
/* No stencil test without a stencil buffer. */
if (!stateblock->device->depth_stencil)
if (!stateblock->device->fb.depth_stencil)
{
glDisable(GL_STENCIL_TEST);
checkGLcall("glDisable GL_STENCIL_TEST");
......@@ -877,7 +877,7 @@ static void state_stencil(DWORD state, struct wined3d_stateblock *stateblock, st
static void state_stencilwrite2s(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
DWORD mask = stateblock->device->depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
const struct wined3d_gl_info *gl_info = context->gl_info;
GL_EXTCALL(glActiveStencilFaceEXT(GL_BACK));
......@@ -891,7 +891,7 @@ static void state_stencilwrite2s(DWORD state, struct wined3d_stateblock *statebl
static void state_stencilwrite(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
DWORD mask = stateblock->device->depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
DWORD mask = stateblock->device->fb.depth_stencil ? stateblock->state.render_states[WINED3DRS_STENCILWRITEMASK] : 0;
glStencilMask(mask);
checkGLcall("glStencilMask");
......@@ -1688,7 +1688,7 @@ static void state_depthbias(DWORD state, struct wined3d_stateblock *stateblock,
if (stateblock->state.render_states[WINED3DRS_SLOPESCALEDEPTHBIAS]
|| stateblock->state.render_states[WINED3DRS_DEPTHBIAS])
{
struct wined3d_surface *depth = stateblock->device->depth_stencil;
struct wined3d_surface *depth = stateblock->device->fb.depth_stencil;
float scale;
union
......@@ -4654,7 +4654,7 @@ static void vertexdeclaration(DWORD state_id, struct wined3d_stateblock *statebl
static void viewport_miscpart(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
struct wined3d_surface *target = stateblock->device->render_targets[0];
struct wined3d_surface *target = stateblock->device->fb.render_targets[0];
UINT width, height;
WINED3DVIEWPORT vp = stateblock->state.viewport;
......@@ -4810,7 +4810,7 @@ static void light(DWORD state, struct wined3d_stateblock *stateblock, struct win
static void scissorrect(DWORD state, struct wined3d_stateblock *stateblock, struct wined3d_context *context)
{
struct wined3d_surface *target = stateblock->device->render_targets[0];
struct wined3d_surface *target = stateblock->device->fb.render_targets[0];
RECT *pRect = &stateblock->state.scissor_rect;
UINT height;
UINT width;
......
......@@ -861,7 +861,8 @@ static void surface_map(struct wined3d_surface *surface, const RECT *rect, DWORD
pass_rect = NULL;
if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE
&& ((surface->container.type == WINED3D_CONTAINER_SWAPCHAIN) || surface == device->render_targets[0])))
&& ((surface->container.type == WINED3D_CONTAINER_SWAPCHAIN)
|| surface == device->fb.render_targets[0])))
surface_load_location(surface, SFLAG_INSYSMEM, pass_rect);
}
......@@ -952,7 +953,7 @@ static void surface_unmap(struct wined3d_surface *surface)
}
if (surface->container.type == WINED3D_CONTAINER_SWAPCHAIN
|| (device->render_targets && surface == device->render_targets[0]))
|| (device->fb.render_targets && surface == device->fb.render_targets[0]))
{
if (wined3d_settings.rendertargetlock_mode == RTL_DISABLE)
{
......@@ -1404,7 +1405,7 @@ static HRESULT surface_bltfast(struct wined3d_surface *dst_surface, DWORD dst_x,
return WINEDDERR_SURFACEBUSY;
}
if (device->inScene && (dst_surface == device->depth_stencil || src_surface == device->depth_stencil))
if (device->inScene && (dst_surface == device->fb.depth_stencil || src_surface == device->fb.depth_stencil))
{
WARN("Attempt to access the depth / stencil surface while in a scene.\n");
return WINED3DERR_INVALIDCALL;
......@@ -1987,9 +1988,9 @@ void surface_bind(struct wined3d_surface *surface, const struct wined3d_gl_info
/* This function checks if the primary render target uses the 8bit paletted format. */
static BOOL primary_render_target_is_p8(struct wined3d_device *device)
{
if (device->render_targets && device->render_targets[0])
if (device->fb.render_targets && device->fb.render_targets[0])
{
struct wined3d_surface *render_target = device->render_targets[0];
struct wined3d_surface *render_target = device->fb.render_targets[0];
if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)
&& (render_target->resource.format->id == WINED3DFMT_P8_UINT))
return TRUE;
......@@ -4159,7 +4160,7 @@ HRESULT d3dfmt_get_conv(struct wined3d_surface *surface, BOOL need_alpha_ck,
* in which the main render target uses p8. Some games like GTA Vice City use P8 for texturing which
* conflicts with this.
*/
if (!((blit_supported && device->render_targets && surface == device->render_targets[0]))
if (!((blit_supported && device->fb.render_targets && surface == device->fb.render_targets[0]))
|| colorkey_active || !use_texturing)
{
format->glFormat = GL_RGBA;
......@@ -5245,8 +5246,8 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa
/* Early sort out of cases where no render target is used */
if (!dstSwapchain && !srcSwapchain
&& src_surface != device->render_targets[0]
&& dst_surface != device->render_targets[0])
&& src_surface != device->fb.render_targets[0]
&& dst_surface != device->fb.render_targets[0])
{
TRACE("No surface is render target, not using hardware blit.\n");
return WINED3DERR_INVALIDCALL;
......@@ -5370,16 +5371,16 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(struct wined3d_surface *dst_surfa
else if (dstSwapchain)
{
/* Handled with regular texture -> swapchain blit */
if (src_surface == device->render_targets[0])
if (src_surface == device->fb.render_targets[0])
TRACE("Blit from active render target to a swapchain\n");
}
else if (srcSwapchain && dst_surface == device->render_targets[0])
else if (srcSwapchain && dst_surface == device->fb.render_targets[0])
{
FIXME("Implement blit from a swapchain to the active render target\n");
return WINED3DERR_INVALIDCALL;
}
if ((srcSwapchain || src_surface == device->render_targets[0]) && !dstSwapchain)
if ((srcSwapchain || src_surface == device->fb.render_targets[0]) && !dstSwapchain)
{
/* Blit from render target to texture */
BOOL stretchx;
......
......@@ -406,6 +406,7 @@ static void swapchain_blit(struct wined3d_swapchain *swapchain,
static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const RECT *src_rect_in,
const RECT *dst_rect_in, const RGNDATA *dirty_region, DWORD flags)
{
const struct wined3d_fb_state *fb = &swapchain->device->fb;
const struct wined3d_gl_info *gl_info;
struct wined3d_context *context;
RECT src_rect, dst_rect;
......@@ -615,15 +616,15 @@ static HRESULT swapchain_gl_present(struct wined3d_swapchain *swapchain, const R
surface_modify_location(swapchain->back_buffers[0], SFLAG_INDRAWABLE, TRUE);
}
if (swapchain->device->depth_stencil)
if (fb->depth_stencil)
{
if (swapchain->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
|| swapchain->device->depth_stencil->flags & SFLAG_DISCARD)
|| fb->depth_stencil->flags & SFLAG_DISCARD)
{
surface_modify_ds_location(swapchain->device->depth_stencil, SFLAG_DS_DISCARDED,
swapchain->device->depth_stencil->resource.width,
swapchain->device->depth_stencil->resource.height);
if (swapchain->device->depth_stencil == swapchain->device->onscreen_depth_stencil)
surface_modify_ds_location(fb->depth_stencil, SFLAG_DS_DISCARDED,
fb->depth_stencil->resource.width,
fb->depth_stencil->resource.height);
if (fb->depth_stencil == swapchain->device->onscreen_depth_stencil)
{
wined3d_surface_decref(swapchain->device->onscreen_depth_stencil);
swapchain->device->onscreen_depth_stencil = NULL;
......
......@@ -2775,7 +2775,7 @@ void gen_ffp_frag_op(struct wined3d_stateblock *stateblock, struct ffp_frag_sett
DWORD ttff;
DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
struct wined3d_device *device = stateblock->device;
struct wined3d_surface *rt = device->render_targets[0];
struct wined3d_surface *rt = device->fb.render_targets[0];
const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
for (i = 0; i < gl_info->limits.texture_stages; ++i)
......
......@@ -1640,6 +1640,12 @@ void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
/* Multithreaded flag. Removed from the public header to signal that IWineD3D::CreateDevice ignores it */
#define WINED3DCREATE_MULTITHREADED 0x00000004
struct wined3d_fb_state
{
struct wined3d_surface **render_targets;
struct wined3d_surface *depth_stencil;
};
struct wined3d_device
{
LONG ref;
......@@ -1710,10 +1716,9 @@ struct wined3d_device
unsigned int highest_dirty_ps_const, highest_dirty_vs_const;
/* Render Target Support */
struct wined3d_surface **render_targets;
struct wined3d_surface *auto_depth_stencil;
struct wined3d_fb_state fb;
struct wined3d_surface *onscreen_depth_stencil;
struct wined3d_surface *depth_stencil;
struct wined3d_surface *auto_depth_stencil;
/* palettes texture management */
PALETTEENTRY **palettes;
......
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