restructuring internal namespaces & function calls

This commit is contained in:
Noel Berry 2022-11-19 16:15:31 -08:00
parent 2437d5841f
commit c89535e328
11 changed files with 249 additions and 269 deletions

View File

@ -18,6 +18,7 @@ add_library(blah
src/blah_spritefont.cpp
src/blah_subtexture.cpp
src/blah_aseprite.cpp
src/blah_audio.cpp
src/blah_font.cpp
src/blah_image.cpp
src/blah_packer.cpp

View File

@ -51,5 +51,4 @@ int main()
#### notes
- There's no Shader abstraction, so you need to swap between GLSL/HLSL depending on the Renderer.
- Only floatN/mat3x2/mat4x4 uniforms are supported.
- There's no Audio API or backend implementation yet.
- No threaded rendering so it will explode if you try that.

View File

@ -15,10 +15,10 @@ using namespace Blah;
#define BLAH_ASSERT_RUNNING() BLAH_ASSERT(app_is_running, "The App is not running (call App::run)")
// Internal Platform Pointer
Platform* App::Internal::platform = nullptr;
Platform* Internal::platform = nullptr;
// Internal Renderer Pointer
Renderer* App::Internal::renderer = nullptr;
Renderer* Internal::renderer = nullptr;
// Internal Audio bool
bool Internal::audio_is_init = false;
@ -37,11 +37,11 @@ namespace
void get_drawable_size(int* w, int* h)
{
// Some renderer implementations might return their own size
if (App::Internal::renderer->get_draw_size(w, h))
if (Internal::renderer->get_draw_size(w, h))
return;
// otherwise fallback to the platform size
App::Internal::platform->get_draw_size(w, h);
Internal::platform->get_draw_size(w, h);
}
// A dummy Target that represents the Back Buffer.
@ -57,8 +57,8 @@ namespace
void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
BLAH_ASSERT_RENDERER();
if (App::Internal::renderer)
App::Internal::renderer->clear_backbuffer(color, depth, stencil, mask);
if (Internal::renderer)
Internal::renderer->clear_backbuffer(color, depth, stencil, mask);
}
};
}
@ -87,7 +87,7 @@ bool App::run(const Config* c)
if (app_is_running || c == nullptr || c->width <= 0 || c->height <= 0 || c->max_updates <= 0 || c->target_framerate <= 0)
{
App::Internal::shutdown();
Internal::app_shutdown();
return false;
}
@ -103,14 +103,14 @@ bool App::run(const Config* c)
if (!Internal::platform)
{
Log::error("Failed to create Platform module");
App::Internal::shutdown();
Internal::app_shutdown();
return false;
}
if (!Internal::platform->init(app_config))
{
Log::error("Failed to initialize Platform module");
App::Internal::shutdown();
Internal::app_shutdown();
return false;
}
}
@ -132,14 +132,14 @@ bool App::run(const Config* c)
if (Internal::renderer == nullptr)
{
Log::error("Renderer module was not found");
App::Internal::shutdown();
Internal::app_shutdown();
return false;
}
if (!Internal::renderer->init())
{
Log::error("Failed to initialize Renderer module");
App::Internal::shutdown();
Internal::app_shutdown();
return false;
}
}
@ -149,8 +149,8 @@ bool App::run(const Config* c)
Internal::renderer->set_app_flags(app_flags);
// input + poll the platform once
Input::Internal::init();
Input::Internal::step_state();
Internal::input_init();
Internal::input_step_state();
Internal::platform->update(Input::state);
// startup
@ -164,16 +164,16 @@ bool App::run(const Config* c)
// Begin main loop
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(App::Internal::iterate, 0, 1);
emscripten_set_main_loop(Internal::iterate, 0, 1);
#else
while (!app_is_exiting)
App::Internal::iterate();
Internal::app_step();
#endif
// shutdown
if (app_config.on_shutdown != nullptr)
app_config.on_shutdown();
App::Internal::shutdown();
Internal::app_shutdown();
return true;
}
@ -182,25 +182,25 @@ bool App::is_running()
return app_is_running;
}
void App::Internal::iterate()
void Internal::app_step()
{
static const auto step = []()
{
Input::Internal::step_state();
Internal::input_step_state();
platform->update(Input::state);
Input::Internal::update_bindings();
Internal::input_step_bindings();
renderer->update();
if (app_config.on_update != nullptr)
app_config.on_update();
};
bool is_fixed_timestep = get_flag(Flags::FixedTimestep);
bool is_fixed_timestep = App::get_flag(Flags::FixedTimestep);
// Update in Fixed Timestep
if (is_fixed_timestep)
{
u64 time_target = (u64)((1.0 / app_config.target_framerate) * Time::ticks_per_second);
u64 ticks_curr = App::Internal::platform->ticks();
u64 ticks_curr = Internal::platform->ticks();
u64 ticks_diff = ticks_curr - app_time_last;
app_time_last = ticks_curr;
app_time_accumulator += ticks_diff;
@ -209,9 +209,9 @@ void App::Internal::iterate()
while (app_time_accumulator < time_target)
{
int milliseconds = (int)(time_target - app_time_accumulator) / (Time::ticks_per_second / 1000);
App::Internal::platform->sleep(milliseconds);
Internal::platform->sleep(milliseconds);
ticks_curr = App::Internal::platform->ticks();
ticks_curr = Internal::platform->ticks();
ticks_diff = ticks_curr - app_time_last;
app_time_last = ticks_curr;
app_time_accumulator += ticks_diff;
@ -250,7 +250,7 @@ void App::Internal::iterate()
// Update with Variable Timestep
else
{
u64 ticks_curr = App::Internal::platform->ticks();
u64 ticks_curr = Internal::platform->ticks();
u64 ticks_diff = ticks_curr - app_time_last;
app_time_last = ticks_curr;
app_time_accumulator += ticks_diff;
@ -285,9 +285,9 @@ void App::Internal::iterate()
Blah::Internal::audio_update();
}
void App::Internal::shutdown()
void Internal::app_shutdown()
{
Input::Internal::shutdown();
Internal::input_shutdown();
if (renderer)
renderer->shutdown();
@ -449,5 +449,5 @@ const TargetRef& App::backbuffer()
void System::open_url(const char* url)
{
BLAH_ASSERT_RUNNING();
App::Internal::platform->open_url(url);
Internal::platform->open_url(url);
}

View File

@ -282,7 +282,7 @@ void Batch::render(const TargetRef& target, const Mat4x4f& matrix)
if (!m_default_material)
{
BLAH_ASSERT_RENDERER();
m_default_material = Material::create(App::Internal::renderer->default_batcher_shader);
m_default_material = Material::create(Internal::renderer->default_batcher_shader);
}
}

View File

@ -8,8 +8,8 @@ FileRef File::open(const FilePath& path, FileMode mode)
BLAH_ASSERT_PLATFORM();
FileRef ref;
if (App::Internal::platform)
ref = App::Internal::platform->file_open(path.cstr(), mode);
if (Internal::platform)
ref = Internal::platform->file_open(path.cstr(), mode);
if (ref)
ref->m_mode = mode;
return ref;
@ -18,16 +18,16 @@ FileRef File::open(const FilePath& path, FileMode mode)
bool File::exists(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
return App::Internal::platform->file_exists(path.cstr());
if (Internal::platform)
return Internal::platform->file_exists(path.cstr());
return false;
}
bool File::destroy(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
return App::Internal::platform->file_delete(path.cstr());
if (Internal::platform)
return Internal::platform->file_delete(path.cstr());
return false;
}
@ -39,24 +39,24 @@ FileMode File::mode() const
bool Directory::create(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
return App::Internal::platform->dir_create(path.cstr());
if (Internal::platform)
return Internal::platform->dir_create(path.cstr());
return false;
}
bool Directory::exists(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
return App::Internal::platform->dir_exists(path.cstr());
if (Internal::platform)
return Internal::platform->dir_exists(path.cstr());
return false;
}
bool Directory::destroy(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
return App::Internal::platform->dir_delete(path.cstr());
if (Internal::platform)
return Internal::platform->dir_delete(path.cstr());
return false;
}
@ -66,9 +66,9 @@ Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
Vector<FilePath> list;
if (App::Internal::platform)
if (Internal::platform)
{
App::Internal::platform->dir_enumerate(list, path.cstr(), recursive);
Internal::platform->dir_enumerate(list, path.cstr(), recursive);
for (auto& it : list)
{
for (int n = 0; n < it.length(); n ++)
@ -82,8 +82,8 @@ Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
void Directory::explore(const FilePath& path)
{
BLAH_ASSERT_PLATFORM();
if (App::Internal::platform)
App::Internal::platform->dir_explore(path);
if (Internal::platform)
Internal::platform->dir_explore(path);
}
FilePath Path::get_file_name(const FilePath& path)

View File

@ -88,8 +88,8 @@ ShaderRef Shader::create(const ShaderData& data)
ShaderRef shader;
if (App::Internal::renderer)
shader = App::Internal::renderer->create_shader(&data);
if (Internal::renderer)
shader = Internal::renderer->create_shader(&data);
// validate the shader
if (shader)
@ -130,9 +130,9 @@ TextureRef Texture::create(int width, int height, TextureFormat format, unsigned
BLAH_ASSERT(width > 0 && height > 0, "Texture width and height must be larger than 0");
BLAH_ASSERT((int)format > (int)TextureFormat::None && (int)format < (int)TextureFormat::Count, "Invalid texture format");
if (App::Internal::renderer)
if (Internal::renderer)
{
auto tex = App::Internal::renderer->create_texture(width, height, format);
auto tex = Internal::renderer->create_texture(width, height, format);
if (tex && data != nullptr)
tex->set_data(data);
@ -194,8 +194,8 @@ TargetRef Target::create(int width, int height, const AttachmentFormats& texture
BLAH_ASSERT(depth_count <= 1, "Target can only have 1 Depth/Stencil Texture");
BLAH_ASSERT(color_count <= Attachments::capacity - 1, "Exceeded maximum Color texture count");
if (App::Internal::renderer)
return App::Internal::renderer->create_target(width, height, textures.data(), textures.size());
if (Internal::renderer)
return Internal::renderer->create_target(width, height, textures.data(), textures.size());
return TargetRef();
}
@ -224,8 +224,8 @@ MeshRef Mesh::create()
{
BLAH_ASSERT_RENDERER();
if (App::Internal::renderer)
return App::Internal::renderer->create_mesh();
if (Internal::renderer)
return Internal::renderer->create_mesh();
return MeshRef();
}
@ -623,7 +623,7 @@ void DrawCall::perform()
BLAH_ASSERT(material->shader(), "Trying to draw with an invalid Shader");
BLAH_ASSERT(mesh, "Trying to draw with an invalid Mesh");
if (!App::Internal::renderer)
if (!Internal::renderer)
return;
// copy call
@ -685,5 +685,5 @@ void DrawCall::perform()
pass.scissor = pass.scissor.overlap_rect(Rectf(0, 0, draw_size.x, draw_size.y));
// perform render
App::Internal::renderer->render(pass);
Internal::renderer->render(pass);
}

View File

@ -24,7 +24,7 @@ InputState Blah::Input::last_state;
float Blah::Input::repeat_delay = 0.35f;
float Blah::Input::repeat_interval = 0.025f;
void Input::Internal::init()
void Internal::input_init()
{
g_empty_controller.name = "Disconnected";
for (int i = 0; i < Input::max_controllers; i++)
@ -37,12 +37,12 @@ void Input::Internal::init()
g_sticks = Vector<Ref<StickBinding>>();
}
void Input::Internal::shutdown()
void Internal::input_shutdown()
{
init();
input_init();
}
void Input::Internal::step_state()
void Internal::input_step_state()
{
// cycle states
Input::last_state = Input::state;
@ -78,11 +78,11 @@ void Input::Internal::step_state()
}
// get clipboard
if (App::Internal::platform)
g_clipboard = App::Internal::platform->get_clipboard();
if (Internal::platform)
g_clipboard = Internal::platform->get_clipboard();
}
void Input::Internal::update_bindings()
void Internal::input_step_bindings()
{
for (int i = 0; i < g_buttons.size(); i++)
{
@ -398,8 +398,8 @@ const String& Input::get_clipboard()
void Input::set_clipboard(const String& text)
{
g_clipboard = text;
if (App::Internal::platform)
App::Internal::platform->set_clipboard(text);
if (Internal::platform)
Internal::platform->set_clipboard(text);
}
ButtonBindingRef Input::register_binding(const ButtonBinding& binding_data)

View File

@ -12,8 +12,8 @@ float Time::pause_timer = 0;
u64 Time::get_ticks()
{
if (App::Internal::platform)
return App::Internal::platform->ticks();
if (Internal::platform)
return Internal::platform->ticks();
return 0;
}

View File

@ -2,45 +2,25 @@
#include "blah_renderer.h"
#include "blah_platform.h"
#define BLAH_ASSERT_RENDERER() BLAH_ASSERT(App::Internal::renderer, "Renderer has not been created")
#define BLAH_ASSERT_PLATFORM() BLAH_ASSERT(App::Internal::platform, "Platform has not been created")
#define BLAH_ASSERT_RENDERER() BLAH_ASSERT(Blah::Internal::renderer, "Renderer has not been created")
#define BLAH_ASSERT_PLATFORM() BLAH_ASSERT(Blah::Internal::platform, "Platform has not been created")
namespace Blah
{
namespace App
{
namespace Internal
{
extern Platform* platform;
extern Renderer* renderer;
void iterate();
void shutdown();
}
}
namespace Input
{
namespace Internal
{
// Initializes the Input State
void init();
// Steps the input state
void step_state();
// Updates bindings
void update_bindings();
// Clears Input State
void shutdown();
}
}
namespace Internal
{
extern bool audio_is_init;
void app_step();
void app_shutdown();
void input_init();
void input_step_state();
void input_step_bindings();
void input_shutdown();
// Pass in NULL for `os_handle`, except for the DirectSound backend this should be hwnd.
// play_frequency_in_Hz depends on your audio file, 44100 seems to be fine.
// buffered_samples is clamped to be at least 1024.

View File

@ -17,7 +17,7 @@
#include <d3dcompiler.h>
// shorthand to our internal state
#define renderer ((Renderer_D3D11*)App::Internal::renderer)
#define RENDERER ((Renderer_D3D11*)Internal::renderer)
namespace Blah
{
@ -228,7 +228,7 @@ namespace Blah
m_dxgi_format = desc.Format;
auto hr = renderer->device->CreateTexture2D(&desc, NULL, &texture);
auto hr = RENDERER->device->CreateTexture2D(&desc, NULL, &texture);
if (!SUCCEEDED(hr))
{
if (texture)
@ -239,7 +239,7 @@ namespace Blah
if (!is_depth_stencil)
{
hr = renderer->device->CreateShaderResourceView(texture, NULL, &view);
hr = RENDERER->device->CreateShaderResourceView(texture, NULL, &view);
if (!SUCCEEDED(hr))
{
texture->Release();
@ -288,7 +288,7 @@ namespace Blah
box.back = 1;
// set data
renderer->context->UpdateSubresource(
RENDERER->context->UpdateSubresource(
texture,
0,
&box,
@ -317,7 +317,7 @@ namespace Blah
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
desc.MiscFlags = 0;
hr = renderer->device->CreateTexture2D(&desc, NULL, &staging);
hr = RENDERER->device->CreateTexture2D(&desc, NULL, &staging);
if (!SUCCEEDED(hr))
{
BLAH_ASSERT(false, "Failed to create staging texture to get data");
@ -334,7 +334,7 @@ namespace Blah
box.back = 1;
// copy data to staging texture
renderer->context->CopySubresourceRegion(
RENDERER->context->CopySubresourceRegion(
staging, 0,
0, 0, 0,
texture, 0,
@ -342,7 +342,7 @@ namespace Blah
// get data
D3D11_MAPPED_SUBRESOURCE map;
hr = renderer->context->Map(staging, 0, D3D11_MAP_READ, 0, &map);
hr = RENDERER->context->Map(staging, 0, D3D11_MAP_READ, 0, &map);
if (!SUCCEEDED(hr))
{
@ -355,7 +355,7 @@ namespace Blah
for (int y = 0; y < m_height; y++)
memcpy(data + y * bytes_per_row, (unsigned char*)map.pData + map.RowPitch * y, bytes_per_row);
renderer->context->Unmap(staging, 0);
RENDERER->context->Unmap(staging, 0);
}
bool is_framebuffer() const override
@ -384,12 +384,12 @@ namespace Blah
if (attachments[i] == TextureFormat::DepthStencil)
{
renderer->device->CreateDepthStencilView(tex->texture, nullptr, &depth_view);
RENDERER->device->CreateDepthStencilView(tex->texture, nullptr, &depth_view);
}
else
{
ID3D11RenderTargetView* view = nullptr;
renderer->device->CreateRenderTargetView(tex->texture, nullptr, &view);
RENDERER->device->CreateRenderTargetView(tex->texture, nullptr, &view);
color_views.push_back(view);
}
}
@ -423,7 +423,7 @@ namespace Blah
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
for (int i = 0; i < color_views.size(); i++)
renderer->context->ClearRenderTargetView(color_views[i], col);
RENDERER->context->ClearRenderTargetView(color_views[i], col);
}
if (depth_view)
@ -435,7 +435,7 @@ namespace Blah
flags |= D3D11_CLEAR_STENCIL;
if (flags != 0)
renderer->context->ClearDepthStencilView(depth_view, flags, depth, stencil);
RENDERER->context->ClearDepthStencilView(depth_view, flags, depth, stencil);
}
}
};
@ -510,7 +510,7 @@ namespace Blah
// create vertex shader
{
hr = renderer->device->CreateVertexShader(
hr = RENDERER->device->CreateVertexShader(
vertex_blob->GetBufferPointer(),
vertex_blob->GetBufferSize(),
NULL,
@ -522,7 +522,7 @@ namespace Blah
// create fragment shader
{
hr = renderer->device->CreatePixelShader(
hr = RENDERER->device->CreatePixelShader(
fragment_blob->GetBufferPointer(),
fragment_blob->GetBufferSize(),
NULL,
@ -675,7 +675,7 @@ namespace Blah
data.pSysMem = indices;
// create
auto hr = renderer->device->CreateBuffer(&desc, &data, &index_buffer);
auto hr = RENDERER->device->CreateBuffer(&desc, &data, &index_buffer);
BLAH_ASSERT(SUCCEEDED(hr), "Failed to update Index Data");
}
}
@ -683,13 +683,13 @@ namespace Blah
{
D3D11_MAPPED_SUBRESOURCE map;
auto hr = renderer->context->Map(index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
auto hr = RENDERER->context->Map(index_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
BLAH_ASSERT(SUCCEEDED(hr), "Failed to update Index Data");
if (SUCCEEDED(hr))
{
memcpy(map.pData, indices, index_stride * count);
renderer->context->Unmap(index_buffer, 0);
RENDERER->context->Unmap(index_buffer, 0);
}
}
}
@ -723,7 +723,7 @@ namespace Blah
data.pSysMem = vertices;
// create
auto hr = renderer->device->CreateBuffer(&desc, &data, &vertex_buffer);
auto hr = RENDERER->device->CreateBuffer(&desc, &data, &vertex_buffer);
BLAH_ASSERT(SUCCEEDED(hr), "Failed to update Vertex Data");
}
}
@ -731,13 +731,13 @@ namespace Blah
else if (vertices)
{
D3D11_MAPPED_SUBRESOURCE map;
auto hr = renderer->context->Map(vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
auto hr = RENDERER->context->Map(vertex_buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
BLAH_ASSERT(SUCCEEDED(hr), "Failed to update Vertex Data");
if (SUCCEEDED(hr))
{
memcpy(map.pData, vertices, vertex_format.stride * count);
renderer->context->Unmap(vertex_buffer, 0);
RENDERER->context->Unmap(vertex_buffer, 0);
}
}
}
@ -776,7 +776,7 @@ namespace Blah
desc.SampleDesc.Quality = 0;
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
desc.BufferCount = 1;
desc.OutputWindow = (HWND)App::Internal::platform->d3d11_get_hwnd();
desc.OutputWindow = (HWND)Internal::platform->d3d11_get_hwnd();
desc.Windowed = true;
// Creation Flags
@ -1258,7 +1258,7 @@ namespace Blah
buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
ID3D11Buffer* buffer;
renderer->device->CreateBuffer(&buffer_desc, nullptr, &buffer);
RENDERER->device->CreateBuffer(&buffer_desc, nullptr, &buffer);
append_buffers_to.push_back(buffer);
}
@ -1366,9 +1366,9 @@ namespace Blah
if (buffers[i])
{
D3D11_MAPPED_SUBRESOURCE map;
renderer->context->Map(buffers[i], 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
RENDERER->context->Map(buffers[i], 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
memcpy(map.pData, values[i].begin(), values[i].size() * sizeof(float));
renderer->context->Unmap(buffers[i], 0);
RENDERER->context->Unmap(buffers[i], 0);
}
}
}
@ -1502,7 +1502,7 @@ namespace Blah
desc.RenderTarget[i] = desc.RenderTarget[0];
ID3D11BlendState* blend_state = nullptr;
auto hr = renderer->device->CreateBlendState(&desc, &blend_state);
auto hr = RENDERER->device->CreateBlendState(&desc, &blend_state);
if (SUCCEEDED(hr))
{
@ -1550,7 +1550,7 @@ namespace Blah
}
ID3D11SamplerState* result;
auto hr = renderer->device->CreateSamplerState(&desc, &result);
auto hr = RENDERER->device->CreateSamplerState(&desc, &result);
if (SUCCEEDED(hr))
{
@ -1590,7 +1590,7 @@ namespace Blah
desc.AntialiasedLineEnable = false;
ID3D11RasterizerState* result;
auto hr = renderer->device->CreateRasterizerState(&desc, &result);
auto hr = RENDERER->device->CreateRasterizerState(&desc, &result);
if (SUCCEEDED(hr))
{
@ -1629,7 +1629,7 @@ namespace Blah
}
ID3D11DepthStencilState* result;
auto hr = renderer->device->CreateDepthStencilState(&desc, &result);
auto hr = RENDERER->device->CreateDepthStencilState(&desc, &result);
if (SUCCEEDED(hr))
{
@ -1650,7 +1650,7 @@ Blah::Renderer* Blah::Renderer::try_make_d3d11()
#else // BLAH_RENDERER_D3D11
#include "blah_renderer.h"
#include "blah_RENDERER.h"
Blah::Renderer* Blah::Renderer::try_make_d3d11()
{
return nullptr;

View File

@ -340,7 +340,7 @@ typedef void (APIENTRY* DEBUGPROC)(GLenum source,
const void* userParam);
// shorthand to our internal state
#define renderer ((Renderer_OpenGL*)App::Internal::renderer)
#define RENDERER ((Renderer_OpenGL*)Internal::renderer)
namespace Blah
{
@ -470,7 +470,7 @@ namespace Blah
GLuint gl_mesh_assign_attributes(GLuint buffer, GLenum buffer_type, const VertexFormat& format, GLint divisor)
{
// bind
renderer->gl.BindBuffer(buffer_type, buffer);
RENDERER->gl.BindBuffer(buffer_type, buffer);
// TODO: disable existing enabled attributes ..
// ...
@ -547,9 +547,9 @@ namespace Blah
}
u32 location = (u32)(attribute.index);
renderer->gl.EnableVertexAttribArray(location);
renderer->gl.VertexAttribPointer(location, components, type, attribute.normalized, format.stride, (void*)ptr);
renderer->gl.VertexAttribDivisor(location, divisor);
RENDERER->gl.EnableVertexAttribArray(location);
RENDERER->gl.VertexAttribPointer(location, components, type, attribute.normalized, format.stride, (void*)ptr);
RENDERER->gl.VertexAttribDivisor(location, divisor);
ptr += components * component_size;
}
@ -627,9 +627,9 @@ namespace Blah
m_gl_format = GL_RED;
m_gl_type = GL_UNSIGNED_BYTE;
if (width > renderer->max_texture_size || height > renderer->max_texture_size)
if (width > RENDERER->max_texture_size || height > RENDERER->max_texture_size)
{
Log::error("Exceeded Max Texture Size of %i", renderer->max_texture_size);
Log::error("Exceeded Max Texture Size of %i", RENDERER->max_texture_size);
return;
}
@ -663,16 +663,16 @@ namespace Blah
return;
}
renderer->gl.GenTextures(1, &m_id);
renderer->gl.ActiveTexture(GL_TEXTURE0);
renderer->gl.BindTexture(GL_TEXTURE_2D, m_id);
renderer->gl.TexImage2D(GL_TEXTURE_2D, 0, m_gl_internal_format, width, height, 0, m_gl_format, m_gl_type, nullptr);
RENDERER->gl.GenTextures(1, &m_id);
RENDERER->gl.ActiveTexture(GL_TEXTURE0);
RENDERER->gl.BindTexture(GL_TEXTURE_2D, m_id);
RENDERER->gl.TexImage2D(GL_TEXTURE_2D, 0, m_gl_internal_format, width, height, 0, m_gl_format, m_gl_type, nullptr);
}
~OpenGL_Texture()
{
if (m_id > 0 && renderer)
renderer->gl.DeleteTextures(1, &m_id);
if (m_id > 0 && RENDERER)
RENDERER->gl.DeleteTextures(1, &m_id);
}
GLuint gl_id() const
@ -701,26 +701,26 @@ namespace Blah
{
m_sampler = sampler;
renderer->gl.BindTexture(GL_TEXTURE_2D, m_id);
renderer->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (m_sampler.filter == TextureFilter::Nearest ? GL_NEAREST : GL_LINEAR));
renderer->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (m_sampler.filter == TextureFilter::Nearest ? GL_NEAREST : GL_LINEAR));
renderer->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (m_sampler.wrap_x == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
renderer->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (m_sampler.wrap_y == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
RENDERER->gl.BindTexture(GL_TEXTURE_2D, m_id);
RENDERER->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (m_sampler.filter == TextureFilter::Nearest ? GL_NEAREST : GL_LINEAR));
RENDERER->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (m_sampler.filter == TextureFilter::Nearest ? GL_NEAREST : GL_LINEAR));
RENDERER->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (m_sampler.wrap_x == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
RENDERER->gl.TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (m_sampler.wrap_y == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT));
}
}
virtual void set_data(const u8* data) override
{
renderer->gl.ActiveTexture(GL_TEXTURE0);
renderer->gl.BindTexture(GL_TEXTURE_2D, m_id);
renderer->gl.TexImage2D(GL_TEXTURE_2D, 0, m_gl_internal_format, m_width, m_height, 0, m_gl_format, m_gl_type, data);
RENDERER->gl.ActiveTexture(GL_TEXTURE0);
RENDERER->gl.BindTexture(GL_TEXTURE_2D, m_id);
RENDERER->gl.TexImage2D(GL_TEXTURE_2D, 0, m_gl_internal_format, m_width, m_height, 0, m_gl_format, m_gl_type, data);
}
virtual void get_data(u8* data) override
{
renderer->gl.ActiveTexture(GL_TEXTURE0);
renderer->gl.BindTexture(GL_TEXTURE_2D, m_id);
renderer->gl.GetTexImage(GL_TEXTURE_2D, 0, m_gl_internal_format, m_gl_type, data);
RENDERER->gl.ActiveTexture(GL_TEXTURE0);
RENDERER->gl.BindTexture(GL_TEXTURE_2D, m_id);
RENDERER->gl.GetTexImage(GL_TEXTURE_2D, 0, m_gl_internal_format, m_gl_type, data);
}
virtual bool is_framebuffer() const override
@ -742,11 +742,11 @@ namespace Blah
OpenGL_Target(int width, int height, const TextureFormat* attachments, int attachmentCount)
{
renderer->gl.GenFramebuffers(1, &m_id);
RENDERER->gl.GenFramebuffers(1, &m_id);
m_width = width;
m_height = height;
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
RENDERER->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
for (int i = 0; i < attachmentCount; i++)
{
@ -758,20 +758,20 @@ namespace Blah
if (attachments[i] != TextureFormat::DepthStencil)
{
renderer->gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, gltex->gl_id(), 0);
RENDERER->gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, gltex->gl_id(), 0);
}
else
{
renderer->gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, gltex->gl_id(), 0);
RENDERER->gl.FramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, gltex->gl_id(), 0);
}
}
}
~OpenGL_Target()
{
if (m_id > 0 && renderer)
if (m_id > 0 && RENDERER)
{
renderer->gl.DeleteFramebuffers(1, &m_id);
RENDERER->gl.DeleteFramebuffers(1, &m_id);
m_id = 0;
}
}
@ -793,33 +793,33 @@ namespace Blah
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
renderer->gl.Disable(GL_SCISSOR_TEST);
RENDERER->gl.BindFramebuffer(GL_FRAMEBUFFER, m_id);
RENDERER->gl.Disable(GL_SCISSOR_TEST);
int clear = 0;
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
clear |= GL_COLOR_BUFFER_BIT;
renderer->gl.ColorMask(true, true, true, true);
renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
RENDERER->gl.ColorMask(true, true, true, true);
RENDERER->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
}
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
{
clear |= GL_DEPTH_BUFFER_BIT;
if (renderer->gl.ClearDepth)
renderer->gl.ClearDepth(depth);
if (RENDERER->gl.ClearDepth)
RENDERER->gl.ClearDepth(depth);
}
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
{
clear |= GL_STENCIL_BUFFER_BIT;
if (renderer->gl.ClearStencil)
renderer->gl.ClearStencil(stencil);
if (RENDERER->gl.ClearStencil)
RENDERER->gl.ClearStencil(stencil);
}
renderer->gl.Clear(clear);
RENDERER->gl.Clear(clear);
}
};
@ -851,47 +851,47 @@ namespace Blah
GLchar log[1024] = { 0 };
GLsizei log_length = 0;
GLuint vertex_shader = renderer->gl.CreateShader(GL_VERTEX_SHADER);
GLuint vertex_shader = RENDERER->gl.CreateShader(GL_VERTEX_SHADER);
{
const GLchar* source = (const GLchar*)data->vertex.cstr();
renderer->gl.ShaderSource(vertex_shader, 1, &source, nullptr);
renderer->gl.CompileShader(vertex_shader);
renderer->gl.GetShaderInfoLog(vertex_shader, 1024, &log_length, log);
RENDERER->gl.ShaderSource(vertex_shader, 1, &source, nullptr);
RENDERER->gl.CompileShader(vertex_shader);
RENDERER->gl.GetShaderInfoLog(vertex_shader, 1024, &log_length, log);
if (log_length > 0)
{
renderer->gl.DeleteShader(vertex_shader);
RENDERER->gl.DeleteShader(vertex_shader);
Log::error(log);
return;
}
}
GLuint fragment_shader = renderer->gl.CreateShader(GL_FRAGMENT_SHADER);
GLuint fragment_shader = RENDERER->gl.CreateShader(GL_FRAGMENT_SHADER);
{
const GLchar* source = (const GLchar*)data->fragment.cstr();
renderer->gl.ShaderSource(fragment_shader, 1, &source, nullptr);
renderer->gl.CompileShader(fragment_shader);
renderer->gl.GetShaderInfoLog(fragment_shader, 1024, &log_length, log);
RENDERER->gl.ShaderSource(fragment_shader, 1, &source, nullptr);
RENDERER->gl.CompileShader(fragment_shader);
RENDERER->gl.GetShaderInfoLog(fragment_shader, 1024, &log_length, log);
if (log_length > 0)
{
renderer->gl.DeleteShader(vertex_shader);
renderer->gl.DeleteShader(fragment_shader);
RENDERER->gl.DeleteShader(vertex_shader);
RENDERER->gl.DeleteShader(fragment_shader);
Log::error(log);
return;
}
}
// create actual shader program
GLuint id = renderer->gl.CreateProgram();
renderer->gl.AttachShader(id, vertex_shader);
renderer->gl.AttachShader(id, fragment_shader);
renderer->gl.LinkProgram(id);
renderer->gl.GetProgramInfoLog(id, 1024, &log_length, log);
renderer->gl.DetachShader(id, vertex_shader);
renderer->gl.DetachShader(id, fragment_shader);
renderer->gl.DeleteShader(vertex_shader);
renderer->gl.DeleteShader(fragment_shader);
GLuint id = RENDERER->gl.CreateProgram();
RENDERER->gl.AttachShader(id, vertex_shader);
RENDERER->gl.AttachShader(id, fragment_shader);
RENDERER->gl.LinkProgram(id);
RENDERER->gl.GetProgramInfoLog(id, 1024, &log_length, log);
RENDERER->gl.DetachShader(id, vertex_shader);
RENDERER->gl.DetachShader(id, fragment_shader);
RENDERER->gl.DeleteShader(vertex_shader);
RENDERER->gl.DeleteShader(fragment_shader);
if (log_length > 0)
{
@ -906,7 +906,7 @@ namespace Blah
GLint active_uniforms = 0;
GLint sampler_uniforms = 0;
renderer->gl.GetProgramiv(id, GL_ACTIVE_UNIFORMS, &active_uniforms);
RENDERER->gl.GetProgramiv(id, GL_ACTIVE_UNIFORMS, &active_uniforms);
for (int i = 0; i < active_uniforms; i++)
{
@ -915,7 +915,7 @@ namespace Blah
GLenum type;
GLchar name[max_name_length + 1] = { 0 };
renderer->gl.GetActiveUniform(id, i, max_name_length, &length, &size, &type, name);
RENDERER->gl.GetActiveUniform(id, i, max_name_length, &length, &size, &type, name);
name[length] = '\0';
// array names end with "[0]", and we don't want that
@ -938,7 +938,7 @@ namespace Blah
tex_uniform.array_length = size;
tex_uniform.type = UniformType::Texture2D;
tex_uniform.shader = ShaderType::Fragment;
uniform_locations.push_back(renderer->gl.GetUniformLocation(id, name));
uniform_locations.push_back(RENDERER->gl.GetUniformLocation(id, name));
m_uniforms.push_back(tex_uniform);
UniformInfo sampler_uniform;
@ -948,7 +948,7 @@ namespace Blah
sampler_uniform.array_length = size;
sampler_uniform.type = UniformType::Sampler2D;
sampler_uniform.shader = ShaderType::Fragment;
uniform_locations.push_back(renderer->gl.GetUniformLocation(id, name));
uniform_locations.push_back(RENDERER->gl.GetUniformLocation(id, name));
m_uniforms.push_back(sampler_uniform);
sampler_uniforms += size;
@ -961,7 +961,7 @@ namespace Blah
uniform.register_index = 0;
uniform.buffer_index = 0;
uniform.array_length = size;
uniform_locations.push_back(renderer->gl.GetUniformLocation(id, name));
uniform_locations.push_back(RENDERER->gl.GetUniformLocation(id, name));
uniform.shader = (ShaderType)((int)ShaderType::Vertex | (int)ShaderType::Fragment);
if (type == GL_FLOAT)
@ -991,15 +991,15 @@ namespace Blah
// assign ID if the uniforms were valid
if (!valid_uniforms)
renderer->gl.DeleteProgram(id);
RENDERER->gl.DeleteProgram(id);
else
m_id = id;
}
~OpenGL_Shader()
{
if (m_id > 0 && renderer)
renderer->gl.DeleteProgram(m_id);
if (m_id > 0 && RENDERER)
RENDERER->gl.DeleteProgram(m_id);
m_id = 0;
}
@ -1054,21 +1054,21 @@ namespace Blah
m_vertex_attribs_enabled = 0;
m_instance_attribs_enabled = 0;
renderer->gl.GenVertexArrays(1, &m_id);
RENDERER->gl.GenVertexArrays(1, &m_id);
}
~OpenGL_Mesh()
{
if (renderer)
if (RENDERER)
{
if (m_vertex_buffer != 0)
renderer->gl.DeleteBuffers(1, &m_vertex_buffer);
RENDERER->gl.DeleteBuffers(1, &m_vertex_buffer);
if (m_index_buffer != 0)
renderer->gl.DeleteBuffers(1, &m_index_buffer);
RENDERER->gl.DeleteBuffers(1, &m_index_buffer);
if (m_instance_buffer != 0)
renderer->gl.DeleteBuffers(1, &m_instance_buffer);
RENDERER->gl.DeleteBuffers(1, &m_instance_buffer);
if (m_id != 0)
renderer->gl.DeleteVertexArrays(1, &m_id);
RENDERER->gl.DeleteVertexArrays(1, &m_id);
}
m_id = 0;
}
@ -1092,10 +1092,10 @@ namespace Blah
{
m_index_count = count;
renderer->gl.BindVertexArray(m_id);
RENDERER->gl.BindVertexArray(m_id);
{
if (m_index_buffer == 0)
renderer->gl.GenBuffers(1, &(m_index_buffer));
RENDERER->gl.GenBuffers(1, &(m_index_buffer));
switch (format)
{
@ -1109,52 +1109,52 @@ namespace Blah
break;
}
renderer->gl.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer);
renderer->gl.BufferData(GL_ELEMENT_ARRAY_BUFFER, m_index_size * count, indices, GL_DYNAMIC_DRAW);
RENDERER->gl.BindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_index_buffer);
RENDERER->gl.BufferData(GL_ELEMENT_ARRAY_BUFFER, m_index_size * count, indices, GL_DYNAMIC_DRAW);
}
renderer->gl.BindVertexArray(0);
RENDERER->gl.BindVertexArray(0);
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
renderer->gl.BindVertexArray(m_id);
RENDERER->gl.BindVertexArray(m_id);
{
// Create Buffer if it doesn't exist yet
if (m_vertex_buffer == 0)
renderer->gl.GenBuffers(1, &(m_vertex_buffer));
RENDERER->gl.GenBuffers(1, &(m_vertex_buffer));
// TODO:
// Cache this
m_vertex_size = gl_mesh_assign_attributes(m_vertex_buffer, GL_ARRAY_BUFFER, format, 0);
// Upload Buffer
renderer->gl.BindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
renderer->gl.BufferData(GL_ARRAY_BUFFER, m_vertex_size * count, vertices, GL_DYNAMIC_DRAW);
RENDERER->gl.BindBuffer(GL_ARRAY_BUFFER, m_vertex_buffer);
RENDERER->gl.BufferData(GL_ARRAY_BUFFER, m_vertex_size * count, vertices, GL_DYNAMIC_DRAW);
}
renderer->gl.BindVertexArray(0);
RENDERER->gl.BindVertexArray(0);
}
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
m_instance_count = count;
renderer->gl.BindVertexArray(m_id);
RENDERER->gl.BindVertexArray(m_id);
{
// Create Buffer if it doesn't exist yet
if (m_instance_buffer == 0)
renderer->gl.GenBuffers(1, &(m_instance_buffer));
RENDERER->gl.GenBuffers(1, &(m_instance_buffer));
// TODO:
// Cache this
m_instance_size = gl_mesh_assign_attributes(m_instance_buffer, GL_ARRAY_BUFFER, format, 1);
// Upload Buffer
renderer->gl.BindBuffer(GL_ARRAY_BUFFER, m_instance_buffer);
renderer->gl.BufferData(GL_ARRAY_BUFFER, m_instance_size * count, instances, GL_DYNAMIC_DRAW);
RENDERER->gl.BindBuffer(GL_ARRAY_BUFFER, m_instance_buffer);
RENDERER->gl.BufferData(GL_ARRAY_BUFFER, m_instance_size * count, instances, GL_DYNAMIC_DRAW);
}
renderer->gl.BindVertexArray(0);
RENDERER->gl.BindVertexArray(0);
}
virtual i64 index_count() const override
@ -1176,16 +1176,16 @@ namespace Blah
bool Renderer_OpenGL::init()
{
// create gl context
context = App::Internal::platform->gl_context_create();
context = Internal::platform->gl_context_create();
if (context == nullptr)
{
Log::error("Failed to create OpenGL Context");
return false;
}
App::Internal::platform->gl_context_make_current(context);
Internal::platform->gl_context_make_current(context);
// bind opengl functions
#define GL_FUNC(name, ...) gl.name = (Renderer_OpenGL::Bindings::name ## Func)(App::Internal::platform->gl_get_func("gl" #name));
#define GL_FUNC(name, ...) gl.name = (Renderer_OpenGL::Bindings::name ## Func)(Internal::platform->gl_get_func("gl" #name));
GL_FUNCTIONS
#undef GL_FUNC
@ -1229,7 +1229,7 @@ namespace Blah
void Renderer_OpenGL::shutdown()
{
App::Internal::platform->gl_context_destroy(context);
Internal::platform->gl_context_destroy(context);
context = nullptr;
}
@ -1294,12 +1294,12 @@ namespace Blah
// Bind the Target
if (pass.target == App::backbuffer())
{
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
RENDERER->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
}
else if (pass.target)
{
auto framebuffer = (OpenGL_Target*)pass.target.get();
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, framebuffer->gl_id());
RENDERER->gl.BindFramebuffer(GL_FRAMEBUFFER, framebuffer->gl_id());
}
auto size = Point(pass.target->width(), pass.target->height());
@ -1311,7 +1311,7 @@ namespace Blah
// TODO: I don't love how material values are assigned or set here
// TODO: this should be cached?
{
renderer->gl.UseProgram(shader->gl_id());
RENDERER->gl.UseProgram(shader->gl_id());
int texture_slot = 0;
GLint texture_ids[64];
@ -1335,61 +1335,61 @@ namespace Blah
auto tex = pass.material->get_texture(texture_slot);
auto sampler = pass.material->get_sampler(texture_slot);
renderer->gl.ActiveTexture(GL_TEXTURE0 + texture_slot);
RENDERER->gl.ActiveTexture(GL_TEXTURE0 + texture_slot);
if (!tex)
{
renderer->gl.BindTexture(GL_TEXTURE_2D, 0);
RENDERER->gl.BindTexture(GL_TEXTURE_2D, 0);
}
else
{
auto gl_tex = ((OpenGL_Texture*)tex.get());
gl_tex->update_sampler(sampler);
renderer->gl.BindTexture(GL_TEXTURE_2D, gl_tex->gl_id());
RENDERER->gl.BindTexture(GL_TEXTURE_2D, gl_tex->gl_id());
}
texture_ids[n] = texture_slot;
texture_slot++;
}
renderer->gl.Uniform1iv(location, (GLint)uniform.array_length, &texture_ids[0]);
RENDERER->gl.Uniform1iv(location, (GLint)uniform.array_length, &texture_ids[0]);
continue;
}
// Float
if (uniform.type == UniformType::Float)
{
renderer->gl.Uniform1fv(location, (GLint)uniform.array_length, data);
RENDERER->gl.Uniform1fv(location, (GLint)uniform.array_length, data);
data += uniform.array_length;
}
// Float2
else if (uniform.type == UniformType::Float2)
{
renderer->gl.Uniform2fv(location, (GLint)uniform.array_length, data);
RENDERER->gl.Uniform2fv(location, (GLint)uniform.array_length, data);
data += 2 * uniform.array_length;
}
// Float3
else if (uniform.type == UniformType::Float3)
{
renderer->gl.Uniform3fv(location, (GLint)uniform.array_length, data);
RENDERER->gl.Uniform3fv(location, (GLint)uniform.array_length, data);
data += 3 * uniform.array_length;
}
// Float4
else if (uniform.type == UniformType::Float4)
{
renderer->gl.Uniform4fv(location, (GLint)uniform.array_length, data);
RENDERER->gl.Uniform4fv(location, (GLint)uniform.array_length, data);
data += 4 * uniform.array_length;
}
// Matrix3x2
else if (uniform.type == UniformType::Mat3x2)
{
renderer->gl.UniformMatrix3x2fv(location, (GLint)uniform.array_length, 0, data);
RENDERER->gl.UniformMatrix3x2fv(location, (GLint)uniform.array_length, 0, data);
data += 6 * uniform.array_length;
}
// Matrix4x4
else if (uniform.type == UniformType::Mat4x4)
{
renderer->gl.UniformMatrix4fv(location, (GLint)uniform.array_length, 0, data);
RENDERER->gl.UniformMatrix4fv(location, (GLint)uniform.array_length, 0, data);
data += 16 * uniform.array_length;
}
}
@ -1404,11 +1404,11 @@ namespace Blah
GLenum alphaSrc = gl_get_blend_factor(pass.blend.alpha_src);
GLenum alphaDst = gl_get_blend_factor(pass.blend.alpha_dst);
renderer->gl.Enable(GL_BLEND);
renderer->gl.BlendEquationSeparate(colorOp, alphaOp);
renderer->gl.BlendFuncSeparate(colorSrc, colorDst, alphaSrc, alphaDst);
RENDERER->gl.Enable(GL_BLEND);
RENDERER->gl.BlendEquationSeparate(colorOp, alphaOp);
RENDERER->gl.BlendFuncSeparate(colorSrc, colorDst, alphaSrc, alphaDst);
renderer->gl.ColorMask(
RENDERER->gl.ColorMask(
((int)pass.blend.mask & (int)BlendMask::Red),
((int)pass.blend.mask & (int)BlendMask::Green),
((int)pass.blend.mask & (int)BlendMask::Blue),
@ -1419,7 +1419,7 @@ namespace Blah
unsigned char b = pass.blend.rgba >> 8;
unsigned char a = pass.blend.rgba;
renderer->gl.BlendColor(
RENDERER->gl.BlendColor(
r / 255.0f,
g / 255.0f,
b / 255.0f,
@ -1430,38 +1430,38 @@ namespace Blah
{
if (pass.depth == Compare::None)
{
renderer->gl.Disable(GL_DEPTH_TEST);
RENDERER->gl.Disable(GL_DEPTH_TEST);
}
else
{
renderer->gl.Enable(GL_DEPTH_TEST);
RENDERER->gl.Enable(GL_DEPTH_TEST);
switch (pass.depth)
{
case Compare::None: break;
case Compare::Always:
renderer->gl.DepthFunc(GL_ALWAYS);
RENDERER->gl.DepthFunc(GL_ALWAYS);
break;
case Compare::Equal:
renderer->gl.DepthFunc(GL_EQUAL);
RENDERER->gl.DepthFunc(GL_EQUAL);
break;
case Compare::Greater:
renderer->gl.DepthFunc(GL_GREATER);
RENDERER->gl.DepthFunc(GL_GREATER);
break;
case Compare::GreaterOrEqual:
renderer->gl.DepthFunc(GL_GEQUAL);
RENDERER->gl.DepthFunc(GL_GEQUAL);
break;
case Compare::Less:
renderer->gl.DepthFunc(GL_LESS);
RENDERER->gl.DepthFunc(GL_LESS);
break;
case Compare::LessOrEqual:
renderer->gl.DepthFunc(GL_LEQUAL);
RENDERER->gl.DepthFunc(GL_LEQUAL);
break;
case Compare::Never:
renderer->gl.DepthFunc(GL_NEVER);
RENDERER->gl.DepthFunc(GL_NEVER);
break;
case Compare::NotEqual:
renderer->gl.DepthFunc(GL_NOTEQUAL);
RENDERER->gl.DepthFunc(GL_NOTEQUAL);
break;
}
}
@ -1471,18 +1471,18 @@ namespace Blah
{
if (pass.cull == Cull::None)
{
renderer->gl.Disable(GL_CULL_FACE);
RENDERER->gl.Disable(GL_CULL_FACE);
}
else
{
renderer->gl.Enable(GL_CULL_FACE);
RENDERER->gl.Enable(GL_CULL_FACE);
if (pass.cull == Cull::Back)
renderer->gl.CullFace(GL_BACK);
RENDERER->gl.CullFace(GL_BACK);
else if (pass.cull == Cull::Front)
renderer->gl.CullFace(GL_FRONT);
RENDERER->gl.CullFace(GL_FRONT);
else
renderer->gl.CullFace(GL_FRONT_AND_BACK);
RENDERER->gl.CullFace(GL_FRONT_AND_BACK);
}
}
@ -1491,14 +1491,14 @@ namespace Blah
Rectf viewport = pass.viewport;
viewport.y = size.y - viewport.y - viewport.h;
renderer->gl.Viewport((GLint)viewport.x, (GLint)viewport.y, (GLint)viewport.w, (GLint)viewport.h);
RENDERER->gl.Viewport((GLint)viewport.x, (GLint)viewport.y, (GLint)viewport.w, (GLint)viewport.h);
}
// Scissor
{
if (!pass.has_scissor)
{
renderer->gl.Disable(GL_SCISSOR_TEST);
RENDERER->gl.Disable(GL_SCISSOR_TEST);
}
else
{
@ -1510,21 +1510,21 @@ namespace Blah
if (scissor.h < 0)
scissor.h = 0;
renderer->gl.Enable(GL_SCISSOR_TEST);
renderer->gl.Scissor((GLint)scissor.x, (GLint)scissor.y, (GLint)scissor.w, (GLint)scissor.h);
RENDERER->gl.Enable(GL_SCISSOR_TEST);
RENDERER->gl.Scissor((GLint)scissor.x, (GLint)scissor.y, (GLint)scissor.w, (GLint)scissor.h);
}
}
// Draw the Mesh
{
renderer->gl.BindVertexArray(mesh->gl_id());
RENDERER->gl.BindVertexArray(mesh->gl_id());
GLenum index_format = mesh->gl_index_format();
int index_size = mesh->gl_index_size();
if (pass.instance_count > 0)
{
renderer->gl.DrawElementsInstanced(
RENDERER->gl.DrawElementsInstanced(
GL_TRIANGLES,
(GLint)(pass.index_count),
index_format,
@ -1533,46 +1533,46 @@ namespace Blah
}
else
{
renderer->gl.DrawElements(
RENDERER->gl.DrawElements(
GL_TRIANGLES,
(GLint)(pass.index_count),
index_format,
(void*)(index_size * pass.index_start));
}
renderer->gl.BindVertexArray(0);
RENDERER->gl.BindVertexArray(0);
}
}
void Renderer_OpenGL::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{
renderer->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
renderer->gl.Disable(GL_SCISSOR_TEST);
RENDERER->gl.BindFramebuffer(GL_FRAMEBUFFER, 0);
RENDERER->gl.Disable(GL_SCISSOR_TEST);
int clear = 0;
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
clear |= GL_COLOR_BUFFER_BIT;
renderer->gl.ColorMask(true, true, true, true);
renderer->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
RENDERER->gl.ColorMask(true, true, true, true);
RENDERER->gl.ClearColor(color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f);
}
if (((int)mask & (int)ClearMask::Depth) == (int)ClearMask::Depth)
{
clear |= GL_DEPTH_BUFFER_BIT;
if (renderer->gl.ClearDepth)
renderer->gl.ClearDepth(depth);
if (RENDERER->gl.ClearDepth)
RENDERER->gl.ClearDepth(depth);
}
if (((int)mask & (int)ClearMask::Stencil) == (int)ClearMask::Stencil)
{
clear |= GL_STENCIL_BUFFER_BIT;
if (renderer->gl.ClearStencil)
renderer->gl.ClearStencil(stencil);
if (RENDERER->gl.ClearStencil)
RENDERER->gl.ClearStencil(stencil);
}
renderer->gl.Clear(clear);
RENDERER->gl.Clear(clear);
}
}