-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
247 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "growl/core/error.h" | ||
namespace Growl { | ||
|
||
class Shader { | ||
public: | ||
Shader(const std::string& vertex_src, const std::string& fragment_src) | ||
: vertex_src{vertex_src} | ||
, fragment_src{fragment_src} {}; | ||
virtual ~Shader() = default; | ||
|
||
// Shader is move-only | ||
Shader(const Shader&) = delete; | ||
Shader& operator=(const Shader&) = delete; | ||
Shader(Shader&&) = default; | ||
Shader& operator=(Shader&&) = default; | ||
|
||
virtual Error compile() = 0; | ||
|
||
virtual const std::string& getVertexSource() { | ||
return vertex_src; | ||
} | ||
|
||
virtual const std::string& getFragmentSource() { | ||
return fragment_src; | ||
} | ||
|
||
virtual void setVertexSource(const std::string& src) { | ||
vertex_src = src; | ||
} | ||
|
||
virtual void setFragmentSource(const std::string& src) { | ||
fragment_src = src; | ||
} | ||
|
||
protected: | ||
std::string vertex_src; | ||
std::string fragment_src; | ||
}; | ||
|
||
} // namespace Growl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "growl/core/error.h" | ||
#include <Foundation/Foundation.h> | ||
namespace Growl { | ||
|
||
class MetalError : public BaseError { | ||
public: | ||
explicit MetalError(std::string message) | ||
: message_str{message} {} | ||
|
||
explicit MetalError(NSError* ns_err) | ||
: message_str{[[ns_err localizedDescription] UTF8String]} {} | ||
|
||
std::string message() override { | ||
return message_str; | ||
} | ||
|
||
private: | ||
std::string message_str; | ||
}; | ||
|
||
} // namespace Growl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
#pragma once | ||
|
||
#include "growl/core/graphics/shader.h" | ||
#include <Metal/Metal.h> | ||
#include <string> | ||
|
||
namespace Growl { | ||
|
||
class MetalShader { | ||
class MetalShader : public Shader { | ||
public: | ||
explicit MetalShader(id<MTLDevice> device, NSString* const shader_src); | ||
explicit MetalShader( | ||
id<MTLDevice> device, const std::string& vertex_src, | ||
const std::string& fragment_src) | ||
: Shader(vertex_src, fragment_src) | ||
, device{device} {} | ||
~MetalShader(); | ||
void bind(id<MTLTexture> dst_texture, id<MTLRenderCommandEncoder> encoder); | ||
|
||
static NSString* const DEFAULT_SHADER; | ||
static NSString* const RECT_SHADER; | ||
static NSString* const SDF_SHADER; | ||
Error compile() override; | ||
|
||
static const std::string default_vertex; | ||
static const std::string default_fragment; | ||
static const std::string sdf_fragment; | ||
static const std::string rect_fragment; | ||
|
||
private: | ||
id<MTLDevice> device; | ||
id<MTLFunction> vertex_func; | ||
id<MTLFunction> fragment_func; | ||
MTLRenderPipelineDescriptor* descriptor = nullptr; | ||
MTLVertexDescriptor* vertex_descriptor; | ||
|
||
static NSString* const GROWL_SHADER_HEADER; | ||
static const std::string growl_shader_header; | ||
}; | ||
|
||
} // namespace Growl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.