Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/graphics'
Browse files Browse the repository at this point in the history
  • Loading branch information
ToniLipponen committed Apr 25, 2023
2 parents 01ecdef + a22b5fa commit 2888807
Show file tree
Hide file tree
Showing 26 changed files with 251 additions and 414 deletions.
2 changes: 0 additions & 2 deletions include/TML/Graphics.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#pragma once
#include <TML/Graphics/Camera.h>
#include <TML/Graphics/Core/ComputeShader.h>
#include <TML/Graphics/Color.h>
#include <TML/Graphics/Font.h>
#include <TML/Graphics/Ray.h>
#include <TML/Graphics/RenderTexture.h>
#include <TML/Graphics/RenderWindow.h>
#include <TML/Graphics/Drawable/Rectangle.h>
Expand Down
27 changes: 7 additions & 20 deletions include/TML/Graphics/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,49 @@ namespace tml
public:
Camera();

[[maybe_unused]]
explicit Camera(tml::Vector2f pos, float zoom = 1.0f, float rotation = 0.0f);

[[maybe_unused]]
void Move(const Vector2f& offset);

/** Multiplicative zoom. The zoom level of the camera is multiplied by amount. */
[[maybe_unused]]
void Zoom(float amount);

[[maybe_unused]]
void Rotate(float degrees);

[[maybe_unused]]

void SetPosition(const Vector2f& position);

/** Sets the zoom of the camera. Bigger value means more zoom. 1.0 is normal / default zoom level. */
[[maybe_unused]]
void SetZoom(float zoomLevel);

/** Sets the rotation of the camera in degrees. */
[[maybe_unused]]
void SetRotation(float degrees);

[[maybe_unused, nodiscard]]
Vector2f GetPosition() const noexcept;
[[nodiscard]] Vector2f GetPosition() const noexcept;

/** @return The zoom level of the camera. A bigger value means more zoom. */
[[maybe_unused, nodiscard]]
float GetZoom() const noexcept;
[[nodiscard]] float GetZoom() const noexcept;

/** @return The rotation of the camera in degrees. */
[[maybe_unused, nodiscard]]
float GetRotation() const noexcept;
[[nodiscard]] float GetRotation() const noexcept;

/** Transforms a screen coordinate to world coordinate.
* @param point The point you wish to transform.
* @param size The size of the RenderTarget you are drawing on.
* @see tml::RenderTarget::ScreenToWorld()
* @return Transformed coordinate. */
[[maybe_unused, nodiscard]]
Vector2f ScreenToWorld(const Vector2f& point, const Vector2f& size) const noexcept;
[[nodiscard]] Vector2f ScreenToWorld(const Vector2f& point, const Vector2f& size) const noexcept;

/**
* Transforms a world coordinate to screen coordinate.
* @param point The point you wish to transform.
* @param size The size of the RenderTarget you are drawing on.
* @return Transformed coordinate. */
[[maybe_unused, nodiscard]]
Vector2f WorldToScreen(const Vector2f& point, const Vector2f& size) const noexcept;
[[nodiscard]] Vector2f WorldToScreen(const Vector2f& point, const Vector2f& size) const noexcept;

/**
* Gets the whole view matrix of the camera.
* @return The view matrix of the camera. */
[[maybe_unused, nodiscard]]
Matrix4f GetMatrix() const noexcept;
[[nodiscard]] Matrix4f GetMatrix() const noexcept;

private:
Vector2f m_pos; //!< Top left position of the camera view.
Expand Down
18 changes: 9 additions & 9 deletions include/TML/Graphics/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ namespace tml
};
}

[[maybe_unused]] inline constexpr Color Color::Red = Color(0xff0000ff);
[[maybe_unused]] inline constexpr Color Color::Green = Color(0x00ff00ff);
[[maybe_unused]] inline constexpr Color Color::Blue = Color(0x0000ffff);
[[maybe_unused]] inline constexpr Color Color::Yellow = Color(0xffff00ff);
[[maybe_unused]] inline constexpr Color Color::Magenta = Color(0xff00ffff);
[[maybe_unused]] inline constexpr Color Color::Cyan = Color(0x00ffffff);
[[maybe_unused]] inline constexpr Color Color::Black = Color(0x000000ff);
[[maybe_unused]] inline constexpr Color Color::White = Color(0xffffffff);
[[maybe_unused]] inline constexpr Color Color::Transparent = Color(0x00000000);
inline constexpr Color Color::Red = Color(0xff0000ff);
inline constexpr Color Color::Green = Color(0x00ff00ff);
inline constexpr Color Color::Blue = Color(0x0000ffff);
inline constexpr Color Color::Yellow = Color(0xffff00ff);
inline constexpr Color Color::Magenta = Color(0xff00ffff);
inline constexpr Color Color::Cyan = Color(0x00ffffff);
inline constexpr Color Color::Black = Color(0x000000ff);
inline constexpr Color Color::White = Color(0xffffffff);
inline constexpr Color Color::Transparent = Color(0x00000000);
}
49 changes: 49 additions & 0 deletions include/TML/Graphics/Core/BufferLayout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once
#include <TML/Export.h>

#include <cstdint>
#include <vector>

namespace tml
{
class BufferLayout
{
public:
enum DataType
{
VERTEX_BYTE = 0x1400,
VERTEX_UNSIGNED_BYTE = 0x1401,
VERTEX_SHORT = 0x1402,
VERTEX_UNSIGNED_SHORT = 0x1403,
VERTEX_INT = 0x1404,
VERTEX_UNSIGNED_INT = 0x1405,
VERTEX_FLOAT = 0x1406,
};
struct Attribute
{
uint32_t elements, size;
DataType dataType;
};
public:
BufferLayout() : m_stride(0) {}

void Push(uint32_t elements, uint32_t size, DataType type) noexcept
{
m_layout.push_back(Attribute{elements, size, type});
m_stride += elements * size;
}

void Clear()
{
m_layout.clear();
m_stride = 0;
}

std::vector<Attribute> const & GetData() const noexcept { return m_layout; }
uint32_t GetStride() const noexcept { return m_stride; }

private:
std::vector<Attribute> m_layout;
uint32_t m_stride;
};
}
127 changes: 0 additions & 127 deletions include/TML/Graphics/Core/Buffers.h

This file was deleted.

6 changes: 3 additions & 3 deletions include/TML/Graphics/Core/ComputeShader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once
#include "Shader.h"
#include "Buffers.h"
#include <TML/System/String.h>
#include <TML/Export.h>
#include <TML/Graphics/Core/Shader.h>
#include <TML/Graphics/Core/StorageBuffer.h>
#include <TML/System/String.h>

namespace tml
{
Expand Down
30 changes: 30 additions & 0 deletions include/TML/Graphics/Core/IndexBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include <TML/Export.h>

#include <cstdint>

namespace tml
{
class TML_API IndexBuffer
{
public:
IndexBuffer() noexcept;
IndexBuffer(const uint32_t *data, uint32_t elements) noexcept;
~IndexBuffer() noexcept;
void Bind() noexcept;
void Unbind() const noexcept;
void BufferData(const uint32_t *data, uint32_t elements) noexcept;
void PushData(const uint32_t *data, uint32_t elements) noexcept;
uint32_t Elements() const noexcept { return m_elements; }

public:
friend class VertexArray;

private:
uint32_t m_id;

protected:
mutable uint32_t m_elements;
uint32_t m_capacity;
};
}
23 changes: 23 additions & 0 deletions include/TML/Graphics/Core/StorageBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <TML/Export.h>

#include <cstdint>

namespace tml
{
class TML_API StorageBuffer /// Shader Storage Buffer
{
public:
StorageBuffer() noexcept;
void Bind() const noexcept;
void Unbind() const noexcept;
void BufferData(const void* data, uint32_t bytes) const noexcept;
void UpdateData(const void* data, uint32_t bytes) const noexcept;
void RetrieveData(void* data, uint32_t bytes) const noexcept;
protected:
void BindBufferBase(uint32_t index) const noexcept;
friend class ComputeShader;
private:
uint32_t m_id;
};
}
20 changes: 10 additions & 10 deletions include/TML/Graphics/Core/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace tml
class TML_API Texture
{
public:
enum [[maybe_unused]] ClampMode
enum ClampMode
{
ClampToBorder = 0x812D,
ClampToEdge = 0x812F,
MirrorClampToEdge = 0x8743,
Repeat = 0x2901,
MirrorRepeat = 0x8370,
};
enum [[maybe_unused]] Filter
enum Filter
{
Nearest = 0x2600,
Linear = 0x2601,
Expand All @@ -43,14 +43,14 @@ namespace tml
void SetMinMagFilter(Filter min, Filter mag) noexcept;
void SetClampMode(ClampMode mode) noexcept;

[[nodiscard, maybe_unused]] Filter GetMinFilter() const noexcept;
[[nodiscard, maybe_unused]] Filter GetMagFilter() const noexcept;
[[nodiscard, maybe_unused]] ClampMode GetClampMode() const noexcept;
[[nodiscard, maybe_unused]] uint32_t GetID() const noexcept;
[[nodiscard, maybe_unused]] uint32_t GetWidth() const noexcept;
[[nodiscard, maybe_unused]] uint32_t GetHeight() const noexcept;
[[nodiscard, maybe_unused]] uint32_t GetBpp() const noexcept;
[[nodiscard, maybe_unused]] Image GetData() const noexcept;
[[nodiscard]] Filter GetMinFilter() const noexcept;
[[nodiscard]] Filter GetMagFilter() const noexcept;
[[nodiscard]] ClampMode GetClampMode() const noexcept;
[[nodiscard]] uint32_t GetID() const noexcept;
[[nodiscard]] uint32_t GetWidth() const noexcept;
[[nodiscard]] uint32_t GetHeight() const noexcept;
[[nodiscard]] uint32_t GetBpp() const noexcept;
[[nodiscard]] Image GetData() const noexcept;

protected:
inline void Update() const noexcept;
Expand Down
Loading

0 comments on commit 2888807

Please sign in to comment.