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

wined3d: Get rid of the offscreenBuffer field in struct wined3d_device.

parent f4c8d814
...@@ -2419,14 +2419,30 @@ static void context_validate_onscreen_formats(struct wined3d_context *context, ...@@ -2419,14 +2419,30 @@ static void context_validate_onscreen_formats(struct wined3d_context *context,
context_set_render_offscreen(context, TRUE); context_set_render_offscreen(context, TRUE);
} }
static DWORD context_generate_rt_mask_no_fbo(const struct wined3d_device *device, const struct wined3d_surface *rt) GLenum context_get_offscreen_gl_buffer(const struct wined3d_context *context)
{
switch (wined3d_settings.offscreen_rendering_mode)
{
case ORM_FBO:
return GL_COLOR_ATTACHMENT0;
case ORM_BACKBUFFER:
return context->aux_buffers > 0 ? GL_AUX0 : GL_BACK;
default:
FIXME("Unhandled offscreen rendering mode %#x.\n", wined3d_settings.offscreen_rendering_mode);
return GL_BACK;
}
}
static DWORD context_generate_rt_mask_no_fbo(const struct wined3d_context *context, const struct wined3d_surface *rt)
{ {
if (!rt || rt->resource.format->id == WINED3DFMT_NULL) if (!rt || rt->resource.format->id == WINED3DFMT_NULL)
return 0; return 0;
else if (rt->container->swapchain) else if (rt->container->swapchain)
return context_generate_rt_mask_from_surface(rt); return context_generate_rt_mask_from_surface(rt);
else else
return context_generate_rt_mask(device->offscreenBuffer); return context_generate_rt_mask(context_get_offscreen_gl_buffer(context));
} }
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
...@@ -2458,7 +2474,7 @@ void context_apply_blit_state(struct wined3d_context *context, const struct wine ...@@ -2458,7 +2474,7 @@ void context_apply_blit_state(struct wined3d_context *context, const struct wine
} }
else else
{ {
rt_mask = context_generate_rt_mask_no_fbo(device, rt); rt_mask = context_generate_rt_mask_no_fbo(context, rt);
} }
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask; cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
...@@ -2547,7 +2563,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win ...@@ -2547,7 +2563,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
} }
else else
{ {
rt_mask = context_generate_rt_mask_no_fbo(device, rt_mask = context_generate_rt_mask_no_fbo(context,
rt_count ? wined3d_rendertarget_view_get_surface(rts[0]) : NULL); rt_count ? wined3d_rendertarget_view_get_surface(rts[0]) : NULL);
} }
} }
...@@ -2562,7 +2578,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win ...@@ -2562,7 +2578,7 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
} }
else else
{ {
rt_mask = context_generate_rt_mask_no_fbo(device, rt_mask = context_generate_rt_mask_no_fbo(context,
rt_count ? wined3d_rendertarget_view_get_surface(rts[0]) : NULL); rt_count ? wined3d_rendertarget_view_get_surface(rts[0]) : NULL);
} }
...@@ -2606,16 +2622,15 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win ...@@ -2606,16 +2622,15 @@ BOOL context_apply_clear_state(struct wined3d_context *context, const struct win
return TRUE; return TRUE;
} }
static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const struct wined3d_device *device) static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const struct wined3d_state *state)
{ {
const struct wined3d_state *state = &device->state;
struct wined3d_rendertarget_view **rts = state->fb->render_targets; struct wined3d_rendertarget_view **rts = state->fb->render_targets;
struct wined3d_shader *ps = state->shader[WINED3D_SHADER_TYPE_PIXEL]; struct wined3d_shader *ps = state->shader[WINED3D_SHADER_TYPE_PIXEL];
DWORD rt_mask, rt_mask_bits; DWORD rt_mask, rt_mask_bits;
unsigned int i; unsigned int i;
if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
return context_generate_rt_mask_no_fbo(device, wined3d_rendertarget_view_get_surface(rts[0])); return context_generate_rt_mask_no_fbo(context, wined3d_rendertarget_view_get_surface(rts[0]));
else if (!context->render_offscreen) else if (!context->render_offscreen)
return context_generate_rt_mask_from_surface(wined3d_rendertarget_view_get_surface(rts[0])); return context_generate_rt_mask_from_surface(wined3d_rendertarget_view_get_surface(rts[0]));
...@@ -2638,9 +2653,8 @@ static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const ...@@ -2638,9 +2653,8 @@ static DWORD find_draw_buffers_mask(const struct wined3d_context *context, const
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
void context_state_fb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) void context_state_fb(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_device *device = context->swapchain->device; DWORD rt_mask = find_draw_buffers_mask(context, state);
const struct wined3d_fb_state *fb = state->fb; const struct wined3d_fb_state *fb = state->fb;
DWORD rt_mask = find_draw_buffers_mask(context, device);
DWORD *cur_mask; DWORD *cur_mask;
if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
...@@ -2917,13 +2931,12 @@ static void context_update_tex_unit_map(struct wined3d_context *context, const s ...@@ -2917,13 +2931,12 @@ static void context_update_tex_unit_map(struct wined3d_context *context, const s
/* Context activation is done by the caller. */ /* Context activation is done by the caller. */
void context_state_drawbuf(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id) void context_state_drawbuf(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{ {
const struct wined3d_device *device = context->swapchain->device;
DWORD rt_mask, *cur_mask; DWORD rt_mask, *cur_mask;
if (isStateDirty(context, STATE_FRAMEBUFFER)) return; if (isStateDirty(context, STATE_FRAMEBUFFER)) return;
cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask; cur_mask = context->current_fbo ? &context->current_fbo->rt_mask : &context->draw_buffers_mask;
rt_mask = find_draw_buffers_mask(context, device); rt_mask = find_draw_buffers_mask(context, state);
if (rt_mask != *cur_mask) if (rt_mask != *cur_mask)
{ {
context_apply_draw_buffers(context, rt_mask); context_apply_draw_buffers(context, rt_mask);
......
...@@ -1021,27 +1021,6 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device, ...@@ -1021,27 +1021,6 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
device->contexts[0]->last_was_rhw = 0; device->contexts[0]->last_was_rhw = 0;
switch (wined3d_settings.offscreen_rendering_mode)
{
case ORM_FBO:
device->offscreenBuffer = GL_COLOR_ATTACHMENT0;
break;
case ORM_BACKBUFFER:
{
if (context_get_current()->aux_buffers > 0)
{
TRACE("Using auxiliary buffer for offscreen rendering\n");
device->offscreenBuffer = GL_AUX0;
}
else
{
TRACE("Using back buffer for offscreen rendering\n");
device->offscreenBuffer = GL_BACK;
}
}
}
TRACE("All defaults now set up, leaving 3D init.\n"); TRACE("All defaults now set up, leaving 3D init.\n");
context_release(context); context_release(context);
......
...@@ -2435,7 +2435,7 @@ static void read_from_framebuffer(struct wined3d_surface *surface, ...@@ -2435,7 +2435,7 @@ static void read_from_framebuffer(struct wined3d_surface *surface,
/* Mapping the primary render target which is not on a swapchain. /* Mapping the primary render target which is not on a swapchain.
* Read from the back buffer. */ * Read from the back buffer. */
TRACE("Mapping offscreen render target.\n"); TRACE("Mapping offscreen render target.\n");
gl_info->gl_ops.gl.p_glReadBuffer(device->offscreenBuffer); gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
srcIsUpsideDown = TRUE; srcIsUpsideDown = TRUE;
} }
else else
...@@ -2541,7 +2541,7 @@ void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb, struct ...@@ -2541,7 +2541,7 @@ void surface_load_fb_texture(struct wined3d_surface *surface, BOOL srgb, struct
TRACE("Reading back offscreen render target %p.\n", surface); TRACE("Reading back offscreen render target %p.\n", surface);
if (wined3d_resource_is_offscreen(&surface->container->resource)) if (wined3d_resource_is_offscreen(&surface->container->resource))
gl_info->gl_ops.gl.p_glReadBuffer(device->offscreenBuffer); gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
else else
gl_info->gl_ops.gl.p_glReadBuffer(surface_get_gl_buffer(surface)); gl_info->gl_ops.gl.p_glReadBuffer(surface_get_gl_buffer(surface));
checkGLcall("glReadBuffer"); checkGLcall("glReadBuffer");
...@@ -2646,7 +2646,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc ...@@ -2646,7 +2646,7 @@ static void fb_copy_to_texture_direct(struct wined3d_surface *dst_surface, struc
{ {
TRACE("Reading from an offscreen target\n"); TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown; upsidedown = !upsidedown;
gl_info->gl_ops.gl.p_glReadBuffer(device->offscreenBuffer); gl_info->gl_ops.gl.p_glReadBuffer(context_get_offscreen_gl_buffer(context));
} }
else else
{ {
...@@ -2735,6 +2735,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st ...@@ -2735,6 +2735,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
const struct wined3d_gl_info *gl_info; const struct wined3d_gl_info *gl_info;
struct wined3d_context *context; struct wined3d_context *context;
GLenum drawBuffer = GL_BACK; GLenum drawBuffer = GL_BACK;
GLenum offscreen_buffer;
GLenum texture_target; GLenum texture_target;
BOOL noBackBufferBackup; BOOL noBackBufferBackup;
BOOL src_offscreen; BOOL src_offscreen;
...@@ -2748,6 +2749,8 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st ...@@ -2748,6 +2749,8 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
context_apply_blit_state(context, device); context_apply_blit_state(context, device);
wined3d_texture_load(dst_surface->container, context, FALSE); wined3d_texture_load(dst_surface->container, context, FALSE);
offscreen_buffer = context_get_offscreen_gl_buffer(context);
src_offscreen = wined3d_resource_is_offscreen(&src_surface->container->resource); src_offscreen = wined3d_resource_is_offscreen(&src_surface->container->resource);
noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO; noBackBufferBackup = src_offscreen && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
if (!noBackBufferBackup && !src_surface->container->texture_rgb.name) if (!noBackBufferBackup && !src_surface->container->texture_rgb.name)
...@@ -2764,7 +2767,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st ...@@ -2764,7 +2767,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
/* Got more than one aux buffer? Use the 2nd aux buffer */ /* Got more than one aux buffer? Use the 2nd aux buffer */
drawBuffer = GL_AUX1; drawBuffer = GL_AUX1;
} }
else if ((!src_offscreen || device->offscreenBuffer == GL_BACK) && context->aux_buffers >= 1) else if ((!src_offscreen || offscreen_buffer == GL_BACK) && context->aux_buffers >= 1)
{ {
/* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */ /* Only one aux buffer, but it isn't used (Onscreen rendering, or non-aux orm)? Use it! */
drawBuffer = GL_AUX0; drawBuffer = GL_AUX0;
...@@ -2805,7 +2808,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st ...@@ -2805,7 +2808,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_surface *dst_surface, st
{ {
TRACE("Reading from an offscreen target\n"); TRACE("Reading from an offscreen target\n");
upsidedown = !upsidedown; upsidedown = !upsidedown;
gl_info->gl_ops.gl.p_glReadBuffer(device->offscreenBuffer); gl_info->gl_ops.gl.p_glReadBuffer(offscreen_buffer);
} }
else else
{ {
......
...@@ -1507,6 +1507,7 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont ...@@ -1507,6 +1507,7 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont
void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN; void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN; void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN; struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
GLenum context_get_offscreen_gl_buffer(const struct wined3d_context *context) DECLSPEC_HIDDEN;
DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN; DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
void context_gl_resource_released(struct wined3d_device *device, void context_gl_resource_released(struct wined3d_device *device,
GLuint name, BOOL rb_namespace) DECLSPEC_HIDDEN; GLuint name, BOOL rb_namespace) DECLSPEC_HIDDEN;
...@@ -2141,9 +2142,6 @@ struct wined3d_device ...@@ -2141,9 +2142,6 @@ struct wined3d_device
LONG style; LONG style;
LONG exStyle; LONG exStyle;
/* X and GL Information */
GLenum offscreenBuffer;
const struct wined3d_shader_backend_ops *shader_backend; const struct wined3d_shader_backend_ops *shader_backend;
void *shader_priv; void *shader_priv;
void *fragment_priv; void *fragment_priv;
......
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