]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - contrib/bobtoolz/DTrainDrawer.cpp
This is a major change that updates the 3rd party libs on Windows builds.
[xonotic/netradiant.git] / contrib / bobtoolz / DTrainDrawer.cpp
index 92b2333a1a10011a9a205bbc5d632e53dda6fa46..f5796c809b66e6a1ac72fd78fd2cf1b76de1cd4f 100644 (file)
@@ -17,45 +17,35 @@ License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#include "DTrainDrawer.h"
-
-#include <list>
-#include "str.h"
-
+#include "StdAfx.h"
 #include "DPoint.h"
-#include "DPlane.h"
-#include "DBrush.h"
+
+#include "DTrainDrawer.h"
 #include "DEPair.h"
-#include "DPatch.h"
-#include "DEntity.h"
 
 #include "misc.h"
 #include "funchandlers.h"
 
-#include "iglrender.h"
-#include "ientity.h"
-#include "math/matrix.h"
-
 #include "dialogs/dialogs-gtk.h"
 
 DTrainDrawer::DTrainDrawer() {
-       m_bDisplay = false;
+       refCount = 1;
+       m_bHooked = FALSE;
+       m_bDisplay = FALSE;
 
        BuildPaths();
-  constructShaders();
-  GlobalShaderCache().attachRenderable(*this);
 }
 
 DTrainDrawer::~DTrainDrawer(void) {
-  GlobalShaderCache().detachRenderable(*this);
-  destroyShaders();
+       if(m_bHooked)
+               UnRegister();
 
        ClearPoints();
        ClearSplines();
 }
 
 void DTrainDrawer::ClearSplines() {
-       for(std::list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
+       for(list<splinePoint_t *>::const_iterator deadSpline = m_splineList.begin(); deadSpline != m_splineList.end(); deadSpline++) {
                (*deadSpline)->m_pointList.clear();
                (*deadSpline)->m_vertexList.clear();
                delete (*deadSpline);
@@ -65,13 +55,25 @@ void DTrainDrawer::ClearSplines() {
 }
 
 void DTrainDrawer::ClearPoints() {
-       for(std::list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
+       for(list<controlPoint_t *>::const_iterator deadPoint = m_pointList.begin(); deadPoint != m_pointList.end(); deadPoint++) {
                delete *deadPoint;
        }
 
        m_pointList.clear();
 }
 
+void DTrainDrawer::Register() {
+       g_QglTable.m_pfnHookGL2DWindow( this );
+       g_QglTable.m_pfnHookGL3DWindow( this );
+       m_bHooked = TRUE;
+}
+
+void DTrainDrawer::UnRegister() {
+       g_QglTable.m_pfnUnHookGL2DWindow( this );
+       g_QglTable.m_pfnUnHookGL3DWindow( this );
+       m_bHooked = FALSE;
+}
+
 void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
        vec3_t dist;
 
@@ -97,70 +99,93 @@ void CalculateSpline_r(vec3_t* v, int count, vec3_t out, float tension) {
        delete[] v2;
 }
 
-void DTrainDrawer::render(RenderStateFlags state) const
-{
-       for(std::list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+void DTrainDrawer::Draw3D() {
+
+       if(!m_bDisplay) {
+               return;
+       }
+
+       g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
+
+       g_QglTable.m_pfn_qglDisable(GL_BLEND);
+       g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);
+
+       g_QglTable.m_pfn_qglPushMatrix();
+       
+       g_QglTable.m_pfn_qglLineWidth(2.0f);
+       g_QglTable.m_pfn_qglColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+
+       g_QglTable.m_pfn_qglEnable(GL_BLEND);
+       g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
+
+       g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);
+
+       for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                splinePoint_t* pSP = (*sp);
 
-               glBegin(GL_LINE_STRIP);
-                       for(std::list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
-                               glVertex3fv((*v)._pnt);
+               g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
+                       for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
+                               g_QglTable.m_pfn_qglVertex3fv((*v)._pnt);
                        }
-               glEnd();
+               g_QglTable.m_pfn_qglEnd();
 
        }
-}
-
-const char* DTrainDrawer_state_wireframe = "$bobtoolz/traindrawer/wireframe";
-const char* DTrainDrawer_state_solid = "$bobtoolz/traindrawer/solid";
-
-void DTrainDrawer::constructShaders()
-{
-  OpenGLState state;
-  GlobalOpenGLStateLibrary().getDefaultState(state);
-  state.m_state = RENDER_COLOURWRITE|RENDER_DEPTHWRITE|RENDER_BLEND;
-  state.m_sort = OpenGLState::eSortOverlayFirst;
-  state.m_linewidth = 1;
-  state.m_colour[0] = 1;
-  state.m_colour[1] = 0;
-  state.m_colour[2] = 0;
-  state.m_colour[3] = 1;
-  state.m_linewidth = 1;
-  GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_wireframe, state);
-
-  state.m_colour[0] = 1;
-  state.m_colour[1] = 1;
-  state.m_colour[2] = 1;
-  state.m_colour[3] = 1;
-  state.m_linewidth = 2;
-  GlobalOpenGLStateLibrary().insert(DTrainDrawer_state_solid, state);
-
-  m_shader_wireframe = GlobalShaderCache().capture(DTrainDrawer_state_wireframe);
-  m_shader_solid = GlobalShaderCache().capture(DTrainDrawer_state_solid);
-}
 
-void DTrainDrawer::destroyShaders()
-{
-  GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_wireframe);
-  GlobalOpenGLStateLibrary().erase(DTrainDrawer_state_solid);
-  GlobalShaderCache().release(DTrainDrawer_state_wireframe);
-  GlobalShaderCache().release(DTrainDrawer_state_solid);
+       g_QglTable.m_pfn_qglPopMatrix();
+       g_QglTable.m_pfn_qglPopAttrib();
 }
 
+void DTrainDrawer::Draw2D(VIEWTYPE vt) {
 
-void DTrainDrawer::renderSolid(Renderer& renderer, const VolumeTest& volume) const
-{
        if(!m_bDisplay) {
                return;
        }
 
-  renderer.SetState(m_shader_wireframe, Renderer::eWireframeOnly);
-  renderer.SetState(m_shader_solid, Renderer::eFullMaterials);
-  renderer.addRenderable(*this, g_matrix4_identity);
-}
-void DTrainDrawer::renderWireframe(Renderer& renderer, const VolumeTest& volume) const
-{
-  renderSolid(renderer, volume);
+       g_QglTable.m_pfn_qglPushAttrib(GL_ALL_ATTRIB_BITS);
+
+       g_QglTable.m_pfn_qglDisable(GL_BLEND);
+       g_QglTable.m_pfn_qglDisable(GL_LINE_SMOOTH);
+
+       g_QglTable.m_pfn_qglPushMatrix();
+       
+       switch(vt)
+       {
+       case XY:
+               break;
+       case XZ:
+               g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
+               break;
+       case YZ:
+               g_QglTable.m_pfn_qglRotatef(270.0f, 1.0f, 0.0f, 0.0f);
+               g_QglTable.m_pfn_qglRotatef(270.0f, 0.0f, 0.0f, 1.0f);
+               break;
+       }
+
+       g_QglTable.m_pfn_qglLineWidth(1.0f);
+       g_QglTable.m_pfn_qglColor4f(1.0f, 0.0f, 0.0f, 0.5f);
+
+       g_QglTable.m_pfn_qglEnable(GL_BLEND);
+       g_QglTable.m_pfn_qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       g_QglTable.m_pfn_qglDisable(GL_POLYGON_SMOOTH);
+
+       g_QglTable.m_pfn_qglDepthFunc(GL_ALWAYS);
+
+       g_QglTable.m_pfn_qglColor4f(1.f, 0.f, 0.f, 1.f);
+
+       for(list<splinePoint_t* >::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+               splinePoint_t* pSP = (*sp);
+
+               g_QglTable.m_pfn_qglBegin(GL_LINE_STRIP);
+                       for(list<DPoint >::const_iterator v = pSP->m_vertexList.begin(); v != pSP->m_vertexList.end(); v++) {
+                               g_QglTable.m_pfn_qglVertex3fv((*v)._pnt);
+                       }
+               g_QglTable.m_pfn_qglEnd();
+
+       }
+
+       g_QglTable.m_pfn_qglPopMatrix();
+       g_QglTable.m_pfn_qglPopAttrib();
 }
 
 void AddSplineControl(const char* control, splinePoint_t* pSP) {
@@ -170,18 +195,15 @@ void AddSplineControl(const char* control, splinePoint_t* pSP) {
        pSP->m_pointList.push_front(cp);
 }
 
-class EntityBuildPaths
-{
-       mutable DEntity e;
-  DTrainDrawer& drawer;
-public:
-  EntityBuildPaths(DTrainDrawer& drawer) : drawer(drawer)
-  {
-  }
-  void operator()(scene::Instance& instance) const
-  {
+void DTrainDrawer::BuildPaths() {
+       int count = g_FuncTable.m_pfnGetEntityCount();
+
+       DEntity e;
+
+       for(int i = 0; i < count; i++) {
+               entity_s* ent = (entity_s*)g_FuncTable.m_pfnGetEntityHandle(i);
                e.ClearEPairs();
-               e.LoadEPairList(Node_getEntity(instance.path().top()));
+               e.LoadEPairList(*g_EntityTable.m_pfnGetEntityKeyValList(ent));
 
                const char* classname = e.m_Classname.GetBuffer();
                const char* target;
@@ -194,16 +216,16 @@ public:
 
                if(!strcmp(classname, "info_train_spline_main")) {
                        if(!targetname) {
-                               globalOutputStream() << "info_train_spline_main with no targetname";
+                               Sys_Printf( "info_train_spline_main with no targetname" );
                                return;
                        }
 
                        e.SpawnString("target", NULL, &target);
 
                        if(!target) {
-                               drawer.AddControlPoint( targetname, vOrigin );
+                               AddControlPoint( targetname, vOrigin );
                        } else {
-                               splinePoint_t* pSP = drawer.AddSplinePoint( targetname, target, vOrigin );
+                               splinePoint_t* pSP = AddSplinePoint( targetname, target, vOrigin );
 
                                e.SpawnString("control", NULL, &control);
 
@@ -218,33 +240,29 @@ public:
                                                if(!control) {
                                                        break;
                                                }
-                               
+                                       
                                                AddSplineControl( control, pSP );
                                        }
                                }
                        }
                } else if(!strcmp(classname, "info_train_spline_control")) {
                        if(!targetname) {
-                               globalOutputStream() << "info_train_spline_control with no targetname";
+                               Sys_Printf( "info_train_spline_control with no targetname" );
                                return;
                        }
 
-                       drawer.AddControlPoint( targetname, vOrigin );
+                       AddControlPoint( targetname, vOrigin );
                }
-  }
-};
-
-void DTrainDrawer::BuildPaths() {
-  Scene_forEachEntity(EntityBuildPaths(*this));
+       }
 
-  std::list<splinePoint_t* >::const_iterator sp;
+  list<splinePoint_t* >::const_iterator sp;
        for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                splinePoint_t* pSP = (*sp);
 
                controlPoint_t* pTarget = FindControlPoint( pSP->strTarget );
 
                if(!pTarget) {
-                       globalOutputStream() << "couldn't find target " << pSP->strTarget;
+                       Sys_Printf( "couldn't find target %s", pSP->strTarget );
                        return;
 //                     continue;
                }
@@ -252,10 +270,10 @@ void DTrainDrawer::BuildPaths() {
                pSP->pTarget = pTarget;
 
 
-               for(std::list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {                   
+               for(list<controlPoint_t >::iterator cp = pSP->m_pointList.begin(); cp != pSP->m_pointList.end(); cp++) {                        
                        controlPoint_t* pControl = FindControlPoint( (*cp).strName );
                        if(!pControl) {
-                               globalOutputStream() << "couldn't find control " << (*cp).strName;
+                               Sys_Printf( "couldn't find control %s", (*cp).strName );
                                return;
                        }
 
@@ -263,7 +281,8 @@ void DTrainDrawer::BuildPaths() {
                }
        }
 
-       m_bDisplay = true;
+       m_bDisplay = TRUE;
+       Register();
 
        for(sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                splinePoint_t* pSP = (*sp);
@@ -273,20 +292,20 @@ void DTrainDrawer::BuildPaths() {
                        continue;
                }
 
-    std::size_t count = pSP->m_pointList.size() + 2;
+               int count = pSP->m_pointList.size() + 2;
                vec3_t* v = new vec3_t[count];
 
                VectorCopy(pSP->point.vOrigin, v[0]);
 
                int i = 1;
-               for(std::list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
+               for(list<controlPoint_t>::reverse_iterator cp = pSP->m_pointList.rbegin(); cp != pSP->m_pointList.rend(); cp++) {
                        VectorCopy((*cp).vOrigin, v[i]);
                        i++;
                }
                VectorCopy(pSP->pTarget->vOrigin, v[i]);
 
                for (float tension = 0.0f; tension <= 1.f; tension += 0.01f) {
-                       CalculateSpline_r(v, static_cast<int>(count), out._pnt, tension);
+                       CalculateSpline_r(v, count, out._pnt, tension);
                        pSP->m_vertexList.push_front(out);
                }
 
@@ -296,7 +315,7 @@ void DTrainDrawer::BuildPaths() {
                pSP->m_vertexList.push_front(out);
        }
 
-  SceneChangeNotify();
+
 }
 
 void DTrainDrawer::AddControlPoint(const char* name, vec_t* origin)
@@ -323,13 +342,13 @@ splinePoint_t* DTrainDrawer::AddSplinePoint(const char* name, const char* target
 
 controlPoint_t* DTrainDrawer::FindControlPoint(const char* name)
 {
-       for(std::list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
+       for(list<controlPoint_t*>::const_iterator cp = m_pointList.begin(); cp != m_pointList.end(); cp++) {
                if(!strcmp(name, (*cp)->strName)) {
                        return (*cp);
                }
        }
 
-       for(std::list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
+       for(list<splinePoint_t*>::const_iterator sp = m_splineList.begin(); sp != m_splineList.end(); sp++) {
                if(!strcmp(name, (*sp)->point.strName)) {
                        return &((*sp)->point);
                }