sdl-gpu icon indicating copy to clipboard operation
sdl-gpu copied to clipboard

GPU_PrimitiveBatch issue

Open kirilledelman opened this issue 8 years ago • 4 comments

Jonathan,

I'm having trouble using GPU_PrimitiveBatch. My intention is to draw a series of line segments with current color. I make a call with:

GPU_PrimitiveBatch( NULL, target, GPU_LINE_STRIP, 5, floatPointsPackedAsXY, 5, uShortIndexes, GPU_BATCH_XY )

and it crashes in get_complete_mod_color, because I'm simultaneously not supplying image, and not using colors. I don't need per-vertex color, or texture. I'd like to use a single color to render this shape. I tried supplying a dummy image param, but then it just draws triangles.

Please hlep.

kirilledelman avatar Feb 14 '18 23:02 kirilledelman

By stepping through code, and patching get_complete_mod_color I arrived to actual rendering inside PrimitiveBatchV in Renderer_GL_Common.inl:

if(indices == NULL)
            glDrawArrays(GL_TRIANGLES, 0, num_indices);
        else
            glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, (void*)0);

As you see, it's always drawing triangles, not the specified primitive. Is this simply unfinished? I'm going to try and plug in the primitive from parameter here. I assume this should be fixed in main branch.

Update

Yes - this appears to be the case - I think you forgot to change it after implementing TriangleBatch sister function.

Found more issues: drawing GPU_LINE_STRIP, GPU_LINE_LOOP doesn't apply current line thickness - is this related to GPU_Polygon also not being able to draw with line thickness?

Color for these could be supplied by setting mod color on target (if you check for image param in get_complete_mod_color, and just use target color if not supplied).

kirilledelman avatar Feb 15 '18 17:02 kirilledelman

For my purposes, it would be perfectly acceptable to use GPU_Polygon, to draw a line strip (if we can get thickness to work), if GPU_Polygon had another parameter that let me specify if I want to close this polygon, or keep it open (line strip). 👍

I can use PrimitiveBatch to draw a filled convex or concave polygon as triangle strip, if the thing with colors and primitive_type is fixed.

Thanks for good work, Jonathan.

kirilledelman avatar Feb 15 '18 18:02 kirilledelman

Could you take a look at my commit, please?

kirilledelman avatar Feb 20 '18 16:02 kirilledelman

Yep, these are good thoughts. Thanks for your work on this! (other discussion on pull thread)

grimfang4 avatar Feb 21 '18 17:02 grimfang4