X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fobjectrenderer.h;h=6f29add264b9572930b9a7b1975882c4c380b553;hp=0790d851a5d57fa51565eaddda918316b43d3ad2;hb=33356addacfe4296ecb613c6c4696f082e351159;hpb=cfe7da763b5d8ef4252ddb94558abb080bbd893d diff --git a/src/objectrenderer.h b/src/objectrenderer.h index 0790d85..6f29add 100644 --- a/src/objectrenderer.h +++ b/src/objectrenderer.h @@ -19,8 +19,8 @@ namespace IPDF * Includes GPU rendering and CPU rendering * For GPU rendering, pass GLSL shader source files to constructor in the constructor of a base class * To leave unimplemented, just pass NULL filename strings - * For CPU rendering, implement RenderUsingCPU in the base class - * To leave unimplemented, just call ObjectRenderer::RenderUsingCPU in the base class + * For CPU rendering, implement RenderUsingCPU in the derived class + * To leave unimplemented, just call ObjectRenderer::RenderUsingCPU in the derived class * The View class uses ObjectRenderer's; see view.h */ class ObjectRenderer @@ -34,7 +34,7 @@ namespace IPDF * Use the GPU to render the objects - GLSL shader approach * This way is definitely faster, but subject to the GPU's limitations on precision */ - void RenderUsingGPU(); + virtual void RenderUsingGPU(); /** * Use the CPU to render the objects - "make a bitmap and convert it to a texture" approach @@ -44,15 +44,18 @@ namespace IPDF struct CPURenderTarget { uint8_t * pixels; - int w; - int h; + int64_t w; + int64_t h; }; - struct CPURenderBounds + struct PixelBounds { - int x; int y; int w; int h; - CPURenderBounds(const Rect & bounds, const View & view, const CPURenderTarget & target); + int64_t x; int64_t y; int64_t w; int64_t h; + PixelBounds(const Rect & bounds) : x(Double(bounds.x)), y(Double(bounds.y)), w(Double(bounds.w)), h(Double(bounds.h)) {} }; + static Rect CPURenderBounds(const Rect & bounds, const View & view, const CPURenderTarget & target); + + static void SaveBMP(const CPURenderTarget & target, const char * filename); @@ -66,7 +69,9 @@ namespace IPDF void PrepareBuffers(unsigned max_size); void FinaliseBuffers(); void AddObjectToBuffers(unsigned index); - + + /** Helper for CPU rendering that will render a line using Bresenham's algorithm. Do not use the transpose argument. **/ + static void RenderLineOnCPU(int64_t x0, int64_t y0, int64_t x1, int64_t y1, const CPURenderTarget & target, const Colour & colour = Colour(0,0,0,1), bool transpose = false); ShaderProgram m_shader_program; /** GLSL shaders for GPU **/ GraphicsBuffer m_ibo; /** Index Buffer Object for GPU rendering **/ @@ -98,6 +103,30 @@ namespace IPDF virtual ~CircleFilledRenderer() {} virtual void RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target); }; + + /** Renderer for bezier curves **/ + class BezierRenderer : public ObjectRenderer + { + public: + BezierRenderer() : ObjectRenderer(BEZIER, "shaders/rect_vert.glsl", "shaders/rect_frag.glsl", "shaders/bezier_texbuf_geom.glsl") {} + virtual ~BezierRenderer() {} + virtual void RenderUsingGPU(); + virtual void RenderUsingCPU(const Objects & objects, const View & view, const CPURenderTarget & target); + void PrepareBezierGPUBuffer(const Objects & objects); + private: + GraphicsBuffer m_bezier_coeffs; + GraphicsBuffer m_bezier_ids; + struct GPUBezierCoeffs + { + float x0, y0; + float x1, y1; + float x2, y2; + }; + + GLuint m_bezier_buffer_texture; + GLuint m_bezier_id_buffer_texture; + + }; } #endif //_OBJECT_RENDERER_H