Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
vite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
solverstack
vite
Commits
c440dbda
Commit
c440dbda
authored
10 years ago
by
Thibault Soucarre
Browse files
Options
Downloads
Patches
Plain Diff
States shaded again, using a float by state
parent
b965c6fd
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/render/Render_alternate.cpp
+7
-6
7 additions, 6 deletions
src/render/Render_alternate.cpp
src/render/Shader.cpp
+12
-12
12 additions, 12 deletions
src/render/Shader.cpp
src/render/vbo.cpp
+13
-10
13 additions, 10 deletions
src/render/vbo.cpp
src/render/vbo.hpp
+2
-2
2 additions, 2 deletions
src/render/vbo.hpp
with
34 additions
and
30 deletions
src/render/Render_alternate.cpp
+
7
−
6
View file @
c440dbda
...
@@ -198,7 +198,7 @@ void Render_alternate::paintGL(){
...
@@ -198,7 +198,7 @@ void Render_alternate::paintGL(){
glDrawArrays
(
GL_QUADS
,
0
,
_containers
.
getNbVertex
());
glDrawArrays
(
GL_QUADS
,
0
,
_containers
.
getNbVertex
());
_containers
.
unlock
();
_containers
.
unlock
();
_modelview
=
tmp
;
_modelview
=
tmp
;
//
glUseProgram(0);
glUseProgram
(
0
);
/*drawing states*/
/*drawing states*/
_modelview
=
glm
::
translate
(
_modelview
,
glm
::
vec3
(
_default_entity_x_translate
-
_x_state_translate
,
_ruler_y
+
_ruler_height
-
_y_state_translate
,
_z_state
));
_modelview
=
glm
::
translate
(
_modelview
,
glm
::
vec3
(
_default_entity_x_translate
-
_x_state_translate
,
_ruler_y
+
_ruler_height
-
_y_state_translate
,
_z_state
));
_modelview
=
glm
::
scale
(
_modelview
,
glm
::
vec3
(
_x_state_scale
,
_y_state_scale
,
1
));
_modelview
=
glm
::
scale
(
_modelview
,
glm
::
vec3
(
_x_state_scale
,
_y_state_scale
,
1
));
...
@@ -206,6 +206,7 @@ void Render_alternate::paintGL(){
...
@@ -206,6 +206,7 @@ void Render_alternate::paintGL(){
std
::
map
<
const
EntityValue
*
,
Vbo
*>::
iterator
it_state
;
std
::
map
<
const
EntityValue
*
,
Vbo
*>::
iterator
it_state
;
it_state
=
_states
.
begin
();
it_state
=
_states
.
begin
();
while
(
it_state
!=
_states
.
end
()){
while
(
it_state
!=
_states
.
end
()){
//std::cout << "drawing states" << std::endl;
Shader
*
s
=
_states_shaders
[
it_state
->
first
];
Shader
*
s
=
_states_shaders
[
it_state
->
first
];
glUseProgram
(
s
->
getProgramID
());
glUseProgram
(
s
->
getProgramID
());
//glUniform1i(glGetUniformLocation(s->getProgramID(), "i"), 0);
//glUniform1i(glGetUniformLocation(s->getProgramID(), "i"), 0);
...
@@ -673,10 +674,10 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
...
@@ -673,10 +674,10 @@ void Render_alternate::draw_quad(Element_pos x, Element_pos y, Element_pos z, El
}
}
else
if
(
_draw_states
){
else
if
(
_draw_states
){
offset_x
=
-
_default_entity_x_translate
;
offset_x
=
-
_default_entity_x_translate
;
_current
->
add
(
x
+
offset_x
,
y
+
offset_y
);
// , _r, _g, _b);
_current
->
add
(
x
+
offset_x
,
y
+
offset_y
,
1.
);
// , _r, _g, _b);
_current
->
add
(
x
+
offset_x
+
w
,
y
+
offset_y
);
// , _r/2, _g/2, _b/2);
_current
->
add
(
x
+
offset_x
+
w
,
y
+
offset_y
,
0.5
);
// , _r/2, _g/2, _b/2);
_current
->
add
(
x
+
offset_x
+
w
,
y
+
offset_y
+
h
);
//, _r/2, _g/2, _b/2);
_current
->
add
(
x
+
offset_x
+
w
,
y
+
offset_y
+
h
,
0.5
);
//, _r/2, _g/2, _b/2);
_current
->
add
(
x
+
offset_x
,
y
+
offset_y
+
h
);
//, _r, _g, _b);
_current
->
add
(
x
+
offset_x
,
y
+
offset_y
+
h
,
1.
);
//, _r, _g, _b);
}
}
else
if
(
_draw_ruler
){
else
if
(
_draw_ruler
){
}
}
...
@@ -760,7 +761,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons
...
@@ -760,7 +761,7 @@ void Render_alternate::draw_state(const Element_pos x, const Element_pos y, cons
_states
.
insert
(
p2
);
_states
.
insert
(
p2
);
}
}
_current
=
_states
[
value
];
_current
=
_states
[
value
];
draw_quad
(
x
,
y
,
z
,
w
*
0.98
,
h
);
draw_quad
(
x
,
y
,
z
,
w
,
h
);
}
}
void
Render_alternate
::
end_draw_states
(){
void
Render_alternate
::
end_draw_states
(){
...
...
This diff is collapsed.
Click to expand it.
src/render/Shader.cpp
+
12
−
12
View file @
c440dbda
...
@@ -29,27 +29,27 @@ Shader::Shader() : m_vertexID(0), m_fragmentID(0), m_programID(0),
...
@@ -29,27 +29,27 @@ Shader::Shader() : m_vertexID(0), m_fragmentID(0), m_programID(0),
{
{
}
}
Shader
::
Shader
(
Element_col
r
,
Element_col
g
,
Element_col
b
)
:
m_vertexID
(
0
),
m_fragmentID
(
0
),
m_programID
(
0
),
m_vertex_code
(
"#version 330 core
\n
in vec2 in_Vertex;
\n
uniform mat4 MVP;
\n
void main(){
\n
gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0);
\n
}"
){
Shader
::
Shader
(
Element_col
r
,
Element_col
g
,
Element_col
b
)
:
m_vertexID
(
0
),
m_fragmentID
(
0
),
m_programID
(
0
),
m_vertex_code
(
"#version 330 core
\n
in vec2 in_Vertex;
\n
in float c;
\n
uniform mat4 MVP;
\n
out float shade;
\n
void main(){
\n
gl_Position = MVP * vec4(in_Vertex, 0.0, 1.0);
\n
shade=c;
\n
}"
){
std
::
ostringstream
os
;
std
::
ostringstream
os
;
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
//std::cout << "rgb" << r << " " << g << " " << b << std::endl;
os
<<
"#version 330 core
\n
out vec4 outColor;
\n
void main(){
\n
if(true) {
\n
outColor = vec4("
;
os
<<
"#version 330 core
\n
in float shade;
\n
out vec4 outColor;
\n
void main(){
\n
outColor = vec4("
;
os
<<
r
;
os
<<
r
;
os
<<
", "
;
os
<<
"
*shade
, "
;
os
<<
g
;
os
<<
g
;
os
<<
", "
;
os
<<
"
*shade
, "
;
os
<<
b
;
os
<<
b
;
os
<<
", 0.5);
\n
}
"
;
/*
os << ", 0.5); \n";
os
<<
"else
{
\n
out
_
Color = vec4("
;
os << "else \n outColor = vec4(";
os
<<
1
;
os <<
r/2
;
os << ", ";
os << ", ";
os
<<
1
;
os <<
g/2
;
os << ", ";
os << ", ";
os
<<
1
;
os <<
b/2;*/
os
<<
", 0.5);
\n
}
\n
\n
}"
;
os
<<
"
*shade
, 0.5);
\n
}"
;
m_fragment_code
=
os
.
str
();
m_fragment_code
=
os
.
str
();
/*
std::cout << "code shaders" << std::endl;
std
::
cout
<<
"code shaders"
<<
std
::
endl
;
std
::
cout
<<
m_vertex_code
<<
std
::
endl
;
std
::
cout
<<
m_vertex_code
<<
std
::
endl
;
std::cout << m_fragment_code << std::endl;
*/
std
::
cout
<<
m_fragment_code
<<
std
::
endl
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/render/vbo.cpp
+
13
−
10
View file @
c440dbda
...
@@ -105,10 +105,12 @@ int Vbo::add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element
...
@@ -105,10 +105,12 @@ int Vbo::add(Element_pos x, Element_pos y, Element_col r, Element_col g, Element
_nbVertex
++
;
_nbVertex
++
;
}
}
int
Vbo
::
add
(
Element_pos
x
,
Element_pos
y
/*, bool b*/
){
int
Vbo
::
add
(
Element_pos
x
,
Element_pos
y
,
float
b
){
_vertex
.
push_back
(
x
);
_vertex
.
push_back
(
x
);
_vertex
.
push_back
(
y
);
_vertex
.
push_back
(
y
);
//_shaded.push_back(b);
_shaded
.
push_back
(
b
);
//_vertex.push_back(3);
//_vertex.push_back(3);
_nbVertex
++
;
_nbVertex
++
;
}
}
...
@@ -116,10 +118,10 @@ void Vbo::config(){
...
@@ -116,10 +118,10 @@ void Vbo::config(){
std
::
cout
<<
"Configuration du VBO. Nombre de points : "
<<
_vertex
.
size
()
/
2
<<
std
::
endl
;
std
::
cout
<<
"Configuration du VBO. Nombre de points : "
<<
_vertex
.
size
()
/
2
<<
std
::
endl
;
int
vertex_size
=
_vertex
.
size
()
*
sizeof
(
Element_pos
);
int
vertex_size
=
_vertex
.
size
()
*
sizeof
(
Element_pos
);
int
colors_size
=
_colors
.
size
()
*
sizeof
(
Element_col
);
int
colors_size
=
_colors
.
size
()
*
sizeof
(
Element_col
);
//in
t shaded_size = _shaded.size() * sizeof(
bool
);
floa
t
shaded_size
=
_shaded
.
size
()
*
sizeof
(
float
);
Element_pos
*
vertex
=
&
_vertex
[
0
];
Element_pos
*
vertex
=
&
_vertex
[
0
];
Element_col
*
colors
=
&
_colors
[
0
];
Element_col
*
colors
=
&
_colors
[
0
];
//bool
* shaded = &_shaded[0];
float
*
shaded
=
&
_shaded
[
0
];
//Delete old vbo if necessary
//Delete old vbo if necessary
if
(
glIsBuffer
(
_vboID
)
==
GL_TRUE
)
if
(
glIsBuffer
(
_vboID
)
==
GL_TRUE
)
glDeleteBuffers
(
1
,
&
_vboID
);
glDeleteBuffers
(
1
,
&
_vboID
);
...
@@ -128,11 +130,11 @@ void Vbo::config(){
...
@@ -128,11 +130,11 @@ void Vbo::config(){
//Select our VBO
//Select our VBO
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vboID
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
_vboID
);
//Allocate memory inside graphic card
//Allocate memory inside graphic card
glBufferData
(
GL_ARRAY_BUFFER
,
vertex_size
+
colors_size
/*
+shaded_size
*/
,
0
,
GL_STATIC_DRAW
);
glBufferData
(
GL_ARRAY_BUFFER
,
vertex_size
+
colors_size
+
shaded_size
,
0
,
GL_STATIC_DRAW
);
//Send datas
//Send datas
glBufferSubData
(
GL_ARRAY_BUFFER
,
0
,
vertex_size
,
vertex
);
glBufferSubData
(
GL_ARRAY_BUFFER
,
0
,
vertex_size
,
vertex
);
glBufferSubData
(
GL_ARRAY_BUFFER
,
vertex_size
,
colors_size
,
colors
);
glBufferSubData
(
GL_ARRAY_BUFFER
,
vertex_size
,
colors_size
,
colors
);
//
glBufferSubData(GL_ARRAY_BUFFER, vertex_size+colors_size, shaded_size, shaded);
glBufferSubData
(
GL_ARRAY_BUFFER
,
vertex_size
+
colors_size
,
shaded_size
,
shaded
);
//Deselect our VBO
//Deselect our VBO
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
//Clear RAM
//Clear RAM
...
@@ -141,7 +143,7 @@ void Vbo::config(){
...
@@ -141,7 +143,7 @@ void Vbo::config(){
//Clear RAM and realoccate _vertex and _colors
//Clear RAM and realoccate _vertex and _colors
std
::
vector
<
Element_pos
>
().
swap
(
_vertex
);
std
::
vector
<
Element_pos
>
().
swap
(
_vertex
);
std
::
vector
<
Element_col
>
().
swap
(
_colors
);
std
::
vector
<
Element_col
>
().
swap
(
_colors
);
//
std::vector<
boolean
>().swap(_shaded);
std
::
vector
<
float
>
().
swap
(
_shaded
);
//Delete old vao if necessary
//Delete old vao if necessary
if
(
glIsVertexArray
(
_vaoID
))
if
(
glIsVertexArray
(
_vaoID
))
glDeleteVertexArrays
(
1
,
&
_vaoID
);
glDeleteVertexArrays
(
1
,
&
_vaoID
);
...
@@ -161,9 +163,10 @@ void Vbo::config(){
...
@@ -161,9 +163,10 @@ void Vbo::config(){
glVertexAttribPointer
(
1
,
3
,
GL_FLOAT
,
GL_FALSE
,
0
,
BUFFER_OFFSET
(
vertex_size
));
glVertexAttribPointer
(
1
,
3
,
GL_FLOAT
,
GL_FALSE
,
0
,
BUFFER_OFFSET
(
vertex_size
));
glEnableVertexAttribArray
(
1
);
glEnableVertexAttribArray
(
1
);
}
}
/*if(shaded_size>0){
if
(
shaded_size
>
0
){
glVertexAttribPointer(2, 1, GL_BOOLEAN, GL_FALSE, 0, BUFFER_OFFSET(vertex_size+colors_size));
glVertexAttribPointer
(
1
,
1
,
GL_FLOAT
,
GL_FALSE
,
0
,
BUFFER_OFFSET
(
vertex_size
+
colors_size
));
glEnableVertexAttribArray(2);*/
glEnableVertexAttribArray
(
1
);
}
//Deselect VBO
//Deselect VBO
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/render/vbo.hpp
+
2
−
2
View file @
c440dbda
...
@@ -63,7 +63,7 @@ private:
...
@@ -63,7 +63,7 @@ private:
GLuint
_vaoID
;
GLuint
_vaoID
;
vector
<
Element_pos
>
_vertex
;
vector
<
Element_pos
>
_vertex
;
vector
<
Element_col
>
_colors
;
vector
<
Element_col
>
_colors
;
//
vector<
bool
> _shaded;
vector
<
float
>
_shaded
;
GLenum
_mode
;
GLenum
_mode
;
int
_nbVertex
;
int
_nbVertex
;
...
@@ -107,7 +107,7 @@ public:
...
@@ -107,7 +107,7 @@ public:
int
add
(
Element_pos
x
,
Element_pos
y
,
Element_col
r
,
Element_col
g
,
Element_col
b
);
int
add
(
Element_pos
x
,
Element_pos
y
,
Element_col
r
,
Element_col
g
,
Element_col
b
);
int
add
(
Element_pos
x
,
Element_pos
y
/*, bool b*/
);
int
add
(
Element_pos
x
,
Element_pos
y
,
float
b
);
void
lock
();
void
lock
();
void
unlock
();
void
unlock
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment