PDA

View Full Version : Porting from 2.3 to 3.0



Noro
11-07-2014, 08:15 PM
Hello again.
I've decided to resume one of my old project and have to port it to 3.0 now, since I had a hdd crash with all of my dev environment, and only project's source was backuped on flash drive. So I've set up new environment with ClanLib 3.0(since 2.3 isn't supported anymore - I couldn't find dependency libraries for it so I had to go with 3.0).
Well, there was some number of unpleasant surprises as always happens with SDK upgrades. Most confusing was resource manager overhaul - I completely don't understand how is it supposed to work now, with the absolute lack of the documentation and examples describing it. I found the way how to use it the old style, anyway. But now I've encountered a problem without any answer I could find so far:
There was a pretty little functions in Sprite class - "set_angle_yaw" and "set_angle_pitch". I used them a lot for a number of graphic effects. And now they are gone. And I don't see anything replacing them. And now I have a lot of broken code without a way to repair it.
Is it possible to return these function to Sprite class? Or is there some replacements I didn't find? I don't see any reason to remove such useful functions.

I think there is one more serious problem ahead - with my custom batch renderer, but I didn't see into it yet.

Noro
11-08-2014, 06:54 PM
I think I'll just implement these functions myself back from 2.3 source code, it's simple enough change.

But I would greatly appreciate if someone described me how render batchers work in 3.0. There was very neat and simple system in 2.3, I implemented my own custom renderer very easy, but now I got confused with VertexArrayVector and VertexArrayBuffer needed for it to work. It seems that vertex data structure all render batchers take is hardcoded now and I couldn't figure out yet how to implement a custom renderer.

Judas
11-10-2014, 05:37 AM
I'm not sure what you mean with the batcher syntax having changed. Looking at the source code in git master, I see the following definition:



class RenderBatcher
{
public:
virtual void flush(GraphicContext &gc) = 0;
virtual void matrix_changed(const Mat4f &modelview, const Mat4f &projection) = 0;
};

class Canvas
{
...
void set_batcher(RenderBatcher *batcher);
...
};


I haven't checked with 2.x, but I believe the syntax was the same back then? Either way, I don't know where you see a VertexArrayVector except in the implementation of the built-in batchers.

If you're making a copy of the built-in batchers, maybe it is easier to just add the set_angle_yaw and set_angle_pitch functions back. They were probably removed mainly because we thought nobody used them.

If its the buffers in RenderBatchBuffer that are confusing you, then the idea here is that the various built-in batchers can share certain GPU buffers (for memory efficiency). VertexArrayBuffer is the class for a generic memory buffer (on the GPU) for vertex data, while VertexArrayVector<T> simplifies accessing the contents of the buffer with a specific type. For example RenderBatchTriangle has a SpriteVertex struct with vertex attributes for triangles and VertexArrayVector<SpriteVertex> allows you to access the contents of a VertexArrayBuffer seen as an array of SpriteVertex elements.

I can't remember the exact way set_angle_yaw and set_angle_pitch worked, but if they are just rotating the sprite in certain ways, then maybe the easiest way to add the feature back in is to add it to Sprite_Impl::draw. This is where the other sprite rotations and such are performed.

rombust
11-10-2014, 09:08 AM
That's my fault.

Looking at the SVN logs...

30 May 2013 "Remove rotate_pitch and rotate_yaw because they were never set" ....
26 October 2012 "Remove Sprite's angle_pitch and angle_yaw, the values were never used"

Oh dear!

The question is, should we restore them?




Revision: 9891
Author: rombust
Date: 30 May 2013 16:09:26
Message:
Since rotate_pitch and rotate_yaw doesn't even exist in clan::Sprite API, lets remove the uninitialised variables that are actually used
----
Modified : /ClanLib/Development/ClanLib-3.0/Sources/Display/2D/sprite_impl.cpp
Modified : /ClanLib/Development/ClanLib-3.0/Sources/Display/2D/sprite_impl.h





Revision: 8416
Author: rombust
Date: 26 October 2012 13:56:41
Message:
Remove Sprite's angle_pitch and angle_yaw ... Which actually did not work anyway, the values were never used!
----
Modified : /ClanLib/Development/ClanLib-2.4/Sources/API/Display/2D/sprite.h
Modified : /ClanLib/Development/ClanLib-2.4/Sources/Display/2D/sprite.cpp
Modified : /ClanLib/Development/ClanLib-2.4/Sources/Display/2D/sprite_impl.cpp
Modified : /ClanLib/Development/ClanLib-2.4/Sources/Display/2D/sprite_impl.h

Noro
11-10-2014, 10:37 AM
They were probably removed mainly because we thought nobody used them.


The question is, should we restore them?
I used them! A lot!
Please restore them.

Noro
11-10-2014, 11:00 AM
As for RenderBatcher, the main problem is in PrimitivesArray class. Previously it's set_attributes function took only a pointer to the data array(of simple data types that I filled myself with my data in simple and easy way). Now it takes VertexArrayVector and... offset?(btw there is cl_ prefix in macros cl_offsetof used there) And I don't know where to go from there. I have my vertex data filled in three arrays(positions, colors, tex_coords) by my custom draw function and when there is time to flush it to render batcher, I don't quite understand how to form a PrimitivesArray from it. Previously my code for rendering looked like this:


CL_PrimitivesArray primarray(gc);
primarray.set_attributes(0, positions);
primarray.set_attributes(1, colors);
primarray.set_attributes(2, tex1_coords);

gc.set_texture(0, current_texture);
gc.set_program_object(cl_program_single_texture);
gc.draw_primitives(cl_triangles, cur_position, primarray);
gc.reset_program_object();
gc.reset_texture(0);

cur_position = 0;
current_texture = CL_Texture();

That was simple and worked perfectly. But how do I implement it now?

rombust
11-13-2014, 08:54 AM
I used them! A lot!
Please restore them.

I have added them back into ClanLib 4.0

I have not got time to update ClanLib 3.0 stable release, and I think it would be foolish to update it anyway. ClanLib 4.0 API is very close to ClanLib 3.0 with unmaintained and obsolete parts taken out ... that as far as I know, nobody uses.

Noro
11-14-2014, 01:12 PM
I have added them back into ClanLib 4.0

I have not got time to update ClanLib 3.0 stable release, and I think it would be foolish to update it anyway. ClanLib 4.0 API is very close to ClanLib 3.0 with unmaintained and obsolete parts taken out ... that as far as I know, nobody uses.

Is there some list of these parts that were taken out?

And what about changed PrimitivesArray implementation?

Noro
11-15-2014, 12:29 AM
Please help with render batcher :cry:
It was so simple and nicely working before, and now I can't get it to work.

Noro
11-15-2014, 05:01 PM
Disregard this, I refactored previous code to use Canvas.fill_triangles() with the same result as previous implementation.
Now I have finished with porting to 3.0 and can continue development :)
Thank you anyway, and thank you for your work on ClanLib.