replaced log.h with common.h, added easier shorthand for int types

This commit is contained in:
Noel Berry
2021-03-20 17:33:04 -07:00
parent 9f9ed08007
commit d73241e8fe
58 changed files with 416 additions and 408 deletions

View File

@ -39,7 +39,7 @@ namespace Blah
void render(const RenderPass& pass);
// Clears the backbuffer
void clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask);
void clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask);
// Creates a new Texture.
// if the Texture is invalid, this should return an empty reference.

View File

@ -5,7 +5,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
@ -36,7 +36,7 @@ namespace Blah
struct StoredInputLayout
{
uint32_t shader_hash;
u32 shader_hash;
VertexFormat format;
ID3D11InputLayout* layout;
};
@ -145,6 +145,8 @@ namespace Blah
m_size = width * height * 4;
is_depth_stencil = true;
break;
case TextureFormat::Count:
break;
}
if (!is_depth_stencil)
@ -349,7 +351,7 @@ namespace Blah
return m_attachments[0]->height();
}
virtual void clear(Color color, float depth, uint8_t stencil, ClearMask mask) override
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
float col[4] = { color.r / 255.0f, color.g / 255.0f, color.b / 255.0f, color.a / 255.0f };
@ -386,7 +388,7 @@ namespace Blah
Vector<Vector<float>> fragment_uniform_values;
StackVector<ShaderData::HLSL_Attribute, 16> attributes;
Vector<UniformInfo> uniform_list;
uint32_t hash = 0;
u32 hash = 0;
bool valid = false;
D3D11_Shader(const ShaderData* data)
@ -542,10 +544,10 @@ namespace Blah
class D3D11_Mesh : public Mesh
{
private:
int64_t m_vertex_count = 0;
int64_t m_vertex_capacity = 0;
int64_t m_index_count = 0;
int64_t m_index_capacity = 0;
i64 m_vertex_count = 0;
i64 m_vertex_capacity = 0;
i64 m_index_count = 0;
i64 m_index_capacity = 0;
public:
ID3D11Buffer* vertex_buffer = nullptr;
@ -567,7 +569,7 @@ namespace Blah
index_buffer->Release();
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
@ -579,8 +581,8 @@ namespace Blah
switch (format)
{
case IndexFormat::UInt16: index_stride = sizeof(int16_t); break;
case IndexFormat::UInt32: index_stride = sizeof(int32_t); break;
case IndexFormat::UInt16: index_stride = sizeof(i16); break;
case IndexFormat::UInt32: index_stride = sizeof(i32); break;
}
if (m_index_capacity > 0 && indices)
@ -621,7 +623,7 @@ namespace Blah
}
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
@ -669,22 +671,22 @@ namespace Blah
}
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return 0;
}
@ -764,10 +766,10 @@ namespace Blah
dxgi_device->GetAdapter(&dxgi_adapter);
dxgi_adapter->GetDesc(&adapter_desc);
Log::print("D3D11 %ls", adapter_desc.Description);
Log::info("D3D11 %ls", adapter_desc.Description);
}
else
Log::print("D3D11");
Log::info("D3D11");
}
return true;
@ -1056,7 +1058,7 @@ namespace Blah
}
}
void GraphicsBackend::clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask)
void GraphicsBackend::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{
if (((int)mask & (int)ClearMask::Color) == (int)ClearMask::Color)
{
@ -1243,6 +1245,7 @@ namespace Blah
int size = 0;
switch (it.type)
{
case UniformType::None: break;
case UniformType::Float: size = 1; break;
case UniformType::Float2: size = 2; break;
case UniformType::Float3: size = 3; break;
@ -1304,6 +1307,7 @@ namespace Blah
{
switch (format.attributes[i].type)
{
case VertexType::None: break;
case VertexType::Float: it->Format = DXGI_FORMAT_R32_FLOAT; break;
case VertexType::Float2: it->Format = DXGI_FORMAT_R32G32_FLOAT; break;
case VertexType::Float3: it->Format = DXGI_FORMAT_R32G32B32_FLOAT; break;
@ -1320,6 +1324,7 @@ namespace Blah
{
switch (format.attributes[i].type)
{
case VertexType::None: break;
case VertexType::Float: it->Format = DXGI_FORMAT_R32_FLOAT; break;
case VertexType::Float2: it->Format = DXGI_FORMAT_R32G32_FLOAT; break;
case VertexType::Float3: it->Format = DXGI_FORMAT_R32G32B32_FLOAT; break;
@ -1428,18 +1433,21 @@ namespace Blah
switch (sampler.filter)
{
case TextureFilter::None: break;
case TextureFilter::Nearest: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; break;
case TextureFilter::Linear: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break;
}
switch (sampler.wrap_x)
{
case TextureWrap::None: break;
case TextureWrap::Clamp: desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; break;
case TextureWrap::Repeat: desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; break;
}
switch (sampler.wrap_y)
{
case TextureWrap::None: break;
case TextureWrap::Clamp: desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; break;
case TextureWrap::Repeat: desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; break;
}

View File

@ -2,7 +2,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
namespace Blah
{
@ -134,9 +134,9 @@ namespace Blah
class Dummy_Mesh : public Mesh
{
private:
int64_t m_index_count = 0;
int64_t m_vertex_count = 0;
int64_t m_instance_count = 0;
i64 m_index_count = 0;
i64 m_vertex_count = 0;
i64 m_instance_count = 0;
public:
Dummy_Mesh()
@ -144,32 +144,32 @@ namespace Blah
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
m_instance_count = count;
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return m_instance_count;
}
@ -177,7 +177,7 @@ namespace Blah
bool GraphicsBackend::init()
{
Log::print("Dummy Renderer");
Log::info("Dummy Renderer");
return true;
}

View File

@ -2,7 +2,7 @@
#include "../internal/graphics_backend.h"
#include "../internal/platform_backend.h"
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <stdio.h>
#include <string.h>
#include <stddef.h>
@ -401,7 +401,7 @@ namespace Blah
else if (severity != GL_DEBUG_SEVERITY_NOTIFICATION)
Log::warn("GL (%s:%s) %s", typeName, severityName, message);
else
Log::print("GL (%s) %s", typeName, message);
Log::info("GL (%s) %s", typeName, message);
}
// assign attributes
@ -484,7 +484,7 @@ namespace Blah
components = 4;
}
uint32_t location = (uint32_t)(attribute.index);
u32 location = (u32)(attribute.index);
gl.EnableVertexAttribArray(location);
gl.VertexAttribPointer(location, components, type, attribute.normalized, format.stride, (void*)ptr);
gl.VertexAttribDivisor(location, divisor);
@ -749,7 +749,7 @@ namespace Blah
return m_height;
}
virtual void clear(Color color, float depth, uint8_t stencil, ClearMask mask) override
virtual void clear(Color color, float depth, u8 stencil, ClearMask mask) override
{
int clear = 0;
@ -967,13 +967,13 @@ namespace Blah
GLuint m_index_buffer;
GLuint m_vertex_buffer;
GLuint m_instance_buffer;
int64_t m_index_count;
int64_t m_vertex_count;
int64_t m_instance_count;
uint16_t m_vertex_size;
uint16_t m_instance_size;
uint8_t m_vertex_attribs_enabled;
uint8_t m_instance_attribs_enabled;
i64 m_index_count;
i64 m_vertex_count;
i64 m_instance_count;
u16 m_vertex_size;
u16 m_instance_size;
u8 m_vertex_attribs_enabled;
u8 m_instance_attribs_enabled;
Vector<GLuint> m_vertex_attribs;
Vector<GLuint> m_instance_attribs;
GLenum m_index_format;
@ -1026,7 +1026,7 @@ namespace Blah
return m_index_size;
}
virtual void index_data(IndexFormat format, const void* indices, int64_t count) override
virtual void index_data(IndexFormat format, const void* indices, i64 count) override
{
m_index_count = count;
@ -1053,7 +1053,7 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual void vertex_data(const VertexFormat& format, const void* vertices, int64_t count) override
virtual void vertex_data(const VertexFormat& format, const void* vertices, i64 count) override
{
m_vertex_count = count;
@ -1074,7 +1074,7 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual void instance_data(const VertexFormat& format, const void* instances, int64_t count) override
virtual void instance_data(const VertexFormat& format, const void* instances, i64 count) override
{
m_instance_count = count;
@ -1095,17 +1095,17 @@ namespace Blah
gl.BindVertexArray(0);
}
virtual int64_t index_count() const override
virtual i64 index_count() const override
{
return m_index_count;
}
virtual int64_t vertex_count() const override
virtual i64 vertex_count() const override
{
return m_vertex_count;
}
virtual int64_t instance_count() const override
virtual i64 instance_count() const override
{
return m_instance_count;
}
@ -1147,7 +1147,7 @@ namespace Blah
gl.GetIntegerv(0x0D33, &gl.max_texture_size);
// log
Log::print("OpenGL %s, %s",
Log::info("OpenGL %s, %s",
gl.GetString(GL_VERSION),
gl.GetString(GL_RENDERER));
@ -1496,7 +1496,7 @@ namespace Blah
}
}
void GraphicsBackend::clear_backbuffer(Color color, float depth, uint8_t stencil, ClearMask mask)
void GraphicsBackend::clear_backbuffer(Color color, float depth, u8 stencil, ClearMask mask)
{
int clear = 0;

View File

@ -37,7 +37,7 @@ namespace Blah
// Call this when a Controller is connected. Note that the Name parameter must be kept valid
// until on_controller_disconnect is called with the same index.
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount, uint16_t vendor, uint16_t product, uint16_t version);
void on_controller_connect(int index, const char* name, int isGamepad, int buttonCount, int axisCount, u16 vendor, u16 product, u16 version);
// Call this when a controller is disconnected
void on_controller_disconnect(int index);

View File

@ -1,5 +1,5 @@
#pragma once
#include <inttypes.h>
#include <blah/core/common.h>
#include <blah/core/filesystem.h>
#include <blah/containers/vector.h>
@ -22,7 +22,7 @@ namespace Blah
void shutdown();
// The time, in ticks (microseconds) since the Application was started
uint64_t ticks();
u64 ticks();
// Called every frame
void frame();
@ -91,19 +91,19 @@ namespace Blah
bool file_open(const char* path, FileHandle* handle, FileMode mode);
// Returns the length of the file
int64_t file_length(FileHandle file);
i64 file_length(FileHandle file);
// Returns the Position of the file
int64_t file_position(FileHandle file);
i64 file_position(FileHandle file);
// Seeks the Position of the file and returns the new position from the start of the file
int64_t file_seek(FileHandle file, int64_t seekTo);
i64 file_seek(FileHandle file, i64 seekTo);
// Reads a specific number of elements of a given size from the file into ptr
int64_t file_read(FileHandle file, void* ptr, int64_t size);
i64 file_read(FileHandle file, void* ptr, i64 size);
// Writes a specific number of elements of the given size from ptr to the file
int64_t file_write(FileHandle file, const void* ptr, int64_t size);
i64 file_write(FileHandle file, const void* ptr, i64 size);
// Closes a file
void file_close(FileHandle file);

View File

@ -6,7 +6,7 @@
#include <blah/input/input.h>
#include <blah/core/app.h>
#include <blah/core/filesystem.h>
#include <blah/core/log.h>
#include <blah/core/common.h>
#include <blah/core/time.h>
#include <SDL.h>
@ -41,7 +41,7 @@ namespace
void sdl_log(void* userdata, int category, SDL_LogPriority priority, const char* message)
{
if (priority <= SDL_LOG_PRIORITY_INFO)
Log::print(message);
Log::info(message);
else if (priority <= SDL_LOG_PRIORITY_WARN)
Log::warn(message);
else
@ -65,7 +65,7 @@ bool PlatformBackend::init(const Config* config)
// Get SDL version
SDL_version version;
SDL_GetVersion(&version);
Log::print("SDL v%i.%i.%i", version.major, version.minor, version.patch);
Log::info("SDL v%i.%i.%i", version.major, version.minor, version.patch);
// initialize SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) != 0)
@ -170,11 +170,11 @@ void PlatformBackend::shutdown()
SDL_Quit();
}
uint64_t PlatformBackend::ticks()
u64 PlatformBackend::ticks()
{
auto counter = SDL_GetPerformanceCounter();
auto per_second = (double)SDL_GetPerformanceFrequency();
return (uint64_t)(counter * (Time::ticks_per_second / per_second));
return (u64)(counter * (Time::ticks_per_second / per_second));
}
// Macro defined by X11 conflicts with MouseButton enum
@ -255,9 +255,9 @@ void PlatformBackend::frame()
const char* name = SDL_JoystickName(ptr);
int button_count = SDL_JoystickNumButtons(ptr);
int axis_count = SDL_JoystickNumAxes(ptr);
uint16_t vendor = SDL_JoystickGetVendor(ptr);
uint16_t product = SDL_JoystickGetProduct(ptr);
uint16_t version = SDL_JoystickGetProductVersion(ptr);
u16 vendor = SDL_JoystickGetVendor(ptr);
u16 product = SDL_JoystickGetProduct(ptr);
u16 version = SDL_JoystickGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 0, button_count, axis_count, vendor, product, version);
}
@ -303,9 +303,9 @@ void PlatformBackend::frame()
Sint32 index = event.cdevice.which;
SDL_GameController* ptr = gamepads[index] = SDL_GameControllerOpen(index);
const char* name = SDL_GameControllerName(ptr);
uint16_t vendor = SDL_GameControllerGetVendor(ptr);
uint16_t product = SDL_GameControllerGetProduct(ptr);
uint16_t version = SDL_GameControllerGetProductVersion(ptr);
u16 vendor = SDL_GameControllerGetVendor(ptr);
u16 product = SDL_GameControllerGetProduct(ptr);
u16 version = SDL_GameControllerGetProductVersion(ptr);
InputBackend::on_controller_connect(index, name, 1, 15, 6, vendor, product, version);
}
@ -357,7 +357,7 @@ void PlatformBackend::frame()
void PlatformBackend::sleep(int milliseconds)
{
if (milliseconds >= 0)
SDL_Delay((uint32_t)milliseconds);
SDL_Delay((u32)milliseconds);
}
void PlatformBackend::present()
@ -611,27 +611,27 @@ bool PlatformBackend::file_open(const char* path, PlatformBackend::FileHandle* h
return ptr != nullptr;
}
int64_t PlatformBackend::file_length(PlatformBackend::FileHandle stream)
i64 PlatformBackend::file_length(PlatformBackend::FileHandle stream)
{
return SDL_RWsize((SDL_RWops*)stream);
}
int64_t PlatformBackend::file_position(PlatformBackend::FileHandle stream)
i64 PlatformBackend::file_position(PlatformBackend::FileHandle stream)
{
return SDL_RWtell((SDL_RWops*)stream);
}
int64_t PlatformBackend::file_seek(PlatformBackend::FileHandle stream, int64_t seekTo)
i64 PlatformBackend::file_seek(PlatformBackend::FileHandle stream, i64 seekTo)
{
return SDL_RWseek((SDL_RWops*)stream, seekTo, RW_SEEK_SET);
}
int64_t PlatformBackend::file_read(PlatformBackend::FileHandle stream, void* ptr, int64_t length)
i64 PlatformBackend::file_read(PlatformBackend::FileHandle stream, void* ptr, i64 length)
{
return SDL_RWread((SDL_RWops*)stream, ptr, sizeof(char), length);
}
int64_t PlatformBackend::file_write(PlatformBackend::FileHandle stream, const void* ptr, int64_t length)
i64 PlatformBackend::file_write(PlatformBackend::FileHandle stream, const void* ptr, i64 length)
{
return SDL_RWwrite((SDL_RWops*)stream, ptr, sizeof(char), length);
}