Finished Buffer Abstraction

14. Also changed toolset to vs 2019
This commit is contained in:
2022-05-03 09:30:17 +10:00
parent 19bfe25d5c
commit 0cb85e7b72
37 changed files with 156 additions and 10 deletions
Binary file not shown.
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "No Configurations"
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -2,7 +2,7 @@
<Project> <Project>
<ProjectOutputs> <ProjectOutputs>
<ProjectOutput> <ProjectOutput>
<FullPath>D:\cpp\OpenGL\Debug\OpenGL.exe</FullPath> <FullPath>C:\dev\OpenGL\Debug\OpenGL.exe</FullPath>
</ProjectOutput> </ProjectOutput>
</ProjectOutputs> </ProjectOutputs>
<ContentFiles /> <ContentFiles />
Binary file not shown.
+7 -2
View File
@@ -1,5 +1,10 @@
Application.cpp Application.cpp
IndexBuffer.cpp
Renderer.cpp
VertexArray.cpp
VertexBuffer.cpp
Generating Code...
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'D:\cpp\OpenGL\Debug\vc120.pdb'; linking object as if no debug info glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'C:\dev\OpenGL\Debug\vc120.pdb'; linking object as if no debug info
OpenGL.vcxproj -> D:\cpp\OpenGL\Debug\OpenGL.exe OpenGL.vcxproj -> C:\dev\OpenGL\Debug\OpenGL.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native32Bit:VCToolsVersion=14.31.31103:TargetPlatformVersion=10.0.19041.0: PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:VCServicingVersionCrtHeaders=14.29.30136:TargetPlatformVersion=10.0.19041.0:
Debug|Win32|D:\cpp\OpenGL\| Debug|Win32|C:\dev\OpenGL\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -1
View File
@@ -29,7 +29,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries> <UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet> <CharacterSet>Unicode</CharacterSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@@ -154,6 +154,7 @@
<ClCompile Include="src\Application.cpp" /> <ClCompile Include="src\Application.cpp" />
<ClCompile Include="src\IndexBuffer.cpp" /> <ClCompile Include="src\IndexBuffer.cpp" />
<ClCompile Include="src\Renderer.cpp" /> <ClCompile Include="src\Renderer.cpp" />
<ClCompile Include="src\VertexArray.cpp" />
<ClCompile Include="src\VertexBuffer.cpp" /> <ClCompile Include="src\VertexBuffer.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -163,6 +164,8 @@
<ClInclude Include="src\IndexBuffer.h" /> <ClInclude Include="src\IndexBuffer.h" />
<ClInclude Include="src\Renderer.h" /> <ClInclude Include="src\Renderer.h" />
<ClInclude Include="src\VertexBuffer.h" /> <ClInclude Include="src\VertexBuffer.h" />
<ClInclude Include="src\VertexArray.h" />
<ClInclude Include="src\VertexBufferLayout.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
+9
View File
@@ -27,6 +27,9 @@
<ClCompile Include="src\IndexBuffer.cpp"> <ClCompile Include="src\IndexBuffer.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\VertexArray.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="res\shaders\Basic.shader" /> <None Include="res\shaders\Basic.shader" />
@@ -41,5 +44,11 @@
<ClInclude Include="src\IndexBuffer.h"> <ClInclude Include="src\IndexBuffer.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\VertexArray.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\VertexBufferLayout.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
+7 -4
View File
@@ -10,6 +10,7 @@
#include "Renderer.h" #include "Renderer.h"
#include "VertexBuffer.h" #include "VertexBuffer.h"
#include "IndexBuffer.h" #include "IndexBuffer.h"
#include "VertexArray.h"
struct ShaderProgramSource struct ShaderProgramSource
{ {
@@ -155,10 +156,12 @@ int main(void)
GLCall(glGenVertexArrays(1, &vao)); GLCall(glGenVertexArrays(1, &vao));
GLCall(glBindVertexArray(vao)); GLCall(glBindVertexArray(vao));
VertexArray va;
VertexBuffer vb(triforcePos, 6 * 2 * sizeof(float)); VertexBuffer vb(triforcePos, 6 * 2 * sizeof(float));
glEnableVertexAttribArray(0); VertexBufferLayout layout;
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0); layout.Push<float>(2);
va.AddBuffer(vb, layout);
IndexBuffer ib(triforceInd, 3 * 3); IndexBuffer ib(triforceInd, 3 * 3);
@@ -191,7 +194,7 @@ int main(void)
glUseProgram(shader); glUseProgram(shader);
glUniform4f(location, r, 1.0f, 0.0f, 1.0f); glUniform4f(location, r, 1.0f, 0.0f, 1.0f);
GLCall(glBindVertexArray(vao)); va.Bind();
ib.Bind(); ib.Bind();
GLCall(glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, nullptr)); GLCall(glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, nullptr));
+37
View File
@@ -0,0 +1,37 @@
#include "VertexArray.h"
#include "Renderer.h"
VertexArray::VertexArray()
{
GLCall(glGenVertexArrays(1, &m_RendererID));
}
VertexArray::~VertexArray()
{
GLCall(glDeleteVertexArrays(1, &m_RendererID));
}
void VertexArray::AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout)
{
Bind();
vb.Bind();
const auto& elements = layout.GetElements();
unsigned int offset = 0;
for(unsigned int i = 0; i < elements.size(); i++)
{
const auto& element = elements[i];
GLCall(glEnableVertexAttribArray(i));
GLCall(glVertexAttribPointer(i , element.count, element.type, element.normalized, layout.GetStride(), (const void*) offset));
offset += element.count * VertexBufferElement::GetSizeOfType(element.type);
}
}
void VertexArray::Bind() const
{
GLCall(glBindVertexArray(m_RendererID));
}
void VertexArray::Unbind() const
{
GLCall(glBindVertexArray(m_RendererID));
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "VertexBuffer.h"
#include "VertexBufferLayout.h"
class VertexArray
{
private:
unsigned int m_RendererID;
public:
VertexArray();
~VertexArray();
void AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout);
void Bind() const;
void Unbind() const;
};
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include <vector>
#include <GL/glew.h>
#include "Renderer.h"
#include <iostream>
struct VertexBufferElement
{
unsigned int type;
unsigned int count;
unsigned char normalized;
static unsigned int GetSizeOfType(unsigned int type)
{
switch (type)
{
case GL_FLOAT: return 4;
case GL_UNSIGNED_INT: return 4;
case GL_UNSIGNED_BYTE: return 1;
default: ASSERT(false);
return 0;
}
}
};
class VertexBufferLayout
{
private:
std::vector<VertexBufferElement> m_Elements;
unsigned int m_Stride;
public:
VertexBufferLayout()
: m_Stride(0)
{
}
template <typename T>
void Push(unsigned int count)
{
std::cout << "SHould this be called? " << std::endl;
static_assert(false);
}
template<>
void Push<float>(unsigned int count)
{
m_Elements.push_back({GL_FLOAT, count, GL_FALSE});
m_Stride += VertexBufferElement::GetSizeOfType(GL_FLOAT) * count;
}
template<>
void Push<unsigned int>(unsigned int count)
{
m_Elements.push_back({GL_UNSIGNED_INT, count, GL_FALSE});
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT) * count;
}
template<>
void Push<unsigned char>(unsigned int count)
{
m_Elements.push_back({GL_UNSIGNED_BYTE, count, GL_TRUE});
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE) * count;
}
inline const std::vector<VertexBufferElement> GetElements() const { return m_Elements; }
inline unsigned int GetStride() const { return m_Stride; }
};