Skip to content

Commit

Permalink
Merge branch 'content-browser' of https://github.com/TheCherno/Hazel
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCherno committed Sep 16, 2021
2 parents 670ce2d + bd084fb commit 3314e83
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 66 deletions.
5 changes: 3 additions & 2 deletions Hazel/src/Hazel/ImGui/ImGuiLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ namespace Hazel {
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons;
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;

io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Bold.ttf", 18.0f);
io.FontDefault = io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Regular.ttf", 18.0f);
float fontSize = 18.0f;// *2.0f;
io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Bold.ttf", fontSize);
io.FontDefault = io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Regular.ttf", fontSize);

// Setup Dear ImGui style
ImGui::StyleColorsDark();
Expand Down
5 changes: 4 additions & 1 deletion Hazel/src/Hazel/Renderer/Renderer2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ namespace Hazel {

void Renderer2D::DrawSprite(const glm::mat4& transform, SpriteRendererComponent& src, int entityID)
{
DrawQuad(transform, src.Color, entityID);
if (src.Texture)
DrawQuad(transform, src.Texture, src.TilingFactor, src.Color, entityID);
else
DrawQuad(transform, src.Color, entityID);
}

void Renderer2D::ResetStats()
Expand Down
4 changes: 3 additions & 1 deletion Hazel/src/Hazel/Renderer/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Hazel {

virtual void Bind(uint32_t slot = 0) const = 0;

virtual bool IsLoaded() const = 0;

virtual bool operator==(const Texture& other) const = 0;
};

Expand All @@ -29,4 +31,4 @@ namespace Hazel {
static Ref<Texture2D> Create(const std::string& path);
};

}
}
3 changes: 3 additions & 0 deletions Hazel/src/Hazel/Scene/Components.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "SceneCamera.h"
#include "ScriptableEntity.h"
#include "Hazel/Renderer/Texture.h"

namespace Hazel {

Expand Down Expand Up @@ -45,6 +46,8 @@ namespace Hazel {
struct SpriteRendererComponent
{
glm::vec4 Color{ 1.0f, 1.0f, 1.0f, 1.0f };
Ref<Texture2D> Texture;
float TilingFactor = 1.0f;

SpriteRendererComponent() = default;
SpriteRendererComponent(const SpriteRendererComponent&) = default;
Expand Down
11 changes: 10 additions & 1 deletion Hazel/src/Hazel/Scene/SceneSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,16 @@ namespace Hazel {

bool SceneSerializer::Deserialize(const std::string& filepath)
{
YAML::Node data = YAML::LoadFile(filepath);
YAML::Node data;
try
{
data = YAML::LoadFile(filepath);
}
catch (YAML::ParserException e)
{
return false;
}

if (!data["Scene"])
return false;

Expand Down
57 changes: 31 additions & 26 deletions Hazel/src/Platform/OpenGL/OpenGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Hazel {
glTextureStorage2D(m_RendererID, 1, m_InternalFormat, m_Width, m_Height);

glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);
Expand All @@ -35,39 +35,44 @@ namespace Hazel {
HZ_PROFILE_SCOPE("stbi_load - OpenGLTexture2D::OpenGLTexture2D(const std::string&)");
data = stbi_load(path.c_str(), &width, &height, &channels, 0);
}
HZ_CORE_ASSERT(data, "Failed to load image!");
m_Width = width;
m_Height = height;

GLenum internalFormat = 0, dataFormat = 0;
if (channels == 4)
{
internalFormat = GL_RGBA8;
dataFormat = GL_RGBA;
}
else if (channels == 3)

if (data)
{
internalFormat = GL_RGB8;
dataFormat = GL_RGB;
}
m_IsLoaded = true;

m_InternalFormat = internalFormat;
m_DataFormat = dataFormat;
m_Width = width;
m_Height = height;

HZ_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!");
GLenum internalFormat = 0, dataFormat = 0;
if (channels == 4)
{
internalFormat = GL_RGBA8;
dataFormat = GL_RGBA;
}
else if (channels == 3)
{
internalFormat = GL_RGB8;
dataFormat = GL_RGB;
}

glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
glTextureStorage2D(m_RendererID, 1, internalFormat, m_Width, m_Height);
m_InternalFormat = internalFormat;
m_DataFormat = dataFormat;

glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
HZ_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!");

glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);
glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID);
glTextureStorage2D(m_RendererID, 1, internalFormat, m_Width, m_Height);

glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, dataFormat, GL_UNSIGNED_BYTE, data);
glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT);

stbi_image_free(data);
glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, dataFormat, GL_UNSIGNED_BYTE, data);

stbi_image_free(data);
}
}

OpenGLTexture2D::~OpenGLTexture2D()
Expand Down
3 changes: 3 additions & 0 deletions Hazel/src/Platform/OpenGL/OpenGLTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ namespace Hazel {

virtual void Bind(uint32_t slot = 0) const override;

virtual bool IsLoaded() const override { return m_IsLoaded; }

virtual bool operator==(const Texture& other) const override
{
return m_RendererID == ((OpenGLTexture2D&)other).m_RendererID;
}
private:
std::string m_Path;
bool m_IsLoaded = false;
uint32_t m_Width, m_Height;
uint32_t m_RendererID;
GLenum m_InternalFormat, m_DataFormat;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hazelnut/Resources/Icons/PlayButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Hazelnut/Resources/Icons/StopButton.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions Hazelnut/assets/shaders/Texture.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TexIndex;
float TilingFactor;
};

layout (location = 0) out VertexOutput Output;
layout (location = 3) out flat float v_TexIndex;
layout (location = 4) out flat int v_EntityID;

void main()
{
Output.Color = a_Color;
Output.TexCoord = a_TexCoord;
Output.TexIndex = a_TexIndex;
Output.TilingFactor = a_TilingFactor;
v_TexIndex = a_TexIndex;
v_EntityID = a_EntityID;

gl_Position = u_ViewProjection * vec4(a_Position, 1.0);
Expand All @@ -47,11 +47,11 @@ struct VertexOutput
{
vec4 Color;
vec2 TexCoord;
float TexIndex;
float TilingFactor;
};

layout (location = 0) in VertexOutput Input;
layout (location = 3) in flat float v_TexIndex;
layout (location = 4) in flat int v_EntityID;

layout (binding = 0) uniform sampler2D u_Textures[32];
Expand All @@ -60,7 +60,7 @@ void main()
{
vec4 texColor = Input.Color;

switch(int(Input.TexIndex))
switch(int(v_TexIndex))
{
case 0: texColor *= texture(u_Textures[ 0], Input.TexCoord * Input.TilingFactor); break;
case 1: texColor *= texture(u_Textures[ 1], Input.TexCoord * Input.TilingFactor); break;
Expand Down Expand Up @@ -98,4 +98,4 @@ void main()
color = texColor;

color2 = v_EntityID;
}
}
52 changes: 34 additions & 18 deletions Hazelnut/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Collapsed=0
DockId=0x00000004,0

[Window][Viewport]
Pos=372,24
Size=780,876
Pos=372,71
Size=856,524
Collapsed=0
DockId=0x00000003,0
DockId=0x0000000C,0

[Window][Scene Hierarchy]
Pos=0,24
Size=370,406
Size=370,435
Collapsed=0
DockId=0x00000005,0

Expand All @@ -34,25 +34,41 @@ Size=1421,1027
Collapsed=0

[Window][Properties]
Pos=0,432
Size=370,468
Pos=0,461
Size=370,439
Collapsed=0
DockId=0x00000006,0

[Window][Stats]
Pos=1154,24
Size=446,876
Pos=1230,24
Size=370,876
Collapsed=0
DockId=0x00000007,0

[Window][Content Browser]
Pos=372,597
Size=856,303
Collapsed=0
DockId=0x0000000A,0

[Window][##toolbar]
Pos=372,24
Size=856,45
Collapsed=0
DockId=0x00000008,0
DockId=0x0000000B,0

[Docking][Data]
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=294,341 Size=1600,876 Split=X Selected=0x995B0CF8
DockNode ID=0x00000007 Parent=0x3BC79352 SizeRef=1409,1094 Split=X
DockNode ID=0x00000001 Parent=0x00000007 SizeRef=453,696 Split=Y Selected=0x9A68760C
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=593,322 Selected=0x9A68760C
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=593,372 Selected=0xC89E3217
DockNode ID=0x00000002 Parent=0x00000007 SizeRef=954,696 Split=X
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=958,701 CentralNode=1 HiddenTabBar=1 Selected=0x995B0CF8
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=272,701 Selected=0x1C33C293
DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=545,1094 Selected=0x968648AE
DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=294,341 Size=1600,876 Split=X Selected=0x995B0CF8
DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=1228,876 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=370,696 Split=Y Selected=0xC89E3217
DockNode ID=0x00000005 Parent=0x00000001 SizeRef=370,435 Selected=0x9A68760C
DockNode ID=0x00000006 Parent=0x00000001 SizeRef=370,439 Selected=0xC89E3217
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=856,696 Split=X
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=958,701 Split=Y Selected=0x995B0CF8
DockNode ID=0x00000009 Parent=0x00000003 SizeRef=856,571 Split=Y Selected=0x995B0CF8
DockNode ID=0x0000000B Parent=0x00000009 SizeRef=856,45 HiddenTabBar=1 Selected=0x28257B55
DockNode ID=0x0000000C Parent=0x00000009 SizeRef=856,524 CentralNode=1 HiddenTabBar=1 Selected=0x995B0CF8
DockNode ID=0x0000000A Parent=0x00000003 SizeRef=856,303 Selected=0x371352B7
DockNode ID=0x00000004 Parent=0x00000002 SizeRef=272,701 Selected=0x1C33C293
DockNode ID=0x00000007 Parent=0x3BC79352 SizeRef=370,876 Selected=0x968648AE

Loading

0 comments on commit 3314e83

Please sign in to comment.