Browse Source

Implement broken apiclip_of_x

rdb 11 years ago
parent
commit
5d1e507aef
1 changed files with 22 additions and 5 deletions
  1. 22 5
      panda/src/display/graphicsStateGuardian.cxx

+ 22 - 5
panda/src/display/graphicsStateGuardian.cxx

@@ -1269,15 +1269,32 @@ fetch_specified_part(Shader::ShaderMatInput part, InternalName *name, LMatrix4 &
     return &t;
     return &t;
   }
   }
   case Shader::SMO_apiclip_x_to_view: {
   case Shader::SMO_apiclip_x_to_view: {
-    // NOT IMPLEMENTED
-    return &LMatrix4::ident_mat();
+    // LIMITATION: only takes the first lens.
+    const NodePath &np = _target_shader->get_shader_input_nodepath(name);
+    nassertr(!np.is_empty(), &LMatrix4::ident_mat());
+    LensNode *ln;
+    DCAST_INTO_R(ln, np.node(), &LMatrix4::ident_mat());
+    Lens *lens = ln->get_lens();
+    nassertr(lens != (Lens *)NULL, &LMatrix4::ident_mat());
+    CPT(TransformState) ts = calc_projection_mat(lens);
+    t = ts->get_inverse()->get_mat() * _inv_cs_transform->get_mat();
+    return &t;
   }
   }
   case Shader::SMO_view_to_apiclip_x: {
   case Shader::SMO_view_to_apiclip_x: {
-    // NOT IMPLEMENTED
-    return &LMatrix4::ident_mat();
+    // LIMITATION: only takes the first lens.
+    const NodePath &np = _target_shader->get_shader_input_nodepath(name);
+    nassertr(!np.is_empty(), &LMatrix4::ident_mat());
+    LensNode *ln;
+    DCAST_INTO_R(ln, np.node(), &LMatrix4::ident_mat());
+    Lens *lens = ln->get_lens();
+    nassertr(lens != (Lens *)NULL, &LMatrix4::ident_mat());
+    CPT(TransformState) ts = calc_projection_mat(lens);
+    nassertr(ts != NULL, &LMatrix4::ident_mat());
+    t = _cs_transform->get_mat() * ts->get_mat();
+    return &t;
   }
   }
   default:
   default:
-    // should never get here
+    nassertr(false /*should never get here*/, &LMatrix4::ident_mat());
     return &LMatrix4::ident_mat();
     return &LMatrix4::ident_mat();
   }
   }
 }
 }