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
ed66d77b
Commit
ed66d77b
authored
Nov 07, 2016
by
Anakin
Browse files
still trying to draw instanced
parent
8a36fe10
Changes
4
Hide whitespace changes
Inline
Side-by-side
MshViewer/Header/OpenGLController.h
View file @
ed66d77b
...
...
@@ -94,7 +94,7 @@ private:
void
startGLEW
();
void
setCallbackFunctions
();
glm
::
mat4
getMVPMatrix
();
glm
::
mat4
getMVPMatrix
(
unsigned
int
index
);
////////////////////////////////////////////////////////////////////////////////////////////
...
...
MshViewer/Shader/TextureShader.vert
View file @
ed66d77b
...
...
@@ -12,12 +12,12 @@ layout(location = 2) in mat4 mvp;
out
vec2
UV
;
// Values that stay constant for the whole mesh.
//
uniform mat4 MVP;
uniform
mat4
MVP
;
void
main
(){
// Output position of the vertex, in clip space : MVP * position
gl_Position
=
mvp
*
vec4
(
vertexPosition_modelspace
,
1
);
gl_Position
=
MVP
*
vec4
(
vertexPosition_modelspace
,
1
);
UV
=
vertexUV
;
...
...
MshViewer/Source/OpenGlController.cpp
View file @
ed66d77b
...
...
@@ -188,7 +188,7 @@ void OpenGLController::setCallbackFunctions()
glfwSetKeyCallback
(
pWindow
,
keyPress
);
}
glm
::
mat4
OpenGLController
::
getMVPMatrix
()
glm
::
mat4
OpenGLController
::
getMVPMatrix
(
unsigned
int
index
)
{
// Projection
glm
::
mat4
m4x4Projection
=
glm
::
perspective
(
fFOV
,
float
(
iWidth
)
/
float
(
iHeight
),
fMinView
,
fMaxView
);
...
...
@@ -202,7 +202,7 @@ glm::mat4 OpenGLController::getMVPMatrix()
// Model
//TODO for all
glm
::
mat4
m4x4Model
=
vModels
.
front
()
->
m4x4Translation
;
glm
::
mat4
m4x4Model
=
vModels
[
index
]
->
m4x4Translation
;
// User controlled rotation
glm
::
mat4
m4x4ModelRot
=
glm
::
mat4
(
1.0
f
);
...
...
@@ -266,23 +266,28 @@ void OpenGLController::updateScene()
// use shader prgm
glUseProgram
(
gluiShaderPrgmID
);
// fill vector with MVPs of all Models (only 1 for testing)
std
::
vector
<
glm
::
mat4
>
mvpMatrices
;
mvpMatrices
.
push_back
(
getMVPMatrix
());
// give the MVPs to the shader
glBindBuffer
(
GL_UNIFORM_BUFFER
,
gluiInstanceBufferID
);
glBufferSubData
(
GL_UNIFORM_BUFFER
,
sizeof
(
glm
::
mat4
)
*
mvpMatrices
.
size
(),
NULL
,
mvpMatrices
.
data
());
glBindBuffer
(
GL_UNIFORM_BUFFER
,
0
);
// bind texture in texture unit 0
glActiveTexture
(
GL_TEXTURE0
);
glBindTexture
(
GL_TEXTURE_2D
,
gluiTextureID
);
// tell sampler to use texture unit 0
glUniform1i
(
gluiSamplerID
,
0
);
//draw objects hardcoded only 1 instance for testing
glDrawArraysInstanced
(
GL_TRIANGLES
,
0
,
vModels
.
front
()
->
meshSize
,
1
);
int
instanceOffset
(
0
);
for
(
unsigned
int
modelIndex
=
0
;
modelIndex
<
vModels
.
size
();
modelIndex
++
)
{
// give the MVPs to the shader
glBindBuffer
(
GL_UNIFORM_BUFFER
,
gluiInstanceBufferID
);
glBufferSubData
(
GL_UNIFORM_BUFFER
,
sizeof
(
glm
::
mat4
),
NULL
,
&
getMVPMatrix
(
0
));
glBindBuffer
(
GL_UNIFORM_BUFFER
,
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
());
instanceOffset
+=
vModels
[
modelIndex
]
->
meshSize
;
}
glfwSwapBuffers
(
pWindow
);
glfwPollEvents
();
...
...
MshViewer/main.cpp
View file @
ed66d77b
...
...
@@ -38,7 +38,7 @@ int main(int argc, char** argv)
openGL:
scene
->
loadMsh
(
"..
\\
Release
\\
Msh
\\
cubeTrans
.msh"
);
scene
->
loadMsh
(
"..
\\
Release
\\
Msh
\\
houseWOnull
.msh"
);
do
{
scene
->
updateScene
();
...
...
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