1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: glDisplayList.C,v 1.7.16.1 2007/03/25 21:57:01 oliver Exp $
//
#include <BALL/VIEW/RENDERING/glDisplayList.h>
#include <BALL/COMMON/exception.h>
#include <BALL/DATATYPE/string.h>
#include <BALL/COMMON/rtti.h>
using namespace std;
// #define BALL_VIEW_DEBUG
#ifdef BALL_VIEW_DEBUG
#define CHECK_GL_ERROR \
{\
GLenum e = glGetError(); \
if (e != GL_NO_ERROR)\
{\
Log.error() << "GL Error occurred in " << __FILE__ << " " << __LINE__ << std::endl;\
switch (e)\
{\
case GL_INVALID_VALUE: Log.error() << " GL_INVALID_VALUE" << std::endl;break;\
case GL_INVALID_ENUM: Log.error() << " GL_INVALID_ENUM" << std::endl;break;\
case GL_INVALID_OPERATION: Log.error() << " GL_INVALID_OPERATION" << std::endl;break;\
case GL_STACK_OVERFLOW: Log.error() << " GL_STACK_OVERFLOW" << std::endl;break;\
case GL_STACK_UNDERFLOW: Log.error() << " GL_STACK_UNDERFLOW" << std::endl;break;\
case GL_TABLE_TOO_LARGE: Log.error() << " GL_TABLE_TOO_LARGE" << std::endl;break;\
default: Log.error() << " UNKNOWN ERROR" << std::endl;\
}\
}\
}
#else
#define CHECK_GL_ERROR
#endif
namespace BALL
{
namespace VIEW
{
const GLDisplayList::GLList
GLDisplayList::DISPLAYLIST_NOT_DEFINED = (GLDisplayList::GLList)0;
GLDisplayList::NestedDisplayList::NestedDisplayList(const char* file, int line)
: Exception::GeneralException(file, line, String("NestedDisplayList"),
String("display list definition inside another is not allowed."))
{
}
GLDisplayList::NoDisplayListAvailable::NoDisplayListAvailable(const char* file, int line)
: Exception::GeneralException(file, line, String("NoDisplayListAvailable"),
String("memory allocation for display list failed."))
{
}
GLDisplayList::DisplayListRedeclaration::DisplayListRedeclaration(const char* file, int line)
: Exception::GeneralException(file, line, String("DisplayListRedeclaration"),
String("display list already defined."))
{
}
GLDisplayList::GLDisplayList()
: compile_(true),
GL_list_(0)
{
}
GLDisplayList::~GLDisplayList()
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "Destructing object " << this << " of class GLDisplayList" << endl;
#endif
clear();
}
void GLDisplayList::clear()
{
if (GL_list_ != 0)
{
CHECK_GL_ERROR
glDeleteLists((GLuint) GL_list_, 1);
CHECK_GL_ERROR
GL_list_ = 0;
}
}
void GLDisplayList::startDefinition()
{
CHECK_GL_ERROR
if (GL_list_ != 0)
{
throw DisplayListRedeclaration(__FILE__, __LINE__);
}
GLint current_index = -1;
glGetIntegerv(GL_LIST_INDEX, ¤t_index);
CHECK_GL_ERROR
// missing OpenGL context
if(current_index == -1)
{
Log.error() << "Display lists cannot be created without OpenGL context!" << endl;
throw NoDisplayListAvailable(__FILE__, __LINE__);
}
// we are already in a display list definition
if (current_index != 0)
{
throw NestedDisplayList(__FILE__, __LINE__);
}
GL_list_ = glGenLists(1);
CHECK_GL_ERROR
if (GL_list_ == GLDisplayList::DISPLAYLIST_NOT_DEFINED)
{
throw NoDisplayListAvailable(__FILE__, __LINE__);
}
if (compile_)
{
glNewList(GL_list_, GL_COMPILE);
CHECK_GL_ERROR
}
else
{
glNewList(GL_list_, GL_COMPILE_AND_EXECUTE);
CHECK_GL_ERROR
}
}
void GLDisplayList::endDefinition()
{
CHECK_GL_ERROR
glEndList();
}
void GLDisplayList::dump(ostream& s, Size depth) const
{
BALL_DUMP_STREAM_PREFIX(s);
BALL_DUMP_DEPTH(s, depth);
BALL_DUMP_HEADER(s, this, this);
BALL_DUMP_DEPTH(s, depth);
s << "display list : " << GL_list_ << endl;
BALL_DUMP_DEPTH(s, depth);
s << "compile mode : "
<< ((compile_) ? "yes" : "no") << endl;
BALL_DUMP_STREAM_SUFFIX(s);
}
# ifdef BALL_NO_INLINE_FUNCTIONS
# include <BALL/VIEW/RENDERING/glDisplayList.iC>
# endif
} // namespace VIEW
} // namespace BALL
|