Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Thu Apr 18, 2024 8:24 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Aug 15, 2008 10:36 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
This commit looks quiet dangerous to me, since the users may think that it's really freeing memory, and may call this function many times ... until Raydium cannot create new handles !

Texture freeing, as well as mesh freeing, requires to dig a bit in Raydium's core. The texture handle allocation need to be changed, for instance.

IMHO, this commit should be canceled until we've a reliable freeing system.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 16, 2008 12:26 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Better than remove it, I'll try to change the allocation of textures tomorrow.
First idea is a raydium_texture_used[] variable to allow a simple loop to know if an "slot" is really free or not.
At least in my mind, it should not be too much hard to do.
By the way, I commited those functions to save a bit of memory in a certain machine (intel graphics card with 32 MB or less) and the game boosted from 4-5 fps to 20fps (I freed 4 big textures). So the freeing is working ;)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 16, 2008 9:59 am 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Sure, at OpenGL "level", I'm sure this function works perfectly ;)

For creating use/unused slot at Raydium level, it sounds OK for me.

The best way to change texture allocation system is to remove "raydium_texture_index", and change all uses of this variable with the new allocation (as it's done for most other entities, like ODE elements, objects, ...).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 10:52 am 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
There are a lot of files involved and the change won't be as easy as I though.
I can see a few har coding of textures here and there.

Can I create a temporal "experimental" branch to go step by step with this?
It's easy to do and to undo, I've already have done it with my own projects.

update:
Looks like the experimental branch won't be needed. The change worked fine at once!!! I have tested with raydium_modler, test8, test6, shader and mania_drive and all textures are working fine.
I have to do a few minor improvements and I'll upload the code soon.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 12:52 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Done.
Also there is a new function raydium_texture_is_slot_used() to check if a certain texture id is used.
And each texture tell us the memory used by it, and the ending output of our application shows the estimated memory used.

And here I post the modified source code of the shdaer_test application to allow:
    key 'l' (L) to load the wall texture
    key 'u' to unload the wall texture

It's curious to see how we can change textures "almost" on the fly. This could be a first step to get progressive-streamed textures.
Just that.

Code:
/*
    Raydium - CQFD Corp.
    http://raydium.org/
    Released under both BSD license and Lesser GPL library license.
    See "license.txt" file.
*/

#include "raydium/index.c"

dReal *lpos;

void display(void)
{
raydium_joy_key_emul();

lpos=raydium_ode_element_pos_get_name("light");
raydium_light_move_3f(0,lpos[0],lpos[1],lpos[2]);

if(raydium_key_last==1027)
    exit(0);

if(raydium_key[GLUT_KEY_F1]) { raydium_projection_fov/=(1.04); raydium_window_view_update(); }
if(raydium_key[GLUT_KEY_F2]) { raydium_projection_fov*=(1.04); raydium_window_view_update(); }
if(raydium_key_last==1000+'l')raydium_texture_load("wallColorMap.tga");
if(raydium_key_last==1000+'u')raydium_texture_free_name("wallColorMap.tga");
raydium_clear_frame();
raydium_camera_freemove(RAYDIUM_CAMERA_FREEMOVE_NORMAL);
raydium_ode_draw_all(0);
raydium_rendering_finish();
}


int main(int argc, char **argv)
{
int obj;

raydium_init_args(argc,argv);
raydium_window_create(640,480,RAYDIUM_RENDERING_WINDOW,"Small shader test");

raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
raydium_window_view_perspective(60,0.01,2500); // fov 60 + near and far planes

raydium_fog_disable();   
raydium_light_enable();
raydium_light_on(0);

raydium_light_conf_7f(0,0,0,0,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB)
raydium_background_color_change(1,0.9,0.7,1);

raydium_sky_box_cache();

raydium_camera_freemove_speed=0.01;

raydium_ode_ground_set_name("crate_parabump.tri");
obj=raydium_ode_object_find("GLOBAL");

raydium_ode_object_box_add("coch",obj,1,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_STANDARD,0,"coch2.tri");
raydium_ode_element_move_name_3f("coch",0,0.2,-0.1);

raydium_ode_object_box_add("head",obj,1,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_STANDARD,0,"derhead.tri");
raydium_ode_element_move_name_3f("head",0.3,-0.2,-0.25);
raydium_object_tangent_smooth_name("derhead.tri");

raydium_ode_object_box_add("headsmooth",obj,1,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_STANDARD,0,"derhead_smooth.tri");
raydium_ode_element_move_name_3f("headsmooth",0,-0.2,-0.25);

raydium_ode_object_box_add("headflat",obj,1,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_STANDARD,0,"derhead_flat.tri");
raydium_ode_element_move_name_3f("headflat",-0.3,-0.2,-0.25);

raydium_ode_object_sphere_add("light",obj,0.01,RAYDIUM_ODE_AUTODETECT,RAYDIUM_ODE_STANDARD,0,"ballon.tri");
raydium_ode_element_move_name_3f("light",0,0,0.25);
raydium_ode_joint_attach_universal("chand",RAYDIUM_ODE_JOINT_FIXED,raydium_ode_element_find("light"),0,0,0.5, 1,0,0, 0,1,0);
raydium_ode_element_addforce_name_3f("light",10,1,0);

raydium_shader_load("shader1","toon.vert","toon.frag");
raydium_shader_var_f_name("shader1","Edge",0.64);
raydium_shader_var_f_name("shader1","Phong",0.954);
raydium_shader_var_3f_name("shader1","DiffuseColor",0.35,0,0.25);
raydium_shader_var_3f_name("shader1","PhongColor",0.94,0.7,0.85);

raydium_shader_load("shader2","bump.vert","bump.frag");
raydium_shader_var_i_name("shader2","normalMap",0);
raydium_shader_var_i_name("shader2","colorMap",1);
raydium_shader_var_4f_name("shader2","specular",0.1,0.1,0.1,1);
raydium_shader_var_f_name("shader2","shininess",30);

raydium_shader_load("shader3","parabump.vert","parabump.frag");
raydium_shader_var_i_name("shader3","Normal",0);
raydium_shader_var_i_name("shader3","Base_Height",1);
raydium_shader_var_f_name("shader3","u_invRad",0.03);
raydium_shader_var_2f_name("shader3","cBumpSize",0.042,-0.050);
raydium_shader_var_i_name("shader3","base_tex",2);

raydium_shader_attach_texture_name("shader1","rgb(0.94,0.7,0.85)");
raydium_shader_attach_texture_name("shader2","crate_nmap.tga");
raydium_shader_attach_texture_name("shader2","derhead_normal.tga");
raydium_shader_attach_texture_name("shader3","wallNormalMap.tga");

raydium_shadow_enable();

raydium_callback(&display);
return 0;
}
// EOF


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 1:00 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Great job, all this seems quiet good !
There's still some uses of "raydium_texture_index", you should remove all this (raydium_modler use it too, but I can change this quickly), and the variable itself, in facts.

Also, try to avoid using to much comments for "old code", it tends to make code searches a bit wired. And SVN allows us to rewind the history of the code in a much cleaner way ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 18, 2008 6:54 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Thanks

Ok, I'll remove ASAP the commented old code with raydium_texture_index and the variable.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 48 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group