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);
enum ogl_LoadStatus
{
ogl_LOAD_FAILED = 0,
- ogl_LOAD_SUCCEEDED = 1,
+ ogl_LOAD_SUCCEEDED = 1
};
int ogl_LoadFunctions();
private:
- Gmpint(const mpz_t & op) : m_op(op) {}
mpz_t m_op;
};
{
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;
Bind();
glUnmapBuffer(target);
- m_map_pointer = nullptr;
+ m_map_pointer = NULL;
m_invalidated = false;
}
Bind();
glBufferData(target, length, data, usage);
}
- if (data != nullptr)
+ if (data != NULL)
m_invalidated = false;
}
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);
BufferTypePixelUnpack,
BufferTypeUniform, // Uniform/Constant buffer
BufferTypeTexture, // I was hoping to avoid this one.
- BufferTypeDrawIndirect,
+ BufferTypeDrawIndirect
};
enum BufferUsage
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;
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;
m_bezier_coeffs.Resize(objects.beziers.size()*sizeof(GPUBezierCoeffs));
BufferBuilder<GPUBezierCoeffs> 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);
}
m_debug_font_atlas = 0;
+ m_view = NULL;
ResizeViewport(800, 600);
Clear();
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:
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:
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);
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<fontvertex> 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<uint16_t> 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));
namespace IPDF
{
+ class View;
/*
* The "Screen" class handles managing the OS window (using SDL2).
*/
void DebugFontPrintF(const char *fmt, ...);
// Handle mouse input.
- typedef std::function<void(int x, int y, int button, int wheel)> MouseHandler;
+ typedef void(*MouseHandler)(int x, int y, int button, int wheel, Screen * scr, View * view);
void SetMouseHandler(MouseHandler handler)
{
m_mouse_handler = handler;
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(); }
GraphicsBuffer m_debug_font_indices;
int m_debug_font_vertex_head;
int m_debug_font_index_head;
+ View * m_view;
};
}
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)
{
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;
}
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());
}
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;
}
{
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();