st/mesa: replace st->ctx with ctx

This commit is contained in:
Brian Paul
2011-06-14 09:15:36 -06:00
parent c1477f6ffe
commit 99feecc7d1
7 changed files with 80 additions and 69 deletions

View File

@@ -156,7 +156,7 @@ translate_logicop(GLenum logicop)
* Figure out if colormasks are different per rt. * Figure out if colormasks are different per rt.
*/ */
static GLboolean static GLboolean
colormask_per_rt(struct gl_context *ctx) colormask_per_rt(const struct gl_context *ctx)
{ {
/* a bit suboptimal have to compare lots of values */ /* a bit suboptimal have to compare lots of values */
unsigned i; unsigned i;
@@ -172,7 +172,7 @@ colormask_per_rt(struct gl_context *ctx)
* Figure out if blend enables/state are different per rt. * Figure out if blend enables/state are different per rt.
*/ */
static GLboolean static GLboolean
blend_per_rt(struct gl_context *ctx) blend_per_rt(const struct gl_context *ctx)
{ {
if (ctx->Color.BlendEnabled && if (ctx->Color.BlendEnabled &&
(ctx->Color.BlendEnabled != ((1 << ctx->Const.MaxDrawBuffers) - 1))) { (ctx->Color.BlendEnabled != ((1 << ctx->Const.MaxDrawBuffers) - 1))) {
@@ -190,13 +190,14 @@ static void
update_blend( struct st_context *st ) update_blend( struct st_context *st )
{ {
struct pipe_blend_state *blend = &st->state.blend; struct pipe_blend_state *blend = &st->state.blend;
const struct gl_context *ctx = st->ctx;
unsigned num_state = 1; unsigned num_state = 1;
unsigned i, j; unsigned i, j;
memset(blend, 0, sizeof(*blend)); memset(blend, 0, sizeof(*blend));
if (blend_per_rt(st->ctx) || colormask_per_rt(st->ctx)) { if (blend_per_rt(ctx) || colormask_per_rt(ctx)) {
num_state = st->ctx->Const.MaxDrawBuffers; num_state = ctx->Const.MaxDrawBuffers;
blend->independent_blend_enable = 1; blend->independent_blend_enable = 1;
} }
/* Note it is impossible to correctly deal with EXT_blend_logic_op and /* Note it is impossible to correctly deal with EXT_blend_logic_op and
@@ -205,52 +206,52 @@ update_blend( struct st_context *st )
and separate alpha/rgb logicop/blend support respectively. Neither and separate alpha/rgb logicop/blend support respectively. Neither
possible in gallium nor most hardware. Assume these combinations possible in gallium nor most hardware. Assume these combinations
don't happen. */ don't happen. */
if (st->ctx->Color.ColorLogicOpEnabled || if (ctx->Color.ColorLogicOpEnabled ||
(st->ctx->Color.BlendEnabled && (ctx->Color.BlendEnabled &&
st->ctx->Color.Blend[0].EquationRGB == GL_LOGIC_OP)) { ctx->Color.Blend[0].EquationRGB == GL_LOGIC_OP)) {
/* logicop enabled */ /* logicop enabled */
blend->logicop_enable = 1; blend->logicop_enable = 1;
blend->logicop_func = translate_logicop(st->ctx->Color.LogicOp); blend->logicop_func = translate_logicop(ctx->Color.LogicOp);
} }
else if (st->ctx->Color.BlendEnabled) { else if (ctx->Color.BlendEnabled) {
/* blending enabled */ /* blending enabled */
for (i = 0, j = 0; i < num_state; i++) { for (i = 0, j = 0; i < num_state; i++) {
blend->rt[i].blend_enable = (st->ctx->Color.BlendEnabled >> i) & 0x1; blend->rt[i].blend_enable = (ctx->Color.BlendEnabled >> i) & 0x1;
if (st->ctx->Extensions.ARB_draw_buffers_blend) if (ctx->Extensions.ARB_draw_buffers_blend)
j = i; j = i;
blend->rt[i].rgb_func = blend->rt[i].rgb_func =
translate_blend(st->ctx->Color.Blend[j].EquationRGB); translate_blend(ctx->Color.Blend[j].EquationRGB);
if (st->ctx->Color.Blend[i].EquationRGB == GL_MIN || if (ctx->Color.Blend[i].EquationRGB == GL_MIN ||
st->ctx->Color.Blend[i].EquationRGB == GL_MAX) { ctx->Color.Blend[i].EquationRGB == GL_MAX) {
/* Min/max are special */ /* Min/max are special */
blend->rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE; blend->rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
blend->rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE; blend->rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
} }
else { else {
blend->rt[i].rgb_src_factor = blend->rt[i].rgb_src_factor =
translate_blend(st->ctx->Color.Blend[j].SrcRGB); translate_blend(ctx->Color.Blend[j].SrcRGB);
blend->rt[i].rgb_dst_factor = blend->rt[i].rgb_dst_factor =
translate_blend(st->ctx->Color.Blend[j].DstRGB); translate_blend(ctx->Color.Blend[j].DstRGB);
} }
blend->rt[i].alpha_func = blend->rt[i].alpha_func =
translate_blend(st->ctx->Color.Blend[j].EquationA); translate_blend(ctx->Color.Blend[j].EquationA);
if (st->ctx->Color.Blend[i].EquationA == GL_MIN || if (ctx->Color.Blend[i].EquationA == GL_MIN ||
st->ctx->Color.Blend[i].EquationA == GL_MAX) { ctx->Color.Blend[i].EquationA == GL_MAX) {
/* Min/max are special */ /* Min/max are special */
blend->rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE; blend->rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
blend->rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE; blend->rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
} }
else { else {
blend->rt[i].alpha_src_factor = blend->rt[i].alpha_src_factor =
translate_blend(st->ctx->Color.Blend[j].SrcA); translate_blend(ctx->Color.Blend[j].SrcA);
blend->rt[i].alpha_dst_factor = blend->rt[i].alpha_dst_factor =
translate_blend(st->ctx->Color.Blend[j].DstA); translate_blend(ctx->Color.Blend[j].DstA);
} }
} }
} }
@@ -260,25 +261,25 @@ update_blend( struct st_context *st )
/* Colormask - maybe reverse these bits? */ /* Colormask - maybe reverse these bits? */
for (i = 0; i < num_state; i++) { for (i = 0; i < num_state; i++) {
if (st->ctx->Color.ColorMask[i][0]) if (ctx->Color.ColorMask[i][0])
blend->rt[i].colormask |= PIPE_MASK_R; blend->rt[i].colormask |= PIPE_MASK_R;
if (st->ctx->Color.ColorMask[i][1]) if (ctx->Color.ColorMask[i][1])
blend->rt[i].colormask |= PIPE_MASK_G; blend->rt[i].colormask |= PIPE_MASK_G;
if (st->ctx->Color.ColorMask[i][2]) if (ctx->Color.ColorMask[i][2])
blend->rt[i].colormask |= PIPE_MASK_B; blend->rt[i].colormask |= PIPE_MASK_B;
if (st->ctx->Color.ColorMask[i][3]) if (ctx->Color.ColorMask[i][3])
blend->rt[i].colormask |= PIPE_MASK_A; blend->rt[i].colormask |= PIPE_MASK_A;
} }
if (st->ctx->Color.DitherFlag) if (ctx->Color.DitherFlag)
blend->dither = 1; blend->dither = 1;
if (st->ctx->Multisample.Enabled) { if (ctx->Multisample.Enabled) {
/* unlike in gallium/d3d10 these operations are only performed /* unlike in gallium/d3d10 these operations are only performed
if msaa is enabled */ if msaa is enabled */
if (st->ctx->Multisample.SampleAlphaToCoverage) if (ctx->Multisample.SampleAlphaToCoverage)
blend->alpha_to_coverage = 1; blend->alpha_to_coverage = 1;
if (st->ctx->Multisample.SampleAlphaToOne) if (ctx->Multisample.SampleAlphaToOne)
blend->alpha_to_one = 1; blend->alpha_to_one = 1;
} }
@@ -286,7 +287,7 @@ update_blend( struct st_context *st )
{ {
struct pipe_blend_color bc; struct pipe_blend_color bc;
COPY_4FV(bc.color, st->ctx->Color.BlendColorUnclamped); COPY_4FV(bc.color, ctx->Color.BlendColorUnclamped);
cso_set_blend_color(st->cso_context, &bc); cso_set_blend_color(st->cso_context, &bc);
} }
} }

View File

@@ -43,20 +43,21 @@
static void update_clip( struct st_context *st ) static void update_clip( struct st_context *st )
{ {
struct pipe_clip_state clip; struct pipe_clip_state clip;
const struct gl_context *ctx = st->ctx;
GLuint i; GLuint i;
memset(&clip, 0, sizeof(clip)); memset(&clip, 0, sizeof(clip));
for (i = 0; i < PIPE_MAX_CLIP_PLANES; i++) { for (i = 0; i < PIPE_MAX_CLIP_PLANES; i++) {
if (st->ctx->Transform.ClipPlanesEnabled & (1 << i)) { if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {
memcpy(clip.ucp[clip.nr], memcpy(clip.ucp[clip.nr],
st->ctx->Transform._ClipUserPlane[i], ctx->Transform._ClipUserPlane[i],
sizeof(clip.ucp[0])); sizeof(clip.ucp[0]));
clip.nr++; clip.nr++;
} }
} }
clip.depth_clamp = st->ctx->Transform.DepthClamp != GL_FALSE; clip.depth_clamp = ctx->Transform.DepthClamp != GL_FALSE;
if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) { if (memcmp(&clip, &st->state.clip, sizeof(clip)) != 0) {
st->state.clip = clip; st->state.clip = clip;

View File

@@ -125,14 +125,15 @@ static void convert_sampler(struct st_context *st,
GLuint texUnit) GLuint texUnit)
{ {
struct gl_texture_object *texobj; struct gl_texture_object *texobj;
struct gl_context *ctx = st->ctx;
struct gl_sampler_object *msamp; struct gl_sampler_object *msamp;
texobj = st->ctx->Texture.Unit[texUnit]._Current; texobj = ctx->Texture.Unit[texUnit]._Current;
if (!texobj) { if (!texobj) {
texobj = st_get_default_texture(st); texobj = st_get_default_texture(st);
} }
msamp = _mesa_get_samplerobj(st->ctx, texUnit); msamp = _mesa_get_samplerobj(ctx, texUnit);
memset(sampler, 0, sizeof(*sampler)); memset(sampler, 0, sizeof(*sampler));
sampler->wrap_s = gl_wrap_xlate(msamp->WrapS); sampler->wrap_s = gl_wrap_xlate(msamp->WrapS);
@@ -146,7 +147,7 @@ static void convert_sampler(struct st_context *st,
if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB) if (texobj->Target != GL_TEXTURE_RECTANGLE_ARB)
sampler->normalized_coords = 1; sampler->normalized_coords = 1;
sampler->lod_bias = st->ctx->Texture.Unit[texUnit].LodBias + sampler->lod_bias = ctx->Texture.Unit[texUnit].LodBias +
msamp->LodBias; msamp->LodBias;
sampler->min_lod = CLAMP(msamp->MinLod, sampler->min_lod = CLAMP(msamp->MinLod,
@@ -188,19 +189,20 @@ static void convert_sampler(struct st_context *st,
} }
sampler->seamless_cube_map = sampler->seamless_cube_map =
st->ctx->Texture.CubeMapSeamless || msamp->CubeMapSeamless; ctx->Texture.CubeMapSeamless || msamp->CubeMapSeamless;
} }
static void static void
update_vertex_samplers(struct st_context *st) update_vertex_samplers(struct st_context *st)
{ {
struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current; const struct gl_context *ctx = st->ctx;
struct gl_vertex_program *vprog = ctx->VertexProgram._Current;
GLuint su; GLuint su;
st->state.num_vertex_samplers = 0; st->state.num_vertex_samplers = 0;
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxVertexTextureImageUnits; su++) { for (su = 0; su < ctx->Const.MaxVertexTextureImageUnits; su++) {
struct pipe_sampler_state *sampler = st->state.vertex_samplers + su; struct pipe_sampler_state *sampler = st->state.vertex_samplers + su;
if (vprog->Base.SamplersUsed & (1 << su)) { if (vprog->Base.SamplersUsed & (1 << su)) {
@@ -223,13 +225,14 @@ update_vertex_samplers(struct st_context *st)
static void static void
update_fragment_samplers(struct st_context *st) update_fragment_samplers(struct st_context *st)
{ {
struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; const struct gl_context *ctx = st->ctx;
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
GLuint su; GLuint su;
st->state.num_samplers = 0; st->state.num_samplers = 0;
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) {
struct pipe_sampler_state *sampler = st->state.samplers + su; struct pipe_sampler_state *sampler = st->state.samplers + su;

View File

@@ -44,7 +44,8 @@ static void
update_scissor( struct st_context *st ) update_scissor( struct st_context *st )
{ {
struct pipe_scissor_state scissor; struct pipe_scissor_state scissor;
const struct gl_framebuffer *fb = st->ctx->DrawBuffer; const struct gl_context *ctx = st->ctx;
const struct gl_framebuffer *fb = ctx->DrawBuffer;
GLint miny, maxy; GLint miny, maxy;
scissor.minx = 0; scissor.minx = 0;
@@ -52,15 +53,15 @@ update_scissor( struct st_context *st )
scissor.maxx = fb->Width; scissor.maxx = fb->Width;
scissor.maxy = fb->Height; scissor.maxy = fb->Height;
if (st->ctx->Scissor.Enabled) { if (ctx->Scissor.Enabled) {
/* need to be careful here with xmax or ymax < 0 */ /* need to be careful here with xmax or ymax < 0 */
GLint xmax = MAX2(0, st->ctx->Scissor.X + st->ctx->Scissor.Width); GLint xmax = MAX2(0, ctx->Scissor.X + ctx->Scissor.Width);
GLint ymax = MAX2(0, st->ctx->Scissor.Y + st->ctx->Scissor.Height); GLint ymax = MAX2(0, ctx->Scissor.Y + ctx->Scissor.Height);
if (st->ctx->Scissor.X > (GLint)scissor.minx) if (ctx->Scissor.X > (GLint)scissor.minx)
scissor.minx = st->ctx->Scissor.X; scissor.minx = ctx->Scissor.X;
if (st->ctx->Scissor.Y > (GLint)scissor.miny) if (ctx->Scissor.Y > (GLint)scissor.miny)
scissor.miny = st->ctx->Scissor.Y; scissor.miny = ctx->Scissor.Y;
if (xmax < (GLint) scissor.maxx) if (xmax < (GLint) scissor.maxx)
scissor.maxx = xmax; scissor.maxx = xmax;

View File

@@ -64,17 +64,18 @@ invert_stipple(GLuint dest[32], const GLuint src[32], GLuint winHeight)
static void static void
update_stipple( struct st_context *st ) update_stipple( struct st_context *st )
{ {
const struct gl_context *ctx = st->ctx;
const GLuint sz = sizeof(st->state.poly_stipple); const GLuint sz = sizeof(st->state.poly_stipple);
assert(sz == sizeof(st->ctx->PolygonStipple)); assert(sz == sizeof(ctx->PolygonStipple));
if (memcmp(st->state.poly_stipple, st->ctx->PolygonStipple, sz)) { if (memcmp(st->state.poly_stipple, ctx->PolygonStipple, sz)) {
/* state has changed */ /* state has changed */
struct pipe_poly_stipple newStipple; struct pipe_poly_stipple newStipple;
memcpy(st->state.poly_stipple, st->ctx->PolygonStipple, sz); memcpy(st->state.poly_stipple, ctx->PolygonStipple, sz);
invert_stipple(newStipple.stipple, st->ctx->PolygonStipple, invert_stipple(newStipple.stipple, ctx->PolygonStipple,
st->ctx->DrawBuffer->Height); ctx->DrawBuffer->Height);
st->pipe->set_polygon_stipple(st->pipe, &newStipple); st->pipe->set_polygon_stipple(st->pipe, &newStipple);
} }

View File

@@ -187,15 +187,16 @@ update_single_texture(struct st_context *st, struct pipe_sampler_view **sampler_
GLuint texUnit) GLuint texUnit)
{ {
struct pipe_context *pipe = st->pipe; struct pipe_context *pipe = st->pipe;
struct gl_context *ctx = st->ctx;
const struct gl_sampler_object *samp; const struct gl_sampler_object *samp;
struct gl_texture_object *texObj; struct gl_texture_object *texObj;
struct st_texture_object *stObj; struct st_texture_object *stObj;
enum pipe_format st_view_format; enum pipe_format st_view_format;
GLboolean retval; GLboolean retval;
samp = _mesa_get_samplerobj(st->ctx, texUnit); samp = _mesa_get_samplerobj(ctx, texUnit);
texObj = st->ctx->Texture.Unit[texUnit]._Current; texObj = ctx->Texture.Unit[texUnit]._Current;
if (!texObj) { if (!texObj) {
texObj = st_get_default_texture(st); texObj = st_get_default_texture(st);
@@ -203,7 +204,7 @@ update_single_texture(struct st_context *st, struct pipe_sampler_view **sampler_
} }
stObj = st_texture_object(texObj); stObj = st_texture_object(texObj);
retval = st_finalize_texture(st->ctx, st->pipe, texObj); retval = st_finalize_texture(ctx, st->pipe, texObj);
if (!retval) { if (!retval) {
/* out of mem */ /* out of mem */
return GL_FALSE; return GL_FALSE;
@@ -253,13 +254,14 @@ update_single_texture(struct st_context *st, struct pipe_sampler_view **sampler_
static void static void
update_vertex_textures(struct st_context *st) update_vertex_textures(struct st_context *st)
{ {
struct gl_vertex_program *vprog = st->ctx->VertexProgram._Current; const struct gl_context *ctx = st->ctx;
struct gl_vertex_program *vprog = ctx->VertexProgram._Current;
GLuint su; GLuint su;
st->state.num_vertex_textures = 0; st->state.num_vertex_textures = 0;
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) {
struct pipe_sampler_view *sampler_view = NULL; struct pipe_sampler_view *sampler_view = NULL;
if (vprog->Base.SamplersUsed & (1 << su)) { if (vprog->Base.SamplersUsed & (1 << su)) {
GLboolean retval; GLboolean retval;
@@ -277,9 +279,9 @@ update_vertex_textures(struct st_context *st)
pipe_sampler_view_reference(&st->state.sampler_vertex_views[su], sampler_view); pipe_sampler_view_reference(&st->state.sampler_vertex_views[su], sampler_view);
} }
if (st->ctx->Const.MaxVertexTextureImageUnits > 0) { if (ctx->Const.MaxVertexTextureImageUnits > 0) {
GLuint numUnits = MIN2(st->state.num_vertex_textures, GLuint numUnits = MIN2(st->state.num_vertex_textures,
st->ctx->Const.MaxVertexTextureImageUnits); ctx->Const.MaxVertexTextureImageUnits);
cso_set_vertex_sampler_views(st->cso_context, cso_set_vertex_sampler_views(st->cso_context,
numUnits, numUnits,
st->state.sampler_vertex_views); st->state.sampler_vertex_views);
@@ -289,13 +291,14 @@ update_vertex_textures(struct st_context *st)
static void static void
update_fragment_textures(struct st_context *st) update_fragment_textures(struct st_context *st)
{ {
struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; const struct gl_context *ctx = st->ctx;
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
GLuint su; GLuint su;
st->state.num_textures = 0; st->state.num_textures = 0;
/* loop over sampler units (aka tex image units) */ /* loop over sampler units (aka tex image units) */
for (su = 0; su < st->ctx->Const.MaxTextureImageUnits; su++) { for (su = 0; su < ctx->Const.MaxTextureImageUnits; su++) {
struct pipe_sampler_view *sampler_view = NULL; struct pipe_sampler_view *sampler_view = NULL;
if (fprog->Base.SamplersUsed & (1 << su)) { if (fprog->Base.SamplersUsed & (1 << su)) {
GLboolean retval; GLboolean retval;
@@ -338,22 +341,23 @@ const struct st_tracked_state st_update_vertex_texture = {
static void static void
finalize_textures(struct st_context *st) finalize_textures(struct st_context *st)
{ {
struct gl_fragment_program *fprog = st->ctx->FragmentProgram._Current; struct gl_context *ctx = st->ctx;
struct gl_fragment_program *fprog = ctx->FragmentProgram._Current;
const GLboolean prev_missing_textures = st->missing_textures; const GLboolean prev_missing_textures = st->missing_textures;
GLuint su; GLuint su;
st->missing_textures = GL_FALSE; st->missing_textures = GL_FALSE;
for (su = 0; su < st->ctx->Const.MaxTextureCoordUnits; su++) { for (su = 0; su < ctx->Const.MaxTextureCoordUnits; su++) {
if (fprog->Base.SamplersUsed & (1 << su)) { if (fprog->Base.SamplersUsed & (1 << su)) {
const GLuint texUnit = fprog->Base.SamplerUnits[su]; const GLuint texUnit = fprog->Base.SamplerUnits[su];
struct gl_texture_object *texObj struct gl_texture_object *texObj
= st->ctx->Texture.Unit[texUnit]._Current; = ctx->Texture.Unit[texUnit]._Current;
if (texObj) { if (texObj) {
GLboolean retval; GLboolean retval;
retval = st_finalize_texture(st->ctx, st->pipe, texObj); retval = st_finalize_texture(ctx, st->pipe, texObj);
if (!retval) { if (!retval) {
/* out of mem */ /* out of mem */
st->missing_textures = GL_TRUE; st->missing_textures = GL_TRUE;

View File

@@ -728,8 +728,8 @@ st_draw_vbo(struct gl_context *ctx,
} }
} }
info.primitive_restart = st->ctx->Array.PrimitiveRestart; info.primitive_restart = ctx->Array.PrimitiveRestart;
info.restart_index = st->ctx->Array.RestartIndex; info.restart_index = ctx->Array.RestartIndex;
/* do actual drawing */ /* do actual drawing */
for (i = 0; i < nr_prims; i++) { for (i = 0; i < nr_prims; i++) {