Skip to content

Commit

Permalink
Working Hello Triangle sample
Browse files Browse the repository at this point in the history
Compiled and Linked Shaders, Implemented Vertex Buffer.
Modifed xmake scripts.
Reorganized the samples asset folder structure.
  • Loading branch information
abhayMore authored Aug 12, 2024
1 parent 4b3663f commit 71e83b6
Show file tree
Hide file tree
Showing 34 changed files with 712 additions and 184 deletions.
16 changes: 8 additions & 8 deletions Core/Application/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "Application.h"
#include "SDL_scancode.h"
#include <SDL2/SDL.h>
#include <chrono>

Expand All @@ -10,7 +9,9 @@ namespace CGL::Core
bool g_isTestMode{ false };

Application::Application(std::string_view name, i32 argc, char** argv)
: m_name(name), m_isRunning(true), m_window(nullptr)
: m_isRunning(true)
, m_name(name)
, m_window(nullptr)
{
// Parse command line arguments
for (int i = 1; i < argc; ++i)
Expand Down Expand Up @@ -56,7 +57,9 @@ namespace CGL::Core
{
switch (e.window.event)
{
case SDL_WINDOWEVENT_RESIZED: OnResize(e.window.data1, e.window.data2); break;
case SDL_WINDOWEVENT_RESIZED:
OnResize(e.window.data1, e.window.data2);
break;
}
}
}
Expand All @@ -80,21 +83,18 @@ namespace CGL::Core
}
}
}

OnShutdown();
}

bool Application::OnInit()
bool Application::OnInit()
{
// Create SDL window
// Create SDL window
u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;

#if defined(CGL_RHI_OPENGL)
flags |= SDL_WINDOW_OPENGL;
#elif defined(CGL_RHI_VULKAN)
flags |= SDL_WINDOW_VULKAN;
#elif defined(CGL_RHI_METAL)

flags |= SDL_WINDOW_METAL;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Core/Application/Application.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <SDL2/SDL_events.h>
#include <Core/Common.h>
#include <Core/Graphics/Renderer.h>
#include <SDL2/SDL_events.h>

struct SDL_Window;

Expand Down
33 changes: 20 additions & 13 deletions Core/External/SimpleMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#include <dxgi1_2.h>
#endif

#if defined(_MSC_VER)
#define CGL_CDECL __cdecl
#else
#define CGL_CDECL
#endif

#include <cassert>
#include <cstddef>
#include <cstring>
Expand Down Expand Up @@ -1017,7 +1023,7 @@ namespace DirectX
float Dot(const Quaternion& Q) const noexcept;

void RotateTowards(const Quaternion& target, float maxAngle) noexcept;
void __cdecl RotateTowards(const Quaternion& target, float maxAngle, Quaternion& result) const noexcept;
void CGL_CDECL RotateTowards(const Quaternion& target, float maxAngle, Quaternion& result) const noexcept;

// Computes rotation about y-axis (y), then x-axis (x), then z-axis (z)
Vector3 ToEuler() const noexcept;
Expand All @@ -1043,11 +1049,10 @@ namespace DirectX
static void Concatenate(const Quaternion& q1, const Quaternion& q2, Quaternion& result) noexcept;
static Quaternion Concatenate(const Quaternion& q1, const Quaternion& q2) noexcept;

static void __cdecl FromToRotation(const Vector3& fromDir, const Vector3& toDir,
Quaternion& result) noexcept;
static void CGL_CDECL FromToRotation(const Vector3& fromDir, const Vector3& toDir, Quaternion& result) noexcept;
static Quaternion FromToRotation(const Vector3& fromDir, const Vector3& toDir) noexcept;

static void __cdecl LookRotation(const Vector3& forward, const Vector3& up, Quaternion& result) noexcept;
static void CGL_CDECL LookRotation(const Vector3& forward, const Vector3& up, Quaternion& result) noexcept;
static Quaternion LookRotation(const Vector3& forward, const Vector3& up) noexcept;

static float Angle(const Quaternion& q1, const Quaternion& q2) noexcept;
Expand Down Expand Up @@ -1254,15 +1259,16 @@ namespace DirectX
: x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz)
{
}
explicit Viewport(const RECT& rct) noexcept
: x(float(rct.left))
, y(float(rct.top))
, width(float(rct.right - rct.left))
, height(float(rct.bottom - rct.top))
, minDepth(0.f)
, maxDepth(1.f)

#ifdef CGL_PLATFORM_WINDOWS
explicit Viewport(const RECT& rct) noexcept :
x(float(rct.left)), y(float(rct.top)),
width(float(rct.right - rct.left)),
height(float(rct.bottom - rct.top)),
minDepth(0.f), maxDepth(1.f)
{
}
#endif

#if defined(__d3d11_h__) || defined(__d3d11_x_h__)
// Direct3D 11 interop
Expand Down Expand Up @@ -1314,8 +1320,9 @@ namespace DirectX
#endif

// Assignment operators
Viewport& operator=(const RECT& rct) noexcept;

#ifdef CGL_PLATFORM_WINDOWS
Viewport& operator= (const RECT& rct) noexcept;
#endif
// Viewport operations
float AspectRatio() const noexcept;

Expand Down
4 changes: 3 additions & 1 deletion Core/External/SimpleMath.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3797,7 +3797,8 @@ inline bool Viewport::operator!=(const Viewport& vp) const noexcept
// Assignment operators
//------------------------------------------------------------------------------

inline Viewport& Viewport::operator=(const RECT& rct) noexcept
#ifdef CGL_PLATFORM_WINDOWS
inline Viewport& Viewport::operator= (const RECT& rct) noexcept
{
x = float(rct.left);
y = float(rct.top);
Expand All @@ -3807,6 +3808,7 @@ inline Viewport& Viewport::operator=(const RECT& rct) noexcept
maxDepth = 1.f;
return *this;
}
#endif

#if defined(__d3d11_h__) || defined(__d3d11_x_h__)
inline Viewport& Viewport::operator=(const D3D11_VIEWPORT& vp) noexcept
Expand Down
5 changes: 4 additions & 1 deletion Core/Graphics/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#endif

#if defined(CGL_RHI_OPENGL)
#include <Core/Graphics/RHI/OpenGL/OPENGLIndexBuffer.h>
#include <Core/Graphics/RHI/OpenGL/OPENGLVertexBuffer.h>
#include <Core/Graphics/RHI/OpenGL/OPENGLIndexBuffer.h>
#include <Core/Graphics/RHI/OpenGL/OPENGLConstantBuffer.h>
#endif

#if defined(CGL_RHI_METAL)
Expand Down Expand Up @@ -49,6 +50,8 @@ namespace CGL::Graphics
#elif defined(CGL_RHI_OPENGL)
using VertexBuffer = OPENGLVertexBuffer;
using IndexBuffer = OPENGLIndexBuffer;
template <typename T>
using ConstantBuffer = OPENGLConstantBuffer<T>;
#elif defined(CGL_RHI_METAL)
using VertexBuffer = METALVertexBuffer;
using IndexBuffer = METALIndexBuffer;
Expand Down
18 changes: 18 additions & 0 deletions Core/Graphics/RHI/OpenGL/OPENGLConstantBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include <GL/glew.h>

namespace CGL::Graphics
{
template <typename T>
struct OPENGLConstantBuffer
{
using value_type = T;

OPENGLConstantBuffer()
{
// Ensure 16-byte alignment
static_assert((sizeof(T) % 16) == 0, "Constant buffer size must be 16-byte aligned.");
}
GLuint Buffer;
};
} // namespace CGL::Graphics
11 changes: 11 additions & 0 deletions Core/Graphics/RHI/OpenGL/OPENGLIndexBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <GL/glew.h>

namespace CGL::Graphics
{
struct OPENGLIndexBuffer
{
u32 Stride;
GLuint EBO;
};
} // namespace CGL::Graphics
10 changes: 10 additions & 0 deletions Core/Graphics/RHI/OpenGL/OPENGLPixelShader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
#include <GL/glew.h>

namespace CGL::Graphics
{
struct OPENGLPixelShader
{
GLuint FragmentShader;
};
} // namespace CGL::Graphics
Loading

0 comments on commit 71e83b6

Please sign in to comment.