Skip to content

Instantly share code, notes, and snippets.

@JonathanCline
Created July 31, 2021 14:58
Show Gist options
  • Save JonathanCline/53cdf4e7a17a2b42ad3398126698c085 to your computer and use it in GitHub Desktop.
Save JonathanCline/53cdf4e7a17a2b42ad3398126698c085 to your computer and use it in GitHub Desktop.
Prototype C++ code generation for a game engine
#pragma once
// file : sprite.h
// generated at 2021-07-31 09:54:44.8542459 CDT
#include <utility>
#include <array>
#include <jclib/gl/shader.h>
#include <jclib/gl/program.h>
struct sprite_vertex
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
uint8_t r = 1.0f;
uint8_t g = 1.0f;
uint8_t b = 1.0f;
uint8_t a = 1.0f;
};
class sprite_shader
{
public:
/**
* @brief sprite shader stages
*/
constexpr static auto shader_stages = std::array
{
::std::pair{ "C:/Users/jonat/source/repos/JonathanCline/NextEngine//sprite/sprite.vert.glsl", ::jc::gl::shader_type::vertex_shader },
::std::pair{ "C:/Users/jonat/source/repos/JonathanCline/NextEngine//sprite/sprite.frag.glsl", ::jc::gl::shader_type::fragment_shader }
};
/**
* @brief Bind's the underlying shader resource
*/
void bind() noexcept
{
::jc::gl::bind(this->program_);
};
/**
* @brief Gets's the underlying shader ID
*/
auto id() const noexcept
{
return this->program_.get();
};
sprite_shader() :
program_{ }
{
// compile stages
::jc::gl::shader _stage0{ this->shader_stages.at(0).second };
::jc::gl::compile_shader_file(_stage0, this->shader_stages.at(0).first);
::jc::gl::shader _stage1{ this->shader_stages.at(1).second };
::jc::gl::compile_shader_file(_stage1, this->shader_stages.at(1).first);
::jc::gl::attach(this->program_, _stage0);
::jc::gl::attach(this->program_, _stage1);
::jc::gl::link_program(this->program_);
::jc::gl::detatch(this->program_, _stage0);
::jc::gl::detatch(this->program_, _stage1);
};
private:
/**
* @brief Underlying shader handle
*/
::jc::gl::program program_{};
};
/**
* @brief sprite art type
*/
class sprite_art
{
public:
/**
* @brief sprite shader type alias
*/
using shader_type = ::sprite_shader;
};
local engine = nextengine
print("defining sprite object")
engine.define(
{
name = "sprite",
type = "gfxobject",
shader =
{
vertex =
{
glsl_version = 330,
core = true,
attributes =
{
{
inout = "in",
type = "vec3",
name = "pos",
location = 0
},
{
inout = "in",
type = "vec4",
name = "col",
location = 1
},
{
inout = "out",
type = "vec4",
name = "vertcol"
}
},
uniforms =
{
},
contents = [[
void main()
{
vertcol = col;
gl_Position = vec4(pos.xyz, 1.0);
};
]]
},
fragment =
{
glsl_version = 330,
core = true,
attributes =
{
{
inout = "out",
type = "vec4",
name = "color"
},
{
inout = "in",
type = "vec4",
name = "vertcol"
}
},
uniforms =
{
},
contents = [[
void main()
{
color = vertcol;
};
]]
}
}
}
)
print("finished defining sprite object")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment