2
0
Эх сурвалжийг харах

use point_sprite extension

David Rose 20 жил өмнө
parent
commit
a1f1b33241

+ 31 - 21
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -401,7 +401,14 @@ reset() {
     _glPointParameterfv = null_glPointParameterfv;
   }
 
-  _supports_point_sprite = false;
+  _supports_point_sprite = has_extension("GL_ARB_point_sprite");
+  if (_supports_point_sprite) {
+    // It appears that the point_sprite extension doesn't support
+    // texture transforms on the generated texture coordinates.  How
+    // inconsistent.  Because of this, we don't advertise
+    // GR_point_sprite_tex_matrix.
+    _supported_geom_rendering |= qpGeom::GR_point_sprite;
+  }
 
   _supports_vertex_blend = has_extension("GL_ARB_vertex_blend");
 
@@ -781,7 +788,8 @@ reset() {
   _polygon_offset_enabled = false;
   _flat_shade_model = false;
   _decal_level = 0;
-
+  _tex_gen_point_sprite = false;
+  
   // Dither is on by default in GL; let's turn it off
   GLP(Disable)(GL_DITHER);
   _dithering_enabled = false;
@@ -5894,18 +5902,23 @@ finish_modify_state() {
     static const float q_data[4] = { 0, 0, 0, 1 };
 
     _tex_gen_modifies_mat = false;
+
+    bool got_point_sprites = false;
     
     for (int i = 0; i < num_stages; i++) {
       TextureStage *stage = _current_texture->get_on_stage(i);
       _glActiveTexture(GL_TEXTURE0 + i);
+      GLP(Disable)(GL_TEXTURE_GEN_S);
+      GLP(Disable)(GL_TEXTURE_GEN_T);
+      GLP(Disable)(GL_TEXTURE_GEN_R);
+      GLP(Disable)(GL_TEXTURE_GEN_Q);
+      if (_supports_point_sprite) {
+        GLP(TexEnvi)(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, FALSE);
+      }
 
       TexGenAttrib::Mode mode = _current_tex_gen->get_mode(stage);
       switch (mode) {
       case TexGenAttrib::M_off:
-        GLP(Disable)(GL_TEXTURE_GEN_S);
-        GLP(Disable)(GL_TEXTURE_GEN_T);
-        GLP(Disable)(GL_TEXTURE_GEN_R);
-        GLP(Disable)(GL_TEXTURE_GEN_Q);
         break;
         
       case TexGenAttrib::M_eye_sphere_map:
@@ -5913,8 +5926,6 @@ finish_modify_state() {
         GLP(TexGeni)(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
         GLP(Enable)(GL_TEXTURE_GEN_S);
         GLP(Enable)(GL_TEXTURE_GEN_T);
-        GLP(Disable)(GL_TEXTURE_GEN_R);
-        GLP(Disable)(GL_TEXTURE_GEN_Q);
         force_normal = true;
         break;
         
@@ -5946,13 +5957,7 @@ finish_modify_state() {
           GLP(Enable)(GL_TEXTURE_GEN_S);
           GLP(Enable)(GL_TEXTURE_GEN_T);
           GLP(Enable)(GL_TEXTURE_GEN_R);
-          GLP(Disable)(GL_TEXTURE_GEN_Q);
           force_normal = true;
-        } else {
-          GLP(Disable)(GL_TEXTURE_GEN_S);
-          GLP(Disable)(GL_TEXTURE_GEN_T);
-          GLP(Disable)(GL_TEXTURE_GEN_R);
-          GLP(Disable)(GL_TEXTURE_GEN_Q);
         }
         break;
         
@@ -5984,13 +5989,7 @@ finish_modify_state() {
           GLP(Enable)(GL_TEXTURE_GEN_S);
           GLP(Enable)(GL_TEXTURE_GEN_T);
           GLP(Enable)(GL_TEXTURE_GEN_R);
-          GLP(Disable)(GL_TEXTURE_GEN_Q);
           force_normal = true;
-        } else {
-          GLP(Disable)(GL_TEXTURE_GEN_S);
-          GLP(Disable)(GL_TEXTURE_GEN_T);
-          GLP(Disable)(GL_TEXTURE_GEN_R);
-          GLP(Disable)(GL_TEXTURE_GEN_Q);
         }
         break;
 
@@ -6067,11 +6066,22 @@ finish_modify_state() {
         break;
 
       case TexGenAttrib::M_point_sprite:
-        // TODO.
+        nassertv(_supports_point_sprite);
+        GLP(TexEnvi)(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, TRUE);
+        got_point_sprites = true;
         break;
       }
     }
 
+    if (got_point_sprites != _tex_gen_point_sprite) {
+      _tex_gen_point_sprite = got_point_sprites;
+      if (_tex_gen_point_sprite) {
+        GLP(Enable)(GL_POINT_SPRITE_ARB);
+      } else {
+        GLP(Disable)(GL_POINT_SPRITE_ARB);
+      }
+    }
+
     // Certain texgen modes (sphere_map, cube_map) require forcing the
     // normal to be sent to the GL while the texgen mode is in effect.
     if (force_normal != _texgen_forced_normal) {

+ 1 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -318,6 +318,7 @@ protected:
   CPT(TexGenAttrib) _current_tex_gen;
   bool _needs_tex_gen;
   bool _tex_gen_modifies_mat;
+  bool _tex_gen_point_sprite;
   bool _auto_antialias_mode;
   RenderModeAttrib::Mode _render_mode;
   float _point_size;