forked from davidgfnet/opengx
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Shader resources #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Shader resources #101
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a770641
to
2557c53
Compare
The association of a VBO to an array is to be saved in the client state: we should look up the VBO only when we draw some geometry. The error was discovered running the cube_tex example (it will be added to the repo in a later commit), which uses two different VBOs for the position and texture coordinate attributes.
This example uses SDL2 and glm. At the moment this example does not work on the Wii/GameCube, as the textured rendering using OpenGL 2.0 will come in a later commit. The "common" directory contains textures that get embedded into the executable, so that examples can be written without access to external files (which makes testing on the console -- or on the emulator -- very straightforward).
Colors are often specifies as a 3 or 4 long vector of floats, but GX does not support specifying colors using floating point components. Therefore, convert such values to GXColor.
The data here is just an integer number representing the texture unit bound to the uniform.
This is all what is needed to let the client developer write a GX shader capable of supporting textured geometries.
This is a bit primitive, because we are hardcoding the texture stage and other TEV variables (we'll improve this later), but it does the job.
To make clear that these functions are to be called only when implementing shaders in the client code, rename them to have a "ogx_shader" prefix. Also use the "_gx" or "_gl" suffix to indicate whether they expect the matrix to be in the GX or OpenGL format.
Shader programs will be able to know which resources are available and will not conflict with other core opengx functionality (like clipping and stencil).
These enums are supported both by glGetBoolean() and glIsEnabled().
It is not very clear how this should work, but we replicate the behaviour of desktop OpenGL.
Clipping and stenciling is not working properly currently (due to the model-view matrix not being up-to-date when drawing with shaders), but the stages do get applied.
Add a couple of pointers in the opengx state, to the currently active model-view and projection matrices: these are not always those set via the immediate-mode API, because with OpenGL 2.0+ these matrices can be implicitly set by the shader programs.
This now works when using shaders, too.
The client can update the matrices in the setup_draw() callback as well, but having a specialized callback makes it possible for opengx to request the client to update the matrices without setting up the whole TEV state. This is required for supporting stencil drawing when using shaders: since the drawing happens in two stages (first we draw to the stencil buffer, and then to the scene) and only the latter stage uses the TEV as setup by the client, it would be a waste to call setup_draw() twice, if all what we need from the first invocation is just the updated transformation matrices.
This is as simple as ensuring that the matrices being considered for the stencil texture projection are those used by the shader pipeline (glUseProgram() takes care of updating the matrix pointers).
This allows to reduce branching, since the function pointer only changes when glUseProgram() is called. We should consider using the same mechanism for the setup_draw() function. We also clean up the dirty bit usage for the normal matrix, partially reverting commit 836fd7e, because the current condition for rebuilding the normal matrix is anyway satisfied when the dirty_matrices flag is set, so we can just set it anytime a matrix is changed. We still keep setting the dirty_tev flag to true when the normal matrix gets changed, in order not to break the idea behind commit 836fd7e.
Fixes a regression introduced by commit 836fd7e, because indeed the _ogx_stencil_draw() function (and draw_op() in particular) alters the TEV setup, which then needs to be restored when drawing to the scene. This fixes an issue in the dinoshade program, where some parts of the reflected dinosaur could be seen outside of the floor.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To be merged after #100
Enable operation of clipping and stencil tests when using shaders, too. In order to do this, expose the OgxGpuResources structure to the client, to let them allocate stages dynamically. The clip and stencil stages need to be run after the other stages, and for this reason it's important for opengx to know how many stages are being used by the shader program.
The last commit fixes an unrelated old regression, discovered when testing these changes.