Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL Rendering Implemented #229

Merged
merged 103 commits into from Aug 30, 2019
Merged
Changes from 1 commit
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
fc884a3
first commit
sckorpio Mar 31, 2019
2739080
grid implemented
sckorpio May 23, 2019
f410803
tempentities added
sckorpio May 31, 2019
b39de56
grid clipping resolved
sckorpio Jun 2, 2019
7c564d7
panning with correct y direction temporary
sckorpio Jun 2, 2019
a589542
final correct viewport all OK
sckorpio Jun 2, 2019
8af6bcc
Context saving and restoring OK
sckorpio Jun 5, 2019
928639f
Roatation matrix implemented OK
sckorpio Jun 6, 2019
da330e5
Simplified CTM matrix implemented OK
sckorpio Jun 11, 2019
5c28e68
correct paperbackground OK
sckorpio Jun 15, 2019
660c6bd
correct entity storage OK
sckorpio Jun 15, 2019
0ca1731
conflict resolved
sckorpio Jun 15, 2019
7f7959a
All_OK_before_caching
sckorpio Jun 15, 2019
3faa94f
caching started
sckorpio Jun 21, 2019
4a402df
caching fixed , basic caching all ok
sckorpio Jun 21, 2019
2abd75f
code cleaned
sckorpio Jun 24, 2019
d46dfb0
syncing
sckorpio Jun 25, 2019
a680cfa
storage fix after sync
sckorpio Jun 25, 2019
b7a075f
final merge
sckorpio Jun 25, 2019
deb96e9
document canvas conflict resolved
sckorpio Jun 25, 2019
11f0028
draw() logic moved to entity class
sckorpio Jun 30, 2019
1ece39b
removed some unnecessary functions
sckorpio Jun 30, 2019
dec9c97
Base class for entities implemented
sckorpio Jun 30, 2019
3024896
gradient implented, temporary without math
sckorpio Jul 1, 2019
fd9c35f
gradient completed with correct math
sckorpio Jul 1, 2019
f0b2787
Finally correct coordinate system
sckorpio Jul 2, 2019
8fddf9a
Update color_vertex_shader.shader
sckorpio Jul 7, 2019
b75f17f
Update color_vertex_shader.shader
sckorpio Jul 7, 2019
69497c8
few files changed
sckorpio Jul 7, 2019
122e7ec
trying to fix strange issue with gradient launch
sckorpio Jul 7, 2019
e5b0c78
using delete instead calling destructor
sckorpio Jul 13, 2019
45bc324
Added OpenGL debug methods
sckorpio Jul 16, 2019
f59f952
version 330 shaders added
sckorpio Jul 16, 2019
2793f5a
removed gl_Frag Color from shaders
sckorpio Jul 16, 2019
3605a20
testing with GL_TRIANGLE_FAN
sckorpio Jul 17, 2019
897df62
seperated freeing gpu call from destructor
sckorpio Jul 18, 2019
0b66448
gl_pack freed after deletion
sckorpio Jul 18, 2019
6b44b40
shaders book implemented
sckorpio Jul 24, 2019
15b4516
Code revamped now it runs using GL_LINE_STRIP_ADJACENCY
sckorpio Jul 25, 2019
a2f3fe6
all Ok Just before Thickline Implementation
sckorpio Jul 26, 2019
f34c929
Shader class updated to support Geometry Shader & a new thickline sha…
sckorpio Jul 27, 2019
c680b7e
LineWidth / Thicklines with Mitter joints Implemented
sckorpio Jul 28, 2019
90e51f0
all OK before linepatterns
sckorpio Jul 28, 2019
e9949e2
thickline shader fixed for NVIDIA
sckorpio Jul 28, 2019
c4f4c9c
LinePattern Implemented(Constant)
sckorpio Jul 31, 2019
cdab488
all OK before variable Dash Pattern from UI
sckorpio Jul 31, 2019
7a8d468
variable line pattern(from UI) implemented
sckorpio Aug 2, 2019
16d4d31
Enabled transparency
sckorpio Aug 2, 2019
27f63c7
fixed a minor segmentation fault because of a garbage value of uninit…
sckorpio Aug 2, 2019
2e409bb
merged with main repo LibreCAD_3 (2nd time)
sckorpio Aug 4, 2019
81dc618
merged 3rd time
sckorpio Aug 7, 2019
665a3a3
Freetype integrated, GL_Font and Font_Book implemented , working OK
sckorpio Aug 13, 2019
35d318d
Text Entity Implemented , Working OK
sckorpio Aug 13, 2019
8482643
Removed some Deprecated OpenGL calls related to Textures
sckorpio Aug 13, 2019
8cf5c9d
Testing Entities with Font, magnified/non-magnified Working OK
sckorpio Aug 13, 2019
b13289d
Finished Abstracting Text Rendering, Working all OK
sckorpio Aug 14, 2019
15af822
quadratic & cubic bezier curve implemented
sckorpio Aug 17, 2019
ed75cb0
Ellipse Implemented, Working OK
sckorpio Aug 18, 2019
6e2be81
Saving Absolute paths of Resources at compilation implemented ,workin…
sckorpio Aug 19, 2019
0bb36d4
codebase cleaned according to LC3 syntax rules
sckorpio Aug 20, 2019
e79e414
shader/font paths settings implemented by ModuleSettings.h
sckorpio Aug 21, 2019
f7dd03c
Single instance of ModuleSetting used for resources path
sckorpio Aug 21, 2019
b3f0ebd
Unused/Dead Codes Removed
sckorpio Aug 21, 2019
18bc5a9
Removed Debug calls from lcUI
sckorpio Aug 21, 2019
ad4874f
Removed Debug calls from lcviewernoqt
sckorpio Aug 21, 2019
65f57d1
Removed Debug calls from viewer::opengl
sckorpio Aug 21, 2019
a2d09ec
Final Code Cleaned, working all OK
sckorpio Aug 21, 2019
f2ab7b7
Extended Character Rendering Implemented
sckorpio Aug 22, 2019
0182dbe
Text Extends Implemented
sckorpio Aug 22, 2019
470c15c
Fixed the arc rendering
sckorpio Aug 22, 2019
fd5f0ec
Final commit , working all OK
sckorpio Aug 22, 2019
93428a9
Final Fix with arcs
sckorpio Aug 22, 2019
6283656
Updated Travis.yml
sckorpio Aug 23, 2019
9f20f71
Update .travis.yml
sckorpio Aug 23, 2019
3b98072
Reset Unnecessary Changed files
sckorpio Aug 23, 2019
56abf9d
Folder names changed from UPPERCASE to lowercase
sckorpio Aug 23, 2019
8296ee7
Indentation Cleaned!!!
sckorpio Aug 23, 2019
ce9b26c
Indentation Cleaned 2!!!
sckorpio Aug 23, 2019
110685e
Indentation Cleaned 3 !!!
sckorpio Aug 23, 2019
2beee65
Added QT_QTOPENGL_INCLUDE_DIR in lcUI CmakeList.txt
sckorpio Aug 23, 2019
f5b7326
Added QT_QTOPENGL_INCLUDE_DIR in lcviewernoqt CmakeList.txt
sckorpio Aug 23, 2019
2f3bb65
findPackage(Qt5OpenGL) added in CmakeList.txt
sckorpio Aug 23, 2019
3b5dbc0
update lcUI CmakeList.txt
sckorpio Aug 23, 2019
d28856d
update lcUI CmakeList.txt -2
sckorpio Aug 23, 2019
842b0f5
resolving codefactor issues
sckorpio Aug 23, 2019
cc34e50
resolving codefactor issues -2
sckorpio Aug 23, 2019
d8ad2a4
MERGE- Updated Travis Ubuntu Version
sckorpio Aug 24, 2019
5982c98
update travis.yml
sckorpio Aug 24, 2019
8dd70b1
update travis.yml-2
sckorpio Aug 24, 2019
743cc96
Fixing for Rendering test
sckorpio Aug 24, 2019
69d3d92
ViewerSettings Name Changed
sckorpio Aug 24, 2019
64a9e7b
Shifted QOpenGLContext from lcviewernoqt to lcUI
sckorpio Aug 24, 2019
b9e88d7
Cleaned CMakeLists.txt of lcUI and lcviewernoqt
sckorpio Aug 24, 2019
40ab208
resolving codefactor issues -3
sckorpio Aug 24, 2019
dbe5df6
resolving codefactor issues -4
sckorpio Aug 24, 2019
a0f216a
used codecvt instead of QString in GL_Font
sckorpio Aug 24, 2019
4b43e5f
Fixed Ellipse 4th Quadrant issue
sckorpio Aug 25, 2019
4836630
Removing Code duplication in renderer & cacher- Abstraction
sckorpio Aug 26, 2019
14f5331
Removed Code duplication from render & cacher openglpainters - Abstra…
sckorpio Aug 27, 2019
e894d28
Added new default font
sckorpio Aug 27, 2019
4798f4a
Used LC LOGGER
sckorpio Aug 27, 2019
c4e2af6
setted opengl major and minor version
sckorpio Aug 28, 2019
c91ca47
Set Opengl version 3.0
sckorpio Aug 29, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

LinePattern Implemented(Constant)

  • Loading branch information...
sckorpio committed Jul 31, 2019
commit c4f4c9cc88f33b4a542649894b315aa3e487a044
@@ -62,7 +62,7 @@ DocumentCanvas::DocumentCanvas(const std::shared_ptr<lc::storage::Document>& doc
double dashes[] = {10.0, 3.0, 3.0, 3.0};
painter.save();
painter.disable_antialias();
painter.line_width(1.0);
painter.line_width(2.0);

if (occupies) {
painter.source_rgba(.2, .2, 1.0, .6);
@@ -84,9 +84,10 @@ DocumentCanvas::DocumentCanvas(const std::shared_ptr<lc::storage::Document>& doc
else {
painter.source_rgba(.2, 1.0, .2, 0.8);
}

painter.source_rgba(1, 1, 1, 1);
painter.set_dash(dashes, 4, 0, true);
painter.stroke();
painter.dash_destroy();
painter.restore();
};

@@ -401,7 +402,8 @@ void DocumentCanvas::drawEntity(LcPainter& painter, const LCVDrawItem_CSPtr& dra

drawable->draw(painter, lcDrawOptions, visibleUserArea);

painter.restore();
painter.restore();
painter.dash_destroy();
}

void DocumentCanvas::drawCachedEntity(LcPainter& painter, const LCVDrawItem_CSPtr& drawable,
@@ -505,6 +507,7 @@ void DocumentCanvas::cacheEntity(unsigned long id, const LCVDrawItem_CSPtr& draw
drawable->draw( (*cachepainter), lcDrawOptions, visibleUserArea);
cachepainter->finishcaching(id);
cachepainter->restore();
cachepainter->dash_destroy();
//===============================================

}
@@ -270,7 +270,12 @@ void LcCacherPainter::new_device_size(unsigned int width, unsigned int height)

void LcCacherPainter::set_dash(const double* dashes, const int num_dashes, double offset, bool scaled)
{
_cacher.Select_Dashes(dashes,num_dashes,offset,scaled);
}

void LcCacherPainter::dash_destroy()
{
_cacher.Select_Dashes(NULL,0,0,false);
}

long LcCacherPainter::image_create(const std::string& file)
@@ -122,6 +122,8 @@ using namespace lc::viewer::opengl;
unsigned char* data();

void set_dash(const double* dashes, const int num_dashes, double offset, bool scaled);

void dash_destroy();

long image_create(const std::string& file);

@@ -520,6 +520,11 @@ public:

}

void dash_destroy()
{

}


//##############################################################
//##############################################################
@@ -105,7 +105,9 @@ namespace lc {

// virtual inline void arrow(double startX, double startY, double endX, double endY, const CapType& startCap, const CapType& endCap) = 0;
virtual void set_dash(const double* dashes, const int num_dashes, double offset, bool scaled) = 0;


virtual void dash_destroy() = 0;

virtual long image_create(const std::string& file) = 0;

virtual void image_destroy(long image) = 0;
@@ -44,6 +44,7 @@ class Cacher
glm::mat4 model; //model matrix

float line_width;
double *dashes; int dashes_size;
bool fill=false;
//--------------------------------------------

@@ -104,6 +105,9 @@ class Cacher

void Select_Line_Width(float width);

void Select_Dashes(const double* dashes, const int num_dashes, double offset, bool scaled);


//----------------------------gradient------------------------------

void Add_Linear_Gradient(float x0,float y0,float x1,float y1);
@@ -38,6 +38,7 @@ class GL_Entity

virtual void SetFillMode(bool fill) = 0;
virtual void SetLineWidth(float width) = 0;
virtual void SetDashes(const double* dashes, const int num_dashes) = 0;
virtual void SetColor(float R,float G,float B,float A) = 0;

virtual void AddLinearGradient(float x0,float y0,float x1,float y1) = 0;
@@ -47,7 +48,7 @@ class GL_Entity

virtual void FreeGPU() = 0;

virtual void Draw(glm::mat4 proj,glm::mat4 view) = 0;
virtual void Draw(glm::mat4 proj,glm::mat4 projB,glm::mat4 view) = 0;
};


@@ -63,6 +63,7 @@ class Gradient_Entity : public GL_Entity

void SetFillMode(bool fill);
void SetLineWidth(float width);
void SetDashes(const double* dashes, const int num_dashes);
void SetColor(float R,float G,float B,float A);

void AddLinearGradient(float x0,float y0,float x1,float y1);
@@ -71,7 +72,7 @@ class Gradient_Entity : public GL_Entity

void FreeGPU();

void Draw(glm::mat4 proj,glm::mat4 view);
void Draw(glm::mat4 proj,glm::mat4 projB,glm::mat4 view);
};


@@ -62,11 +62,13 @@ class Renderer
bool closed=false;

float line_width;
double *dashes; int dashes_size;
bool fill=false;

Shaders_book shaders;

glm::mat4 proj; //projection matrix
glm::mat4 projB;
glm::mat4 view; //view matrix for pan
glm::mat4 ctm;

@@ -154,6 +156,8 @@ class Renderer

void Select_Line_Width(float width);

void Select_Dashes(const double* dashes, const int num_dashes, double offset, bool scaled);

//--------------------------for gradient entity----------------------------

void Add_Linear_Gradient(float x0,float y0,float x1,float y1);
@@ -39,7 +39,8 @@ class Shape_Entity : public GL_Entity

float _linewidth; //linewidth

float* _dashes; //to store dash gap
std::vector<float> _dashes; //to store dash gap
int _dashes_size;
float _sum_dashes; //total sum of dash-gap


@@ -61,6 +62,7 @@ class Shape_Entity : public GL_Entity

void SetFillMode(bool fill);
void SetLineWidth(float width);
void SetDashes(const double* dashes, const int num_dashes);
void SetColor(float R,float G,float B,float A);

void AddLinearGradient(float x0,float y0,float x1,float y1);
@@ -70,7 +72,7 @@ class Shape_Entity : public GL_Entity

void FreeGPU();

void Draw(glm::mat4 proj,glm::mat4 view);
void Draw(glm::mat4 proj,glm::mat4 projB,glm::mat4 view);
};


@@ -0,0 +1,193 @@
#shader vertex

#version 330 core
layout (location = 0) in vec3 pos;
layout (location = 1) in float prev_distance;
uniform mat4 u_MVP;
uniform mat4 u_X;

out VS_OUT
{
vec4 PD;
} vs_out;


void main()
{
gl_Position = u_MVP *vec4(pos, 1.0);

vec4 temp_d= u_X *vec4(prev_distance,0.0,0.0,1.0);
vs_out.PD=temp_d;
}

//############################################################

#shader geometry
#version 330 core
layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 4) out;

in VS_OUT {
vec4 PD;
} gs_in[];

out vec2 TXC;
flat out float PL;
flat out float L;

uniform float u_W;
uniform float MITER_LIMIT=0.75f;
uniform vec2 WIN_SCALE= vec2(500,500);
uniform mat4 u_MVP;

vec2 screen_space(vec4 vertex)
{
return vec2( vertex.xy /vertex.w ) * (WIN_SCALE/2.0f);
}

vec2 rotate(vec2 v, vec2 ref)
{
float s= ref.y;
float c = ref.x;
mat2 m = mat2(c,-s,s,c);
return m*v;
}

void main(void)
{
float THICKNESS=u_W/2.0f;

// get the four vertices passed to the shader:

vec2 p0 = screen_space(gl_in[0].gl_Position );
// start of previous segment

vec2 p1 = screen_space(gl_in[1].gl_Position);
// end of previous segment, start of current segment

vec2 p2 = screen_space( gl_in[2].gl_Position );
// end of current segment, start of next segment

vec2 p3 = screen_space( gl_in[3].gl_Position);
// end of next segment

vec2 pdv = screen_space(gs_in[1].PD);
PL=length(pdv);

L=length(p2-p1);
// determine the direction of each of the 3 segments (previous, current, next)
vec2 v0 = normalize(p1-p0);
vec2 v1 = normalize(p2-p1);
vec2 v2 = normalize(p3-p2);

// determine the normal of each of the 3 segments (previous, current, next)
vec2 n0 = vec2(-v0.y, v0.x);
vec2 n1 = vec2(-v1.y, v1.x);
vec2 n2 = vec2(-v2.y, v2.x);



// determine miter lines by averaging the normals of the 2 segments
vec2 miter_a = normalize(n0 + n1); // miter at start of current segment
vec2 miter_b = normalize(n1 + n2); // miter at end of current segment

// determine the length of the miter by projecting it onto normal and then inverse it
float length_a = THICKNESS / dot(miter_a, n1);
float length_b = THICKNESS / dot(miter_b, n1);

//--------------------------------

// prevent excessively long miters at sharp corners
if(( dot(v0,v1) < -MITER_LIMIT ) )
{
miter_a = n1;
length_a = THICKNESS;
}

if(( dot(v1,v2) < -MITER_LIMIT ) )
{
miter_b = n1;
length_b = THICKNESS;
}
//------------------

vec2 mra=rotate(miter_a,v1);
vec2 mrb=rotate(miter_b,v1);

// generate the triangle strip

TXC=vec2( (length_a*mra).x,THICKNESS);
gl_Position = vec4( 2.0f*(p1 + length_a * miter_a) / WIN_SCALE, 0.0, 1.0 );
EmitVertex();


TXC=vec2(-(length_a*mra).x,-THICKNESS);
gl_Position = vec4( 2.0f*(p1 - length_a * miter_a) / WIN_SCALE, 0.0, 1.0 );
EmitVertex();


TXC=vec2(L+(length_b*mrb).x,THICKNESS);
gl_Position = vec4( 2.0f*(p2 + length_b * miter_b) / WIN_SCALE, 0.0, 1.0 );
EmitVertex();


TXC=vec2(L-(length_b*mrb).x,-THICKNESS);
gl_Position = vec4( 2.0f*(p2 - length_b * miter_b) / WIN_SCALE, 0.0, 1.0 );
EmitVertex();

EndPrimitive();
}
//############################################################

#shader fragment

#version 330 core

uniform vec4 u_Color;
out vec4 out_Color;

in vec2 TXC;
flat in float PL;
flat in float L;

uniform float dashes[64]; // dash-gap data (in pixel)
uniform int dashes_size; // size of dash gap data
uniform float dashes_sum; // total sum of all dash-gap(in pixel)

void main()
{

float u=TXC.x; // u or x coordinate of current fragment
float TD= u + PL; // total distance from start point(in pixel)

float R = fract(TD / (dashes_sum)); // ratio of length of current
// fragment to total dash-gap length


//--------------------- deciding in dash or gap-------

float r=0; float s=0;
for(int i=0;i<dashes_size;i++)
{
s+=dashes[i];

r=s/dashes_sum;

if(R<=r) // current fragment belong to this
{
if(i%2!=0) // this is gap
{
discard;
}
break;
}
}


//----------------------------------------------------


out_Color = u_Color;


}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.