![]() |
TGX 1.0.3
A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.
|
3D triangle rasterizer function. More...
#include "ShaderParams.h"
Go to the source code of this file.
Macros | |
#define | TGX_RASTERIZE_SUBPIXEL_BITS (6) |
Sub-pixel precision bits. More... | |
Functions | |
template<typename SHADER_FUNCTION , typename RASTERIZER_PARAMS > | |
void | tgx::rasterizeTriangle (const int LX, const int LY, const RasterizerVec4 &V0, const RasterizerVec4 &V1, const RasterizerVec4 &V2, const int32_t offset_x, const int32_t offset_y, const RASTERIZER_PARAMS &data, SHADER_FUNCTION shader_fun) |
Fast triangle rasterizer for 3D graphics: More... | |
3D triangle rasterizer function.
#define TGX_RASTERIZE_SUBPIXEL_BITS (6) |
Sub-pixel precision bits.
Value should range between 1 and 8. Larger value provide greater resolution and smoother animation but at the expense of the maximum viewport size:
subpixel bits | max viewport size LX*LY |
---|---|
8 | 2048 x 2048 |
6 | 4096 x 4096 |
4 | 8192 x 8192 |
2 | 16384 x 16384 |
void tgx::rasterizeTriangle | ( | const int | LX, |
const int | LY, | ||
const RasterizerVec4 & | V0, | ||
const RasterizerVec4 & | V1, | ||
const RasterizerVec4 & | V2, | ||
const int32_t | offset_x, | ||
const int32_t | offset_y, | ||
const RASTERIZER_PARAMS & | data, | ||
SHADER_FUNCTION | shader_fun | ||
) |
Fast triangle rasterizer for 3D graphics:
Features
TGX_RASTERIZE_SUBPIXEL_BITS
). SHADER_FUNCTION | the shader function to call. |
RASTERIZER_PARAMS | the type of the object containing the 'uniform' data (ie data not specific to a vertex). |
LX,LY | Viewport size. The image itself may be smaller than the viewport and an offset may be specified so it is possible to draw the whole viewport in 'tile" mode be calling this method several times with different offsets. The maximum viewport size depend on TGX_RASTERIZE_SUBPIXEL_BITS |
V0,V1,V2 | Normalized coordinates of the vertices of the triangle (x,y,z,w) where, 'a la opengl' the viewport is mapped to [-1, 1]^2. These vectors also optionally contain the 'varying' parameters associated with each vertex, namely the texture coords and the color associated with each vertex (when applicable) that are used by the shader function. |
offset_x,offset_y | Offset of this image inside the viewport. So the image corresponds to to the box [offset_x, offset_x + im.width[x[offset_x, offset_x + im.height[ and only the intersection of this box with the viewport box [0, LX[x[0, LY[ is drawn onto the image. |
data | 'Uniform' parameters (depending on the rasterization type). |
shader_fun | the shader function. see Shaders.h for the implementation of classic shaders. |
TGX_RASTERIZE_SUBPIXEL_BITS
: (x,y)
coordinates of the vertices V0,V1,V2
do not need to be inside the viewport [-1,1]^2
and yet the triangle will still be perfectly rasterized provided that they are not 'too far away'. This 'too far away' correspond to the maximum viewport size according to the chosen sub-pixel precision (for instance, [-2,2]^2 will work any viewport at most 1024x1024 when using 8 bits precision).