Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
C-Fu
OpenGL
Commits
42c94f29
Commit
42c94f29
authored
Nov 07, 2016
by
Anakin
Browse files
instance was not the right thing for me,
now it's working
parent
de76f718
Changes
3
Hide whitespace changes
Inline
Side-by-side
MshViewer/Header/OpenGLController.h
View file @
42c94f29
...
...
@@ -53,7 +53,6 @@ private:
//object data
GLuint
gluiVertexArrayID
=
0
;
GLuint
gluiVertexBufferID
=
0
;
GLuint
gluiInstanceBufferID
=
0
;
//obj color
GLuint
gluiTextureID
=
0
;
...
...
MshViewer/Shader/TextureShader.vert
View file @
42c94f29
...
...
@@ -3,10 +3,6 @@
// Input vertex data, different for all executions of this shader.
layout
(
location
=
0
)
in
vec3
vertexPosition_modelspace
;
layout
(
location
=
1
)
in
vec2
vertexUV
;
layout
(
location
=
2
)
in
mat4
mvp
;
//layout(location = 3) in mat4 mvp;
//layout(location = 4) in mat4 mvp;
//layout(location = 5) in mat4 mvp;
// Output
out
vec2
UV
;
...
...
MshViewer/Source/OpenGlController.cpp
View file @
42c94f29
...
...
@@ -24,7 +24,6 @@ OpenGLController* OpenGLController::getInstance(int oglMajor, int oglMinor)
OpenGLController
::~
OpenGLController
()
{
glDeleteBuffers
(
1
,
&
gluiInstanceBufferID
);
glDeleteBuffers
(
1
,
&
gluiVertexBufferID
);
glDeleteVertexArrays
(
1
,
&
gluiVertexArrayID
);
glDeleteProgram
(
gluiShaderPrgmID
);
...
...
@@ -83,7 +82,6 @@ void OpenGLController::processInit()
glBindVertexArray
(
gluiVertexArrayID
);
glGenBuffers
(
1
,
&
gluiVertexBufferID
);
glGenBuffers
(
1
,
&
gluiInstanceBufferID
);
// open attribute position
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
...
...
@@ -91,28 +89,10 @@ void OpenGLController::processInit()
glVertexAttribPointer
(
VERTEX_INDEX_UV
,
VERTEX_COMPONENTS_UV
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
Vertex
),
(
void
*
)
VERTEX_OFFSET_UV
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiInstanceBufferID
);
glVertexAttribPointer
(
2
,
4
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
glm
::
mat4
),
(
void
*
)(
sizeof
(
GLfloat
)
*
0
));
glVertexAttribPointer
(
3
,
4
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
glm
::
mat4
),
(
void
*
)(
sizeof
(
GLfloat
)
*
4
));
glVertexAttribPointer
(
4
,
4
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
glm
::
mat4
),
(
void
*
)(
sizeof
(
GLfloat
)
*
8
));
glVertexAttribPointer
(
5
,
4
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
glm
::
mat4
),
(
void
*
)(
sizeof
(
GLfloat
)
*
12
));
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
// enable position, UV and mvp
glEnableVertexAttribArray
(
0
);
glEnableVertexAttribArray
(
1
);
glEnableVertexAttribArray
(
2
);
glEnableVertexAttribArray
(
3
);
glEnableVertexAttribArray
(
4
);
glEnableVertexAttribArray
(
5
);
// MPV only once per instance
glVertexAttribDivisor
(
2
,
1
);
glVertexAttribDivisor
(
3
,
1
);
glVertexAttribDivisor
(
4
,
1
);
glVertexAttribDivisor
(
5
,
1
);
// get the painter ready
try
{
...
...
@@ -271,21 +251,17 @@ void OpenGLController::updateScene()
int
instanceOffset
(
0
);
for
(
unsigned
int
modelIndex
=
0
;
modelIndex
<
vModels
.
size
();
modelIndex
++
)
for
(
int
modelIndex
=
0
;
modelIndex
<
vModels
.
size
();
modelIndex
++
)
{
// give the MVPs to the shader
//glUniformMatrix4fv(gluiMatrixID, 1, GL_FALSE, &getMVPMatrix(modelIndex)[0][0]);
glUniformMatrix4fv
(
gluiMatrixID
,
1
,
GL_FALSE
,
&
getMVPMatrix
(
modelIndex
)[
0
][
0
]);
//draw objects hardcoded only 1 instance for testing
glDrawArraysInstanced
(
GL_TRIANGLES
,
instanceOffset
,
vModels
[
modelIndex
]
->
meshSize
,
vModels
.
size
());
glDrawArrays
(
GL_TRIANGLES
,
instanceOffset
,
vModels
[
modelIndex
]
->
meshSize
);
instanceOffset
+=
vModels
[
modelIndex
]
->
meshSize
;
}
glfwSwapBuffers
(
pWindow
);
glfwPollEvents
();
}
void
OpenGLController
::
loadMsh
(
const
char
*
path
)
...
...
@@ -350,26 +326,29 @@ void OpenGLController::loadMsh(const char * path)
////TODO: for all
std
::
vector
<
Vertex
>
tempBufferData
;
for
(
unsigned
i
n
t
i
=
0
;
i
<
vModels
.
front
()
->
meshSize
;
i
++
)
for
(
auto
&
it
:
vModels
)
{
Vertex
tempVertex
;
tempVertex
.
position
[
0
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
];
tempVertex
.
position
[
1
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
1
];
tempVertex
.
position
[
2
]
=
(
GLfloat
)
vModels
.
front
()
->
vertex
[
vModels
.
front
()
->
mesh
[
i
]
*
3
+
2
];
if
(
vModels
.
front
()
->
uv
==
NULL
)
{
tempVertex
.
uv
[
0
]
=
1.0
;
tempVertex
.
uv
[
1
]
=
1.0
;
}
else
for
(
unsigned
int
i
=
0
;
i
<
it
->
meshSize
;
i
++
)
{
tempVertex
.
uv
[
0
]
=
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
];
tempVertex
.
uv
[
1
]
=
(
GLfloat
)
vModels
.
front
()
->
uv
[
vModels
.
front
()
->
mesh
[
i
]
*
2
+
1
];
Vertex
tempVertex
;
tempVertex
.
position
[
0
]
=
(
GLfloat
)
it
->
vertex
[
it
->
mesh
[
i
]
*
3
];
tempVertex
.
position
[
1
]
=
(
GLfloat
)
it
->
vertex
[
it
->
mesh
[
i
]
*
3
+
1
];
tempVertex
.
position
[
2
]
=
(
GLfloat
)
it
->
vertex
[
it
->
mesh
[
i
]
*
3
+
2
];
if
(
it
->
uv
==
NULL
)
{
tempVertex
.
uv
[
0
]
=
1.0
;
tempVertex
.
uv
[
1
]
=
1.0
;
}
else
{
tempVertex
.
uv
[
0
]
=
(
GLfloat
)
it
->
uv
[
it
->
mesh
[
i
]
*
2
];
tempVertex
.
uv
[
1
]
=
(
GLfloat
)
it
->
uv
[
it
->
mesh
[
i
]
*
2
+
1
];
}
tempBufferData
.
push_back
(
tempVertex
);
}
tempBufferData
.
push_back
(
tempVertex
);
}
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiVertexBufferID
);
...
...
@@ -381,24 +360,4 @@ void OpenGLController::loadMsh(const char * path)
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
// set instance buffer data
std
::
vector
<
glm
::
mat4
>
tempMVPs
;
for
(
int
i
=
0
;
i
<
vModels
.
size
();
i
++
)
tempMVPs
.
push_back
(
getMVPMatrix
(
i
));
glBindBuffer
(
GL_ARRAY_BUFFER
,
gluiInstanceBufferID
);
glBufferData
(
GL_ARRAY_BUFFER
,
vModels
.
size
()
>
MAX_MODEL_COUNT
?
MAX_MODEL_COUNT
*
sizeof
(
glm
::
mat4
)
:
vModels
.
size
()
*
sizeof
(
glm
::
mat4
),
tempMVPs
.
data
(),
GL_STREAM_DRAW
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
0
);
//glBindBuffer(GL_UNIFORM_BUFFER, gluiInstanceBufferID);
//glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4) * vModels.size(), NULL, tempMVPs.data());
//glBindBuffer(GL_UNIFORM_BUFFER, 0);
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment