Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Generated based on style: LLVM
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveMacros: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros:
- __capability
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeConceptDeclarations: true
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
QualifierAlignment: Leave
CompactNamespaces: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: LogicalBlock
ExperimentalAutoDetectBinPacking: false
PackConstructorInitializers: BinPack
BasedOnStyle: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
AllowAllConstructorInitializersOnNextLine: true
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseLabels: false
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: BeforeHash
IndentExternBlock: AfterExternBlock
IndentRequires: false
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakOpenParenthesis: 0
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PenaltyIndentedWhitespace: 0
PointerAlignment: Middle
PPIndentWidth: -1
ReferenceAlignment: Left
ReflowComments: true
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 1
SortIncludes: CaseSensitive
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
BitFieldColonSpacing: Both
Standard: Latest
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...
2 changes: 2 additions & 0 deletions scripts/reformat-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use this only when changing the style spec. For local changes, use git clang-format
clang-format -i $(find src -path 'glad' -prune -o -name 'stb_*' -o -name '*.[ch]pp' -print)
2 changes: 1 addition & 1 deletion src/game/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ void Player::render() {
tex::PLAYER_TEX->render(this->x, this->y, PLAYER_SIZE, PLAYER_SIZE, tex::RenderBasis::MID, tex::RenderBasis::MID);
}

}
} // namespace game
3 changes: 1 addition & 2 deletions src/game/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class Player : GameObject, Renderable {
public:
void render() override;
Player(int xloc, int yloc);

};

} // namespace
} // namespace game
14 changes: 8 additions & 6 deletions src/graphics/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@
#include <glad/glad.h>

Mesh::Mesh(std::vector<float> vertices, std::vector<int> indices, std::vector<float> texcoords) {

glGenVertexArrays(1, &vao);

glBindVertexArray(vao);

// Vertices
glGenBuffers(1, &vertices_id);
glBindBuffer(GL_ARRAY_BUFFER, vertices_id);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof (float), vertices.data(), GL_STATIC_DRAW);
// clang-format off
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, 0, 0, 0);
// clang-format on
glBindBuffer(GL_ARRAY_BUFFER, 0);

// Indices
glGenBuffers(1, &index_id);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof (int), indices.data(), GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(int), indices.data(), GL_STATIC_DRAW);

indices_ct = indices.size();

// Texture coordinates
glGenBuffers(1, &texcoords_id);
glBindBuffer(GL_ARRAY_BUFFER, texcoords_id);
glBufferData(GL_ARRAY_BUFFER, texcoords.size() * sizeof (float), texcoords.data(), GL_STATIC_DRAW);
// clang-format off
glBufferData(GL_ARRAY_BUFFER, texcoords.size() * sizeof(float), texcoords.data(), GL_STATIC_DRAW);
glVertexAttribPointer(1, 2, GL_FLOAT, 0, 0, 0);
// clang-format on
glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindVertexArray(0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

}

void Mesh::draw() {
Expand All @@ -46,7 +49,6 @@ void Mesh::draw() {
glBindVertexArray(0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);

}

Mesh::~Mesh() {
Expand Down
5 changes: 2 additions & 3 deletions src/graphics/mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

class Mesh {

private:
private:
unsigned vao, vertices_id, index_id, texcoords_id, indices_ct;

public:
public:
Mesh(std::vector<float> vertices, std::vector<int> indices, std::vector<float> texcoords);
void draw();
~Mesh();

};
14 changes: 7 additions & 7 deletions src/graphics/shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace gl {

static std::string_view bytes_as_string_view(const std::vector<unsigned char>& vec) {
return std::string_view(reinterpret_cast<const char*>(vec.data()), vec.size());
return std::string_view(reinterpret_cast<const char *>(vec.data()), vec.size());
}

Shader::Shader(std::string_view vertex_source, std::string_view fragment_source) {
Expand All @@ -37,7 +37,7 @@ int Shader::create_subshader(std::string_view source, GLenum type) {
// TODO -- log some error
}

const char* src = source.data();
const char * src = source.data();
int len = source.size();
glShaderSource(id, 1, &src, &len);
glCompileShader(id);
Expand All @@ -52,13 +52,12 @@ int Shader::create_subshader(std::string_view source, GLenum type) {
}

return id;

}

void Shader::link(int vert, int frag) {
glAttachShader(this->program_id, vert);
glAttachShader(this->program_id, frag);
glLinkProgram (this->program_id);
glLinkProgram(this->program_id);
// We no longer need these sub-shaders.
glDetachShader(this->program_id, vert);
glDetachShader(this->program_id, frag);
Expand Down Expand Up @@ -101,13 +100,14 @@ void Shader::set_uniform_value(std::string name, float value) {
}

void load_all_shaders() {
// clang-format off
GAME_SHADER = std::make_unique<Shader>(Shader::load_from_file(
"src/shader/basic_vert.glsl", "src/shader/basic_frag.glsl"
));
"src/shader/basic_vert.glsl", "src/shader/basic_frag.glsl"));
// clang-format on
}

void unload_all_shaders() {
GAME_SHADER->destroy();
}

}
} // namespace gl
26 changes: 12 additions & 14 deletions src/graphics/shader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace gl {

class Shader {

private:
private:
// The OpenGL ID of this shader.
unsigned program_id;
// Create a single vertex or fragment shader.
Expand All @@ -26,23 +26,21 @@ class Shader {
// All uniforms.
std::map<std::string, int> uniforms;

public:
public:
// Take in the file paths.
Shader(std::string_view vertex_source, std::string_view fragment_source);
~Shader();
Shader(std::string_view vertex_source, std::string_view fragment_source);
~Shader();

static Shader load_from_file(ZStringView vertex_fname,
ZStringView fragment_fname);
static Shader load_from_file(ZStringView vertex_fname, ZStringView fragment_fname);

void bind(); // set as active shader
void unbind();
void destroy();
void bind(); // set as active shader
void unbind();
void destroy();

void register_uniform(std::string name);
void set_uniform_value(std::string name, float value);

friend void unload_all_shaders();
void register_uniform(std::string name);
void set_uniform_value(std::string name, float value);

friend void unload_all_shaders();
};

extern std::unique_ptr<Shader> GAME_SHADER; // the basic shader
Expand All @@ -53,4 +51,4 @@ extern std::unique_ptr<Shader> GAME_SHADER; // the basic shader
void load_all_shaders();
void unload_all_shaders();

}
} // namespace gl
Loading