Max,
I did a REALLY quick hack to get this working with GapiDraw and to avoid having a function call on each pixel being rendered to the backbuffer.
I have attached a sample project that you can use. I placed all the Polygon code in the file "GapiBufferTool.h" which is located in the "common" folder. Unzip the sample into your "\gapidraw\samples" folder.
To use the Polygon tool, please check the following code:
- Code:
GDBUFFERDESC bufferdesc;
if (SUCCEEDED(pBackBuffer->GetBuffer(&bufferdesc)))
{
// Draw a polygon
CPoint points[3]; points[0].SetPoint(10, 10); points[1].SetPoint(210, 70); points[2].SetPoint(150, 237);
COLORREF colors[3]; colors[0] = RGB(255, 0, 0); colors[1] = RGB(0, 255, 0); colors[2] = RGB(0, 0, 255);
if (bufferdesc.dwPixelFormat & GDPIXELFORMAT_565)
{
CGapiBufferTool< GDShader::Opaque<GDPixelFormat::GD565> > buffertool;
buffertool.FillPoly(&bufferdesc, points, colors, 3);
}
else if (bufferdesc.dwPixelFormat & GDPIXELFORMAT_555)
{
CGapiBufferTool< GDShader::Opaque<GDPixelFormat::GD555> > buffertool;
buffertool.FillPoly(&bufferdesc, points, colors, 3);
}
else if (bufferdesc.dwPixelFormat & GDPIXELFORMAT_444)
{
CGapiBufferTool< GDShader::Opaque<GDPixelFormat::GD444> > buffertool;
buffertool.FillPoly(&bufferdesc, points, colors, 3);
}
pBackBuffer->ReleaseBuffer();
}
As you can see, there are three classes involved:
(1) The Pixel Shader class ("Opaque"). I have attached a 50% quick antialias and an alpha blend shader you can use. To set the opacity value for the alpha blend, simply call buffertool.SetParam1(n).
(2) The Pixel Format class. For maximum performance, GapiDraw renders in native mode on all devices. Thus, on some symbian devices this will be the 444 pixel format. This is generally no issue if you use template code.
(3) The BufferTool class. This at the moment only contains the FillPoly function. Please note that:
1. It does not support clipping at the moment
2. It does not support 1- or 2-point polygons
3. It draws the polygon at incorrect coordinates (I borrowed the code for the FillPoly function (with permission) from the forum user fast_rx). This is probably an issue in the FillPoly function but I have not had the chance to look into this. You clearly see this issue if you first draw the polygon and then call a number of DrawLine at the same coordinates.
If you fix any of the above issues then please feel free to contribute by posting the updates you do.
You can download the sample project with all the code from:
http://www.develant.com/temp/Minimal-FillPoly.zip