diff --git a/include/igl.h b/include/igl.h index e6dc2c11..0f1f705c 100644 --- a/include/igl.h +++ b/include/igl.h @@ -2657,7 +2657,7 @@ struct OpenGLBinding void ( QGL_DLLEXPORT *m_glGetBufferSubData )( GLenum target, GLintptr offset, GLsizeiptr size, GLvoid* data ); void ( QGL_DLLEXPORT *m_glGetQueryObjectiv )( GLuint id, GLenum pname, GLint* params ); void ( QGL_DLLEXPORT *m_glGetQueryObjectuiv )( GLuint id, GLenum pname, GLuint* params ); - void ( QGL_DLLEXPORT *m_glGetQueryiv )( GLenum target, GLenum pname, GLint params ); + void ( QGL_DLLEXPORT *m_glGetQueryiv )( GLenum target, GLenum pname, GLint* params ); GLboolean ( QGL_DLLEXPORT *m_glIsBuffer )( GLuint buffer ); GLboolean ( QGL_DLLEXPORT *m_glIsQuery )( GLuint id ); GLvoid* ( QGL_DLLEXPORT * m_glMapBuffer )( GLenum target, GLenum access ); diff --git a/include/iglrender.h b/include/iglrender.h index 23477199..53e030b5 100644 --- a/include/iglrender.h +++ b/include/iglrender.h @@ -66,7 +66,7 @@ enum ESort eSortOverlayFirst = 1028, eSortOverlayLast = 2047, eSortText = 2048, - eSortControlFirst = 2049, + eSortControlFirst = 2050, eSortControlLast = 3071, eSortGUI0 = 3072, eSortGUI1 = 3073, diff --git a/libs/render.h b/libs/render.h index 2c191170..335c7c1c 100644 --- a/libs/render.h +++ b/libs/render.h @@ -287,6 +287,7 @@ struct Colour4b }; const Colour4b colour_vertex( 0, 255, 0, 255 ); +const Colour4b colour_occluded( 74, 150, 75, 255 ); const Colour4b colour_selected( 0, 0, 255, 255 ); inline bool operator<( const Colour4b& self, const Colour4b& other ){ @@ -768,6 +769,26 @@ inline bool operator!=( const PointVertex& self, const PointVertex& other ){ return !operator==( self, other ); } +struct DepthTestedPointVertex +{ + Colour4b colour; + Vertex3f vertex; + GLuint query = 0; + + DepthTestedPointVertex(){ + } + ~DepthTestedPointVertex(){ + if( query != 0 ) + glDeleteQueries( 1, &query ); + } + DepthTestedPointVertex( Vertex3f _vertex ) + : colour( Colour4b( 255, 255, 255, 255 ) ), vertex( _vertex ){ + } + DepthTestedPointVertex( Vertex3f _vertex, Colour4b _colour ) + : colour( _colour ), vertex( _vertex ){ + } +}; + /// \brief Standard vertex type for lit/textured meshes. struct ArbitraryMeshVertex { @@ -821,21 +842,23 @@ inline ArbitraryMeshVertex arbitrarymeshvertex_quantised( const ArbitraryMeshVer /// \brief Sets up the OpenGL colour and vertex arrays for \p array. -inline void pointvertex_gl_array( const PointVertex* array ){ - glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( PointVertex ), &array->colour ); - glVertexPointer( 3, GL_FLOAT, sizeof( PointVertex ), &array->vertex ); +template +inline void pointvertex_gl_array( const PointVertex_t* array ){ + glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( PointVertex_t ), &array->colour ); + glVertexPointer( 3, GL_FLOAT, sizeof( PointVertex_t ), &array->vertex ); } +template class RenderablePointArray : public OpenGLRenderable { -const Array& m_array; +const Array& m_array; const GLenum m_mode; public: -RenderablePointArray( const Array& array, GLenum mode ) +RenderablePointArray( const Array& array, GLenum mode ) : m_array( array ), m_mode( mode ){ } void render( RenderStateFlags state ) const { -#define NV_DRIVER_BUG 1 +#define NV_DRIVER_BUG 0 #if NV_DRIVER_BUG glColorPointer( 4, GL_UNSIGNED_BYTE, 0, 0 ); glVertexPointer( 3, GL_FLOAT, 0, 0 ); @@ -928,6 +951,42 @@ void render( RenderStateFlags state ) const { } }; +class RenderableDepthTestedPointArray : public OpenGLRenderable +{ +Array& m_array; +const GLenum m_mode; +public: +RenderableDepthTestedPointArray( Array& array, GLenum mode ) + : m_array( array ), m_mode( mode ){ +} +void render( RenderStateFlags state ) const { + if( state & RENDER_COLOURWRITE ){ // render depending on visibility + for( auto& p : m_array ){ + GLuint sampleCount; + glGetQueryObjectuiv( p.query, GL_QUERY_RESULT, &sampleCount ); + if ( sampleCount == 0 ){ + p.colour = colour_occluded; + } + else{ + p.colour = colour_vertex; + } + } + pointvertex_gl_array( m_array.data() ); + glDrawArrays( m_mode, 0, GLsizei( m_array.size() ) ); + } + else{ // test visibility + for( auto& p : m_array ){ + if( p.query == 0 ) + glGenQueries( 1, &p.query ); + glBeginQuery( GL_SAMPLES_PASSED, p.query ); + glVertexPointer( 3, GL_FLOAT, 0, &p.vertex ); + glDrawArrays( m_mode, 0, 1 ); + glEndQuery( GL_SAMPLES_PASSED ); + } + } +} +}; + class RemapXYZ { diff --git a/radiant/brush.cpp b/radiant/brush.cpp index 820703f3..018b4071 100644 --- a/radiant/brush.cpp +++ b/radiant/brush.cpp @@ -41,6 +41,7 @@ bool g_brush_textureVertexlock_enabled = false; EBrushType Brush::m_type; double Brush::m_maxWorldCoord = 0; Shader* Brush::m_state_point; +Shader* Brush::m_state_deeppoint; Shader* BrushClipPlane::m_state = 0; Shader* BrushInstance::m_state_selpoint; Counter* BrushInstance::m_counter = 0; @@ -256,7 +257,7 @@ void Brush::buildBRep(){ FaceVertexId faceVertex = faceVertices[ProximalVertexArray_index( vertexRings, uniqueVertices[i] )]; const Winding& winding = m_faces[faceVertex.getFace()]->getWinding(); - m_uniqueVertexPoints[i] = pointvertex_for_windingpoint( winding[faceVertex.getVertex()].vertex, colour_vertex ); + m_uniqueVertexPoints[i] = depthtested_pointvertex_for_windingpoint( winding[faceVertex.getVertex()].vertex, colour_vertex ); } } } diff --git a/radiant/brush.h b/radiant/brush.h index 3becf4cf..744df64b 100644 --- a/radiant/brush.h +++ b/radiant/brush.h @@ -257,6 +257,13 @@ inline PointVertex pointvertex_for_windingpoint( const Vector3& point, const Col ); } +inline DepthTestedPointVertex depthtested_pointvertex_for_windingpoint( const Vector3& point, const Colour4b& colour ){ + return DepthTestedPointVertex( + vertex3f_for_vector3( point ), + colour + ); +} + inline bool check_plane_is_integer( const PlanePoints& planePoints ){ return !float_is_integer( planePoints[0][0] ) || !float_is_integer( planePoints[0][1] ) @@ -1409,8 +1416,7 @@ class RenderableWireframe : public OpenGLRenderable public: void render( RenderStateFlags state ) const { #if 1 - glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof( PointVertex ), &m_vertices->colour ); - glVertexPointer( 3, GL_FLOAT, sizeof( PointVertex ), &m_vertices->vertex ); + glVertexPointer( 3, GL_FLOAT, sizeof( DepthTestedPointVertex ), &m_vertices->vertex ); glDrawElements( GL_LINES, GLsizei( m_size << 1 ), RenderIndexTypeID, m_faceVertex.data() ); #else glBegin( GL_LINES ); @@ -1425,7 +1431,7 @@ void render( RenderStateFlags state ) const { Array m_faceVertex; std::size_t m_size; -const PointVertex* m_vertices; +const DepthTestedPointVertex* m_vertices; }; class Brush; @@ -1592,17 +1598,18 @@ Faces m_faces; // cached data compiled from state Array m_faceCentroidPoints; -RenderablePointArray m_render_faces; +RenderablePointArray m_render_faces; -Array m_uniqueVertexPoints; +mutable Array m_uniqueVertexPoints; typedef std::vector SelectableVertices; SelectableVertices m_select_vertices; -RenderablePointArray m_render_vertices; +RenderablePointArray m_render_vertices; +RenderableDepthTestedPointArray m_render_deepvertices; Array m_uniqueEdgePoints; typedef std::vector SelectableEdges; SelectableEdges m_select_edges; -RenderablePointArray m_render_edges; +RenderablePointArray m_render_edges; Array m_edge_indices; Array m_edge_faces; @@ -1625,6 +1632,7 @@ Callback m_lightsChanged; // static data static Shader* m_state_point; +static Shader* m_state_deeppoint; // ---- static EBrushType m_type; @@ -1636,6 +1644,7 @@ Brush( scene::Node& node, const Callback& evaluateTransform, const Callback& bou m_map( 0 ), m_render_faces( m_faceCentroidPoints, GL_POINTS ), m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_deepvertices( m_uniqueVertexPoints, GL_POINTS ), m_render_edges( m_uniqueEdgePoints, GL_POINTS ), m_evaluateTransform( evaluateTransform ), m_boundsChanged( boundsChanged ), @@ -1649,6 +1658,7 @@ Brush( const Brush& other, scene::Node& node, const Callback& evaluateTransform, m_map( 0 ), m_render_faces( m_faceCentroidPoints, GL_POINTS ), m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_deepvertices( m_uniqueVertexPoints, GL_POINTS ), m_render_edges( m_uniqueEdgePoints, GL_POINTS ), m_evaluateTransform( evaluateTransform ), m_boundsChanged( boundsChanged ), @@ -1671,6 +1681,7 @@ Brush( const Brush& other ) : m_map( 0 ), m_render_faces( m_faceCentroidPoints, GL_POINTS ), m_render_vertices( m_uniqueVertexPoints, GL_POINTS ), + m_render_deepvertices( m_uniqueVertexPoints, GL_POINTS ), m_render_edges( m_uniqueEdgePoints, GL_POINTS ), m_planeChanged( false ), m_transformChanged( false ){ @@ -1837,7 +1848,22 @@ void renderComponents( SelectionSystem::EComponentMode mode, Renderer& renderer, switch ( mode ) { case SelectionSystem::eVertex: - renderer.addRenderable( m_render_vertices, localToWorld ); + { + if( GlobalOpenGL().GL_1_5() ){ + if( volume.fill() ){ + renderer.SetState( m_state_deeppoint, Renderer::eFullMaterials ); + renderer.addRenderable( m_render_deepvertices, localToWorld ); + } + else{ + for( auto& p : m_uniqueVertexPoints ) + p.colour = colour_vertex; + renderer.addRenderable( m_render_vertices, localToWorld ); + } + } + else{ + renderer.addRenderable( m_render_vertices, localToWorld ); + } + } break; case SelectionSystem::eEdge: renderer.addRenderable( m_render_edges, localToWorld ); @@ -2004,9 +2030,11 @@ static void constructStatic( EBrushType type ){ g_bp_globals.m_texdefTypeId = BrushType_getTexdefType( type ); m_state_point = GlobalShaderCache().capture( "$POINT" ); + m_state_deeppoint = GlobalShaderCache().capture( "$DEEPPOINT" ); } static void destroyStatic(){ GlobalShaderCache().release( "$POINT" ); + GlobalShaderCache().release( "$DEEPPOINT" ); } std::size_t DEBUG_size(){ @@ -2798,7 +2826,6 @@ public: RenderablePointVectorPushBack( RenderablePointVector& points ) : m_points( points ){ } void operator()( const Vector3& point ) const { - const Colour4b colour_selected( 0, 0, 255, 255 ); m_points.push_back( pointvertex_for_windingpoint( point, colour_selected ) ); } }; @@ -3342,7 +3369,7 @@ mutable RenderableWireframe m_render_wireframe; mutable RenderablePointVector m_render_selected; mutable AABB m_aabb_component; mutable Array m_faceCentroidPointsCulled; -RenderablePointArray m_render_faces_wireframe; +RenderablePointArray m_render_faces_wireframe; mutable bool m_viewChanged; // requires re-evaluation of view-dependent cached data BrushClipPlane m_clipPlane; diff --git a/radiant/renderstate.cpp b/radiant/renderstate.cpp index de7a3f20..6a69d65c 100644 --- a/radiant/renderstate.cpp +++ b/radiant/renderstate.cpp @@ -2195,7 +2195,18 @@ void OpenGLShader::construct( const char* name ){ else if ( string_equal( name + 1, "POINT" ) ) { state.m_state = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_DEPTHWRITE; state.m_sort = OpenGLState::eSortControlFirst; - state.m_pointsize = 4; + state.m_pointsize = 6; + } + else if ( string_equal( name + 1, "DEEPPOINT" ) ) { + state.m_state = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_DEPTHWRITE; + state.m_sort = OpenGLState::eSortControlFirst; + state.m_pointsize = 6; + + OpenGLState& hiddenLine = appendDefaultPass(); // glBeginQuery glEndQuery + hiddenLine.m_state = RENDER_DEPTHTEST; + hiddenLine.m_sort = OpenGLState::eSortControlFirst - 1; + hiddenLine.m_pointsize = 6; + hiddenLine.m_depthfunc = GL_LEQUAL; } else if ( string_equal( name + 1, "SELPOINT" ) ) { state.m_state = RENDER_COLOURARRAY | RENDER_COLOURWRITE | RENDER_DEPTHWRITE;