[Mesa-dev] OSMesa Help

Brian Paul brianp at vmware.com
Mon Jul 15 07:24:58 PDT 2013


On 07/14/2013 09:34 PM, Andy Li wrote:
> Hi,
> 
> I have some questions on the OSMesa code.
> As you suggested, I have continue looking into the swrast code.
> However, I have trouble figuring out how the code works exactly.
> Now I am now only focusing on the functions which draw lines.
> As I look into s_lines.c, I saw the _swrast_choose_line().
> And depends on different cases, it will call
> 
> _swrast_choose_aa_line_function(ctx)
> or
>   USE(general_line)
> or
> USE(rgba_line)
> or
> USE(simple_no_z_rgba_line)
> etc.
> 
> The first thing I did is looking into the 
> _swrast_choose_aa_line_function() and it direct me to s_aaline.c
> In that file, I saw the struct of LineInfo and other computation 
> functions for plane.
> Then I looked at the _swrast_choose_aa_line_function()
> 
> and when I saw the code:
> swrast->Line = aa_general_rgba_line;
> and
> swrast->Line = aa_rgba_line;
> 
> I am not sure what do they mean. And I won't be able to continue finding 
> useful info.

aa_rgba_line() drawns a "simple" RGBA antialiased line while
aa_general_rgba_line() also computes texture coords, fog coord, etc.



> I think the main problem I am having is I am not sure what are the steps 
> OSMesa have to take in order to draw a line into the frame buffer.
> Would you be able to explain a bit on that? (what are the steps OSMesa 
> have to take in order to draw a line into the frame buffer?)
> Does drawing a line involve computing the plane?

AA lines are drawn by drawing a quadrilateral and computing pixel
coverage involves computing plane equations.

> What do s_aaline.c and s_aalinetemp.h actually mean?

the "temp" files contain template code that's re-used multiple times in
the .c file.


> What is USE(general_line) ? Where is USE() define?

grep "define USE" src/mesa/swrast/*.[ch]


> What is swrast->Line = aa_general_rgba_line;?

swrast->Line is a function pointer that points to the current line
drawing function.  The function is chosen by examining current GL
rasterization state.


> Would you suggest any debugging tool for me so that I can trace which 
> functions are called while the program is running?
> For example I have the code below:
> glBegin(GL_LINES);
> glVertex3f(0.0, 0.0, 0.0);
> glVertex3f(15, 0, 0);
> glEnd();
> Is there any debugging tool which can trace glVertex3f back in the 
> library and see how OSMesa works?
> I have tried using gdb, however, it would only by-pass the call the go 
> to the next command.

You'll need to build mesa for debugging (CFLAGS="-g -O0"
--enable-debug).  But I don't really have time to explain all the
nuances of debugging/tracing in Mesa.  I'm not sure that'd really help
you anyway.

In general, when you drawing points/lines/triangles the s_points.c or
s_lines.c or s_triangle.c code winds up calling _swrast_write_rgba()
span.  This function does Z testing, texturing, stippling, etc before
calling a "put_pixels" or "put_row" function.  Those functions call a
"pack" function to pack an array of RGBA ubyte/float values into the
framebuffer.  Packing involves converting a canonical RGBA format into a
specific pixel format, like RGBA8888, or RGB565, etc.  The color buffer
address, stride, etc. is obtained earlier through a call to
ctx->Driver.MapRenderbuffer().  In the case of OSMesa, the color buffer
is ordinary malloc'd memory that the user allocated.

-Brian





More information about the mesa-dev mailing list