LibreCAD 3 OpenGL Rendering – GSoC “Phase 1”

Hello Everyone,

This year’s LibreCAD GSoC project involves the integrating pure OpenGL rendering module in “LibreCAD version 3”. Before the official coding period began i did a lot of research work , discussions with mentors regarding the project , did some setup and implemented some basic things. Initially with the research work and planning the project seems to be very challenging.
The overall thing about rendering module involves to manage data in CPU and GPU as well. Manipulation like Sending, saving , deleting the data corresponding to entities in CAD kernel of LibreCAD 3.
–>The major milestones in “Phase 1” planned and finished are —-

Follow the LcPainter layout for OpenGLpainter
First challenge was to design the OpenGL Rendering module so that the rendering draw() codes should not be hindered and follow the LcPainter layout. For this thing I designed a number of classes . The most important are gl_entity( The one which hold the data in CPU and GPU) , renderer ( The one which actually builds the gl_entities ) , LcOpenGLPainter ( It is the uppermost layer which implements LcPainter )

Matrix manipulations and context saving
The Renderer have the projection and view matrix. There is also a CTM ( Current transition matrix) used for transitions. There is also case of Isolated Transitions for which i implemented the context saving using stack implementation which saves and restores context.

Correct viewport & Coordinate System
Basically there are two coordinate system. First the Device Coordinate System (Downward Y as +ve) and the second is the User Coordinate System(Downward Y as -ve). Implemented multiple functions that convert Device to user Coordinates and vice versa using manipulations on CTM.

Caching Mechanism
This was the biggest challenge to cache the entities. Basically the idea was to don’t go through the draw() code of entities again and again. This will stop the repetitive sending of data from CPU to GPU. The entities in LibreCAD can be simple(line,circle,..) to complex (dimensions etc..) . For thing i implemented separate classes gl_pack (to store gl_entities), cacher (which generates gl_pack and save them with an ID= entity id in kernel), cacherpainter which also implements LcPainter and used for caching but it doesn’t render anything, it only saves data.
When an entity is already cached it is then rendered using already saved cached gl_pack

Gradient Rendering
Besides Shape Entities there are possibility of entities which have gradient ( mostly gradient background..which uses linear gradient).For this i created a class Gradient_Entity which also implements gl_entity. It holds data of linear gradient and calculates the (R,G,B,A) data for each vertex using some vector mathematics ( dot product , scalar projection etc

So Phase 1 is finished and below is a comparison of Cairo (Existing) and opengl rendering (implemented till Phase 1 ) in LibreCAD 3

Using existing Cairo graphics
Using the OpenGL Rendering module ( partially implemented till now )

The upcoming challenges are Shader based Linepatterns, dashes and Text Rendering.

Overall within 1st Phase alot of work happened and i really thank my mentors Armin and Florian . They always help me , discuss almost every doubt before writing code , gave me ideas whenever i got stuck during coding and keeping a cool environment.
GSoc Dev Log- dev_log
About me – Kartik_Kumar

One thought on “LibreCAD 3 OpenGL Rendering – GSoC “Phase 1”

  1. Pingback: LibreCAD 3 “OpenGL Rendering” – GSoC 2019 Final Report | LibreCAD

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.