Welcome! Log In Create A New Profile

Advanced

Some help with GX settings

Posted by LegacyCrono 
Some help with GX settings
January 06, 2010 07:06PM
Hey guys,

I've begun coding a simple engine to port our PC game to Wii. I've installed devkitPro, tested some demos, did a thing here and there and everything seems fine. It's the first time I'm coding on such low-level library, so I'm a bit confused.

Actually, there are some functions that setups GX subsystem on the initialization that I really can't understand. If possible, I'd like some help with those just to clarify why they are used and hopefully figure out some ninja rendering techniques... XD
The following lines were took from gxsprites example demo:

GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter);
I believe that this changes how the video do the copy from buffer to screen according to your TV mode (NTSC, PAL, etc). But that's just my guess.

GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
Clueless. What's a field? I have no idea.

GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

Set Vertex Attribute Format? I have some guesses, but this description is misleading, I think: tells the flipper to expect direct data
How should I tell to the flipper to expect indirect data, and how would this be useful?

GX_SetNumChans(1);
GX_SetNumTexGens(1);
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

I don't know what those are doing. Only GX_SetTevOp has some description on the documentation but it's not helpful at all.

GX_InvalidateTexAll();
I think it... invalidate all the textures? But why?

The code I currently have is working but I still haven't implemented this part because I'm not sure of what I should be really using and why...
I'll not be using 3D on this project, only 2D. Still, I don't want to use SDL for Wii or anything like that... I prefer to learn how things works before moving to easier libraries.

Thanks in advance guys. :D
Re: Some help with GX settings
January 07, 2010 12:06PM
Quote
LegacyCrono
GX_SetCopyFilter(rmode->aa,rmode->sample_pattern,GX_TRUE,rmode->vfilter);
I believe that this changes how the video do the copy from buffer to screen according to your TV mode (NTSC, PAL, etc). But that's just my guess.
It let you configure hardware filtering during the copy from internal GX buffer (EFB) to the framebuffer in external memory (XFB). The video hardware then use this external framebuffer to output a video signal on TV screen.

The first and second argument let you configure anti-aliasing during the copy. If the first argument is TRUE, the second argument is used, otherwise it's not. It holds a table with weightpounded coefficients to configure anti-aliasing for a pixel region. It's not commonly used in homebrew application because of the restrictions imposed by anti-aliasing (pixel format, internal buffer size, etc) so not much is knwon about these coefficients: it's generally better to use a rendering mode with AA set to FALSE.

The third and last arguments let you configure bilinear filtering during the copy. Indeed, the copy has the ability to vertically scale the image from the internal buffer to the external framebuffer and it's generally a good idea to use bilinerar filtering (especially when the scale factor is not an integer). When the third argument is set to TRUE, the last argument is used: it's a table that gives the weight for each neighbor lines when upscaling. When filtering is disabled, default weight values are used for vertical scaling.

You can find the default rmode->sample_pattern and rmode->vfilter tables in video_types.h for each common rendering modes. But you could eventually use your own pattern tables if you know what you are doing. It's indeed possible to configure your own rendering mode.

Quote
LegacyCrono
GX_SetFieldMode(rmode->field_rendering,((rmode->viHeight==2*rmode->xfbHeight)?GX_ENABLE:GX_DISABLE));
Clueless. What's a field? I have no idea.

A frame (480 lines) is composed of two fields, one composed by odd lines , the other by even lines:

- in interlaced mode (240i, 480i), a single frame is refreshed each 1/30 s, with each field being displayed each 1/60 s and interlaced by the video hardware. Both fields can either be rendered at once, desinterlacing being handled by the hardware (480i) or each field can be rendered & swapped separetely at the correct frequency (240i), in order to save some memory in the framebuffer.

- in non-interlaced mode (240p), only one same single field is rendered & displayed each 1/60s: this gives the illusion of each frame being refreshed at 60hz but with only half the max resolution (odd lines are blanked, this is the known "scanline" effect).

- in progressive mode (480p), a frame is displayed at 1/60s with both fields being rendered AND displayed in one pass.

Basically, this function tells to GX hardware the way fields are going to be rendered and displayed, depending on the current mode.

Quote
LegacyCrono
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0);
GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

Set Vertex Attribute Format? I have some guesses, but this description is misleading, I think: tells the flipper to expect direct data
How should I tell to the flipper to expect indirect data, and how would this be useful?

A vertex (vertice) is a virtual point in 3D space and an attribute is a parameter (can be Position, Texture Coordinate, Color, ...) that defines each vertex.
You must define the format of each attribute that are going to define your vertexes before rendering something with GX, this is what this function is used for.
For example, the first call indicates that all "Position" attributes will be defined by a (X,Y) couple value, with the values being in 32-bits float format.
It's possible to store multiple attribute format configurations to use them later, this is specified by the first parameter (GX_VTXFMT0 is the first, default, configuration set).

Direct or Indirect data are something different: it tells how the attribute value are passed to GX, either directly (i.e raw values) or indirectly (using an index into a table that stores raw value).
You configure this using GX_SetVtxDesc.

for example:
GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

When using an indexed table where attributes value are stored, you need to define the address and size of the table in memory using the function GX_SetArray.

Quote
LegacyCrono
GX_SetNumChans(1);
GX_SetNumTexGens(1);
GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

I don't know what those are doing. Only GX_SetTevOp has some description on the documentation but it's not helpful at all.

GX_SetNumChans sets the total number of simultaneous color channels you are going to use for rendering.

GX_SetNumTexGens sets the number of simultaneous texture sets you are going to use.

GX_SetTevOp lets you apply a preconfigured scheme for a specific TEV stage: there are 8 TEV stages that can be used and mixed to produce the final pixel output. I'm not very comfortable with this to explain you exactly how it works but just can tell you need at least one stage, that most applications only use STAGE0 and that GX_REPLACE indicates that the output pixel will directly use the texture map pixel (texel) output. Some other configuration (GX_MODULATE, etc) let you mix color channel with texture map for some effects.

GX_SetTevOrder configures the available inputs for a specific TEV stage (indicates which texture coordinates, texture map and color channel it is going to use). Most applications limit themselves to one texture coordinate and one texture map, with eventually a color channel if effects are required (or textures not used).

GX_SetTexCoordGen lets you configure a specific texture coordinate, I don't know much about this one, most homebrew developpers use this default setting as they only use texturing for basic rendering (textured quads).

Quote
LegacyCrono
GX_InvalidateTexAll();
I think it... invalidate all the textures? But why?

GX has an internal texture cache where it stores texture data; If you modify a texture, you have to invalidate the cache first, to make sure the new data is being used, not the one in the cache (cache will automatically be updated afterwards).



Edited 2 time(s). Last edit at 01/07/2010 12:29PM by ekeeke.
Sorry, only registered users may post in this forum.

Click here to login