clangd changes, rename funcs, modernize vertex attrib binding
This commit is contained in:
parent
2a7c7b75b3
commit
808ddee045
@ -1,6 +1,7 @@
|
|||||||
BasedOnStyle: Chromium
|
BasedOnStyle: Chromium
|
||||||
IndentWidth: 4
|
IndentWidth: 4
|
||||||
SortIncludes: false
|
SortIncludes: false
|
||||||
|
AlignTrailingComments: true
|
||||||
|
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
# Force pointers to the type for C++.
|
# Force pointers to the type for C++.
|
||||||
|
32
.clangd
32
.clangd
@ -1,19 +1,23 @@
|
|||||||
Diagnostics:
|
Diagnostics:
|
||||||
ClangTidy:
|
ClangTidy:
|
||||||
Add: [
|
Add: [modernize*, bugprone*, performance*, readability*]
|
||||||
modernize*,
|
Remove:
|
||||||
bugprone*,
|
[
|
||||||
performance*,
|
modernize-use-trailing-return-type,
|
||||||
readability*
|
modernize-avoid-c-arrays,
|
||||||
]
|
readability-magic-numbers,
|
||||||
Remove: [
|
readability-implicit-bool-conversion,
|
||||||
modernize-use-trailing-return-type,
|
readability-identifier-length,
|
||||||
modernize-avoid-c-arrays,
|
bugprone-easily-swappable-parameters,
|
||||||
readability-magic-numbers,
|
]
|
||||||
readability-implicit-bool-conversion,
|
|
||||||
readability-identifier-length,
|
InlayHints:
|
||||||
bugprone-easily-swappable-parameters
|
Enabled: Yes
|
||||||
]
|
ParameterNames: Yes
|
||||||
|
DeducedTypes: Yes
|
||||||
|
|
||||||
|
Hover:
|
||||||
|
ShowAKA: No
|
||||||
|
|
||||||
Completion:
|
Completion:
|
||||||
AllScopes: Yes
|
AllScopes: Yes
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -1,5 +1,6 @@
|
|||||||
{
|
{
|
||||||
"C_Cpp.intelliSenseEngine": "disabled",
|
"C_Cpp.intelliSenseEngine": "disabled",
|
||||||
|
"editor.inlayHints.enabled": "on",
|
||||||
"cmake.statusbar.advanced": {
|
"cmake.statusbar.advanced": {
|
||||||
"debug": {
|
"debug": {
|
||||||
"visibility": "hidden"
|
"visibility": "hidden"
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <game/game.h>
|
#include <game/game.h>
|
||||||
#include <graphics/graphics.h>
|
#include <graphics/graphics.h>
|
||||||
#include <window/window.h>
|
#include <window/window.h>
|
||||||
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -95,7 +96,7 @@ void Graphics::storeVertexBufObj(GLuint& dest, GLsizeiptr size, int* target) {
|
|||||||
glBufferData(GL_ARRAY_BUFFER, size, target, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, size, target, GL_STATIC_DRAW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::multiply4x4Matrices(GLfloat* m, const GLfloat* n) {
|
void Graphics::mulMat4x4(GLfloat* m, const GLfloat* n) {
|
||||||
GLfloat tmp[16];
|
GLfloat tmp[16];
|
||||||
const GLfloat* row;
|
const GLfloat* row;
|
||||||
const GLfloat* column;
|
const GLfloat* column;
|
||||||
@ -104,20 +105,20 @@ void Graphics::multiply4x4Matrices(GLfloat* m, const GLfloat* n) {
|
|||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
tmp[i] = 0;
|
tmp[i] = 0;
|
||||||
d = div(i, 4);
|
d = div(i, 4);
|
||||||
row = n + d.quot * 4;
|
row = n + (ptrdiff_t)(d.quot * 4);
|
||||||
column = m + d.rem;
|
column = m + d.rem;
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
tmp[i] += row[j] * column[j * 4];
|
tmp[i] += row[j] * column[(ptrdiff_t)(j * 4)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memcpy(m, &tmp, sizeof tmp);
|
memcpy(m, &tmp, sizeof tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::rotate4x4Matrix(GLfloat* m,
|
void Graphics::rotMat4x4(GLfloat* m,
|
||||||
GLfloat angle,
|
GLfloat angle,
|
||||||
GLfloat x,
|
GLfloat x,
|
||||||
GLfloat y,
|
GLfloat y,
|
||||||
GLfloat z) {
|
GLfloat z) {
|
||||||
double sin;
|
double sin;
|
||||||
double cos;
|
double cos;
|
||||||
|
|
||||||
@ -139,16 +140,16 @@ void Graphics::rotate4x4Matrix(GLfloat* m,
|
|||||||
0,
|
0,
|
||||||
1};
|
1};
|
||||||
|
|
||||||
multiply4x4Matrices(m, r);
|
mulMat4x4(m, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::translate4x4Matrix(GLfloat* m, GLfloat x, GLfloat y, GLfloat z) {
|
void Graphics::tlateMat4x4(GLfloat* m, GLfloat x, GLfloat y, GLfloat z) {
|
||||||
GLfloat t[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1};
|
GLfloat t[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1};
|
||||||
|
|
||||||
multiply4x4Matrices(m, t);
|
mulMat4x4(m, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::create4x4IdentityMatrix(GLfloat* m) {
|
void Graphics::identMat4x4(GLfloat* m) {
|
||||||
GLfloat t[16] = {
|
GLfloat t[16] = {
|
||||||
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
|
0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
|
||||||
@ -157,16 +158,16 @@ void Graphics::create4x4IdentityMatrix(GLfloat* m) {
|
|||||||
memcpy(m, t, sizeof(t));
|
memcpy(m, t, sizeof(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::transpose4x4Matrix(GLfloat* m) {
|
void Graphics::tposeMat4x4(GLfloat* m) {
|
||||||
GLfloat t[16] = {m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13],
|
GLfloat t[16] = {m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13],
|
||||||
m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]};
|
m[2], m[6], m[10], m[14], m[3], m[7], m[11], m[15]};
|
||||||
|
|
||||||
memcpy(m, t, sizeof(t));
|
memcpy(m, t, sizeof(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::invert4x4Matrix(GLfloat* m) {
|
void Graphics::invMat4x4(GLfloat* m) {
|
||||||
GLfloat t[16];
|
GLfloat t[16];
|
||||||
create4x4IdentityMatrix(t);
|
identMat4x4(t);
|
||||||
|
|
||||||
// Extract and invert the translation part 't'. The inverse of a
|
// Extract and invert the translation part 't'. The inverse of a
|
||||||
// translation matrix can be calculated by negating the translation
|
// translation matrix can be calculated by negating the translation
|
||||||
@ -178,19 +179,19 @@ void Graphics::invert4x4Matrix(GLfloat* m) {
|
|||||||
// Invert the rotation part 'r'. The inverse of a rotation matrix is
|
// Invert the rotation part 'r'. The inverse of a rotation matrix is
|
||||||
// equal to its transpose.
|
// equal to its transpose.
|
||||||
m[12] = m[13] = m[14] = 0;
|
m[12] = m[13] = m[14] = 0;
|
||||||
transpose4x4Matrix(m);
|
tposeMat4x4(m);
|
||||||
|
|
||||||
// inv(m) = inv(r) * inv(t)
|
// inv(m) = inv(r) * inv(t)
|
||||||
multiply4x4Matrices(m, t);
|
mulMat4x4(m, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::calcPerspectiveProjectTransformation(GLfloat* m,
|
void Graphics::calcPersProjTform(GLfloat* m,
|
||||||
GLfloat yFOV,
|
GLfloat yFOV,
|
||||||
GLfloat aspect,
|
GLfloat aspect,
|
||||||
GLfloat zNear,
|
GLfloat zNear,
|
||||||
GLfloat zFar) {
|
GLfloat zFar) {
|
||||||
GLfloat tmp[16];
|
GLfloat tmp[16];
|
||||||
create4x4IdentityMatrix(tmp);
|
identMat4x4(tmp);
|
||||||
|
|
||||||
double sine;
|
double sine;
|
||||||
double cosine;
|
double cosine;
|
||||||
|
@ -44,7 +44,7 @@ class Graphics {
|
|||||||
* @param m first matrix
|
* @param m first matrix
|
||||||
* @param n second matrix
|
* @param n second matrix
|
||||||
*/
|
*/
|
||||||
static void multiply4x4Matrices(GLfloat*, const GLfloat*);
|
static void mulMat4x4(GLfloat*, const GLfloat*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotates a 4x4 matrix
|
* Rotates a 4x4 matrix
|
||||||
@ -55,7 +55,7 @@ class Graphics {
|
|||||||
* @param y the y component of the direction to rotate to
|
* @param y the y component of the direction to rotate to
|
||||||
* @param z the z component of the direction to rotate to
|
* @param z the z component of the direction to rotate to
|
||||||
*/
|
*/
|
||||||
static void rotate4x4Matrix(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
static void rotMat4x4(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates a 4x4 matrix
|
* Translates a 4x4 matrix
|
||||||
@ -65,28 +65,28 @@ class Graphics {
|
|||||||
* @param y the y component of the direction to translate to
|
* @param y the y component of the direction to translate to
|
||||||
* @param z the z component of the direction to translate to
|
* @param z the z component of the direction to translate to
|
||||||
*/
|
*/
|
||||||
static void translate4x4Matrix(GLfloat*, GLfloat, GLfloat, GLfloat);
|
static void tlateMat4x4(GLfloat*, GLfloat, GLfloat, GLfloat);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a 4x4 identity matrix
|
* Creates a 4x4 identity matrix
|
||||||
*
|
*
|
||||||
* @param m the matrix to convert to an identity matrix
|
* @param m the matrix to convert to an identity matrix
|
||||||
*/
|
*/
|
||||||
static void create4x4IdentityMatrix(GLfloat*);
|
static void identMat4x4(GLfloat*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transposes a 4x4 matrix.
|
* Transposes a 4x4 matrix.
|
||||||
*
|
*
|
||||||
* @param m the matrix to transpose
|
* @param m the matrix to transpose
|
||||||
*/
|
*/
|
||||||
static void transpose4x4Matrix(GLfloat*);
|
static void tposeMat4x4(GLfloat*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inverts a 4x4 matrix.
|
* Inverts a 4x4 matrix.
|
||||||
*
|
*
|
||||||
* @param m the matrix to invert
|
* @param m the matrix to invert
|
||||||
*/
|
*/
|
||||||
static void invert4x4Matrix(GLfloat*);
|
static void invMat4x4(GLfloat*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate a perspective projection transformation.
|
* Calculate a perspective projection transformation.
|
||||||
@ -97,11 +97,7 @@ class Graphics {
|
|||||||
* @param zNear the near clipping plane
|
* @param zNear the near clipping plane
|
||||||
* @param zFar the far clipping plane
|
* @param zFar the far clipping plane
|
||||||
*/
|
*/
|
||||||
static void calcPerspectiveProjectTransformation(GLfloat*,
|
static void calcPersProjTform(GLfloat*, GLfloat, GLfloat, GLfloat, GLfloat);
|
||||||
GLfloat,
|
|
||||||
GLfloat,
|
|
||||||
GLfloat,
|
|
||||||
GLfloat);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -263,14 +263,14 @@ void GearsScene::drawGear(Gear* gear,
|
|||||||
|
|
||||||
// Translate and rotate the gear
|
// Translate and rotate the gear
|
||||||
memcpy(modelView, transform, sizeof(modelView));
|
memcpy(modelView, transform, sizeof(modelView));
|
||||||
Graphics::translate4x4Matrix(modelView, x, y, 0);
|
Graphics::tlateMat4x4(modelView, x, y, 0);
|
||||||
Graphics::rotate4x4Matrix(modelView, 2.0F * (float)M_PI * angle / 360.0F, 0,
|
Graphics::rotMat4x4(modelView, 2.0F * (float)M_PI * angle / 360.0F, 0, 0,
|
||||||
0, 1);
|
1);
|
||||||
|
|
||||||
/* Create and set the ModelViewProjectionMatrix */
|
/* Create and set the ModelViewProjectionMatrix */
|
||||||
memcpy(modelViewProjection, this->projectionMatrix,
|
memcpy(modelViewProjection, this->projectionMatrix,
|
||||||
sizeof(modelViewProjection));
|
sizeof(modelViewProjection));
|
||||||
Graphics::multiply4x4Matrices(modelViewProjection, modelView);
|
Graphics::mulMat4x4(modelViewProjection, modelView);
|
||||||
Graphics::setUniformMatrixValue((GLint)this->modelViewProjectionMatrixLoc,
|
Graphics::setUniformMatrixValue((GLint)this->modelViewProjectionMatrixLoc,
|
||||||
modelViewProjection);
|
modelViewProjection);
|
||||||
|
|
||||||
@ -279,8 +279,8 @@ void GearsScene::drawGear(Gear* gear,
|
|||||||
* ModelView matrix.
|
* ModelView matrix.
|
||||||
*/
|
*/
|
||||||
memcpy(normalMatrix, modelView, sizeof(normalMatrix));
|
memcpy(normalMatrix, modelView, sizeof(normalMatrix));
|
||||||
Graphics::invert4x4Matrix(normalMatrix);
|
Graphics::invMat4x4(normalMatrix);
|
||||||
Graphics::transpose4x4Matrix(normalMatrix);
|
Graphics::tposeMat4x4(normalMatrix);
|
||||||
Graphics::setUniformMatrixValue((GLint)this->normalMatrixLoc, normalMatrix);
|
Graphics::setUniformMatrixValue((GLint)this->normalMatrixLoc, normalMatrix);
|
||||||
|
|
||||||
/* Set the gear color */
|
/* Set the gear color */
|
||||||
@ -290,14 +290,17 @@ void GearsScene::drawGear(Gear* gear,
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, gear->vertexBufObj);
|
glBindBuffer(GL_ARRAY_BUFFER, gear->vertexBufObj);
|
||||||
|
|
||||||
/* Set up the position of the attributes in the vertex buffer object */
|
/* Set up the position of the attributes in the vertex buffer object */
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
int bindingIdx = 0;
|
||||||
nullptr);
|
|
||||||
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat),
|
|
||||||
(GLfloat*)(sizeof(GLfloat) * 3));
|
|
||||||
|
|
||||||
/* Enable the attributes */
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||||
|
glVertexAttribBinding(0, bindingIdx);
|
||||||
|
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
|
glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3);
|
||||||
|
glVertexAttribBinding(1, bindingIdx);
|
||||||
|
|
||||||
|
glBindVertexBuffer(bindingIdx, gear->vertexBufObj, 0, sizeof(GLfloat) * 6);
|
||||||
|
|
||||||
/* Draw the triangle strips that comprise the gear */
|
/* Draw the triangle strips that comprise the gear */
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->nVertices);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, gear->nVertices);
|
||||||
@ -313,9 +316,9 @@ void GearsScene::reshape() {
|
|||||||
this->width = this->pGame->pWindow->getWidth();
|
this->width = this->pGame->pWindow->getWidth();
|
||||||
this->height = this->pGame->pWindow->getHeight();
|
this->height = this->pGame->pWindow->getHeight();
|
||||||
|
|
||||||
Graphics::calcPerspectiveProjectTransformation(
|
Graphics::calcPersProjTform(this->projectionMatrix, 60.0,
|
||||||
this->projectionMatrix, 60.0,
|
(float)this->width / (float)this->height,
|
||||||
(float)this->width / (float)this->height, 1.0, 1024.0);
|
1.0, 1024.0);
|
||||||
glViewport(0, 0, (GLint)this->width, (GLint)this->height);
|
glViewport(0, 0, (GLint)this->width, (GLint)this->height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,7 +337,7 @@ void GearsScene::idle() {
|
|||||||
tRot0 = t;
|
tRot0 = t;
|
||||||
|
|
||||||
/* advance rotation for next frame */
|
/* advance rotation for next frame */
|
||||||
this->currentAngle += 70.0 * dt; /* 70 degrees per second */
|
this->currentAngle += 70.0F * (GLfloat)dt; /* 70 degrees per second */
|
||||||
if (this->currentAngle > 3600.0) {
|
if (this->currentAngle > 3600.0) {
|
||||||
this->currentAngle -= 3600.0;
|
this->currentAngle -= 3600.0;
|
||||||
}
|
}
|
||||||
@ -346,8 +349,8 @@ void GearsScene::idle() {
|
|||||||
tRate0 = t;
|
tRate0 = t;
|
||||||
}
|
}
|
||||||
if (t - tRate0 >= 5.0) {
|
if (t - tRate0 >= 5.0) {
|
||||||
GLfloat seconds = t - tRate0;
|
auto seconds = (GLfloat)(t - tRate0);
|
||||||
GLfloat fps = frames / seconds;
|
GLfloat fps = (GLfloat)frames / seconds;
|
||||||
printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
|
printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
|
||||||
fps);
|
fps);
|
||||||
tRate0 = t;
|
tRate0 = t;
|
||||||
@ -360,19 +363,19 @@ void GearsScene::draw() {
|
|||||||
const static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
|
const static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
|
||||||
const static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
|
const static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
|
||||||
GLfloat transform[16];
|
GLfloat transform[16];
|
||||||
Graphics::create4x4IdentityMatrix(transform);
|
Graphics::identMat4x4(transform);
|
||||||
|
|
||||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
/* Translate and rotate the view */
|
/* Translate and rotate the view */
|
||||||
Graphics::translate4x4Matrix(transform, 0, 0, -20);
|
Graphics::tlateMat4x4(transform, 0, 0, -20);
|
||||||
Graphics::rotate4x4Matrix(
|
Graphics::rotMat4x4(transform,
|
||||||
transform, 2.0F * (float)M_PI * viewRotation[0] / 360.0F, 1, 0, 0);
|
2.0F * (float)M_PI * viewRotation[0] / 360.0F, 1, 0, 0);
|
||||||
Graphics::rotate4x4Matrix(
|
Graphics::rotMat4x4(transform,
|
||||||
transform, 2.0F * (float)M_PI * viewRotation[1] / 360.0F, 0, 1, 0);
|
2.0F * (float)M_PI * viewRotation[1] / 360.0F, 0, 1, 0);
|
||||||
Graphics::rotate4x4Matrix(
|
Graphics::rotMat4x4(transform,
|
||||||
transform, 2.0F * (float)M_PI * viewRotation[2] / 360.0F, 0, 0, 1);
|
2.0F * (float)M_PI * viewRotation[2] / 360.0F, 0, 0, 1);
|
||||||
|
|
||||||
/* Draw the gears */
|
/* Draw the gears */
|
||||||
drawGear(gears[0], transform, -3.0, -2.0, currentAngle, red);
|
drawGear(gears[0], transform, -3.0, -2.0, currentAngle, red);
|
||||||
|
@ -96,7 +96,6 @@ class GearsScene : public Scene {
|
|||||||
/**
|
/**
|
||||||
* Draws a gear
|
* Draws a gear
|
||||||
*
|
*
|
||||||
* @param gear the gear to draw
|
|
||||||
* @param transform the current transformation matrix
|
* @param transform the current transformation matrix
|
||||||
* @param x the x pos to draw the gear at
|
* @param x the x pos to draw the gear at
|
||||||
* @param y the y pos to draw the gear at
|
* @param y the y pos to draw the gear at
|
||||||
|
Reference in New Issue
Block a user