31 #include <libFreeWRL.h>
33 #include "../vrml_parser/Structs.h"
34 #include "../main/headers.h"
36 #include "../x3d_parser/Bindable.h"
38 #include "../opengl/OpenGL_Utils.h"
39 #include "../scenegraph/RenderFuncs.h"
67 int layerId, saveActive, binding_stack_set;
70 void *Component_Layering_constructor(){
75 void Component_Layering_init(
struct tComponent_Layering *t){
78 t->prv = Component_Layering_constructor();
81 p->layersetnode = NULL;
84 p->binding_stack_set = 0;
87 void Component_Layering_clear(
struct tComponent_Text *t){
96 void getPickrayXY(
int *x,
int *y);
98 ivec4 childViewport(
ivec4 parentViewport,
float *clipBoundary){
100 vport.W = (int)((clipBoundary[1] - clipBoundary[0]) *parentViewport.W);
101 vport.X = (int)(parentViewport.X + (clipBoundary[0] * parentViewport.W));
102 vport.H = (int)((clipBoundary[3] - clipBoundary[2]) *parentViewport.H);
103 vport.Y = (int)(parentViewport.Y + (clipBoundary[2] * parentViewport.H));
106 void prep_Viewport(
struct X3D_Node * node);
107 void fin_Viewport(
struct X3D_Node * node);
108 static float defaultClipBoundary [] = {0.0f, 1.0f, 0.0f, 1.0f};
112 void prep_Layer(
struct X3D_Node * _node){
122 if(!rs->render_vp && !rs->render_collision){
124 if(node->viewport) prep_Viewport(node->viewport);
128 void child_Layer(
struct X3D_Node * _node){
138 if(!rs->render_vp && !rs->render_collision){
141 vportstack = (
Stack *)tg->Mainloop._vportstack;
142 ivpvis = currentviewportvisible(vportstack);
144 setcurrentviewport(vportstack);
147 if (rs->render_geom == VF_Geom)
148 glClear(GL_DEPTH_BUFFER_BIT);
149 prep_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
150 normalChildren(node->children);
151 fin_sibAffectors((
struct X3D_Node*)node,&node->__sibAffectors);
154 void fin_Layer(
struct X3D_Node * _node){
160 if(!rs->render_vp && !rs->render_collision){
161 if(node->viewport) fin_Viewport(node->viewport);
185 void push_binding_stack_set(
struct X3D_Node* layersetnode){
189 p->binding_stack_set++;
190 p->saveActive = tg->Bindable.activeLayer;
192 p->layersetnode = layersetnode;
194 void push_next_layerId_from_binding_stack_set(
struct X3D_Node *layer){
200 if(p->binding_stack_set > 0){
202 bstack = getBindableStacksByLayer(tg, p->layerId );
205 init_bindablestack(bstack, p->layerId, layer->_nodeType);
206 addBindableStack(tg,bstack);
209 tg->Bindable.activeLayer = p->layerId;
213 void pop_binding_stack_set(){
217 p->binding_stack_set--;
218 tg->Bindable.activeLayer = p->saveActive;
220 void post_parse_set_activeLayer(){
224 if(p->layersetnode && p->layersetnode->_nodeType == NODE_LayerSet){
226 tg->Bindable.activeLayer = ls->activeLayer;
232 void prep_LayoutLayer(
struct X3D_Node * _node);
233 void child_LayoutLayer(
struct X3D_Node * _node);
234 void fin_LayoutLayer(
struct X3D_Node * _node);
236 void setup_viewpoint_part1();
237 void setup_viewpoint_part3();
238 void set_viewmatrix();
239 void setup_projection();
240 void setup_projection_tinkering();
244 void setup_pickray0();
245 void child_LayerSet(
struct X3D_Node * node){
254 if(node && node->_nodeType == NODE_LayerSet){
268 for(i=0;i<layerset->order.n;i++){
270 int i0, saveActive, isActive;
278 if(rs->render_sensitive == VF_Sensitive){
279 ii = layerset->order.n - ii -1;
282 layerId = layerset->order.p[ii];
283 isActive = layerId == tg->Bindable.activeLayer;
284 i0 = max(0,layerId -1);
285 layer = (
struct X3D_Layer*)layerset->layers.p[i0];
287 if(rs->render_sensitive == VF_Sensitive){
288 if(!layer->isPickable)
continue;
290 if(rs->render_collision == VF_Collision && !isActive)
295 bstack = getBindableStacksByLayer(tg, layerId );
298 init_bindablestack(bstack, layerId, layer->_nodeType);
299 addBindableStack(tg,bstack);
301 saveActive = tg->Bindable.activeLayer;
305 tg->Bindable.activeLayer = layerId;
313 FW_GL_MATRIX_MODE(GL_PROJECTION);
315 FW_GL_MATRIX_MODE(GL_MODELVIEW);
317 if(rs->render_vp == VF_Viewpoint){
318 setup_viewpoint_part1();
323 if(!rs->render_vp && !rs->render_collision )
325 if(rs->render_sensitive == VF_Sensitive){
327 if(!isActive) upd_ray();
332 if(layer->_nodeType == NODE_Layer){
333 prep_Layer((
struct X3D_Node*)layer);
334 child_Layer((
struct X3D_Node*)layer);
337 else if(layer->_nodeType == NODE_LayoutLayer){
338 prep_LayoutLayer((
struct X3D_Node*)layer);
339 child_LayoutLayer((
struct X3D_Node*)layer);
340 fin_LayoutLayer((
struct X3D_Node*)layer);
343 if(rs->render_sensitive == VF_Sensitive){
344 rayhit = getRayHit();
351 if(rs->render_vp == VF_Viewpoint){
352 setup_viewpoint_part3();
354 FW_GL_MATRIX_MODE(GL_PROJECTION);
356 FW_GL_MATRIX_MODE(GL_MODELVIEW);
361 tg->Bindable.activeLayer = saveActive;
365 tg->Bindable.activeLayer = layerset->activeLayer;
380 void prep_Viewport(
struct X3D_Node * node){
381 if(node && node->_nodeType == NODE_Viewport){
394 if(!rs->render_vp && !rs->render_collision){
397 vportstack = (
Stack *)tg->Mainloop._vportstack;
398 pvport = stack_top(
ivec4,vportstack);
399 clipBoundary = defaultClipBoundary;
400 if(viewport->clipBoundary.p && viewport->clipBoundary.n > 3)
401 clipBoundary = viewport->clipBoundary.p;
403 vport = childViewport(pvport,clipBoundary);
404 if(rs->render_sensitive){
405 int mouseX, mouseY, inside;
407 getPickrayXY(&mouseX, &mouseY);
410 inside = pointinsideviewport(vport,pt);
416 pushviewport(vportstack, vport);
417 if(currentviewportvisible(vportstack)){
418 setcurrentviewport(vportstack);
426 void child_Viewport(
struct X3D_Node * node){
427 if(node && node->_nodeType == NODE_Viewport){
434 vportstack = (
Stack *)tg->Mainloop._vportstack;
436 if(currentviewportvisible(vportstack)){
437 prep_sibAffectors((
struct X3D_Node*)node,&viewport->__sibAffectors);
438 normalChildren(viewport->children);
439 fin_sibAffectors((
struct X3D_Node*)node,&viewport->__sibAffectors);
443 void fin_Viewport(
struct X3D_Node * node){
444 if(node && node->_nodeType == NODE_Viewport){
457 if(!rs->render_vp && !rs->render_collision){
459 vportstack = (
Stack *)tg->Mainloop._vportstack;
462 popviewport(vportstack);
463 setcurrentviewport(vportstack);