Skip to content

Commit

Permalink
#5584: Remove GL code from entitylib.h
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 25, 2022
1 parent 8601fa7 commit 28b3cd9
Showing 1 changed file with 0 additions and 206 deletions.
206 changes: 0 additions & 206 deletions libs/entitylib.h
@@ -1,12 +1,8 @@
#pragma once

#include "debugging/debugging.h"

#include "ientity.h"
#include "ieclass.h"
#include "irender.h"
#include "iselection.h"
#include "igl.h"
#include "iselectiontest.h"

#include "generic/callback.h"
Expand Down Expand Up @@ -35,208 +31,6 @@ inline void aabb_testselect(const AABB& aabb, SelectionTest& test, SelectionInte
test.TestQuads(pointer, IndexPointer(indices, 24), best);
}

inline void aabb_draw_wire(const Vector3 points[8])
{
typedef unsigned int index_t;
index_t indices[24] = {
0, 1, 1, 2, 2, 3, 3, 0,
4, 5, 5, 6, 6, 7, 7, 4,
0, 4, 1, 5, 2, 6, 3, 7,
};
#if 1
glVertexPointer(3, GL_DOUBLE, 0, points);
glDrawElements(GL_LINES, sizeof(indices)/sizeof(index_t), GL_UNSIGNED_INT, indices);
#else
glBegin(GL_LINES);
for(std::size_t i = 0; i < sizeof(indices)/sizeof(index_t); ++i)
{
glVertex3dv(points[indices[i]]);
}
glEnd();
#endif
}

inline void aabb_draw_flatshade(const Vector3 points[8])
{
glBegin(GL_QUADS);

glNormal3dv(aabb_normals[0]);
glVertex3dv(points[2]);
glVertex3dv(points[1]);
glVertex3dv(points[5]);
glVertex3dv(points[6]);

glNormal3dv(aabb_normals[1]);
glVertex3dv(points[1]);
glVertex3dv(points[0]);
glVertex3dv(points[4]);
glVertex3dv(points[5]);

glNormal3dv(aabb_normals[2]);
glVertex3dv(points[0]);
glVertex3dv(points[1]);
glVertex3dv(points[2]);
glVertex3dv(points[3]);

glNormal3dv(aabb_normals[3]);
glVertex3dv(points[0]);
glVertex3dv(points[3]);
glVertex3dv(points[7]);
glVertex3dv(points[4]);

glNormal3dv(aabb_normals[4]);
glVertex3dv(points[3]);
glVertex3dv(points[2]);
glVertex3dv(points[6]);
glVertex3dv(points[7]);

glNormal3dv(aabb_normals[5]);
glVertex3dv(points[7]);
glVertex3dv(points[6]);
glVertex3dv(points[5]);
glVertex3dv(points[4]);

glEnd();
}

inline void aabb_draw_wire(const AABB& aabb)
{
Vector3 points[8];
aabb.getCorners(points);
aabb_draw_wire(points);
}

inline void aabb_draw_flatshade(const AABB& aabb)
{
Vector3 points[8];
aabb.getCorners(points);
aabb_draw_flatshade(points);
}

inline void aabb_draw_textured(const AABB& aabb)
{
Vector3 points[8];
aabb.getCorners(points);

glBegin(GL_QUADS);

glNormal3dv(aabb_normals[0]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[2]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[1]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[5]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[6]);

glNormal3dv(aabb_normals[1]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[1]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[0]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[4]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[5]);

glNormal3dv(aabb_normals[2]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[0]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[1]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[2]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[3]);

glNormal3dv(aabb_normals[3]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[0]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[3]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[7]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[4]);

glNormal3dv(aabb_normals[4]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[3]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[2]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[6]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[7]);

glNormal3dv(aabb_normals[5]);
glTexCoord2dv(aabb_texcoord_topleft);
glVertex3dv(points[7]);
glTexCoord2dv(aabb_texcoord_topright);
glVertex3dv(points[6]);
glTexCoord2dv(aabb_texcoord_botright);
glVertex3dv(points[5]);
glTexCoord2dv(aabb_texcoord_botleft);
glVertex3dv(points[4]);

glEnd();
}

inline void aabb_draw_solid(const AABB& aabb, RenderStateFlags state)
{
if(state & RENDER_TEXTURE_2D)
{
aabb_draw_textured(aabb);
}
else
{
aabb_draw_flatshade(aabb);
}
}

inline void aabb_draw(const AABB& aabb, RenderStateFlags state)
{
if(state & RENDER_FILL)
{
aabb_draw_solid(aabb, state);
}
else
{
aabb_draw_wire(aabb);
}
}

class RenderableSolidAABB : public OpenGLRenderable
{
const AABB& m_aabb;
public:
RenderableSolidAABB(const AABB& aabb) : m_aabb(aabb)
{
}
void render(const RenderInfo& info) const
{
aabb_draw_solid(m_aabb, info.getFlags());
}
const AABB& getAABB() const
{
return m_aabb;
}
};

class RenderableWireframeAABB : public OpenGLRenderable
{
const AABB& m_aabb;
public:
RenderableWireframeAABB(const AABB& aabb) : m_aabb(aabb)
{
}
void render(const RenderInfo& info) const
{
aabb_draw_wire(m_aabb);
}
};

/**
* Stream insertion for Entity objects.
*/
Expand Down

0 comments on commit 28b3cd9

Please sign in to comment.