diff --git a/doomsday/apps/api/api_gl.h b/doomsday/apps/api/api_gl.h index 504f7b0590..98b104ebbb 100644 --- a/doomsday/apps/api/api_gl.h +++ b/doomsday/apps/api/api_gl.h @@ -118,6 +118,7 @@ typedef enum dgltexformat_e { /// Primitive types. typedef enum dglprimtype_e { + DGL_NO_PRIMITIVE, DGL_LINES, DGL_LINE_STRIP, DGL_LINE_LOOP, @@ -126,7 +127,7 @@ typedef enum dglprimtype_e { DGL_TRIANGLE_STRIP, DGL_QUADS, DGL_QUAD_STRIP, - DGL_POINTS + DGL_POINTS, } dglprimtype_t; #define DDNUM_BLENDMODES 9 @@ -257,7 +258,7 @@ DENG_API_TYPEDEF(GL) void (*SetScissor)(RectRaw const *rect); void (*SetScissor2)(int x, int y, int width, int height); - void (*MatrixMode)(int mode); + void (*MatrixMode)(DGLenum mode); void (*PushMatrix)(void); void (*PopMatrix)(void); void (*LoadIdentity)(void); diff --git a/doomsday/apps/client/include/gl/gl_main.h b/doomsday/apps/client/include/gl/gl_main.h index 1c92be0173..5d8b9d3adc 100644 --- a/doomsday/apps/client/include/gl/gl_main.h +++ b/doomsday/apps/client/include/gl/gl_main.h @@ -61,6 +61,8 @@ DENG_EXTERN_C int r_detail; # define DENG_ASSERT_GL_CONTEXT_ACTIVE() #endif +#define Sys_GLCheckError() Sys_GLCheckErrorArgs(__FILE__, __LINE__) + #ifdef _DEBUG # define LIBDENG_ASSERT_GL_TEXTURE_ISBOUND(tex) { \ GLint p; \ @@ -315,6 +317,8 @@ void GL_CalcLuminance(uint8_t const *buffer, int width, int height, int comps, void DGL_AssertNotInPrimitive(void); +de::Matrix4f DGL_Matrix(DGLenum matrixMode); + // Console commands. D_CMD(UpdateGammaRamp); diff --git a/doomsday/apps/client/include/gl/sys_opengl.h b/doomsday/apps/client/include/gl/sys_opengl.h index bf027a73ed..2f4c9a8d94 100644 --- a/doomsday/apps/client/include/gl/sys_opengl.h +++ b/doomsday/apps/client/include/gl/sys_opengl.h @@ -151,7 +151,7 @@ void Sys_GLConfigureDefaultState(void); */ void Sys_GLPrintExtensions(void); -dd_bool Sys_GLCheckError(void); +dd_bool Sys_GLCheckErrorArgs(char const *file, int line); #endif // __CLIENT__ diff --git a/doomsday/apps/client/src/gl/dgl_common.cpp b/doomsday/apps/client/src/gl/dgl_common.cpp index 14f87e711e..b90899f582 100644 --- a/doomsday/apps/client/src/gl/dgl_common.cpp +++ b/doomsday/apps/client/src/gl/dgl_common.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "api_gl.h" @@ -38,6 +39,64 @@ using namespace de; +struct DGLState +{ + int matrixMode = 0; + QVector matrixStacks[3]; + bool enableTexture = true; + bool enableFog = false; + + DGLState() + { + // The matrix stacks initially contain identity matrices. + for (auto &stack : matrixStacks) + { + stack.append(Matrix4f()); + } + } + + static int stackIndex(DGLenum id) + { + int const index = int(id) - DGL_MODELVIEW; + DENG2_ASSERT(index >=0 && index < 3); + return index; + } + + void pushMatrix() + { + auto &stack = matrixStacks[matrixMode]; + stack.push_back(stack.back()); + } + + void popMatrix() + { + auto &stack = matrixStacks[matrixMode]; + DENG2_ASSERT(stack.size() > 1); + stack.pop_back(); + } + + void loadMatrix(Matrix4f const &mat) + { + auto &stack = matrixStacks[matrixMode]; + DENG2_ASSERT(!stack.isEmpty()); + stack.back() = mat; + } + + void multMatrix(Matrix4f const &mat) + { + auto &stack = matrixStacks[matrixMode]; + DENG2_ASSERT(!stack.isEmpty()); + stack.back() = stack.back() * mat; + } +}; + +static DGLState dgl; + +Matrix4f DGL_Matrix(DGLenum matrixMode) +{ + return dgl.matrixStacks[DGLState::stackIndex(matrixMode)].back(); +} + #if 0 /** * Requires a texture environment mode that can add and multiply. @@ -381,6 +440,10 @@ dd_bool DGL_GetIntegerv(int name, int *v) float color[4]; switch(name) { + case DGL_TEXTURE_2D: + *v = (dgl.enableTexture? 1 : 0); + break; + case DGL_MODULATE_ADD_COMBINE: qDebug() << "DGL_GetIntegerv: tex env not available"; //*v = GLInfo::extensions().NV_texture_env_combine4 || GLInfo::extensions().ATI_texture_env_combine3; @@ -530,7 +593,7 @@ dd_bool DGL_SetFloat(int name, float value) { case DGL_LINE_WIDTH: GL_state.currentLineWidth = value; - LIBGUI_GL.glLineWidth(value); + GLInfo::setLineWidth(value); break; case DGL_POINT_SIZE: @@ -569,11 +632,13 @@ int DGL_Enable(int cap) switch(cap) { case DGL_TEXTURE_2D: - Deferred_glEnable(GL_TEXTURE_2D); + //Deferred_glEnable(GL_TEXTURE_2D); + dgl.enableTexture = true; break; case DGL_FOG: - Deferred_glEnable(GL_FOG); + //Deferred_glEnable(GL_FOG); + dgl.enableFog = true; GL_state.currentUseFog = true; break; @@ -594,6 +659,7 @@ int DGL_Enable(int cap) return 0; } + LIBGUI_ASSERT_GL_OK(); return 1; } @@ -606,11 +672,13 @@ void DGL_Disable(int cap) switch(cap) { case DGL_TEXTURE_2D: - Deferred_glDisable(GL_TEXTURE_2D); + //Deferred_glDisable(GL_TEXTURE_2D); + dgl.enableTexture = false; break; case DGL_FOG: - Deferred_glDisable(GL_FOG); + //Deferred_glDisable(GL_FOG); + dgl.enableFog = false; GL_state.currentUseFog = false; break; @@ -631,6 +699,8 @@ void DGL_Disable(int cap) DENG_ASSERT(!"DGL_Disable: Invalid cap"); break; } + + LIBGUI_ASSERT_GL_OK(); } #undef DGL_BlendOp @@ -676,32 +746,6 @@ void DGL_BlendMode(blendmode_t mode) GL_BlendMode(mode); } -#undef DGL_MatrixMode -void DGL_MatrixMode(int mode) -{ - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - DENG_ASSERT(mode == DGL_PROJECTION || mode == DGL_TEXTURE || mode == DGL_MODELVIEW); - -// LIBGUI_GL.glMatrixMode(mode == DGL_PROJECTION ? GL_PROJECTION : -// mode == DGL_TEXTURE ? GL_TEXTURE : -// GL_MODELVIEW); -} - -#undef DGL_PushMatrix -void DGL_PushMatrix(void) -{ - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - - DGL_PushMatrix(); - -#if _DEBUG - if(LIBGUI_GL.glGetError() == GL_STACK_OVERFLOW) - App_Error("DG_PushMatrix: Stack overflow.\n"); -#endif -} - #undef DGL_SetNoMaterial void DGL_SetNoMaterial(void) { @@ -713,12 +757,15 @@ static gl::Wrapping DGL_ToGLWrapCap(DGLint cap) switch(cap) { case DGL_CLAMP: - case DGL_CLAMP_TO_EDGE: return gl::ClampToEdge; + case DGL_CLAMP_TO_EDGE: + return gl::ClampToEdge; + + case DGL_REPEAT: + return gl::Repeat; - case DGL_REPEAT: return gl::Repeat; default: - App_Error("DGL_ToGLWrapCap: Unknown cap value %i.", (int)cap); - exit(1); // Unreachable. + DENG2_ASSERT(!"DGL_ToGLWrapCap: Unknown cap value"); + break; } } @@ -770,64 +817,77 @@ void DGL_SetRawImage(lumpnum_t lumpNum, DGLint wrapS, DGLint wrapT) GL_SetRawImage(lumpNum, DGL_ToGLWrapCap(wrapS), DGL_ToGLWrapCap(wrapT)); } +#undef DGL_MatrixMode +void DGL_MatrixMode(DGLenum mode) +{ + DENG_ASSERT_IN_MAIN_THREAD(); + DENG_ASSERT(mode == DGL_PROJECTION || mode == DGL_TEXTURE || mode == DGL_MODELVIEW); + + dgl.matrixMode = DGLState::stackIndex(mode); +} + +#undef DGL_PushMatrix +void DGL_PushMatrix(void) +{ + DENG_ASSERT_IN_MAIN_THREAD(); + + dgl.pushMatrix(); +} + #undef DGL_PopMatrix void DGL_PopMatrix(void) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_PopMatrix(); + dgl.popMatrix(); } #undef DGL_LoadIdentity void DGL_LoadIdentity(void) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_LoadIdentity(); + dgl.loadMatrix(Matrix4f()); } #undef DGL_LoadMatrix void DGL_LoadMatrix(float const *matrix4x4) { - // TODO: replace matrix in stack + DENG_ASSERT_IN_MAIN_THREAD(); + + dgl.loadMatrix(Matrix4f(matrix4x4)); } #undef DGL_Translatef void DGL_Translatef(float x, float y, float z) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Translatef(x, y, z); + dgl.multMatrix(Matrix4f::translate(Vector3f(x, y, z))); } #undef DGL_Rotatef void DGL_Rotatef(float angle, float x, float y, float z) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Rotatef(angle, x, y, z); + dgl.multMatrix(Matrix4f::rotate(angle, Vector3f(x, y, z))); } #undef DGL_Scalef void DGL_Scalef(float x, float y, float z) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Scalef(x, y, z); + dgl.multMatrix(Matrix4f::scale(Vector3f(x, y, z))); } #undef DGL_Ortho void DGL_Ortho(float left, float top, float right, float bottom, float znear, float zfar) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Ortho(left, right, bottom, top, znear, zfar); + dgl.multMatrix(Matrix4f::ortho(left, right, top, bottom, znear, zfar)); } #undef DGL_DeleteTextures @@ -835,7 +895,7 @@ void DGL_DeleteTextures(int num, DGLuint const *names) { if(!num || !names) return; - Deferred_glDeleteTextures(num, (GLuint const *) names); + Deferred_glDeleteTextures(num, names); } #undef DGL_Bind @@ -869,10 +929,6 @@ DGLuint DGL_NewTextureWithParams(dgltexformat_t format, int width, int height, // dgl_draw.cpp DENG_EXTERN_C void DGL_Begin(dglprimtype_t mode); DENG_EXTERN_C void DGL_End(void); -DENG_EXTERN_C dd_bool DGL_NewList(DGLuint list, int mode); -DENG_EXTERN_C DGLuint DGL_EndList(void); -DENG_EXTERN_C void DGL_CallList(DGLuint list); -DENG_EXTERN_C void DGL_DeleteLists(DGLuint list, int range); DENG_EXTERN_C void DGL_Color3ub(DGLubyte r, DGLubyte g, DGLubyte b); DENG_EXTERN_C void DGL_Color3ubv(const DGLubyte* vec); DENG_EXTERN_C void DGL_Color4ub(DGLubyte r, DGLubyte g, DGLubyte b, DGLubyte a); diff --git a/doomsday/apps/client/src/gl/dgl_draw.cpp b/doomsday/apps/client/src/gl/dgl_draw.cpp index 16f09273c3..97c5472857 100644 --- a/doomsday/apps/client/src/gl/dgl_draw.cpp +++ b/doomsday/apps/client/src/gl/dgl_draw.cpp @@ -1,4 +1,6 @@ -/** @file dgl_draw.cpp Drawing Operations and Vertex Arrays. +/** @file dgl_draw.cpp Drawing operations and vertex arrays. + * + * Emulates OpenGL 1.x drawing for legacy code. * * @authors Copyright © 2003-2017 Jaakko Keränen * @authors Copyright © 2007-2015 Daniel Swanson @@ -17,8 +19,6 @@ * http://www.gnu.org/licenses */ -#define DENG_NO_API_MACROS_GL - #include "de_base.h" #include "gl/gl_main.h" @@ -26,232 +26,348 @@ #include #include #include +#include +#include +#include +#include #include "sys_system.h" #include "gl/gl_draw.h" #include "gl/sys_opengl.h" +#include "clientapp.h" using namespace de; -static int primLevel = 0; -static DGLuint inList = 0; -#ifdef _DEBUG -static dd_bool inPrim = false; -#endif +uint constexpr MAX_TEX_COORDS = 3; -dd_bool GL_NewList(DGLuint list, int mode) +struct DGLDrawState { -#if 0 - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + struct Vertex + { + Vector3f vertex; + Vector4ub color { 255, 255, 255, 255 }; + Vector2f texCoord[MAX_TEX_COORDS]; + }; + + // Indices for vertex attribute arrays. + enum + { + VAA_VERTEX, + VAA_COLOR, + VAA_TEXCOORD0, + VAA_TEXCOORD1, + VAA_TEXCOORD2, + NUM_VERTEX_ATTRIB_ARRAYS + }; + + int primLevel = 0; + dglprimtype_t currentPrimitive = DGL_NO_PRIMITIVE; + QVector vertices; + + struct GLData + { + GLProgram shader; + GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 }; + GLUniform uTextureMatrix { "uTextureMatrix", GLUniform::Mat4 }; + GLUniform uEnabledTextures { "uEnabledTextures", GLUniform::Int }; + GLuint vertexArray = 0; + }; + std::unique_ptr gl; + + DGLDrawState() + { + clearVertices(); + } + + void commitVertex() + { + vertices.append(vertices.last()); + } + + void clearVertices() + { + vertices.clear(); + vertices.append(Vertex()); + } + + int numVertices() const + { + // The last one is always the incomplete one. + return vertices.size() - 1; + } + + Vertex &vertex() + { + return vertices.last(); + } + + static Vector4ub colorFromFloat(Vector4f const &color) + { + Vector4i rgba = (color * 255 + Vector4f(0.5f, 0.5f, 0.5f, 0.5f)) + .toVector4i() + .max(Vector4i(0, 0, 0, 0)) + .min(Vector4i(255, 255, 255, 255)); + return Vector4ub(dbyte(rgba.x), dbyte(rgba.y), dbyte(rgba.z), dbyte(rgba.w)); + } - // We enter a New/End list section. -#ifdef _DEBUG - if(inList) - App_Error("GL_NewList: Already in list"); - Sys_GLCheckError(); -#endif + void beginPrimitive(dglprimtype_t primitive) + { + // We enter a Begin/End section. + primLevel++; + + DENG2_ASSERT(currentPrimitive == DGL_NO_PRIMITIVE); + currentPrimitive = primitive; + } - if(list) - { // A specific list id was requested. Is it free? - if(LIBGUI_GL.glIsList(list)) + void endPrimitive() + { + DENG2_ASSERT(primLevel > 0); + DENG2_ASSERT(currentPrimitive != DGL_NO_PRIMITIVE); + + if (primLevel > 0) { -#if _DEBUG - App_Error("GL_NewList: List %u already in use.", (unsigned int) list); -#endif - return false; + primLevel--; + drawPrimitives(); } + clearVertices(); } - else + + void glInit() { - // Just get a new list id, it doesn't matter. - list = LIBGUI_GL.glGenLists(1); + DENG_ASSERT_GL_CONTEXT_ACTIVE(); + + if (!gl) + { + gl.reset(new GLData); + + // Set up the shader. + ClientApp::shaders().build(gl->shader, "dgl.draw") + << gl->uMvpMatrix + << gl->uTextureMatrix + << gl->uEnabledTextures; + + auto &GL = LIBGUI_GL; + + // Sampler uniforms. + { + auto prog = gl->shader.glName(); + GL.glUseProgram(prog); + GL.glUniform1i(GL.glGetUniformLocation(prog, "uTex0"), 0); + GL.glUniform1i(GL.glGetUniformLocation(prog, "uTex1"), 1); + GL.glUniform1i(GL.glGetUniformLocation(prog, "uTex2"), 2); + GL.glUseProgram(0); + } + + // Vertex array object. + { + GL.glGenVertexArrays(1, &gl->vertexArray); + GL.glBindVertexArray(gl->vertexArray); + for (uint i = 0; i < NUM_VERTEX_ATTRIB_ARRAYS; ++i) + { + GL.glEnableVertexAttribArray(i); + } + GL.glBindVertexArray(0); + } + } } - LIBGUI_GL.glNewList(list, mode == DGL_COMPILE? GL_COMPILE : GL_COMPILE_AND_EXECUTE); - inList = list; - return true; -#endif - qDebug() << "OpenGL drawing lists are not available"; - return false; -} + void glBindArrays() + { + uint const stride = sizeof(Vertex); + auto &GL = LIBGUI_GL; -DGLuint GL_EndList(void) -{ -#if 0 - DGLuint currentList = inList; + GL.glBindVertexArray(gl->vertexArray); - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + // Updated pointers. + GL.glVertexAttribPointer(VAA_VERTEX, 3, GL_FLOAT, GL_FALSE, stride, &vertices[0].vertex); + GL.glVertexAttribPointer(VAA_COLOR, 4, GL_UNSIGNED_BYTE, GL_FALSE, stride, &vertices[0].color); + GL.glVertexAttribPointer(VAA_TEXCOORD0, 2, GL_FLOAT, GL_FALSE, stride, &vertices[0].texCoord[0]); + GL.glVertexAttribPointer(VAA_TEXCOORD1, 2, GL_FLOAT, GL_FALSE, stride, &vertices[0].texCoord[1]); + GL.glVertexAttribPointer(VAA_TEXCOORD2, 2, GL_FLOAT, GL_FALSE, stride, &vertices[0].texCoord[2]); - DGL_EndList(); -#ifdef _DEBUG - inList = 0; - Sys_GLCheckError(); -#endif + LIBGUI_ASSERT_GL_OK(); + } - return currentList; -#endif - return 0; -} + void glUnbindArrays() + { + LIBGUI_GL.glBindVertexArray(0); + } -void GL_CallList(DGLuint list) -{ -#if 0 - if(!list) return; // We do not consider zero a valid list id. + GLenum glPrimitive() const + { + switch (currentPrimitive) + { + case DGL_POINTS: return GL_POINTS; + case DGL_LINES: return GL_LINES; + case DGL_LINE_LOOP: return GL_LINE_LOOP; + case DGL_LINE_STRIP: return GL_LINE_STRIP; + case DGL_QUADS: return GL_QUADS; + case DGL_QUAD_STRIP: return GL_QUAD_STRIP; + case DGL_TRIANGLES: return GL_TRIANGLES; + case DGL_TRIANGLE_FAN: return GL_TRIANGLE_FAN; + case DGL_TRIANGLE_STRIP: return GL_TRIANGLE_STRIP; + + case DGL_NO_PRIMITIVE: DENG2_ASSERT(!"No primitive type specified"); return GL_NONE; + } + } - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + /** + * Draws all the primitives currently stored in the vertex array. + */ + void drawPrimitives() + { + glInit(); - LIBGUI_GL.glCallList(list); -#endif -} + // Update uniforms. + gl->uMvpMatrix = DGL_Matrix(DGL_PROJECTION) * DGL_Matrix(DGL_MODELVIEW); + gl->uTextureMatrix = DGL_Matrix(DGL_TEXTURE); -void GL_DeleteLists(DGLuint list, int range) -{ -#if 0 - DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + gl->uEnabledTextures = DGL_GetInteger(DGL_TEXTURE_2D)? 1 : 0; - LIBGUI_GL.glDeleteLists(list, range); -#endif -} + gl->shader.beginUse(); + { + glBindArrays(); + LIBGUI_GL.glDrawArrays(glPrimitive(), 0, numVertices()); + glUnbindArrays(); + } + gl->shader.endUse(); + } +}; + +static DGLDrawState dglDraw; #undef DGL_Color3ub DENG_EXTERN_C void DGL_Color3ub(DGLubyte r, DGLubyte g, DGLubyte b) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //LIBGUI_GL.glColor3ub(r, g, b); + dglDraw.vertex().color = Vector4ub(r, g, b, 255); } #undef DGL_Color3ubv DENG_EXTERN_C void DGL_Color3ubv(const DGLubyte* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //LIBGUI_GL.glColor3ubv(vec); + dglDraw.vertex().color = Vector4ub(Vector3ub(vec), 255); } #undef DGL_Color4ub DENG_EXTERN_C void DGL_Color4ub(DGLubyte r, DGLubyte g, DGLubyte b, DGLubyte a) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //LIBGUI_GL.glColor4ub(r, g, b, a); + dglDraw.vertex().color = Vector4ub(r, g, b, a); } #undef DGL_Color4ubv DENG_EXTERN_C void DGL_Color4ubv(const DGLubyte* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //LIBGUI_GL.glColor4ubv(vec); + dglDraw.vertex().color = Vector4ub(vec); } #undef DGL_Color3f DENG_EXTERN_C void DGL_Color3f(float r, float g, float b) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //LIBGUI_GL.glColor3f(r, g, b); + dglDraw.vertex().color = DGLDrawState::colorFromFloat(Vector4f(r, g, b, 1.f)); } #undef DGL_Color3fv DENG_EXTERN_C void DGL_Color3fv(const float* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Color3fv(vec); + dglDraw.vertex().color = DGLDrawState::colorFromFloat(Vector4f(Vector3f(vec), 1.f)); } #undef DGL_Color4f DENG_EXTERN_C void DGL_Color4f(float r, float g, float b, float a) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Color4f(r, g, b, a); + dglDraw.vertex().color = DGLDrawState::colorFromFloat(Vector4f(r, g, b, a)); } #undef DGL_Color4fv DENG_EXTERN_C void DGL_Color4fv(const float* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - DGL_Color4fv(vec); + dglDraw.vertex().color = DGLDrawState::colorFromFloat(Vector4f(vec)); } #undef DGL_TexCoord2f DENG_EXTERN_C void DGL_TexCoord2f(byte target, float s, float t) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + DENG2_ASSERT(target < MAX_TEX_COORDS); - //LIBGUI_GL.glMultiTexCoord2f(GL_TEXTURE0 + target, s, t); + if (target < MAX_TEX_COORDS) + { + dglDraw.vertex().texCoord[target] = Vector2f(s, t); + } } #undef DGL_TexCoord2fv DENG_EXTERN_C void DGL_TexCoord2fv(byte target, float const *vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); + DENG2_ASSERT(target < MAX_TEX_COORDS); - //LIBGUI_GL.glMultiTexCoord2fv(GL_TEXTURE0 + target, vec); + if (target < MAX_TEX_COORDS) + { + dglDraw.vertex().texCoord[target] = Vector2f(vec); + } } #undef DGL_Vertex2f DENG_EXTERN_C void DGL_Vertex2f(float x, float y) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Vertex2f(x, y); + dglDraw.vertex().vertex = Vector3f(x, y, 0.f); + dglDraw.commitVertex(); } #undef DGL_Vertex2fv DENG_EXTERN_C void DGL_Vertex2fv(const float* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Vertex2fv(vec); + dglDraw.vertex().vertex = Vector3f(vec[0], vec[1], 0.f); + dglDraw.commitVertex(); } #undef DGL_Vertex3f DENG_EXTERN_C void DGL_Vertex3f(float x, float y, float z) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Vertex3f(x, y, z); + dglDraw.vertex().vertex = Vector3f(x, y, z); + dglDraw.commitVertex(); } #undef DGL_Vertex3fv DENG_EXTERN_C void DGL_Vertex3fv(const float* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - DGL_Vertex3fv(vec); + dglDraw.vertex().vertex = Vector3f(vec); + dglDraw.commitVertex(); } #undef DGL_Vertices2ftv DENG_EXTERN_C void DGL_Vertices2ftv(int num, const dgl_ft2vertex_t* vec) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); for(; num > 0; num--, vec++) { DGL_TexCoord2fv(0, vec->tex); - //DGL_Vertex2fv(vec->pos); + DGL_Vertex2fv(vec->pos); } } @@ -291,29 +407,12 @@ DENG_EXTERN_C void DGL_Begin(dglprimtype_t mode) DENG_ASSERT_IN_MAIN_THREAD(); DENG_ASSERT_GL_CONTEXT_ACTIVE(); - // We enter a Begin/End section. - primLevel++; - -#ifdef _DEBUG - DENG2_ASSERT(!inPrim); - inPrim = true; - Sys_GLCheckError(); -#endif - - /*LIBGUI_GL.glBegin(mode == DGL_POINTS ? GL_POINTS : mode == - DGL_LINES ? GL_LINES : mode == - DGL_LINE_STRIP ? GL_LINE_STRIP : mode == - DGL_TRIANGLES ? GL_TRIANGLES : mode == - DGL_TRIANGLE_FAN ? GL_TRIANGLE_FAN : mode == - DGL_TRIANGLE_STRIP ? GL_TRIANGLE_STRIP : mode == - DGL_QUAD_STRIP ? GL_QUAD_STRIP : GL_QUADS);*/ - - // TODO: Start a new primitive + dglDraw.beginPrimitive(mode); } void DGL_AssertNotInPrimitive(void) { - DENG_ASSERT(!inPrim); + DENG_ASSERT(dglDraw.currentPrimitive == DGL_NO_PRIMITIVE); } #undef DGL_End @@ -325,43 +424,8 @@ DENG_EXTERN_C void DGL_End(void) DENG_ASSERT_IN_MAIN_THREAD(); DENG_ASSERT_GL_CONTEXT_ACTIVE(); - if(primLevel > 0) - { - primLevel--; - //DGL_End(); - } - -#ifdef _DEBUG - inPrim = false; - Sys_GLCheckError(); -#endif -} - -#if 0 -#undef DGL_NewList -DENG_EXTERN_C dd_bool DGL_NewList(DGLuint list, int mode) -{ - return GL_NewList(list, mode); -} - -#undef DGL_EndList -DENG_EXTERN_C DGLuint DGL_EndList(void) -{ - return GL_EndList(); -} - -#undef DGL_CallList -DENG_EXTERN_C void DGL_CallList(DGLuint list) -{ - GL_CallList(list); -} - -#undef DGL_DeleteLists -DENG_EXTERN_C void DGL_DeleteLists(DGLuint list, int range) -{ - GL_DeleteLists(list, range); + dglDraw.endPrimitive(); } -#endif #undef DGL_DrawLine DENG_EXTERN_C void DGL_DrawLine(float x1, float y1, float x2, float y2, float r, @@ -400,9 +464,8 @@ DENG_EXTERN_C void DGL_DrawRectf2(double x, double y, double w, double h) DENG_EXTERN_C void DGL_DrawRectf2Color(double x, double y, double w, double h, float r, float g, float b, float a) { DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); - //DGL_Color4f(r, g, b, a); + DGL_Color4f(r, g, b, a); GL_DrawRectf2(x, y, w, h); } @@ -433,7 +496,6 @@ DENG_EXTERN_C void DGL_DrawQuadOutline(Point2Raw const *tl, Point2Raw const *tr, if(!tl || !tr || !br || !bl || (color && !(color[CA] > 0))) return; DENG_ASSERT_IN_MAIN_THREAD(); - DENG_ASSERT_GL_CONTEXT_ACTIVE(); if(color) DGL_Color4fv(color); DGL_Begin(DGL_LINE_STRIP); diff --git a/doomsday/apps/client/src/gl/gl_main.cpp b/doomsday/apps/client/src/gl/gl_main.cpp index 28964acad2..87b800c937 100644 --- a/doomsday/apps/client/src/gl/gl_main.cpp +++ b/doomsday/apps/client/src/gl/gl_main.cpp @@ -363,7 +363,7 @@ void GL_Init2DState() //glDisable(GL_TEXTURE_1D); DGL_Disable(DGL_TEXTURE_2D); - LIBGUI_GL.glDisable(GL_TEXTURE_CUBE_MAP); + //LIBGUI_GL.glDisable(GL_TEXTURE_CUBE_MAP); // The projection matrix. DGL_MatrixMode(DGL_PROJECTION); @@ -372,7 +372,7 @@ void GL_Init2DState() // Default state for the white fog is off. fogParams.usingFog = false; - LIBGUI_GL.glDisable(GL_FOG); + DGL_Disable(DGL_FOG); Deferred_glFogi(GL_FOG_MODE, (fogModeDefault == 0 ? GL_LINEAR : fogModeDefault == 1 ? GL_EXP : GL_EXP2)); Deferred_glFogf(GL_FOG_START, DEFAULT_FOG_START); @@ -383,6 +383,8 @@ void GL_Init2DState() fogParams.fogColor[2] = DEFAULT_FOG_COLOR_BLUE; fogParams.fogColor[3] = 1; Deferred_glFogfv(GL_FOG_COLOR, fogParams.fogColor); + + LIBGUI_ASSERT_GL_OK(); } Rangef GL_DepthClipRange() diff --git a/doomsday/apps/client/src/gl/svg.cpp b/doomsday/apps/client/src/gl/svg.cpp index 8c5d55f599..390eae23c5 100644 --- a/doomsday/apps/client/src/gl/svg.cpp +++ b/doomsday/apps/client/src/gl/svg.cpp @@ -49,7 +49,7 @@ struct svg_s { svgid_t id; /// GL display list containing all commands for drawing all primitives (no state changes). - DGLuint dlist; + //DGLuint dlist; /// Set of lines for this graphic. uint lineCount; @@ -86,21 +86,19 @@ svgid_t Svg_UniqueId(Svg* svg) static void draw(const Svg* svg) { dglprimtype_t nextPrimType, primType = DGL_LINE_STRIP; - const SvgLine* lIt; - uint i; DENG_ASSERT_IN_MAIN_THREAD(); DENG_ASSERT_GL_CONTEXT_ACTIVE(); - lIt = svg->lines; - for(i = 0; i < svg->lineCount; ++i, lIt++) + SvgLine const *lIt = svg->lines; + for (uint i = 0; i < svg->lineCount; ++i, lIt++) { - if(lIt->numPoints != 2) + if (lIt->numPoints != 2) { nextPrimType = SvgLine_IsLoop(lIt)? DGL_LINE_LOOP : DGL_LINE_STRIP; // Do we need to end the current primitive? - if(primType == DGL_LINES) + if (primType == DGL_LINES) { DGL_End(); // 2-vertex set ends. } @@ -111,7 +109,7 @@ static void draw(const Svg* svg) else { // Do we need to start a new 2-vertex primitive set? - if(primType != DGL_LINES) + if (primType != DGL_LINES) { primType = DGL_LINES; DGL_Begin(DGL_LINES); @@ -119,7 +117,7 @@ static void draw(const Svg* svg) } // Write the vertex data. - if(lIt->head) + if (lIt->head) { const SvgLinePoint* pIt = lIt->head; do @@ -128,77 +126,78 @@ static void draw(const Svg* svg) DGL_TexCoord2f(0, pIt->coords.x, pIt->coords.y);; DGL_Vertex2f(pIt->coords.x, pIt->coords.y); } - while(NULL != (pIt = pIt->next) && pIt != lIt->head); + while (NULL != (pIt = pIt->next) && pIt != lIt->head); } - if(lIt->numPoints != 2) + if (lIt->numPoints != 2) { DGL_End(); // N-vertex primitive ends. } } - if(primType == DGL_LINES) + if (primType == DGL_LINES) { // Close any remaining open 2-vertex set. DGL_End(); } } -static DGLuint constructDisplayList(DGLuint name, const Svg* svg) +/*static DGLuint constructDisplayList(DGLuint name, const Svg* svg) { - if(GL_NewList(name, DGL_COMPILE)) + if (GL_NewList(name, DGL_COMPILE)) { draw(svg); return GL_EndList(); } return 0; -} +}*/ void Svg_Draw(Svg* svg) { assert(svg); - if(novideo || isDedicated) + if (novideo || isDedicated) { assert(0); // Should not have been called! return; } // Have we uploaded our draw-optimized representation yet? - if(svg->dlist) + /*if (svg->dlist) { // Draw! GL_CallList(svg->dlist); return; - } + }*/ // Draw manually in so-called 'immediate' mode. draw(svg); } dd_bool Svg_Prepare(Svg* svg) -{ +{/* assert(svg); - if(!novideo && !isDedicated) + if (!novideo && !isDedicated) { - if(!svg->dlist) + if (!svg->dlist) { svg->dlist = constructDisplayList(0, svg); } } - return !!svg->dlist; + return !!svg->dlist;*/ + return true; } void Svg_Unload(Svg* svg) { assert(svg); - if(novideo || isDedicated) return; + if (novideo || isDedicated) return; - if(svg->dlist) + /*if (svg->dlist) { GL_DeleteLists(svg->dlist, 1); svg->dlist = 0; - } + }*/ } Svg* Svg_FromDef(svgid_t uniqueId, const def_svgline_t* lines, uint lineCount) @@ -212,31 +211,31 @@ Svg* Svg_FromDef(svgid_t uniqueId, const def_svgline_t* lines, uint lineCount) uint i, j; Svg* svg; - if(!lines || lineCount == 0) return NULL; + if (!lines || lineCount == 0) return NULL; svg = (Svg*)malloc(sizeof(*svg)); - if(!svg) Libdeng_BadAlloc(); + if (!svg) Libdeng_BadAlloc(); svg->id = uniqueId; - svg->dlist = 0; + //svg->dlist = 0; // Count how many lines and points we actually need. finalLineCount = 0; finalPointCount = 0; slIt = lines; - for(i = 0; i < lineCount; ++i, slIt++) + for (i = 0; i < lineCount; ++i, slIt++) { // Skip lines with missing vertices... - if(slIt->numPoints < 2) continue; + if (slIt->numPoints < 2) continue; ++finalLineCount; finalPointCount += slIt->numPoints; - if(slIt->numPoints > 2) + if (slIt->numPoints > 2) { // If the end point is equal to the start point, we'll ommit it and // set this line up as a loop. - if(FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && + if (FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && FEQUAL(slIt->points[slIt->numPoints-1].y, slIt->points[0].y)) { finalPointCount -= 1; @@ -252,30 +251,30 @@ Svg* Svg_FromDef(svgid_t uniqueId, const def_svgline_t* lines, uint lineCount) // Allocate the final point set. svg->numPoints = finalPointCount; svg->points = (SvgLinePoint*)malloc(sizeof(*svg->points) * svg->numPoints); - if(!svg->points) Libdeng_BadAlloc(); + if (!svg->points) Libdeng_BadAlloc(); // Allocate the final line set. svg->lineCount = finalLineCount; svg->lines = (SvgLine*)malloc(sizeof(*svg->lines) * finalLineCount); - if(!svg->lines) Libdeng_BadAlloc(); + if (!svg->lines) Libdeng_BadAlloc(); // Setup the lines. slIt = lines; dlIt = svg->lines; dpIt = svg->points; - for(i = 0; i < lineCount; ++i, slIt++) + for (i = 0; i < lineCount; ++i, slIt++) { // Skip lines with missing vertices... - if(slIt->numPoints < 2) continue; + if (slIt->numPoints < 2) continue; // Determine how many points we'll need. dlIt->numPoints = slIt->numPoints; lineIsLoop = false; - if(slIt->numPoints > 2) + if (slIt->numPoints > 2) { // If the end point is equal to the start point, we'll ommit it and // set this line up as a loop. - if(FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && + if (FEQUAL(slIt->points[slIt->numPoints-1].x, slIt->points[0].x) && FEQUAL(slIt->points[slIt->numPoints-1].y, slIt->points[0].y)) { dlIt->numPoints -= 1; @@ -287,7 +286,7 @@ Svg* Svg_FromDef(svgid_t uniqueId, const def_svgline_t* lines, uint lineCount) spIt = slIt->points; dlIt->head = dpIt; prev = NULL; - for(j = 0; j < dlIt->numPoints; ++j, spIt++) + for (j = 0; j < dlIt->numPoints; ++j, spIt++) { SvgLinePoint* next = (j < dlIt->numPoints-1)? dpIt + 1 : NULL; diff --git a/doomsday/apps/client/src/gl/sys_opengl.cpp b/doomsday/apps/client/src/gl/sys_opengl.cpp index ec9368f909..9cf649b448 100644 --- a/doomsday/apps/client/src/gl/sys_opengl.cpp +++ b/doomsday/apps/client/src/gl/sys_opengl.cpp @@ -59,11 +59,12 @@ static void initialize(void) } #ifdef USE_TEXTURE_COMPRESSION_S3 // Enabled by default if available. - if(ext.EXT_texture_compression_s3tc) + if (ext.EXT_texture_compression_s3tc) { GLint iVal; LIBGUI_GL.glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &iVal); - if(iVal == 0 || LIBGUI_GL.glGetError() != GL_NO_ERROR) + LIBGUI_ASSERT_GL_OK(); + if (iVal == 0)// || LIBGUI_GL.glGetError() != GL_NO_ERROR) GL_state.features.texCompression = false; } #else @@ -87,6 +88,8 @@ de::String Sys_GLDescription() os << TABBED("Renderer:", (char const *) LIBGUI_GL.glGetString(GL_RENDERER)); os << TABBED("Vendor:", (char const *) LIBGUI_GL.glGetString(GL_VENDOR)); + LIBGUI_ASSERT_GL_OK(); + os << _E(T`) "Capabilities:\n"; GLint iVal; @@ -95,34 +98,31 @@ de::String Sys_GLDescription() if(de::GLInfo::extensions().EXT_texture_compression_s3tc) { LIBGUI_GL.glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &iVal); + LIBGUI_ASSERT_GL_OK(); os << TABBED("Compressed texture formats:", iVal); } #endif os << TABBED("Use texture compression:", (GL_state.features.texCompression? "yes" : "no")); - LIBGUI_GL.glGetIntegerv(GL_MAX_TEXTURE_UNITS, &iVal); - os << TABBED("Available texture units:", iVal); + os << TABBED("Available texture units:", de::GLInfo::limits().maxTexUnits); if(de::GLInfo::extensions().EXT_texture_filter_anisotropic) { - LIBGUI_GL.glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &iVal); - os << TABBED("Maximum texture anisotropy:", iVal); + os << TABBED("Maximum texture anisotropy:", de::GLInfo::limits().maxTexFilterAniso); } else { os << _E(Ta) " Variable texture anisotropy unavailable."; } - LIBGUI_GL.glGetIntegerv(GL_MAX_TEXTURE_SIZE, &iVal); - os << TABBED("Maximum texture size:", iVal); + os << TABBED("Maximum texture size:", de::GLInfo::limits().maxTexSize); - GLfloat fVals[2]; - LIBGUI_GL.glGetFloatv(GL_LINE_WIDTH_GRANULARITY, fVals); - os << TABBED("Line width granularity:", fVals[0]); + os << TABBED("Line width granularity:", de::GLInfo::limits().smoothLineWidthGranularity); - LIBGUI_GL.glGetFloatv(GL_LINE_WIDTH_RANGE, fVals); - os << TABBED("Line width range:", fVals[0] << "..." << fVals[1]); + os << TABBED("Line width range:", + de::GLInfo::limits().smoothLineWidth.start << "..." << + de::GLInfo::limits().smoothLineWidth.end); return str.rightStrip(); @@ -180,7 +180,7 @@ dd_bool Sys_GLInitialize(void) LOG_GL_WARNING("Failed to determine OpenGL version; driver reports: %s") << LIBGUI_GL.glGetString(GL_VERSION); } - else if(version < 2.0) + else if(version < 3.3) { if(!CommandLine_Exists("-noglcheck")) { @@ -192,7 +192,7 @@ dd_bool Sys_GLInitialize(void) } else { - LOG_GL_WARNING("OpenGL may be too old (2.0+ required, " + LOG_GL_WARNING("OpenGL may be too old (3.3+ required, " "but driver reports %s)") << LIBGUI_GL.glGetString(GL_VERSION); } } @@ -213,8 +213,7 @@ dd_bool Sys_GLInitialize(void) // Use nice quality for mipmaps please. //if(GL_state.features.genMipmap && de::GLInfo::extensions().SGIS_generate_mipmap) - - LIBGUI_GL.glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); + //LIBGUI_GL.glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST); assert(!Sys_GLCheckError()); @@ -230,6 +229,8 @@ void Sys_GLShutdown(void) void Sys_GLConfigureDefaultState(void) { + LIBGUI_ASSERT_GL_OK(); + GLfloat fogcol[4] = { .54f, .54f, .54f, 1 }; /** @@ -246,13 +247,18 @@ void Sys_GLConfigureDefaultState(void) DENG_ASSERT_GL_CONTEXT_ACTIVE(); LIBGUI_GL.glFrontFace(GL_CW); + LIBGUI_ASSERT_GL_OK(); + de::GLState::current() .setCull(de::gl::None) .setDepthTest(false) .setDepthFunc(de::gl::Less); DGL_Disable(DGL_TEXTURE_2D); - LIBGUI_GL.glDisable(GL_TEXTURE_CUBE_MAP); + //LIBGUI_GL.glDisable(GL_TEXTURE_CUBE_MAP); + + LIBGUI_GL.glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); + LIBGUI_ASSERT_GL_OK(); // The projection matrix. DGL_MatrixMode(DGL_PROJECTION); @@ -268,12 +274,16 @@ void Sys_GLConfigureDefaultState(void) // Setup for antialiased lines/points. LIBGUI_GL.glEnable(GL_LINE_SMOOTH); + LIBGUI_ASSERT_GL_OK(); LIBGUI_GL.glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - LIBGUI_GL.glLineWidth(GL_state.currentLineWidth); + LIBGUI_ASSERT_GL_OK(); + + de::GLInfo::setLineWidth(GL_state.currentLineWidth); - LIBGUI_GL.glEnable(GL_POINT_SMOOTH); - LIBGUI_GL.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + //LIBGUI_GL.glEnable(GL_POINT_SMOOTH); + //LIBGUI_GL.glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); LIBGUI_GL.glPointSize(GL_state.currentPointSize); + LIBGUI_ASSERT_GL_OK(); //LIBGUI_GL.glShadeModel(GL_SMOOTH); @@ -283,11 +293,13 @@ void Sys_GLConfigureDefaultState(void) Deferred_glFogi(GL_FOG_END, 2100); // This should be tweaked a bit. Deferred_glFogfv(GL_FOG_COLOR, fogcol); - LIBGUI_GL.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + LIBGUI_ASSERT_GL_OK(); // Prefer good quality in texture compression. LIBGUI_GL.glHint(GL_TEXTURE_COMPRESSION_HINT, GL_NICEST); + LIBGUI_ASSERT_GL_OK(); + // Configure the default GLState (bottom of the stack). de::GLState::current() .setBlendFunc(de::gl::SrcAlpha, de::gl::OneMinusSrcAlpha) @@ -370,17 +382,11 @@ void Sys_GLPrintExtensions(void) */ } -dd_bool Sys_GLCheckError() +dd_bool Sys_GLCheckErrorArgs(char const *file, int line) { + if (novideo) return false; #ifdef DENG_DEBUG - if(!novideo) - { - GLenum error = LIBGUI_GL.glGetError(); - if(error != GL_NO_ERROR) - { - LOGDEV_GL_ERROR("OpenGL error: 0x%x") << error; - } - } + de::GLInfo::checkError(file, line); #endif return false; } diff --git a/doomsday/apps/client/src/render/rend_main.cpp b/doomsday/apps/client/src/render/rend_main.cpp index 0a32b24962..371843f995 100644 --- a/doomsday/apps/client/src/render/rend_main.cpp +++ b/doomsday/apps/client/src/render/rend_main.cpp @@ -284,7 +284,7 @@ dint rendMaxLumobjs; ///< Max lumobjs per viewer, per frame. @c 0= n dint extraLight; ///< Bumped light from gun blasts. dfloat extraLightDelta; -DGLuint dlBBox; ///< Display list id for the active-textured bbox model. +//DGLuint dlBBox; ///< Display list id for the active-textured bbox model. /* * Debug/Development cvars: @@ -406,11 +406,11 @@ void Rend_Reset() { App_World().map().removeAllLumobjs(); } - if (dlBBox) - { - GL_DeleteLists(dlBBox, 1); - dlBBox = 0; - } +// if (dlBBox) +// { +// GL_DeleteLists(dlBBox, 1); +// dlBBox = 0; +// } } bool Rend_IsMTexLights() @@ -5166,47 +5166,47 @@ void Rend_DrawLightModMatrix() #undef BLOCK_WIDTH } -static DGLuint constructBBox(DGLuint name, dfloat br) +static void drawBBox(dfloat br) { - if(GL_NewList(name, GL_COMPILE)) +// if(GL_NewList(name, GL_COMPILE)) +// { + DGL_Begin(DGL_QUADS); { - DGL_Begin(DGL_QUADS); - { - // Top - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br, 1.0f,-1.0f-br); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br, 1.0f,-1.0f-br); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br, 1.0f, 1.0f+br); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br, 1.0f, 1.0f+br); // BR - // Bottom - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br,-1.0f, 1.0f+br); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br,-1.0f, 1.0f+br); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br,-1.0f,-1.0f-br); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br,-1.0f,-1.0f-br); // BR - // Front - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br, 1.0f+br, 1.0f); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br, 1.0f+br, 1.0f); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br,-1.0f-br, 1.0f); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br,-1.0f-br, 1.0f); // BR - // Back - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br,-1.0f-br,-1.0f); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br,-1.0f-br,-1.0f); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br, 1.0f+br,-1.0f); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br, 1.0f+br,-1.0f); // BR - // Left - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f(-1.0f, 1.0f+br, 1.0f+br); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f, 1.0f+br,-1.0f-br); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f,-1.0f-br,-1.0f-br); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f(-1.0f,-1.0f-br, 1.0f+br); // BR - // Right - DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f, 1.0f+br,-1.0f-br); // TR - DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f( 1.0f, 1.0f+br, 1.0f+br); // TL - DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f( 1.0f,-1.0f-br, 1.0f+br); // BL - DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f,-1.0f-br,-1.0f-br); // BR - } - DGL_End(); - return GL_EndList(); + // Top + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br, 1.0f,-1.0f-br); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br, 1.0f,-1.0f-br); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br, 1.0f, 1.0f+br); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br, 1.0f, 1.0f+br); // BR + // Bottom + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br,-1.0f, 1.0f+br); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br,-1.0f, 1.0f+br); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br,-1.0f,-1.0f-br); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br,-1.0f,-1.0f-br); // BR + // Front + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br, 1.0f+br, 1.0f); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br, 1.0f+br, 1.0f); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br,-1.0f-br, 1.0f); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br,-1.0f-br, 1.0f); // BR + // Back + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f+br,-1.0f-br,-1.0f); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f-br,-1.0f-br,-1.0f); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f-br, 1.0f+br,-1.0f); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f+br, 1.0f+br,-1.0f); // BR + // Left + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f(-1.0f, 1.0f+br, 1.0f+br); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f(-1.0f, 1.0f+br,-1.0f-br); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f(-1.0f,-1.0f-br,-1.0f-br); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f(-1.0f,-1.0f-br, 1.0f+br); // BR + // Right + DGL_TexCoord2f(0, 1.0f, 1.0f); DGL_Vertex3f( 1.0f, 1.0f+br,-1.0f-br); // TR + DGL_TexCoord2f(0, 0.0f, 1.0f); DGL_Vertex3f( 1.0f, 1.0f+br, 1.0f+br); // TL + DGL_TexCoord2f(0, 0.0f, 0.0f); DGL_Vertex3f( 1.0f,-1.0f-br, 1.0f+br); // BL + DGL_TexCoord2f(0, 1.0f, 0.0f); DGL_Vertex3f( 1.0f,-1.0f-br,-1.0f-br); // BR } - return 0; + DGL_End(); + // return GL_EndList(); + //} + //return 0; } /** @@ -5242,7 +5242,8 @@ void Rend_DrawBBox(Vector3d const &pos, coord_t w, coord_t l, coord_t h, DGL_Scalef(w - br - br, h - br - br, l - br - br); DGL_Color4f(color[0], color[1], color[2], alpha); - GL_CallList(dlBBox); + //GL_CallList(dlBBox); + drawBBox(.08f); DGL_MatrixMode(DGL_MODELVIEW); DGL_PopMatrix(); @@ -5259,7 +5260,7 @@ void Rend_DrawBBox(Vector3d const &pos, coord_t w, coord_t l, coord_t h, * @param alpha Alpha to make the box (uniform vertex color). */ void Rend_DrawArrow(Vector3d const &pos, dfloat a, dfloat s, dfloat const color[3], - dfloat alpha) + dfloat alpha) { DGL_MatrixMode(DGL_MODELVIEW); DGL_PushMatrix(); @@ -5346,8 +5347,8 @@ static void drawMobjBoundingBoxes(Map &map) if(netGame) return; #endif - if(!dlBBox) - dlBBox = constructBBox(0, .08f); +// if(!dlBBox) +// dlBBox = constructBBox(0, .08f); GLState::current().setDepthTest(false).apply(); DGL_Enable(DGL_TEXTURE_2D); diff --git a/doomsday/apps/client/src/ui/zonedebug.cpp b/doomsday/apps/client/src/ui/zonedebug.cpp index 6f1319df21..36238a9d0f 100644 --- a/doomsday/apps/client/src/ui/zonedebug.cpp +++ b/doomsday/apps/client/src/ui/zonedebug.cpp @@ -89,7 +89,7 @@ void Z_DebugDrawVolume(MemoryZonePrivateData *pd, memvolume_t *volume, Rectangle GL_DrawRect(rect); // Outline. - LIBGUI_GL.glLineWidth(1); + GLInfo::setLineWidth(1); DGL_Color4f(1, 1, 1, opacity/2); LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); GL_DrawRect(rect); @@ -125,7 +125,7 @@ void Z_DebugDrawVolume(MemoryZonePrivateData *pd, memvolume_t *volume, Rectangle if (pd->isVolumeTooFull(volume)) { - LIBGUI_GL.glLineWidth(2); + GLInfo::setLineWidth(2); DGL_Color4f(1, 0, 0, 1); LIBGUI_GL.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); GL_DrawRect(rect);