Skip to content

Commit

Permalink
Version 0.4.0.5: mat4 array uniforms, torus geometry, marching cubes …
Browse files Browse the repository at this point in the history
…fix, colored gui text, fixes

--HG--
branch : stable
  • Loading branch information
iondune committed Apr 30, 2016
2 parents 8449d04 + a209ca3 commit 191b673
Show file tree
Hide file tree
Showing 40 changed files with 492 additions and 319 deletions.
10 changes: 9 additions & 1 deletion Demo03-GUI/DemoGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ int main()
ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiSetCond_FirstUseEver);
ImGui::ShowTestWindow();
}
GUIManager->Text(vec2i(Window->GetCursorLocation()) + 100, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 100), Colors::White, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 120), Colors::Red, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 140), Colors::Orange, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 160), Colors::Yellow, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 180), Colors::Green, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 200), Colors::Cyan, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 220), Colors::Blue, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 240), Colors::Magenta, "Hello, world!");
GUIManager->Text(vec2i(Window->GetCursorLocation()) + vec2i(100, 260), Colors::Black, "Hello, world!");
GUIManager->Draw();

Window->SwapBuffers();
Expand Down
2 changes: 1 addition & 1 deletion Demo05-Application/DemoApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main()

CWindow * Window = WindowManager->CreateWindow(vec2i(1600, 900), "DemoApplication", EWindowType::Windowed);

AssetManager->SetAssetPath("Assets/");
AssetManager->AddAssetPath("Assets/");
AssetManager->SetShaderPath("Shaders/");
AssetManager->SetTexturePath("Images/");

Expand Down
2 changes: 1 addition & 1 deletion Properties/Include/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ItemDefinitionGroup>
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PreprocessorDefinitions>GLM_FORCE_RADIANS;NOMINMAX;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>GLM_FORCE_RADIANS;NOMINMAX;_CRT_SECURE_NO_WARNINGS;ION_PROJECT_BASE_DIRECTORY= "$(ProjectDir.Replace('\', '/'))";%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down
107 changes: 70 additions & 37 deletions ionApplication/CAssetManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,67 @@ namespace ion
return nullptr;
}

SharedPointer<Graphics::IVertexShader> VertexShader = GraphicsAPI->CreateVertexShaderFromFile(AssetPath + ShaderPath + Name + ".vert");
SharedPointer<Graphics::IPixelShader> PixelShader = GraphicsAPI->CreatePixelShaderFromFile(AssetPath + ShaderPath + Name + ".frag");

if (! VertexShader)
{
Log::Error("Failed to compile vertex shader '%s'", Name);
return nullptr;
}

if (! PixelShader)
for (string AssetPath : AssetPaths)
{
Log::Error("Failed to compile pixel shader '%s'", Name);
return nullptr;
if (! File::Exists(AssetPath + ShaderPath + Name + ".vert"))
{
continue;
}

SharedPointer<Graphics::IVertexShader> VertexShader = GraphicsAPI->CreateVertexShaderFromFile(AssetPath + ShaderPath + Name + ".vert");
SharedPointer<Graphics::IPixelShader> PixelShader = GraphicsAPI->CreatePixelShaderFromFile(AssetPath + ShaderPath + Name + ".frag");

if (! VertexShader)
{
Log::Error("Failed to compile vertex shader '%s'", Name);
return nullptr;
}

if (! PixelShader)
{
Log::Error("Failed to compile pixel shader '%s'", Name);
return nullptr;
}

SharedPointer<Graphics::IShaderProgram> ShaderProgram = GraphicsAPI->CreateShaderProgram();
ShaderProgram->SetVertexStage(VertexShader);
ShaderProgram->SetPixelStage(PixelShader);

return ShaderProgram;
}

SharedPointer<Graphics::IShaderProgram> ShaderProgram = GraphicsAPI->CreateShaderProgram();
ShaderProgram->SetVertexStage(VertexShader);
ShaderProgram->SetPixelStage(PixelShader);

return ShaderProgram;
Log::Error("Cannot find shader file in any asset directory: '%s'", Name);
return nullptr;
}

SharedPointer<Graphics::ITexture2D> CAssetManager::LoadTexture(string const & FileName)
SharedPointer<Graphics::ITexture2D> CAssetManager::LoadTexture(string const & FileName, Graphics::ITexture::EMipMaps const MipMaps)
{
if (! GraphicsAPI)
{
Log::Error("CAssetManager being used without being initialized, Texture '%s' will not be loaded.", FileName);
return nullptr;
}

CImage * Image = CImage::Load(AssetPath + TexturePath + FileName);
if (Image)
for (string AssetPath : AssetPaths)
{
return GraphicsAPI->CreateTexture2D(Image);
}
else
{
return nullptr;
if (! File::Exists(AssetPath + TexturePath + FileName))
{
continue;
}

CImage * Image = CImage::Load(AssetPath + TexturePath + FileName);
if (Image)
{
return GraphicsAPI->CreateTexture2D(Image, MipMaps);
}
else
{
return nullptr;
}
}

Log::Error("Cannot find image file in any asset directory: '%s'", FileName);
return nullptr;
}

Scene::CSimpleMesh * CAssetManager::LoadMesh(string const & FileName)
Expand All @@ -65,24 +87,35 @@ namespace ion
return nullptr;
}

vector<Scene::CSimpleMesh *> Shapes = Scene::CGeometryCreator::LoadOBJFile(AssetPath + MeshPath + FileName, AssetPath + MeshPath);

if (Shapes.size() == 0)
{
Log::Error("Failed to load mesh: %s", FileName);
return nullptr;
}
else if (Shapes.size() > 1)
for (string AssetPath : AssetPaths)
{
Log::Error("Mesh contains %d shapes but only one was expected: %s", Shapes.size(), FileName);
if (! File::Exists(AssetPath + MeshPath + FileName))
{
continue;
}

vector<Scene::CSimpleMesh *> Shapes = Scene::CGeometryCreator::LoadOBJFile(AssetPath + MeshPath + FileName, AssetPath + MeshPath);

if (Shapes.size() == 0)
{
Log::Error("Failed to load mesh: %s", FileName);
return nullptr;
}
else if (Shapes.size() > 1)
{
Log::Error("Mesh contains %d shapes but only one was expected: %s", Shapes.size(), FileName);
}

return Shapes[0];
}

return Shapes[0];
Log::Error("Cannot find mesh file in any asset directory: '%s'", FileName);
return nullptr;
}

void CAssetManager::SetAssetPath(string const & Path)
void CAssetManager::AddAssetPath(string const & Path)
{
AssetPath = Path + "/";
AssetPaths.push_back(Path + "/");
}

void CAssetManager::SetTexturePath(string const & Path)
Expand Down
12 changes: 6 additions & 6 deletions ionApplication/CAssetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace ion
void Init(CGraphicsAPI * GraphicsAPI);

SharedPointer<Graphics::IShaderProgram> LoadShader(string const & Name);
SharedPointer<Graphics::ITexture2D> LoadTexture(string const & FileName);
SharedPointer<Graphics::ITexture2D> LoadTexture(string const & FileName, Graphics::ITexture::EMipMaps const MipMaps = Graphics::ITexture::EMipMaps::True);
Scene::CSimpleMesh * LoadMesh(string const & FileName);

void SetAssetPath(string const & Path);
void AddAssetPath(string const & Path);
void SetTexturePath(string const & Path);
void SetShaderPath(string const & Path);
void SetMeshPath(string const & Path);
Expand All @@ -31,10 +31,10 @@ namespace ion

SingletonPointer<CGraphicsAPI> GraphicsAPI;

string AssetPath;
string TexturePath;
string ShaderPath;
string MeshPath;
vector<string> AssetPaths;
string TexturePath = "Textures/";
string ShaderPath = "Shaders/";
string MeshPath = "Meshes/";

private:

Expand Down
10 changes: 7 additions & 3 deletions ionGUI/CGUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace ion
switch (MouseEvent.Type)
{
case SMouseEvent::EType::Click:
if (ImGui::IsMouseHoveringAnyWindow())
if (IO.WantCaptureMouse)
{
Event.Block();
}
Expand Down Expand Up @@ -387,7 +387,10 @@ void CGUIManager::Draw()

for (auto Text : TextQueue)
{
DrawList->AddText(ImVec2((float) Text.Position.X, (float) Text.Position.Y), 0xFFFFFFFF, Text.Text.c_str());
uint Red = Text.Color.Red;
uint Green = Text.Color.Green;
uint Blue = Text.Color.Blue;
DrawList->AddText(ImVec2((float) Text.Position.X, (float) Text.Position.Y), (0xFF000000) | (Blue << 16) | (Green << 8) | (Red), Text.Text.c_str());
}
TextQueue.clear();

Expand All @@ -396,11 +399,12 @@ void CGUIManager::Draw()
ImGui::Render();
}

void CGUIManager::TextUnformatted(vec2i const & Position, string const & Text)
void CGUIManager::TextUnformatted(vec2i const & Position, color3i const & Color, string const & Text)
{
SDrawText Draw;
Draw.Text = Text;
Draw.Position = Position;
Draw.Color = Color;

TextQueue.push_back(Draw);
}
Expand Down
7 changes: 4 additions & 3 deletions ionGUI/CGUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace ion
void Draw();

template <typename... Args>
void Text(vec2i const & Position, char const * const Format, Args const &... args)
void Text(vec2i const & Position, color3i const & Color, char const * const Format, Args const &... args)
{
TextUnformatted(Position, tfm::format(Format, args...));
TextUnformatted(Position, Color, tfm::format(Format, args...));
}

void TextUnformatted(vec2i const & Position, string const & Text);
void TextUnformatted(vec2i const & Position, color3i const & Color, string const & Text);

void OnEvent(IEvent & Event);
void AddFontFromFile(string const & FileName, float const Size);
Expand Down Expand Up @@ -54,6 +54,7 @@ namespace ion
struct SDrawText
{
vec2i Position;
color3i Color;
string Text;
};

Expand Down
4 changes: 2 additions & 2 deletions ionGraphics/CGraphicsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ namespace ion
return Texture;
}

SharedPointer<Graphics::ITexture2D> CGraphicsAPI::CreateTexture2D(CImage * Image)
SharedPointer<Graphics::ITexture2D> CGraphicsAPI::CreateTexture2D(CImage * Image, Graphics::ITexture::EMipMaps MipMaps)
{
if (! Image)
{
Expand All @@ -207,7 +207,7 @@ namespace ion
}
SharedPointer<Graphics::ITexture2D> Texture = CreateTexture2D(
Image->GetSize(),
Graphics::ITexture::EMipMaps::True,
MipMaps,
Format,
Graphics::ITexture::EInternalFormatType::Fix8);
Texture->Upload(
Expand Down
2 changes: 1 addition & 1 deletion ionGraphics/CGraphicsAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace ion
SharedPointer<Graphics::IDepthBuffer> CreateDepthBuffer(vec2u const & Size);

SharedPointer<Graphics::ITexture2D> CreateTexture2D(vec2u const & Size, Graphics::ITexture::EMipMaps const MipMaps, Graphics::ITexture::EFormatComponents const Components, Graphics::ITexture::EInternalFormatType const Type);
SharedPointer<Graphics::ITexture2D> CreateTexture2D(CImage * Image);
SharedPointer<Graphics::ITexture2D> CreateTexture2D(CImage * Image, Graphics::ITexture::EMipMaps const MipMaps = Graphics::ITexture::EMipMaps::True);
SharedPointer<Graphics::ITexture3D> CreateTexture3D(vec3u const & Size, Graphics::ITexture::EMipMaps const MipMaps, Graphics::ITexture::EFormatComponents const Components, Graphics::ITexture::EInternalFormatType const Type);

SharedPointer<Graphics::IGraphicsContext> GetWindowContext(CWindow * Window);
Expand Down
9 changes: 8 additions & 1 deletion ionGraphics/IRenderTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <ionCore.h>
#include <ionMath.h>
#include <ionFramework.h>

#include "ITexture.h"

Expand All @@ -21,7 +22,11 @@ namespace ion
virtual void ClearDepth() = 0;
virtual void ClearColorAndDepth() = 0;

virtual void SetClearColor(color3f const & Color) = 0;
virtual void SetClearColor(color4f const & Color) = 0;

virtual void Bind() = 0;

virtual CImage * ReadImage() = 0;

virtual ~IRenderTarget()
{}
Expand All @@ -47,6 +52,8 @@ namespace ion
virtual void AttachDepthTexture(SharedPointer<ITexture2D> Texture) = 0;
virtual void AttachDepthBuffer(SharedPointer<IDepthBuffer> DepthBuffer) = 0;

virtual bool CheckCorrectness() = 0;

virtual ~IFrameBuffer()
{}

Expand Down
4 changes: 3 additions & 1 deletion ionGraphics/ITexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ namespace ion
enum class EInternalFormatType
{
Fix8 = 0,
Float32 = 1,
Float16 = 1,
Float32 = 2,
Depth = 3,
};

enum class EMipMaps
Expand Down
Loading

0 comments on commit 191b673

Please sign in to comment.