Quadtree Rendering for CPU transorm+render
[ipdf/code.git] / src / objectrenderer.cpp
index 86b6430..f5202cb 100644 (file)
@@ -32,9 +32,9 @@ ObjectRenderer::ObjectRenderer(const ObjectType & type,
 void ObjectRenderer::RenderUsingGPU(unsigned first_obj_id, unsigned last_obj_id)
 {
        unsigned first_index = 0;
 void ObjectRenderer::RenderUsingGPU(unsigned first_obj_id, unsigned last_obj_id)
 {
        unsigned first_index = 0;
-       while (m_indexes[first_index] < first_obj_id*2) first_index += 2;
+       while (m_indexes[first_index] < first_obj_id) first_index ++;
        unsigned last_index = first_index;
        unsigned last_index = first_index;
-       while (m_indexes[last_index] < last_obj_id*2) last_index += 2;
+       while (m_indexes[last_index] < last_obj_id) last_index ++;
 
        m_shader_program.Use();
        m_ibo.Bind();
 
        m_shader_program.Use();
        m_ibo.Bind();
@@ -45,7 +45,7 @@ void ObjectRenderer::RenderUsingGPU(unsigned first_obj_id, unsigned last_obj_id)
 /**
  * Default implementation for rendering using CPU
  */
 /**
  * Default implementation for rendering using CPU
  */
-void ObjectRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target)
+void ObjectRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target, unsigned first_obj_id, unsigned last_obj_id)
 {
        Error("Cannot render objects of type %d on CPU", m_type);
        //TODO: Render a rect or something instead?
 {
        Error("Cannot render objects of type %d on CPU", m_type);
        //TODO: Render a rect or something instead?
@@ -110,10 +110,12 @@ void ObjectRenderer::FinaliseBuffers()
 /**
  * Rectangle (filled)
  */
 /**
  * Rectangle (filled)
  */
-void RectFilledRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target)
+void RectFilledRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target, unsigned first_obj_id, unsigned last_obj_id)
 {
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
 {
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
+               if (m_indexes[i] < first_obj_id) continue;
+               if (m_indexes[i] >= last_obj_id) continue;
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                for (int64_t x = max(0L, bounds.x); x <= min(bounds.x+bounds.w, target.w-1); ++x)
                {
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                for (int64_t x = max(0L, bounds.x); x <= min(bounds.x+bounds.w, target.w-1); ++x)
                {
@@ -132,11 +134,13 @@ void RectFilledRenderer::RenderUsingCPU(const Objects & objects, const View & vi
 /**
  * Rectangle (outine)
  */
 /**
  * Rectangle (outine)
  */
-void RectOutlineRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target)
+void RectOutlineRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target, unsigned first_obj_id, unsigned last_obj_id)
 {
        //Debug("Render %u outlined rectangles on CPU", m_indexes.size());
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
 {
        //Debug("Render %u outlined rectangles on CPU", m_indexes.size());
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
+               if (m_indexes[i] < first_obj_id) continue;
+               if (m_indexes[i] >= last_obj_id) continue;
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                
                // Using bresenham's lines now mainly because I want to see if they work
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                
                // Using bresenham's lines now mainly because I want to see if they work
@@ -158,10 +162,12 @@ void RectOutlineRenderer::RenderUsingCPU(const Objects & objects, const View & v
 /**
  * Circle (filled)
  */
 /**
  * Circle (filled)
  */
-void CircleFilledRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target)
+void CircleFilledRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target, unsigned first_obj_id, unsigned last_obj_id)
 {
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
 {
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
+               if (m_indexes[i] < first_obj_id) continue;
+               if (m_indexes[i] >= last_obj_id) continue;
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                int64_t centre_x = bounds.x + bounds.w / 2;
                int64_t centre_y = bounds.y + bounds.h / 2;
                PixelBounds bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                int64_t centre_x = bounds.x + bounds.w / 2;
                int64_t centre_y = bounds.y + bounds.h / 2;
@@ -205,11 +211,13 @@ Rect ObjectRenderer::CPURenderBounds(const Rect & bounds, const View & view, con
  * Bezier curve
  * Not sure how to apply De'Casteljau, will just use a bunch of Bresnham lines for now.
  */
  * Bezier curve
  * Not sure how to apply De'Casteljau, will just use a bunch of Bresnham lines for now.
  */
-void BezierRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target)
+void BezierRenderer::RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target, unsigned first_obj_id, unsigned last_obj_id)
 {
        //Warn("Rendering Beziers on CPU. Things may explode.");
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
 {
        //Warn("Rendering Beziers on CPU. Things may explode.");
        for (unsigned i = 0; i < m_indexes.size(); ++i)
        {
+               if (m_indexes[i] < first_obj_id) continue;
+               if (m_indexes[i] >= last_obj_id) continue;
                Rect bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                PixelBounds pix_bounds(bounds);
 
                Rect bounds(CPURenderBounds(objects.bounds[m_indexes[i]], view, target));
                PixelBounds pix_bounds(bounds);
 
@@ -297,9 +305,9 @@ void BezierRenderer::RenderUsingGPU(unsigned first_obj_id, unsigned last_obj_id)
                Warn("Shader is invalid (objects are of type %d)", m_type);
 
        unsigned first_index = 0;
                Warn("Shader is invalid (objects are of type %d)", m_type);
 
        unsigned first_index = 0;
-       while (m_indexes[first_index] < first_obj_id*2) first_index += 2;
+       while (m_indexes[first_index] < first_obj_id) first_index ++;
        unsigned last_index = first_index;
        unsigned last_index = first_index;
-       while (m_indexes[last_index] < last_obj_id*2) last_index += 2;
+       while (m_indexes[last_index] < last_obj_id) last_index ++;
 
        m_shader_program.Use();
        glUniform1i(m_shader_program.GetUniformLocation("bezier_buffer_texture"), 0);
 
        m_shader_program.Use();
        glUniform1i(m_shader_program.GetUniformLocation("bezier_buffer_texture"), 0);

UCC git Repository :: git.ucc.asn.au