Skip to content

Commit

Permalink
Working Hello Triangle sample (#40)
Browse files Browse the repository at this point in the history
* Implemented RHI for OpenGL

* Modified to support OpenGL RHI

* Added support for OnRender function for OpenGL, Fixed xmake files

* fixed indentation and xmake files

* Removed OnRender implementation for OpenGL

* Removed default ctor

* Working Hello Triangle sample

Compiled and Linked Shaders, Implemented Vertex Buffer.
Modifed xmake scripts.
Reorganized the samples asset folder structure.

* PR changes
  • Loading branch information
abhayMore authored Aug 14, 2024
1 parent 4886b6c commit ed50fff
Show file tree
Hide file tree
Showing 34 changed files with 573 additions and 80 deletions.
3 changes: 1 addition & 2 deletions Core/Application/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Application.h"
#include "SDL_scancode.h"
#include <SDL_scancode.h>
#include <chrono>
#include <SDL2/SDL.h>

Expand Down Expand Up @@ -99,7 +99,6 @@ namespace CGL::Core
#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
18 changes: 14 additions & 4 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 @@ -742,7 +748,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 @@ -767,10 +773,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 @@ -933,13 +939,16 @@ namespace DirectX
x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz)
{
}

#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 @@ -985,8 +994,9 @@ namespace DirectX
#endif

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

#endif
// Viewport operations
float AspectRatio() const noexcept;

Expand Down
2 changes: 2 additions & 0 deletions Core/External/SimpleMath.inl
Original file line number Diff line number Diff line change
Expand Up @@ -3746,6 +3746,7 @@ inline bool Viewport::operator != (const Viewport& vp) const noexcept
// Assignment operators
//------------------------------------------------------------------------------

#ifdef CGL_PLATFORM_WINDOWS
inline Viewport& Viewport::operator= (const RECT& rct) noexcept
{
x = float(rct.left); y = float(rct.top);
Expand All @@ -3754,6 +3755,7 @@ inline Viewport& Viewport::operator= (const RECT& rct) noexcept
minDepth = 0.f; 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
3 changes: 3 additions & 0 deletions Core/Graphics/Buffer.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <Core/Graphics/Buffer.h>
#include <Core/Types.h>

#if defined(CGL_RHI_DX11)
Expand All @@ -16,6 +17,7 @@
#if defined(CGL_RHI_OPENGL)
#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 +51,7 @@ 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 PixelShader;
};
} // namespace CGL::Graphics
Loading

0 comments on commit ed50fff

Please sign in to comment.