Finished Buffer Abstraction
14. Also changed toolset to vs 2019
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
.vs/OpenGL/v17/ipch/AutoPCH/1a89d84355aa73c3/VERTEXARRAY.ipch
Normal file
BIN
.vs/OpenGL/v17/ipch/AutoPCH/1a89d84355aa73c3/VERTEXARRAY.ipch
Normal file
Binary file not shown.
BIN
.vs/OpenGL/v17/ipch/AutoPCH/6164a016e334bea5/VERTEXBUFFER.ipch
Normal file
BIN
.vs/OpenGL/v17/ipch/AutoPCH/6164a016e334bea5/VERTEXBUFFER.ipch
Normal file
Binary file not shown.
BIN
.vs/OpenGL/v17/ipch/AutoPCH/67c994b9f0b48893/INDEXBUFFER.ipch
Normal file
BIN
.vs/OpenGL/v17/ipch/AutoPCH/67c994b9f0b48893/INDEXBUFFER.ipch
Normal file
Binary file not shown.
BIN
.vs/OpenGL/v17/ipch/AutoPCH/69fe50f9c0bee003/APPLICATION.ipch
Normal file
BIN
.vs/OpenGL/v17/ipch/AutoPCH/69fe50f9c0bee003/APPLICATION.ipch
Normal file
Binary file not shown.
BIN
.vs/OpenGL/v17/ipch/AutoPCH/bfcc1813f187b59e/VERTEXARRAY.ipch
Normal file
BIN
.vs/OpenGL/v17/ipch/AutoPCH/bfcc1813f187b59e/VERTEXARRAY.ipch
Normal file
Binary file not shown.
Binary file not shown.
3
.vs/ProjectSettings.json
Normal file
3
.vs/ProjectSettings.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"CurrentProjectSetting": "No Configurations"
|
||||
}
|
||||
BIN
.vs/slnx.sqlite
BIN
.vs/slnx.sqlite
Binary file not shown.
BIN
Debug/OpenGL.exe
BIN
Debug/OpenGL.exe
Binary file not shown.
BIN
Debug/OpenGL.pdb
BIN
Debug/OpenGL.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
<Project>
|
||||
<ProjectOutputs>
|
||||
<ProjectOutput>
|
||||
<FullPath>D:\cpp\OpenGL\Debug\OpenGL.exe</FullPath>
|
||||
<FullPath>C:\dev\OpenGL\Debug\OpenGL.exe</FullPath>
|
||||
</ProjectOutput>
|
||||
</ProjectOutputs>
|
||||
<ContentFiles />
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,10 @@
|
||||
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 '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
|
||||
OpenGL.vcxproj -> D:\cpp\OpenGL\Debug\OpenGL.exe
|
||||
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 -> 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:
|
||||
Debug|Win32|D:\cpp\OpenGL\|
|
||||
PlatformToolSet=v142:VCToolArchitecture=Native32Bit:VCToolsVersion=14.29.30133:VCServicingVersionCrtHeaders=14.29.30136:TargetPlatformVersion=10.0.19041.0:
|
||||
Debug|Win32|C:\dev\OpenGL\|
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
OpenGL/Debug/VertexArray.obj
Normal file
BIN
OpenGL/Debug/VertexArray.obj
Normal file
Binary file not shown.
Binary file not shown.
BIN
OpenGL/Debug/vc142.idb
Normal file
BIN
OpenGL/Debug/vc142.idb
Normal file
Binary file not shown.
BIN
OpenGL/Debug/vc142.pdb
Normal file
BIN
OpenGL/Debug/vc142.pdb
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -29,7 +29,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
@@ -154,6 +154,7 @@
|
||||
<ClCompile Include="src\Application.cpp" />
|
||||
<ClCompile Include="src\IndexBuffer.cpp" />
|
||||
<ClCompile Include="src\Renderer.cpp" />
|
||||
<ClCompile Include="src\VertexArray.cpp" />
|
||||
<ClCompile Include="src\VertexBuffer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -163,6 +164,8 @@
|
||||
<ClInclude Include="src\IndexBuffer.h" />
|
||||
<ClInclude Include="src\Renderer.h" />
|
||||
<ClInclude Include="src\VertexBuffer.h" />
|
||||
<ClInclude Include="src\VertexArray.h" />
|
||||
<ClInclude Include="src\VertexBufferLayout.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<ClCompile Include="src\IndexBuffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\VertexArray.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\shaders\Basic.shader" />
|
||||
@@ -41,5 +44,11 @@
|
||||
<ClInclude Include="src\IndexBuffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\VertexArray.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\VertexBufferLayout.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Renderer.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "IndexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
|
||||
struct ShaderProgramSource
|
||||
{
|
||||
@@ -155,10 +156,12 @@ int main(void)
|
||||
GLCall(glGenVertexArrays(1, &vao));
|
||||
GLCall(glBindVertexArray(vao));
|
||||
|
||||
VertexArray va;
|
||||
VertexBuffer vb(triforcePos, 6 * 2 * sizeof(float));
|
||||
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);
|
||||
|
||||
VertexBufferLayout layout;
|
||||
layout.Push<float>(2);
|
||||
va.AddBuffer(vb, layout);
|
||||
|
||||
IndexBuffer ib(triforceInd, 3 * 3);
|
||||
|
||||
@@ -191,7 +194,7 @@ int main(void)
|
||||
glUseProgram(shader);
|
||||
glUniform4f(location, r, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
GLCall(glBindVertexArray(vao));
|
||||
va.Bind();
|
||||
ib.Bind();
|
||||
|
||||
GLCall(glDrawElements(GL_TRIANGLES, 9, GL_UNSIGNED_INT, nullptr));
|
||||
|
||||
37
OpenGL/src/VertexArray.cpp
Normal file
37
OpenGL/src/VertexArray.cpp
Normal 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
OpenGL/src/VertexArray.h
Normal file
18
OpenGL/src/VertexArray.h
Normal 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
OpenGL/src/VertexBufferLayout.h
Normal file
68
OpenGL/src/VertexBufferLayout.h
Normal 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; }
|
||||
};
|
||||
Reference in New Issue
Block a user