Commit 157440e3 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Return a wined3d_context_gl structure from context_get_current().

parent 360e1a46
......@@ -3983,10 +3983,11 @@ static void WINE_GLAPI invalid_generic_attrib_func(GLuint idx, const void *data)
* draw_primitive_immediate_mode(). */
static void WINE_GLAPI position_d3dcolor(const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
DWORD pos = *((const DWORD *)data);
FIXME("Add a test for fixed function position from d3dcolor type.\n");
context_get_current()->gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
D3DCOLOR_B_G(pos),
D3DCOLOR_B_B(pos),
D3DCOLOR_B_A(pos));
......@@ -3994,25 +3995,27 @@ static void WINE_GLAPI position_d3dcolor(const void *data)
static void WINE_GLAPI position_float4(const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
const GLfloat *pos = data;
if (pos[3] != 0.0f && pos[3] != 1.0f)
{
float w = 1.0f / pos[3];
context_get_current()->gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
}
else
{
context_get_current()->gl_info->gl_ops.gl.p_glVertex3fv(pos);
gl_info->gl_ops.gl.p_glVertex3fv(pos);
}
}
static void WINE_GLAPI diffuse_d3dcolor(const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
DWORD diffuseColor = *((const DWORD *)data);
context_get_current()->gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
D3DCOLOR_B_G(diffuseColor),
D3DCOLOR_B_B(diffuseColor),
D3DCOLOR_B_A(diffuseColor));
......@@ -4020,6 +4023,7 @@ static void WINE_GLAPI diffuse_d3dcolor(const void *data)
static void WINE_GLAPI specular_d3dcolor(const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
DWORD specularColor = *((const DWORD *)data);
GLubyte d[] =
{
......@@ -4028,7 +4032,7 @@ static void WINE_GLAPI specular_d3dcolor(const void *data)
D3DCOLOR_B_B(specularColor)
};
context_get_current()->gl_info->gl_ops.ext.p_glSecondaryColor3ubvEXT(d);
gl_info->gl_ops.ext.p_glSecondaryColor3ubvEXT(d);
}
static void WINE_GLAPI warn_no_specular_func(const void *data)
......@@ -4038,43 +4042,48 @@ static void WINE_GLAPI warn_no_specular_func(const void *data)
static void WINE_GLAPI generic_d3dcolor(GLuint idx, const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
DWORD color = *((const DWORD *)data);
context_get_current()->gl_info->gl_ops.ext.p_glVertexAttrib4Nub(idx,
gl_info->gl_ops.ext.p_glVertexAttrib4Nub(idx,
D3DCOLOR_B_R(color), D3DCOLOR_B_G(color),
D3DCOLOR_B_B(color), D3DCOLOR_B_A(color));
}
static void WINE_GLAPI generic_short2n(GLuint idx, const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
const GLshort s[] = {((const GLshort *)data)[0], ((const GLshort *)data)[1], 0, 1};
context_get_current()->gl_info->gl_ops.ext.p_glVertexAttrib4Nsv(idx, s);
gl_info->gl_ops.ext.p_glVertexAttrib4Nsv(idx, s);
}
static void WINE_GLAPI generic_ushort2n(GLuint idx, const void *data)
{
const GLushort s[] = {((const GLushort *)data)[0], ((const GLushort *)data)[1], 0, 1};
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
context_get_current()->gl_info->gl_ops.ext.p_glVertexAttrib4Nusv(idx, s);
gl_info->gl_ops.ext.p_glVertexAttrib4Nusv(idx, s);
}
static void WINE_GLAPI generic_float16_2(GLuint idx, const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
float x = float_16_to_32(((const unsigned short *)data) + 0);
float y = float_16_to_32(((const unsigned short *)data) + 1);
context_get_current()->gl_info->gl_ops.ext.p_glVertexAttrib2f(idx, x, y);
gl_info->gl_ops.ext.p_glVertexAttrib2f(idx, x, y);
}
static void WINE_GLAPI generic_float16_4(GLuint idx, const void *data)
{
const struct wined3d_gl_info *gl_info = wined3d_context_gl_get_current()->c.gl_info;
float x = float_16_to_32(((const unsigned short *)data) + 0);
float y = float_16_to_32(((const unsigned short *)data) + 1);
float z = float_16_to_32(((const unsigned short *)data) + 2);
float w = float_16_to_32(((const unsigned short *)data) + 3);
context_get_current()->gl_info->gl_ops.ext.p_glVertexAttrib4f(idx, x, y, z, w);
gl_info->gl_ops.ext.p_glVertexAttrib4f(idx, x, y, z, w);
}
static void wined3d_adapter_init_ffp_attrib_ops(struct wined3d_adapter *adapter)
......
......@@ -720,12 +720,12 @@ static void shader_arb_load_constants(void *shader_priv, struct wined3d_context
static void shader_arb_update_float_vertex_constants(struct wined3d_device *device, UINT start, UINT count)
{
struct wined3d_context *context = context_get_current();
struct wined3d_context_gl *context_gl = wined3d_context_gl_get_current();
struct shader_arb_priv *priv = device->shader_priv;
/* 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 */
if (!context || context->device != device)
if (!context_gl || context_gl->c.device != device)
return;
memset(priv->vshader_const_dirty + start, 1, sizeof(*priv->vshader_const_dirty) * count);
......@@ -734,12 +734,12 @@ static void shader_arb_update_float_vertex_constants(struct wined3d_device *devi
static void shader_arb_update_float_pixel_constants(struct wined3d_device *device, UINT start, UINT count)
{
struct wined3d_context *context = context_get_current();
struct wined3d_context_gl *context_gl = wined3d_context_gl_get_current();
struct shader_arb_priv *priv = device->shader_priv;
/* 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 */
if (!context || context->device != device)
if (!context_gl || context_gl->c.device != device)
return;
memset(priv->pshader_const_dirty + start, 1, sizeof(*priv->pshader_const_dirty) * count);
......
......@@ -1503,17 +1503,16 @@ void context_set_tls_idx(DWORD idx)
wined3d_context_tls_idx = idx;
}
struct wined3d_context *context_get_current(void)
struct wined3d_context_gl *wined3d_context_gl_get_current(void)
{
return TlsGetValue(wined3d_context_tls_idx);
}
BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl)
{
struct wined3d_context *ctx = context_gl ? &context_gl->c : NULL;
struct wined3d_context *old = context_get_current();
struct wined3d_context_gl *old = wined3d_context_gl_get_current();
if (old == ctx)
if (old == context_gl)
{
TRACE("Already using D3D context %p.\n", context_gl);
return TRUE;
......@@ -1521,22 +1520,22 @@ BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl)
if (old)
{
if (old->destroyed)
if (old->c.destroyed)
{
TRACE("Switching away from destroyed context %p.\n", old);
wined3d_context_gl_cleanup(wined3d_context_gl(old));
heap_free((void *)old->gl_info);
wined3d_context_gl_cleanup(old);
heap_free((void *)old->c.gl_info);
heap_free(old);
}
else
{
if (wglGetCurrentContext())
{
const struct wined3d_gl_info *gl_info = old->gl_info;
const struct wined3d_gl_info *gl_info = old->c.gl_info;
TRACE("Flushing context %p before switching to %p.\n", old, context_gl);
gl_info->gl_ops.gl.p_glFlush();
}
old->current = 0;
old->c.current = 0;
}
}
......@@ -1566,7 +1565,7 @@ BOOL wined3d_context_gl_set_current(struct wined3d_context_gl *context_gl)
}
}
return TlsSetValue(wined3d_context_tls_idx, ctx);
return TlsSetValue(wined3d_context_tls_idx, context_gl);
}
void wined3d_context_gl_release(struct wined3d_context_gl *context_gl)
......@@ -1579,7 +1578,7 @@ void wined3d_context_gl_release(struct wined3d_context_gl *context_gl)
{
if (!context->level)
WARN("Context %p is not active.\n", context);
else if (context != context_get_current())
else if (context_gl != wined3d_context_gl_get_current())
WARN("Context %p is not the current context.\n", context);
}
......@@ -1623,10 +1622,10 @@ static void wined3d_context_gl_enter(struct wined3d_context_gl *context_gl)
if (!context_gl->c.level++)
{
const struct wined3d_context *current_context = context_get_current();
const struct wined3d_context_gl *current_context = wined3d_context_gl_get_current();
HGLRC current_gl = wglGetCurrentContext();
if (current_gl && (!current_context || wined3d_context_gl_const(current_context)->gl_ctx != current_gl))
if (current_gl && (!current_context || current_context->gl_ctx != current_gl))
{
TRACE("Another GL context (%p on device context %p) is already current.\n",
current_gl, wglGetCurrentDC());
......@@ -4198,7 +4197,7 @@ static void wined3d_context_gl_activate(struct wined3d_context_gl *context_gl,
if (!context_gl->valid)
return;
if (&context_gl->c != context_get_current())
if (context_gl != wined3d_context_gl_get_current())
{
if (!wined3d_context_gl_set_current(context_gl))
ERR("Failed to activate the new context.\n");
......@@ -4212,22 +4211,22 @@ static void wined3d_context_gl_activate(struct wined3d_context_gl *context_gl,
struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device *device,
struct wined3d_texture *texture, unsigned int sub_resource_idx)
{
struct wined3d_context *current_context = context_get_current();
struct wined3d_context *context;
struct wined3d_context_gl *current_context = wined3d_context_gl_get_current();
struct wined3d_context_gl *context_gl;
TRACE("device %p, texture %p, sub_resource_idx %u.\n", device, texture, sub_resource_idx);
if (current_context && current_context->destroyed)
if (current_context && current_context->c.destroyed)
current_context = NULL;
if (!texture)
{
if (current_context
&& current_context->current_rt.texture
&& current_context->device == device)
&& current_context->c.current_rt.texture
&& current_context->c.device == device)
{
texture = current_context->current_rt.texture;
sub_resource_idx = current_context->current_rt.sub_resource_idx;
texture = current_context->c.current_rt.texture;
sub_resource_idx = current_context->c.current_rt.sub_resource_idx;
}
else
{
......@@ -4241,15 +4240,15 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device *
}
}
if (current_context && current_context->current_rt.texture == texture)
if (current_context && current_context->c.current_rt.texture == texture)
{
context = current_context;
context_gl = current_context;
}
else if (texture && !wined3d_resource_is_offscreen(&texture->resource))
{
TRACE("Rendering onscreen.\n");
if (!(context = swapchain_get_context(texture->swapchain)))
if (!(context_gl = wined3d_context_gl(swapchain_get_context(texture->swapchain))))
return NULL;
}
else
......@@ -4258,15 +4257,15 @@ struct wined3d_context *wined3d_context_gl_acquire(const struct wined3d_device *
/* Stay with the current context if possible. Otherwise use the
* context for the primary swapchain. */
if (current_context && current_context->device == device)
context = current_context;
else if (!(context = swapchain_get_context(device->swapchains[0])))
if (current_context && current_context->c.device == device)
context_gl = current_context;
else if (!(context_gl = wined3d_context_gl(swapchain_get_context(device->swapchains[0]))))
return NULL;
}
wined3d_context_gl_activate(wined3d_context_gl(context), texture, sub_resource_idx);
wined3d_context_gl_activate(context_gl, texture, sub_resource_idx);
return context;
return &context_gl->c;
}
struct wined3d_context_gl *wined3d_context_gl_reacquire(struct wined3d_context_gl *context_gl)
......
......@@ -2105,6 +2105,7 @@ void wined3d_context_gl_free_occlusion_query(struct wined3d_occlusion_query *que
void wined3d_context_gl_free_pipeline_statistics_query(struct wined3d_pipeline_statistics_query *query) DECLSPEC_HIDDEN;
void wined3d_context_gl_free_so_statistics_query(struct wined3d_so_statistics_query *query) DECLSPEC_HIDDEN;
void wined3d_context_gl_free_timestamp_query(struct wined3d_timestamp_query *query) DECLSPEC_HIDDEN;
struct wined3d_context_gl *wined3d_context_gl_get_current(void) DECLSPEC_HIDDEN;
GLenum wined3d_context_gl_get_offscreen_gl_buffer(const struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
const unsigned int *wined3d_context_gl_get_tex_unit_mapping(const struct wined3d_context_gl *context_gl,
const struct wined3d_shader_version *shader_version, unsigned int *base, unsigned int *count) DECLSPEC_HIDDEN;
......@@ -2263,7 +2264,6 @@ BOOL fbo_blitter_supported(enum wined3d_blit_op blit_op, const struct wined3d_gl
BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other) DECLSPEC_HIDDEN;
HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;
struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
void context_gl_resource_released(struct wined3d_device *device,
GLuint name, BOOL rb_namespace) DECLSPEC_HIDDEN;
......
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