LibreCAD 3 OpenGL Rendering – GSoC “Phase 2”

“Getting the right basis before jumping into action”
And that’s the reason for the successful finish of Phase 1st. Mentors help was amazing during this period. We got the correct base for the project and finished most of the basic but the major things which will decide the implementation of upcoming challenges.

The things completed till now were–
–> Basic painter following the predefined layout (outermost layer)
–> A strong Renderer class ( which is the core and everything will moves around this)
–> Viewport System ( User-Device-User coordinate system)
–> Matrix Manipulation ( involves a lot of matrix and vector math )
–> Caching mechanism (Crucial part which now enable us high performant rendering )
–> Gradient Rendering

“Feeling the graphics pipeline ;)”
Although even before starting the project i had used and planned the Modern OpenGL way for implementation.
But As the Phase 2 period started i figured out that a lot more simple and familiar functionalities are been “replaced with nothing”!!! And actually it required implementing things using completely scratch and following graphics pipeline.
And here starts the experience of deprecated functionalities of such a low level API. It became more understandable the difference of Legacy and Modern OpenGL and how computer graphics actually works.

“Seriously…Rendering Lines is not easy :)”
Simpler the things seems , the complex they are.
It was all going good, rendered lines seems very nice until i came across ThickLines.
So basically in LibreCAD we have standard linewidths whose thickness can/cannot get enlarged on zooming (its up to the requirement ). Ultimately we needed lines rendered with variable thickness. Now Initially i have planned to simply implement this using the given functions in OpenGL API (glLineWidth().. which is deprecated ).
I discussed alot with the mentors about the strategy( and seriously their guidance at this moment decided the later implementations )
It required almost revamping the codebase at both the CPU and GPU side. On CPU side the GL_LINES/GL_LINE_STRIP/GL_LINE_LOOP were replaced by the GL_LINE_STRIP_ADJACENCY and changing the way renderer works for this.
Then passing the data to GPU , then to Vertex Shader to Geometry Shader to finally Fragment Shader. Basically using 2 triangles for a line, using mitter joints (which required geometry math in shader) and finally it worked.

“Dash – Gap – Dash — — —
Linepatterns or dash patterns. Here also initially i thought it would be easy and i can use glLineStipple()..( Ah..which again is depreciated : | and actually it can’t render every possible pattern which is the requirement of our LibreCAD , here the user can even generate its own linepattern )
Now this was even more harder , the patterns has any possible combination and that too seamless. So what i did was storing the path length of the point along with their coordinates , passing data from CPU to GPU ( vertex shader -> Geometry shader -> Fragment shader , using the texel coordinates for deciding the dash and gaps and Finally abstracting it properly.
And Yes there can be multiple ways but this suits best for LibreCAD (atleast till now), there are another method(s) like 1D Texture etc.( But the codebase is designed to support those methods and it will only require changes in GPU side or shaders)

“How it looks now”

Thick lines and User defined Line patterns ,Our Tank is back!!!

Overall the 2nd Phase was much more challenging and required more research work before actually coding it. For even simple changes it required a lot revamping code.
Regarding mentors , Armin helped me a lot in understanding the requirements and explaining stuff( which he does very well 🙂 and is also very concerned about the standards.
And Florian is always there for guiding me like always (and is quite friendly and cool 😉 ). For example during this phase we encountered a strange bug(on different graphic cards ) It was almost unreachable for me but he helped me in fixing that step by step, almost a week went into it but finally we got more robust and refined code!!!
The next work to be done is Text Rendering and finishing the remaining painters methods and much more. My college re-opened , getting less time as compared to i was giving till now but will try to manage.

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 alot 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 doest 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

LibreCAD 3 OpenGL Rendering – GSoC 2019

Hello

LibreCAD is a free Open Source CAD application for Windows, Apple and Linux. It allows industrial designers and graphics enthusiast to create CAD projects of the highest standard and precision. With this precision and standard comes the need of high quality and accelerated rendering to visualize a document.

This year during GSoC the project consists of making a complete well abstracted OpenGL implementation with C++ for the rendering in LibreCAD 3.

As the coding period is just about to begin next week right now i am doing some more research work and debugging on how it will be implemented. Till now a partial implementation of opengl painter is done with basic features of VertexBuffer Objects, pan, zoom etc. The Project is not just about to use OpenGL but to use it in the way LibreCAD painter calls. Few challenges in this project are the caching mechanism(saving bufferobjects in GPU), text rendering( ttf fonts/MSDF fonts),complex entities(dimensions etc) , gradients,spline curves and doing all of them with keeping thread safe also.

From next week as the coding period will begin i will start working on caching mechanism and making graphic entities more robust and abstracted.

Google Summer of Code 2019 (GSoC)

A new round of Google Summer of Code is gather speed.

We are happy to announce, that once again, LibreCAD is part of GSoC in 2019!

Again, under the umbrella of BRL-CAD, a couple of CAD/CAM/CAE or short CAx organizations going to mentor students for a 3 month full time coding challenge during their summer break.
The students, when they participate successfully, will gain experience, reputation and also a certificate and a stipend from Google.
Our value will be the progress, bringing LibreCAD 3 to a new level and hopefully attract the participants to stay longer with us and become a regular contributor.

This year we try a new approach and created a common platform under the name OpenCAx for cross-cutting concerns. We use the OpenCAx term for quite some time, but now it becomes more clearer.
Beside the information from Google at https://summerofcode.withgoogle.com/ we have additional content for students at https://opencax.github.io/.
Project ideas are listed under https://github.com/opencax/GSoC/issues and especially for LibreCAD one can filter by project.

If you are a student who is eligible for the program, have some C++ skills and prefer coding over selling burgers, don’t hesitate to get in touch with us. Or you know one who might be interested, let him know about this great chance.
Look out for Armin (LordOfBikes) or Florian (Feragon) on our community chat channels IRC #librecad or Zulip or reply to any project idea.

The LibreCAD Team

GSoC 2018, Week 4

Made few commits and submitted code with a few bugs left with the rendering of the painter due to QWidget.

June 8, 2018

Made a from changes in painter workflow. Now draw the line, rectangle, etc. will store instructions to draw particular patterns in form of drawing lines between two coordinates. Once stroke function is called all the data that is stored is drawn.

June 5-6, 2018

Removing the instances of the previous painter and working on rendering new painter.

June 4, 2018

Creating another function for the check of repeated drawing of the same pattern. So it stores the pattern in GPU cache and calls ‘glDrawArray’ to draw pattern instead of drawing it again.

June 4, 2018

Once the pattern is saved then dashes are rendered using stroke function by drawing the line for the ‘on’ part and draw nothing for the ‘off’ part.

June 3, 2018

Started working on the dash patterns. As no OpenGL libraries work on rendering dashes considering the line width and offset. For set_dash creating an array for storing the dash lengths with offset.

GSoC 2018, Week 3

June 1,2018

Continued working on replacing of the painter member functions.

May 31,2018

Working on replacing the part where the pointer to the painter is made and its member functions are called with the new painter and creating new member functions which do not exists in OpenGL library.

May 29-30,2018

Learning about OpenGL Shaders for the working of the fill (to fill an object with the color given through RGBA code). In particular, using vertex shaders and fragment shaders for rendering on the graphics card and not on CPU.

May 28,2018

Rendering of the coordinates with the cursor using OpenGL functions. Using glutBitmapCharacter() for the printing of the text on the screen and glRasterPos2f(x,y) for the position to render the text. Also changing the font type and font size.

GSoC 2018, Week 2

May 26,2018

Read about working of OpenGL Vertex Buffers and usage of some new functions like glPushMatrix and glPopMatrix and implemented the conversion of the device to user coordinates and vice versa.

May 25,2018

Got stuck with the rendering of the new painter due to some issues with the pointers but was finally able to resolve them with the help of my mentors. Also used QOpenGLWidget in place of QWidget for the rendering and read its documentation.

May 24,2018

Add new functions to the new painter such as creating lines, rectangles, etc using Vertex buffer objects. Also added many similar functions like clear, fill color with arguments as RGB codes.

May 23,2018

Learned few things about QOpenGLWidget and replaced it with QWidget at few places in order to create an OpenGL window. Removed the previous function to create painter and added files for new painter and make use of its members to create a window.

May 22,2018

Removing the part of the grid that was earlier rendered through Cairo but now it is done with the new painter. Now the grid will be rendered using the new painter and rest all things are same. Changes made are mostly in grid.cpp file and the functions related to the previous painter is removed.

May 21,2018

Completing the task of the grid for the new painter. The grid is rendered through OpenGL and lines are formed using ‘vertex buffer objects’ and then glDrawArrays(GL_LINES, 0, 2) will draw them on the painter.

Beginning of the Working period for GSoC 2018

Hello,

With the end of the Community Bonding period, the official coding period has begun. During the Community Bonding period, I interacted with my mentors and did some research for my projects i.e. LibreCAD 3 OpenGL Rendering. With help from them, I was able to build the LibreCAD 3 and run it. I went through the code base and had a reading of the module ‘lcviewernoqt’ inside LibreCAD 3 which is directly involved with my project.

Also along with these readings, I went through some research papers and articles for the formation of different types of lines i.e. different dashed lines/strokes formed using OpenGL libraries that is to be used in the formation of the grid in the painter and other shapes such as lines, circles, etc.

During the first week of the coding period, I would be working on the formation of the grid inside the painter, creating lines using Vertex Buffers and working of the scrollbar. Also, it would involve the extraction of the coordinates of the mouse pointer.

Thank You

Congrats for another LibreCAD 3 Google Summer of Code in 2018

Yesterday Google announced the 1,264 students from 64 countries, who have been accepted to work with 206+ open source projects for Google Summer of Code 2018!
Congratulations to all of them!

We are happy to welcome Parth Partani to become a member of our team. He was accepted with his proposal about LibreCAD 3 OpenGL rendering and will spend his summer with coding for LibreCAD. Florian and I will mentor Parth to make this GSoC participation a success for all again.

We expect an exciting time working with Parth and hope to have also a lot of fun together.

Many thanks to our friends at BRL-CAD too, who again take us under their umbrella, with several other CAx related organizations. Beside mentoring a couple of students for themselves they also have to administer the 9 students with their mentors from 4 organizations this year.

Good luck for Parth, our friends students from BRL-CAD, FreeCAD and slic3r and all the other GSoC participants!

The LibreCAD Team

LibreCAD is preparing for GSoC 2018

LibreCAD is again on course for a Summer of Code with Google in 2018.

The first step is done, our umbrella organization BRL-CAD is again selected for mentoring students in GSoC 2018 and so we are too.
Now its up to eligible students to take the challenge and get in contact with us to prepare a great proposal, so we can get at least one of the treasured slots.

More information is available on our wiki page GSoC Check List and the Google site linked above.

The LibreCAD Team