From: Sam Moore Date: Fri, 25 Jul 2014 05:03:15 +0000 (+0800) Subject: Get it compiling on Cabellera (g++0x not c++11) X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=f71f97f4fd251d02882ace4be3ead033ced434c4 Get it compiling on Cabellera (g++0x not c++11) ... But at what cost? --- diff --git a/src/framebuffer.cpp b/src/framebuffer.cpp index 2f5005e..f3b1bd9 100644 --- a/src/framebuffer.cpp +++ b/src/framebuffer.cpp @@ -16,7 +16,7 @@ void FrameBuffer::Create(int w, int h) glGenFramebuffers(1, &m_render_fbo); glBindTexture(GL_TEXTURE_2D, m_render_texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glBindFramebuffer(GL_FRAMEBUFFER, m_render_fbo); diff --git a/src/gl_core44.h b/src/gl_core44.h index ba88224..da9f003 100644 --- a/src/gl_core44.h +++ b/src/gl_core44.h @@ -2630,7 +2630,7 @@ extern void (CODEGEN_FUNCPTR *_ptrc_glClearTexSubImage)(GLuint, GLint, GLint, GL enum ogl_LoadStatus { ogl_LOAD_FAILED = 0, - ogl_LOAD_SUCCEEDED = 1, + ogl_LOAD_SUCCEEDED = 1 }; int ogl_LoadFunctions(); diff --git a/src/gmpint.h b/src/gmpint.h index 4f45231..f39cd51 100644 --- a/src/gmpint.h +++ b/src/gmpint.h @@ -55,7 +55,6 @@ class Gmpint private: - Gmpint(const mpz_t & op) : m_op(op) {} mpz_t m_op; }; diff --git a/src/graphicsbuffer.cpp b/src/graphicsbuffer.cpp index 576c2d6..712caf8 100644 --- a/src/graphicsbuffer.cpp +++ b/src/graphicsbuffer.cpp @@ -190,7 +190,7 @@ void GraphicsBuffer::UnMap() { Upload(m_buffer_size, m_map_pointer); free(m_map_pointer); - m_map_pointer = nullptr; + m_map_pointer = NULL; m_invalidated = false; m_faking_map = false; return; @@ -198,7 +198,7 @@ void GraphicsBuffer::UnMap() Bind(); glUnmapBuffer(target); - m_map_pointer = nullptr; + m_map_pointer = NULL; m_invalidated = false; } @@ -215,7 +215,7 @@ void GraphicsBuffer::Upload(size_t length, const void* data) Bind(); glBufferData(target, length, data, usage); } - if (data != nullptr) + if (data != NULL) m_invalidated = false; } @@ -242,7 +242,7 @@ void GraphicsBuffer::Resize(size_t length) UnMap(); GLuint old_buffer = m_buffer_handle; glGenBuffers(1, &m_buffer_handle); - Upload(length, nullptr); + Upload(length, NULL); glBindBuffer(GL_COPY_READ_BUFFER, old_buffer); glBindBuffer(GL_COPY_WRITE_BUFFER, m_buffer_handle); glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER, 0, 0, m_buffer_size); diff --git a/src/graphicsbuffer.h b/src/graphicsbuffer.h index 3dbb6fb..4665345 100644 --- a/src/graphicsbuffer.h +++ b/src/graphicsbuffer.h @@ -21,7 +21,7 @@ namespace IPDF BufferTypePixelUnpack, BufferTypeUniform, // Uniform/Constant buffer BufferTypeTexture, // I was hoping to avoid this one. - BufferTypeDrawIndirect, + BufferTypeDrawIndirect }; enum BufferUsage @@ -64,7 +64,7 @@ namespace IPDF void Bind() const; private: - bool RecreateBuffer(const void *data = nullptr); + bool RecreateBuffer(const void *data = NULL); GLuint m_buffer_handle; BufferType m_buffer_type; BufferUsage m_buffer_usage; diff --git a/src/main.h b/src/main.h index 43d195f..ee78f59 100644 --- a/src/main.h +++ b/src/main.h @@ -22,66 +22,69 @@ inline void OverlayBMP(Document & doc, const char * input, const char * output, scr.Present(); } -inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f)) +// It is the only way. +void RatCatcher(int x, int y, int buttons, int wheel, Screen * scr, View * view) { - // order is important... segfaults occur when screen (which inits GL) is not constructed first -_- - Screen scr; - View view(doc,scr, bounds, c); - scr.DebugFontInit("DejaVuSansMono.ttf"); - scr.SetMouseHandler([&](int x, int y, int buttons, int wheel) // [?] seriously WTF + static bool oldButtonDown = false; + static int oldx, oldy; + if (buttons == 3 && !oldButtonDown) { - static bool oldButtonDown = false; - static int oldx, oldy; - if (buttons == 3 && !oldButtonDown) - { - oldButtonDown = true; - view.ToggleGPUTransform(); - oldx = x; - oldy = y; - return; - } - if (buttons == 2 && !oldButtonDown) - { - oldButtonDown = true; - view.ToggleGPURendering(); - oldx = x; - oldy = y; - } - if (buttons && !oldButtonDown) - { - // We're beginning a drag. - oldButtonDown = true; - oldx = x; - oldy = y; - scr.SetMouseCursor(Screen::CursorMove); - } - if (buttons) - { - #if REAL >= REAL_RATIONAL - view.Translate(Real(oldx, scr.ViewportWidth()) -Real(x,scr.ViewportWidth()), Real(oldy, scr.ViewportHeight()) - Real(y,scr.ViewportHeight())); - #else - view.Translate(Real(oldx-x)/Real(scr.ViewportWidth()), Real(oldy-y)/Real(scr.ViewportHeight())); - #endif - } - else - { - oldButtonDown = false; - scr.SetMouseCursor(Screen::CursorArrow); - } + oldButtonDown = true; + view->ToggleGPUTransform(); oldx = x; oldy = y; + return; + } + if (buttons == 2 && !oldButtonDown) + { + oldButtonDown = true; + view->ToggleGPURendering(); + oldx = x; + oldy = y; + } + if (buttons && !oldButtonDown) + { + // We're beginning a drag. + oldButtonDown = true; + oldx = x; + oldy = y; + scr->SetMouseCursor(Screen::CursorMove); + } + if (buttons) + { + #if REAL >= REAL_RATIONAL + view->Translate(Real(oldx, scr->ViewportWidth()) -Real(x,scr->ViewportWidth()), Real(oldy, scr->ViewportHeight()) - Real(y,scr->ViewportHeight())); + #else + view->Translate(Real(oldx-x)/Real(scr->ViewportWidth()), Real(oldy-y)/Real(scr->ViewportHeight())); + #endif + } + else + { + oldButtonDown = false; + scr->SetMouseCursor(Screen::CursorArrow); + } + oldx = x; + oldy = y; - if (wheel) - { - #if REAL >= REAL_RATIONAL - view.ScaleAroundPoint(Real(x,scr.ViewportWidth()), Real(y,scr.ViewportHeight()), Real(20-wheel, 20)); - #else - view.ScaleAroundPoint(Real(x)/Real(scr.ViewportWidth()),Real(y)/Real(scr.ViewportHeight()), Real(expf(-wheel/20.f))); - #endif - - } + if (wheel) + { + #if REAL >= REAL_RATIONAL + view->ScaleAroundPoint(Real(x,scr->ViewportWidth()), Real(y,scr->ViewportHeight()), Real(20-wheel, 20)); + #else + view->ScaleAroundPoint(Real(x)/Real(scr->ViewportWidth()),Real(y)/Real(scr->ViewportHeight()), Real(expf(-wheel/20.f))); + #endif + } - ); +} + + +inline void MainLoop(Document & doc, const Rect & bounds = Rect(0,0,1,1), const Colour & c = Colour(0.f,0.f,0.f,1.f)) +{ + // order is important... segfaults occur when screen (which inits GL) is not constructed first -_- + Screen scr; + View view(doc,scr, bounds, c); + scr.DebugFontInit("DejaVuSansMono.ttf"); + scr.SetMouseHandler(RatCatcher); double total_cpu_time = 0; double total_gpu_time = 0; diff --git a/src/objectrenderer.cpp b/src/objectrenderer.cpp index f5202cb..a5cd625 100644 --- a/src/objectrenderer.cpp +++ b/src/objectrenderer.cpp @@ -274,12 +274,12 @@ void BezierRenderer::PrepareBezierGPUBuffer(const Objects& objects) m_bezier_coeffs.Resize(objects.beziers.size()*sizeof(GPUBezierCoeffs)); BufferBuilder builder(m_bezier_coeffs.Map(false, true, true), m_bezier_coeffs.GetSize()); - for (auto bez : objects.beziers) + for (auto bez = objects.beziers.begin(); bez != objects.beziers.end(); ++bez) { GPUBezierCoeffs coeffs = { - Float(bez.x0), Float(bez.y0), - Float(bez.x1 - bez.x0), Float(bez.y1 - bez.y0), - Float(bez.x2 - bez.x0), Float(bez.y2 - bez.y0) + Float(bez->x0), Float(bez->y0), + Float(bez->x1 - bez->x0), Float(bez->y1 - bez->y0), + Float(bez->x2 - bez->x0), Float(bez->y2 - bez->y0) }; builder.Add(coeffs); } diff --git a/src/screen.cpp b/src/screen.cpp index fdda252..3bbf008 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -89,6 +89,7 @@ Screen::Screen() m_debug_font_atlas = 0; + m_view = NULL; ResizeViewport(800, 600); Clear(); @@ -145,7 +146,7 @@ bool Screen::PumpEvents() m_last_mouse_y = evt.motion.y; if (m_mouse_handler) { - m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0); + m_mouse_handler(evt.motion.x, evt.motion.y,evt.motion.state, 0, this, m_view); } break; case SDL_MOUSEBUTTONDOWN: @@ -154,13 +155,13 @@ bool Screen::PumpEvents() m_last_mouse_y = evt.button.y; if (m_mouse_handler) { - m_mouse_handler(evt.button.x, evt.button.y, evt.button.state?evt.button.button:0, 0); + m_mouse_handler(evt.button.x, evt.button.y, evt.button.state?evt.button.button:0, 0, this, m_view); } break; case SDL_MOUSEWHEEL: if (m_mouse_handler) { - m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y); + m_mouse_handler(m_last_mouse_x, m_last_mouse_y, 0, evt.wheel.y, this, m_view); } break; case SDL_KEYDOWN: @@ -390,7 +391,7 @@ void Screen::DebugFontInit(const char *name, float font_size) m_debug_font_vertices.SetUsage(GraphicsBuffer::BufferUsageStreamDraw); m_debug_font_vertices.SetType(GraphicsBuffer::BufferTypeVertex); - m_debug_font_vertices.Upload(8192, nullptr); + m_debug_font_vertices.Upload(8192,NULL); m_debug_font_vertex_head = 0; m_debug_font_indices.SetUsage(GraphicsBuffer::BufferUsageStreamDraw); @@ -438,14 +439,15 @@ void Screen::DebugFontFlush() m_debug_font_index_head = 0; } +struct fontvertex +{ + float x, y, s, t; +}; + void Screen::DebugFontPrint(const char* str) { if (!m_debug_font_atlas) return; - struct fontvertex - { - float x, y, s, t; - }; BufferBuilder vertexData(m_debug_font_vertices.MapRange(m_debug_font_vertex_head*sizeof(float), m_debug_font_vertices.GetSize() - m_debug_font_vertex_head*sizeof(float), false, true, true), m_debug_font_vertices.GetSize() - m_debug_font_vertex_head*sizeof(float)); BufferBuilder indexData(m_debug_font_indices.MapRange(m_debug_font_index_head*sizeof(uint16_t), m_debug_font_indices.GetSize() - m_debug_font_index_head*sizeof(uint16_t), false, true, true), m_debug_font_indices.GetSize() - m_debug_font_index_head*sizeof(uint16_t)); diff --git a/src/screen.h b/src/screen.h index 9666c32..2d28db2 100644 --- a/src/screen.h +++ b/src/screen.h @@ -11,6 +11,7 @@ namespace IPDF { + class View; /* * The "Screen" class handles managing the OS window (using SDL2). */ @@ -41,7 +42,7 @@ namespace IPDF void DebugFontPrintF(const char *fmt, ...); // Handle mouse input. - typedef std::function MouseHandler; + typedef void(*MouseHandler)(int x, int y, int button, int wheel, Screen * scr, View * view); void SetMouseHandler(MouseHandler handler) { m_mouse_handler = handler; @@ -62,6 +63,7 @@ namespace IPDF void RenderPixels(int x, int y, int w, int h, uint8_t * pixels) const; + void SetView(View * new_view) {m_view = new_view;} // Returns the CPU time (in seconds) it took to render the last completed frame. double GetLastFrameTimeCPU() const { return m_last_frame_time / SDL_GetPerformanceFrequency(); } @@ -97,6 +99,7 @@ namespace IPDF GraphicsBuffer m_debug_font_indices; int m_debug_font_vertex_head; int m_debug_font_index_head; + View * m_view; }; } diff --git a/src/shaderprogram.cpp b/src/shaderprogram.cpp index 0a5cb2e..45f4585 100644 --- a/src/shaderprogram.cpp +++ b/src/shaderprogram.cpp @@ -47,10 +47,10 @@ bool ShaderProgram::InitialiseShaders(const char * vertex_file, const char * fra ShaderProgram::~ShaderProgram() { m_valid = false; - for(auto shader : m_shaders) + for(auto shader = m_shaders.begin(); shader != m_shaders.end(); ++shader) { - glDetachShader(m_program, shader.obj); - glDeleteShader(shader.obj); + glDetachShader(m_program, shader->obj); + glDeleteShader(shader->obj); } if (m_program) @@ -121,7 +121,7 @@ bool ShaderProgram::AttachShader(const char * src_file, GLenum type) { char info_log[2048]; - glGetShaderInfoLog(shader_obj, 2048, nullptr, info_log); + glGetShaderInfoLog(shader_obj, 2048, NULL, info_log); Error("Shader compile error (file \"%s\"): %s (type %d)", src_file, info_log, type); return false; } diff --git a/src/vfpu.cpp b/src/vfpu.cpp index 8783ca1..18e1bde 100644 --- a/src/vfpu.cpp +++ b/src/vfpu.cpp @@ -114,9 +114,10 @@ float Exec(float opa, float opb, Opcode op, Rmode rmode) Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode) { assert(g_running); - + Fatal("Unsupported"); stringstream s; - s << hex << setw(8) << setfill('0') << a.to_ullong() << "\n" << b.to_ullong() << "\n" << setw(1) << op <<"\n" << setw(1) << rmode << "\n"; + //TODO: Make it compile again + //s << hex << setw(8) << setfill('0') << a.to_ullong() << "\n" << b.to_ullong() << "\n" << setw(1) << op <<"\n" << setw(1) << rmode << "\n"; string str(s.str()); //Debug("Writing: %s", str.c_str()); @@ -138,7 +139,8 @@ Register Exec(const Register & a, const Register & b, Opcode op, Rmode rmode) } stringstream s2; - s2 << hex << result.to_ullong(); + //TODO: Make it comp[ile again + //s2 << hex << result.to_ullong(); //Debug("Result is: %s", s2.str().c_str()); return result; } diff --git a/src/view.cpp b/src/view.cpp index 4a7bb08..1fe0728 100644 --- a/src/view.cpp +++ b/src/view.cpp @@ -20,6 +20,8 @@ View::View(Document & document, Screen & screen, const Rect & bounds, const Colo { Debug("View Created - Bounds => {%s}", m_bounds.Str().c_str()); + screen.SetView(this); // oh dear... + // Create ObjectRenderers - new's match delete's in View::~View //TODO: Don't forget to put new renderers here or things will be segfaultastic m_object_renderers[RECT_FILLED] = new RectFilledRenderer();