mirror of
https://github.com/NoelFB/blah.git
synced 2024-11-29 17:08:56 +08:00
refactoring rendering backend a little
This commit is contained in:
parent
f73973cc6f
commit
be989cdde9
|
@ -17,8 +17,8 @@ add_library(blah
|
||||||
public/blah/time.cpp
|
public/blah/time.cpp
|
||||||
public/blah/time.h
|
public/blah/time.h
|
||||||
|
|
||||||
public/blah/graphics/graphics.cpp
|
|
||||||
public/blah/graphics/graphics.h
|
public/blah/graphics/graphics.h
|
||||||
|
public/blah/graphics/graphics.cpp
|
||||||
public/blah/graphics/texture.h
|
public/blah/graphics/texture.h
|
||||||
public/blah/graphics/framebuffer.h
|
public/blah/graphics/framebuffer.h
|
||||||
public/blah/graphics/shader.h
|
public/blah/graphics/shader.h
|
||||||
|
@ -27,8 +27,8 @@ add_library(blah
|
||||||
public/blah/graphics/material.h
|
public/blah/graphics/material.h
|
||||||
public/blah/graphics/material.cpp
|
public/blah/graphics/material.cpp
|
||||||
|
|
||||||
public/blah/input/input.cpp
|
|
||||||
public/blah/input/input.h
|
public/blah/input/input.h
|
||||||
|
public/blah/input/input.cpp
|
||||||
public/blah/input/virtual_stick.cpp
|
public/blah/input/virtual_stick.cpp
|
||||||
public/blah/input/virtual_stick.h
|
public/blah/input/virtual_stick.h
|
||||||
public/blah/input/virtual_button.cpp
|
public/blah/input/virtual_button.cpp
|
||||||
|
@ -94,14 +94,15 @@ add_library(blah
|
||||||
public/blah/streams/stream.cpp
|
public/blah/streams/stream.cpp
|
||||||
public/blah/streams/stream.h
|
public/blah/streams/stream.h
|
||||||
|
|
||||||
|
private/blah/internal/graphics_backend.h
|
||||||
|
private/blah/internal/graphics_backend_gl.cpp
|
||||||
|
private/blah/internal/input_backend.h
|
||||||
|
private/blah/internal/platform_backend.h
|
||||||
|
private/blah/internal/platform_backend_sdl2.cpp
|
||||||
|
|
||||||
private/blah/third_party/stb_image.h
|
private/blah/third_party/stb_image.h
|
||||||
private/blah/third_party/stb_image_write.h
|
private/blah/third_party/stb_image_write.h
|
||||||
private/blah/third_party/stb_truetype.h
|
private/blah/third_party/stb_truetype.h)
|
||||||
private/blah/internal/graphics.h
|
|
||||||
private/blah/internal/graphics_opengl.cpp
|
|
||||||
private/blah/internal/input.h
|
|
||||||
private/blah/internal/platform.h
|
|
||||||
private/blah/internal/platform_sdl2.cpp)
|
|
||||||
|
|
||||||
target_include_directories(blah
|
target_include_directories(blah
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <blah/graphics/graphics.h>
|
|
||||||
|
|
||||||
namespace Blah
|
|
||||||
{
|
|
||||||
namespace Internal
|
|
||||||
{
|
|
||||||
class GraphicsDevice;
|
|
||||||
|
|
||||||
// graphics device metadata used to instantiate and destroy
|
|
||||||
// devices of specific apis
|
|
||||||
struct GraphicsDeviceInfo
|
|
||||||
{
|
|
||||||
GfxAPI api;
|
|
||||||
bool (*supported)();
|
|
||||||
GraphicsDevice* (*create)();
|
|
||||||
void (*destroy)(GraphicsDevice*);
|
|
||||||
};
|
|
||||||
|
|
||||||
// graphics implementations
|
|
||||||
extern GraphicsDeviceInfo OpenGL_DeviceInfo;
|
|
||||||
|
|
||||||
// graphics device
|
|
||||||
// each graphics implementation needs to implement this
|
|
||||||
// ex. one for opengl, one for vulkan, etc
|
|
||||||
class GraphicsDevice
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool valid = false;
|
|
||||||
GraphicsInfo info;
|
|
||||||
|
|
||||||
virtual ~GraphicsDevice() = default;
|
|
||||||
virtual void startup() = 0;
|
|
||||||
virtual void update() = 0;
|
|
||||||
virtual void shutdown() = 0;
|
|
||||||
virtual void before_render() = 0;
|
|
||||||
virtual void after_render() = 0;
|
|
||||||
|
|
||||||
virtual TextureRef create_texture(int width, int height, TextureFilter filter, TextureWrap wrap_x, TextureWrap wrap_y, TextureFormat format) = 0;
|
|
||||||
virtual FrameBufferRef create_framebuffer(int width, int height, const TextureFormat* attachments, int attachmentCount) = 0;
|
|
||||||
virtual ShaderRef create_shader(const ShaderData* data) = 0;
|
|
||||||
virtual MeshRef create_mesh() = 0;
|
|
||||||
virtual void render(RenderCall* call) = 0;
|
|
||||||
virtual void clear(const FrameBufferRef& target, uint32_t rgba) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Graphics
|
|
||||||
{
|
|
||||||
// Picks a graphics API based on the available APIs
|
|
||||||
GfxAPI pick_api();
|
|
||||||
|
|
||||||
// Initializes the Graphics with the given API
|
|
||||||
bool init(GfxAPI api);
|
|
||||||
|
|
||||||
// Is called internally by the Application every update
|
|
||||||
void frame();
|
|
||||||
|
|
||||||
// Is called internally by the Application before every render
|
|
||||||
void before_render();
|
|
||||||
|
|
||||||
// Is called internally by the Application after every render
|
|
||||||
void after_render();
|
|
||||||
|
|
||||||
// Called when the Application is shutting down
|
|
||||||
void shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
24
private/blah/internal/graphics_backend.h
Normal file
24
private/blah/internal/graphics_backend.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#pragma once
|
||||||
|
#include <blah/graphics/graphics.h>
|
||||||
|
|
||||||
|
namespace Blah
|
||||||
|
{
|
||||||
|
namespace GraphicsBackend
|
||||||
|
{
|
||||||
|
bool init();
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
const GraphicsInfo* info();
|
||||||
|
GraphicsRenderer renderer();
|
||||||
|
void frame();
|
||||||
|
void before_render();
|
||||||
|
void after_render();
|
||||||
|
void render(RenderCall* call);
|
||||||
|
void clear(const FrameBufferRef& target, uint32_t rgba);
|
||||||
|
|
||||||
|
TextureRef create_texture(int width, int height, TextureFilter filter, TextureWrap wrap_x, TextureWrap wrap_y, TextureFormat format);
|
||||||
|
FrameBufferRef create_framebuffer(int width, int height, const TextureFormat* attachments, int attachmentCount);
|
||||||
|
ShaderRef create_shader(const ShaderData* data);
|
||||||
|
MeshRef create_mesh();
|
||||||
|
}
|
||||||
|
}
|
1495
private/blah/internal/graphics_backend_gl.cpp
Normal file
1495
private/blah/internal/graphics_backend_gl.cpp
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,57 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <blah/input/input.h>
|
|
||||||
|
|
||||||
namespace Blah
|
|
||||||
{
|
|
||||||
namespace Internal
|
|
||||||
{
|
|
||||||
namespace Input
|
|
||||||
{
|
|
||||||
// This is called internally by the app, and initializes the input state
|
|
||||||
void init();
|
|
||||||
|
|
||||||
// This is called internally by the app, and updates the input state
|
|
||||||
void frame();
|
|
||||||
|
|
||||||
// Call this when the Mouse moves relative to the window
|
|
||||||
void on_mouse_move(float x, float y);
|
|
||||||
|
|
||||||
// Call this when the Mouse moves relative to the screen
|
|
||||||
void on_mouse_screen_move(float x, float y);
|
|
||||||
|
|
||||||
// Call this when a Mouse Button is pressed
|
|
||||||
void on_mouse_down(MouseButton button);
|
|
||||||
|
|
||||||
// Call this when a Mouse Button is released
|
|
||||||
void on_mouse_up(MouseButton button);
|
|
||||||
|
|
||||||
// Call this when the Mouse Wheel moves
|
|
||||||
void on_mouse_wheel(Point wheel);
|
|
||||||
|
|
||||||
// Call this when a keyboard key is pressed
|
|
||||||
void on_key_down(Key key);
|
|
||||||
|
|
||||||
// Call this when a keyboard key is released
|
|
||||||
void on_key_up(Key key);
|
|
||||||
|
|
||||||
// Call this on Text Input
|
|
||||||
void on_text_utf8(const char* text);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Call this when a controller is disconnected
|
|
||||||
void on_controller_disconnect(int index);
|
|
||||||
|
|
||||||
// Call this when a controller button is pressed
|
|
||||||
void on_button_down(int index, int button);
|
|
||||||
|
|
||||||
// Call this when a controller button is released
|
|
||||||
void on_button_up(int index, int button);
|
|
||||||
|
|
||||||
/// Call this when a controller axis is moved
|
|
||||||
void on_axis_move(int index, int axis, float value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
54
private/blah/internal/input_backend.h
Normal file
54
private/blah/internal/input_backend.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
#include <blah/input/input.h>
|
||||||
|
|
||||||
|
namespace Blah
|
||||||
|
{
|
||||||
|
namespace InputBackend
|
||||||
|
{
|
||||||
|
// This is called internally by the app, and initializes the input state
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// This is called internally by the app, and updates the input state
|
||||||
|
void frame();
|
||||||
|
|
||||||
|
// Call this when the Mouse moves relative to the window
|
||||||
|
void on_mouse_move(float x, float y);
|
||||||
|
|
||||||
|
// Call this when the Mouse moves relative to the screen
|
||||||
|
void on_mouse_screen_move(float x, float y);
|
||||||
|
|
||||||
|
// Call this when a Mouse Button is pressed
|
||||||
|
void on_mouse_down(MouseButton button);
|
||||||
|
|
||||||
|
// Call this when a Mouse Button is released
|
||||||
|
void on_mouse_up(MouseButton button);
|
||||||
|
|
||||||
|
// Call this when the Mouse Wheel moves
|
||||||
|
void on_mouse_wheel(Point wheel);
|
||||||
|
|
||||||
|
// Call this when a keyboard key is pressed
|
||||||
|
void on_key_down(Key key);
|
||||||
|
|
||||||
|
// Call this when a keyboard key is released
|
||||||
|
void on_key_up(Key key);
|
||||||
|
|
||||||
|
// Call this on Text Input
|
||||||
|
void on_text_utf8(const char* text);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Call this when a controller is disconnected
|
||||||
|
void on_controller_disconnect(int index);
|
||||||
|
|
||||||
|
// Call this when a controller button is pressed
|
||||||
|
void on_button_down(int index, int button);
|
||||||
|
|
||||||
|
// Call this when a controller button is released
|
||||||
|
void on_button_up(int index, int button);
|
||||||
|
|
||||||
|
/// Call this when a controller axis is moved
|
||||||
|
void on_axis_move(int index, int axis, float value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,120 +0,0 @@
|
||||||
#pragma once
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <blah/filesystem.h>
|
|
||||||
#include <blah/containers/vector.h>
|
|
||||||
|
|
||||||
namespace Blah
|
|
||||||
{
|
|
||||||
struct Config;
|
|
||||||
enum class FileMode;
|
|
||||||
|
|
||||||
namespace Internal
|
|
||||||
{
|
|
||||||
namespace Platform
|
|
||||||
{
|
|
||||||
typedef void* FileHandle;
|
|
||||||
|
|
||||||
// Initialize the System
|
|
||||||
bool init(const Config* config);
|
|
||||||
|
|
||||||
// Called after the on_startup callback, but before the update loop begins
|
|
||||||
void ready();
|
|
||||||
|
|
||||||
// Called during shutdown
|
|
||||||
void shutdown();
|
|
||||||
|
|
||||||
// The time, in milliseconds, since the Application was started
|
|
||||||
uint64_t time();
|
|
||||||
|
|
||||||
// Called every frame
|
|
||||||
void frame();
|
|
||||||
|
|
||||||
// Sleeps the current thread
|
|
||||||
void sleep(int milliseconds);
|
|
||||||
|
|
||||||
// Called to present the window contents
|
|
||||||
void present();
|
|
||||||
|
|
||||||
// Gets the Application Window Title in UTF-8
|
|
||||||
const char* get_title();
|
|
||||||
|
|
||||||
// Sets the Application Window Title in UTF-8
|
|
||||||
void set_title(const char* title);
|
|
||||||
|
|
||||||
// Gets the Application Window Position, in Screen Coordinates
|
|
||||||
void get_position(int* x, int* y);
|
|
||||||
|
|
||||||
// Sets the Application Window Position, in Screen Coordinates
|
|
||||||
void set_position(int x, int y);
|
|
||||||
|
|
||||||
// Sets the Window Fullscreen if enabled is not 0
|
|
||||||
void set_fullscreen(bool enabled);
|
|
||||||
|
|
||||||
// Gets the Application Window Size, in Screen Coordinates
|
|
||||||
void get_size(int* width, int* height);
|
|
||||||
|
|
||||||
// Sets the Application Window Size, in Screen Coordinates
|
|
||||||
void set_size(int width, int height);
|
|
||||||
|
|
||||||
// Gets the Application Window Drawing Size, in Pixels. This may differ from the Window Size on hi-dpi displays.
|
|
||||||
void get_draw_size(int* width, int* height);
|
|
||||||
|
|
||||||
// Gets the Desktop Content Scale. Gui should be scaled by this value
|
|
||||||
float get_content_scale();
|
|
||||||
|
|
||||||
// Returns the absoluate path to the directory that the application was started from
|
|
||||||
const char* app_path();
|
|
||||||
|
|
||||||
// Returns the absolute path to the user directory where save data and settings should be stored
|
|
||||||
const char* user_path();
|
|
||||||
|
|
||||||
// Returns true if a file with the given path exists
|
|
||||||
bool file_exists(const char* path);
|
|
||||||
|
|
||||||
// Returns true if a file with the given path was deleted
|
|
||||||
bool file_delete(const char* path);
|
|
||||||
|
|
||||||
// Returns true if a directory with the given path was successfully created
|
|
||||||
bool dir_create(const char* path);
|
|
||||||
|
|
||||||
// Returns true if a directory with the given path exists
|
|
||||||
bool dir_exists(const char* path);
|
|
||||||
|
|
||||||
// Returns true if a directory with the given path was deleted
|
|
||||||
bool dir_delete(const char* path);
|
|
||||||
|
|
||||||
// enumerates a directory and appends each file to the given list
|
|
||||||
void dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive);
|
|
||||||
|
|
||||||
// opens a directory in the OS file explorer / finder
|
|
||||||
void dir_explore(const char* path);
|
|
||||||
|
|
||||||
// Opens a file and sets the handle. returns true if the file was successfully opened
|
|
||||||
bool file_open(const char* path, FileHandle* handle, FileMode mode);
|
|
||||||
|
|
||||||
// Returns the length of the file
|
|
||||||
int64_t file_length(FileHandle file);
|
|
||||||
|
|
||||||
// Returns the Position of the file
|
|
||||||
int64_t 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);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// Closes a file
|
|
||||||
void file_close(FileHandle file);
|
|
||||||
|
|
||||||
// OpenGL Methods
|
|
||||||
void* gl_get_func(const char* name);
|
|
||||||
void* gl_context_create();
|
|
||||||
void gl_context_make_current(void* context);
|
|
||||||
void gl_context_destroy(void* context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
117
private/blah/internal/platform_backend.h
Normal file
117
private/blah/internal/platform_backend.h
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
#pragma once
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <blah/filesystem.h>
|
||||||
|
#include <blah/containers/vector.h>
|
||||||
|
|
||||||
|
namespace Blah
|
||||||
|
{
|
||||||
|
struct Config;
|
||||||
|
enum class FileMode;
|
||||||
|
|
||||||
|
namespace PlatformBackend
|
||||||
|
{
|
||||||
|
typedef void* FileHandle;
|
||||||
|
|
||||||
|
// Initialize the System
|
||||||
|
bool init(const Config* config);
|
||||||
|
|
||||||
|
// Called after the on_startup callback, but before the update loop begins
|
||||||
|
void ready();
|
||||||
|
|
||||||
|
// Called during shutdown
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
// The time, in milliseconds, since the Application was started
|
||||||
|
uint64_t time();
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
void frame();
|
||||||
|
|
||||||
|
// Sleeps the current thread
|
||||||
|
void sleep(int milliseconds);
|
||||||
|
|
||||||
|
// Called to present the window contents
|
||||||
|
void present();
|
||||||
|
|
||||||
|
// Gets the Application Window Title in UTF-8
|
||||||
|
const char* get_title();
|
||||||
|
|
||||||
|
// Sets the Application Window Title in UTF-8
|
||||||
|
void set_title(const char* title);
|
||||||
|
|
||||||
|
// Gets the Application Window Position, in Screen Coordinates
|
||||||
|
void get_position(int* x, int* y);
|
||||||
|
|
||||||
|
// Sets the Application Window Position, in Screen Coordinates
|
||||||
|
void set_position(int x, int y);
|
||||||
|
|
||||||
|
// Sets the Window Fullscreen if enabled is not 0
|
||||||
|
void set_fullscreen(bool enabled);
|
||||||
|
|
||||||
|
// Gets the Application Window Size, in Screen Coordinates
|
||||||
|
void get_size(int* width, int* height);
|
||||||
|
|
||||||
|
// Sets the Application Window Size, in Screen Coordinates
|
||||||
|
void set_size(int width, int height);
|
||||||
|
|
||||||
|
// Gets the Application Window Drawing Size, in Pixels. This may differ from the Window Size on hi-dpi displays.
|
||||||
|
void get_draw_size(int* width, int* height);
|
||||||
|
|
||||||
|
// Gets the Desktop Content Scale. Gui should be scaled by this value
|
||||||
|
float get_content_scale();
|
||||||
|
|
||||||
|
// Returns the absoluate path to the directory that the application was started from
|
||||||
|
const char* app_path();
|
||||||
|
|
||||||
|
// Returns the absolute path to the user directory where save data and settings should be stored
|
||||||
|
const char* user_path();
|
||||||
|
|
||||||
|
// Returns true if a file with the given path exists
|
||||||
|
bool file_exists(const char* path);
|
||||||
|
|
||||||
|
// Returns true if a file with the given path was deleted
|
||||||
|
bool file_delete(const char* path);
|
||||||
|
|
||||||
|
// Returns true if a directory with the given path was successfully created
|
||||||
|
bool dir_create(const char* path);
|
||||||
|
|
||||||
|
// Returns true if a directory with the given path exists
|
||||||
|
bool dir_exists(const char* path);
|
||||||
|
|
||||||
|
// Returns true if a directory with the given path was deleted
|
||||||
|
bool dir_delete(const char* path);
|
||||||
|
|
||||||
|
// enumerates a directory and appends each file to the given list
|
||||||
|
void dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive);
|
||||||
|
|
||||||
|
// opens a directory in the OS file explorer / finder
|
||||||
|
void dir_explore(const char* path);
|
||||||
|
|
||||||
|
// Opens a file and sets the handle. returns true if the file was successfully opened
|
||||||
|
bool file_open(const char* path, FileHandle* handle, FileMode mode);
|
||||||
|
|
||||||
|
// Returns the length of the file
|
||||||
|
int64_t file_length(FileHandle file);
|
||||||
|
|
||||||
|
// Returns the Position of the file
|
||||||
|
int64_t 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// Closes a file
|
||||||
|
void file_close(FileHandle file);
|
||||||
|
|
||||||
|
// OpenGL Methods
|
||||||
|
void* gl_get_func(const char* name);
|
||||||
|
void* gl_context_create();
|
||||||
|
void gl_context_make_current(void* context);
|
||||||
|
void gl_context_destroy(void* context);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,8 @@
|
||||||
#ifdef BLAH_USE_SDL2
|
#ifdef BLAH_USE_SDL2
|
||||||
|
|
||||||
#include <blah/internal/platform.h>
|
#include <blah/internal/platform_backend.h>
|
||||||
#include <blah/internal/input.h>
|
#include <blah/internal/input_backend.h>
|
||||||
|
#include <blah/internal/graphics_backend.h>
|
||||||
#include <blah/input/input.h>
|
#include <blah/input/input.h>
|
||||||
#include <blah/app.h>
|
#include <blah/app.h>
|
||||||
#include <blah/filesystem.h>
|
#include <blah/filesystem.h>
|
||||||
|
@ -26,7 +27,6 @@ namespace fs = std::filesystem;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
using namespace Internal;
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ namespace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::init(const Config* config)
|
bool PlatformBackend::init(const Config* config)
|
||||||
{
|
{
|
||||||
// Required to call this for Windows
|
// Required to call this for Windows
|
||||||
// I'm not sure why SDL2 doesn't do this on Windows automatically?
|
// I'm not sure why SDL2 doesn't do this on Windows automatically?
|
||||||
|
@ -73,9 +73,13 @@ bool Platform::init(const Config* config)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
||||||
|
|
||||||
// GL Attributes
|
// GL Attributes
|
||||||
if (config->graphics == GfxAPI::OpenGL)
|
if (GraphicsBackend::renderer() == GraphicsRenderer::OpenGL)
|
||||||
{
|
{
|
||||||
|
flags |= SDL_WINDOW_OPENGL;
|
||||||
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
@ -90,11 +94,6 @@ bool Platform::init(const Config* config)
|
||||||
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set up window flags
|
|
||||||
int flags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN | SDL_WINDOW_RESIZABLE;
|
|
||||||
if (config->graphics == GfxAPI::OpenGL)
|
|
||||||
flags |= SDL_WINDOW_OPENGL;
|
|
||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
window = SDL_CreateWindow(config->name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, config->width, config->height, flags);
|
window = SDL_CreateWindow(config->name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, config->width, config->height, flags);
|
||||||
if (window == nullptr)
|
if (window == nullptr)
|
||||||
|
@ -133,14 +132,14 @@ bool Platform::init(const Config* config)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::ready()
|
void PlatformBackend::ready()
|
||||||
{
|
{
|
||||||
// enable V-Sync
|
// enable V-Sync
|
||||||
if (App::config()->graphics == GfxAPI::OpenGL)
|
if (GraphicsBackend::renderer() == GraphicsRenderer::OpenGL)
|
||||||
SDL_GL_SetSwapInterval(1);
|
SDL_GL_SetSwapInterval(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::shutdown()
|
void PlatformBackend::shutdown()
|
||||||
{
|
{
|
||||||
if (window != nullptr)
|
if (window != nullptr)
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
@ -156,12 +155,12 @@ void Platform::shutdown()
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Platform::time()
|
uint64_t PlatformBackend::time()
|
||||||
{
|
{
|
||||||
return (uint64_t)SDL_GetTicks();
|
return (uint64_t)SDL_GetTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::frame()
|
void PlatformBackend::frame()
|
||||||
{
|
{
|
||||||
// update the mouse every frame
|
// update the mouse every frame
|
||||||
{
|
{
|
||||||
|
@ -169,8 +168,8 @@ void Platform::frame()
|
||||||
SDL_GetWindowPosition(window, &winX, &winY);
|
SDL_GetWindowPosition(window, &winX, &winY);
|
||||||
SDL_GetGlobalMouseState(&x, &y);
|
SDL_GetGlobalMouseState(&x, &y);
|
||||||
|
|
||||||
Internal::Input::on_mouse_move((float)(x - winX), (float)(y - winY));
|
InputBackend::on_mouse_move((float)(x - winX), (float)(y - winY));
|
||||||
Internal::Input::on_mouse_screen_move((float)x, (float)y);
|
InputBackend::on_mouse_screen_move((float)x, (float)y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// poll normal events
|
// poll normal events
|
||||||
|
@ -193,7 +192,7 @@ void Platform::frame()
|
||||||
btn = MouseButton::Right;
|
btn = MouseButton::Right;
|
||||||
else if (event.button.button == SDL_BUTTON_MIDDLE)
|
else if (event.button.button == SDL_BUTTON_MIDDLE)
|
||||||
btn = MouseButton::Middle;
|
btn = MouseButton::Middle;
|
||||||
Internal::Input::on_mouse_down(btn);
|
InputBackend::on_mouse_down(btn);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_MOUSEBUTTONUP)
|
else if (event.type == SDL_MOUSEBUTTONUP)
|
||||||
{
|
{
|
||||||
|
@ -204,26 +203,26 @@ void Platform::frame()
|
||||||
btn = MouseButton::Right;
|
btn = MouseButton::Right;
|
||||||
else if (event.button.button == SDL_BUTTON_MIDDLE)
|
else if (event.button.button == SDL_BUTTON_MIDDLE)
|
||||||
btn = MouseButton::Middle;
|
btn = MouseButton::Middle;
|
||||||
Internal::Input::on_mouse_up(btn);
|
InputBackend::on_mouse_up(btn);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_MOUSEWHEEL)
|
else if (event.type == SDL_MOUSEWHEEL)
|
||||||
{
|
{
|
||||||
Internal::Input::on_mouse_wheel(Point(event.wheel.x, event.wheel.y));
|
InputBackend::on_mouse_wheel(Point(event.wheel.x, event.wheel.y));
|
||||||
}
|
}
|
||||||
// Keyboard
|
// Keyboard
|
||||||
else if (event.type == SDL_KEYDOWN)
|
else if (event.type == SDL_KEYDOWN)
|
||||||
{
|
{
|
||||||
if (event.key.repeat == 0)
|
if (event.key.repeat == 0)
|
||||||
Internal::Input::on_key_down((Key)event.key.keysym.scancode);
|
InputBackend::on_key_down((Key)event.key.keysym.scancode);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_KEYUP)
|
else if (event.type == SDL_KEYUP)
|
||||||
{
|
{
|
||||||
if (event.key.repeat == 0)
|
if (event.key.repeat == 0)
|
||||||
Internal::Input::on_key_up((Key)event.key.keysym.scancode);
|
InputBackend::on_key_up((Key)event.key.keysym.scancode);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_TEXTINPUT)
|
else if (event.type == SDL_TEXTINPUT)
|
||||||
{
|
{
|
||||||
Internal::Input::on_text_utf8(event.text.text);
|
InputBackend::on_text_utf8(event.text.text);
|
||||||
}
|
}
|
||||||
// Joystick Controller
|
// Joystick Controller
|
||||||
else if (event.type == SDL_JOYDEVICEADDED)
|
else if (event.type == SDL_JOYDEVICEADDED)
|
||||||
|
@ -237,7 +236,7 @@ void Platform::frame()
|
||||||
int button_count = SDL_JoystickNumButtons(ptr);
|
int button_count = SDL_JoystickNumButtons(ptr);
|
||||||
int axis_count = SDL_JoystickNumAxes(ptr);
|
int axis_count = SDL_JoystickNumAxes(ptr);
|
||||||
|
|
||||||
Internal::Input::on_controller_connect(index, name, 0, button_count, axis_count);
|
InputBackend::on_controller_connect(index, name, 0, button_count, axis_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_JOYDEVICEREMOVED)
|
else if (event.type == SDL_JOYDEVICEREMOVED)
|
||||||
|
@ -246,7 +245,7 @@ void Platform::frame()
|
||||||
|
|
||||||
if (SDL_IsGameController(index) == SDL_FALSE)
|
if (SDL_IsGameController(index) == SDL_FALSE)
|
||||||
{
|
{
|
||||||
Internal::Input::on_controller_disconnect(index);
|
InputBackend::on_controller_disconnect(index);
|
||||||
SDL_JoystickClose(joysticks[index]);
|
SDL_JoystickClose(joysticks[index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,13 +253,13 @@ void Platform::frame()
|
||||||
{
|
{
|
||||||
Sint32 index = event.jdevice.which;
|
Sint32 index = event.jdevice.which;
|
||||||
if (SDL_IsGameController(index) == SDL_FALSE)
|
if (SDL_IsGameController(index) == SDL_FALSE)
|
||||||
Internal::Input::on_button_down(index, event.jbutton.button);
|
InputBackend::on_button_down(index, event.jbutton.button);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_JOYBUTTONUP)
|
else if (event.type == SDL_JOYBUTTONUP)
|
||||||
{
|
{
|
||||||
Sint32 index = event.jdevice.which;
|
Sint32 index = event.jdevice.which;
|
||||||
if (SDL_IsGameController(index) == SDL_FALSE)
|
if (SDL_IsGameController(index) == SDL_FALSE)
|
||||||
Internal::Input::on_button_up(index, event.jbutton.button);
|
InputBackend::on_button_up(index, event.jbutton.button);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_JOYAXISMOTION)
|
else if (event.type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
|
@ -272,7 +271,7 @@ void Platform::frame()
|
||||||
value = event.jaxis.value / 32767.0f;
|
value = event.jaxis.value / 32767.0f;
|
||||||
else
|
else
|
||||||
value = event.jaxis.value / 32768.0f;
|
value = event.jaxis.value / 32768.0f;
|
||||||
Internal::Input::on_axis_move(index, event.jaxis.axis, value);
|
InputBackend::on_axis_move(index, event.jaxis.axis, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Gamepad Controller
|
// Gamepad Controller
|
||||||
|
@ -281,12 +280,12 @@ void Platform::frame()
|
||||||
Sint32 index = event.cdevice.which;
|
Sint32 index = event.cdevice.which;
|
||||||
SDL_GameController* ptr = gamepads[index] = SDL_GameControllerOpen(index);
|
SDL_GameController* ptr = gamepads[index] = SDL_GameControllerOpen(index);
|
||||||
const char* name = SDL_GameControllerName(ptr);
|
const char* name = SDL_GameControllerName(ptr);
|
||||||
Internal::Input::on_controller_connect(index, name, 1, 15, 6);
|
InputBackend::on_controller_connect(index, name, 1, 15, 6);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_CONTROLLERDEVICEREMOVED)
|
else if (event.type == SDL_CONTROLLERDEVICEREMOVED)
|
||||||
{
|
{
|
||||||
Sint32 index = event.cdevice.which;
|
Sint32 index = event.cdevice.which;
|
||||||
Internal::Input::on_controller_disconnect(index);
|
InputBackend::on_controller_disconnect(index);
|
||||||
SDL_GameControllerClose(gamepads[index]);
|
SDL_GameControllerClose(gamepads[index]);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_CONTROLLERBUTTONDOWN)
|
else if (event.type == SDL_CONTROLLERBUTTONDOWN)
|
||||||
|
@ -297,7 +296,7 @@ void Platform::frame()
|
||||||
if (event.cbutton.button >= 0 && event.cbutton.button < 15)
|
if (event.cbutton.button >= 0 && event.cbutton.button < 15)
|
||||||
button = event.cbutton.button; // NOTE: These map directly to Engine Buttons enum!
|
button = event.cbutton.button; // NOTE: These map directly to Engine Buttons enum!
|
||||||
|
|
||||||
Internal::Input::on_button_down(index, button);
|
InputBackend::on_button_down(index, button);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_CONTROLLERBUTTONUP)
|
else if (event.type == SDL_CONTROLLERBUTTONUP)
|
||||||
{
|
{
|
||||||
|
@ -307,7 +306,7 @@ void Platform::frame()
|
||||||
if (event.cbutton.button >= 0 && event.cbutton.button < 15)
|
if (event.cbutton.button >= 0 && event.cbutton.button < 15)
|
||||||
button = event.cbutton.button; // NOTE: These map directly to Engine Buttons enum!
|
button = event.cbutton.button; // NOTE: These map directly to Engine Buttons enum!
|
||||||
|
|
||||||
Internal::Input::on_button_up(index, button);
|
InputBackend::on_button_up(index, button);
|
||||||
}
|
}
|
||||||
else if (event.type == SDL_CONTROLLERAXISMOTION)
|
else if (event.type == SDL_CONTROLLERAXISMOTION)
|
||||||
{
|
{
|
||||||
|
@ -323,20 +322,20 @@ void Platform::frame()
|
||||||
else
|
else
|
||||||
value = event.caxis.value / 32768.0f;
|
value = event.caxis.value / 32768.0f;
|
||||||
|
|
||||||
Internal::Input::on_axis_move(index, axis, value);
|
InputBackend::on_axis_move(index, axis, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::sleep(int milliseconds)
|
void PlatformBackend::sleep(int milliseconds)
|
||||||
{
|
{
|
||||||
if (milliseconds >= 0)
|
if (milliseconds >= 0)
|
||||||
SDL_Delay((uint32_t)milliseconds);
|
SDL_Delay((uint32_t)milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::present()
|
void PlatformBackend::present()
|
||||||
{
|
{
|
||||||
if (App::config()->graphics == GfxAPI::OpenGL)
|
if (GraphicsBackend::renderer() == GraphicsRenderer::OpenGL)
|
||||||
{
|
{
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
}
|
||||||
|
@ -350,27 +349,27 @@ void Platform::present()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Platform::get_title()
|
const char* PlatformBackend::get_title()
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::set_title(const char* title)
|
void PlatformBackend::set_title(const char* title)
|
||||||
{
|
{
|
||||||
SDL_SetWindowTitle(window, title);
|
SDL_SetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::get_position(int* x, int* y)
|
void PlatformBackend::get_position(int* x, int* y)
|
||||||
{
|
{
|
||||||
SDL_GetWindowPosition(window, x, y);
|
SDL_GetWindowPosition(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::set_position(int x, int y)
|
void PlatformBackend::set_position(int x, int y)
|
||||||
{
|
{
|
||||||
SDL_SetWindowPosition(window, x, y);
|
SDL_SetWindowPosition(window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::set_fullscreen(bool enabled)
|
void PlatformBackend::set_fullscreen(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
@ -378,36 +377,30 @@ void Platform::set_fullscreen(bool enabled)
|
||||||
SDL_SetWindowFullscreen(window, 0);
|
SDL_SetWindowFullscreen(window, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::get_size(int* width, int* height)
|
void PlatformBackend::get_size(int* width, int* height)
|
||||||
{
|
{
|
||||||
SDL_GetWindowSize(window, width, height);
|
SDL_GetWindowSize(window, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::set_size(int width, int height)
|
void PlatformBackend::set_size(int width, int height)
|
||||||
{
|
{
|
||||||
SDL_SetWindowSize(window, width, height);
|
SDL_SetWindowSize(window, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::get_draw_size(int* width, int* height)
|
void PlatformBackend::get_draw_size(int* width, int* height)
|
||||||
{
|
{
|
||||||
auto config = App::config();
|
auto config = App::config();
|
||||||
if (config->graphics == GfxAPI::OpenGL)
|
if (GraphicsBackend::renderer() == GraphicsRenderer::OpenGL)
|
||||||
{
|
{
|
||||||
SDL_GL_GetDrawableSize(window, width, height);
|
SDL_GL_GetDrawableSize(window, width, height);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
else if (config->graphics == GfxAPI::Vulkan)
|
|
||||||
{
|
|
||||||
SDL_Vulkan_GetDrawableSize(window, width, height);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_GetWindowSize(window, width, height);
|
SDL_GetWindowSize(window, width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float Platform::get_content_scale()
|
float PlatformBackend::get_content_scale()
|
||||||
{
|
{
|
||||||
// TODO:
|
// TODO:
|
||||||
// This is incorrect! but for some reason the scale
|
// This is incorrect! but for some reason the scale
|
||||||
|
@ -435,14 +428,14 @@ float Platform::get_content_scale()
|
||||||
|
|
||||||
// FILE IO
|
// FILE IO
|
||||||
|
|
||||||
const char* Platform::app_path()
|
const char* PlatformBackend::app_path()
|
||||||
{
|
{
|
||||||
if (basePath == nullptr)
|
if (basePath == nullptr)
|
||||||
basePath = SDL_GetBasePath();
|
basePath = SDL_GetBasePath();
|
||||||
return basePath;
|
return basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Platform::user_path()
|
const char* PlatformBackend::user_path()
|
||||||
{
|
{
|
||||||
if (userPath == nullptr)
|
if (userPath == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -456,34 +449,34 @@ const char* Platform::user_path()
|
||||||
// Windows File System methods
|
// Windows File System methods
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
|
|
||||||
bool Platform::file_exists(const char* path)
|
bool PlatformBackend::file_exists(const char* path)
|
||||||
{
|
{
|
||||||
return fs::is_regular_file(path);
|
return fs::is_regular_file(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::file_delete(const char* path)
|
bool PlatformBackend::file_delete(const char* path)
|
||||||
{
|
{
|
||||||
return fs::remove(path);
|
return fs::remove(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_create(const char* path)
|
bool PlatformBackend::dir_create(const char* path)
|
||||||
{
|
{
|
||||||
std::error_code error;
|
std::error_code error;
|
||||||
return fs::create_directories(path, error);
|
return fs::create_directories(path, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_exists(const char* path)
|
bool PlatformBackend::dir_exists(const char* path)
|
||||||
{
|
{
|
||||||
return fs::is_directory(path);
|
return fs::is_directory(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_delete(const char* path)
|
bool PlatformBackend::dir_delete(const char* path)
|
||||||
{
|
{
|
||||||
BLAH_ERROR("not implemented");
|
BLAH_ERROR("not implemented");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive)
|
void PlatformBackend::dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive)
|
||||||
{
|
{
|
||||||
if (fs::is_directory(path))
|
if (fs::is_directory(path))
|
||||||
{
|
{
|
||||||
|
@ -500,7 +493,7 @@ void Platform::dir_enumerate(Vector<FilePath>& list, const char* path, bool recu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::dir_explore(const char* path)
|
void PlatformBackend::dir_explore(const char* path)
|
||||||
{
|
{
|
||||||
ShellExecute(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT);
|
ShellExecute(NULL, "open", path, NULL, NULL, SW_SHOWDEFAULT);
|
||||||
}
|
}
|
||||||
|
@ -508,19 +501,19 @@ void Platform::dir_explore(const char* path)
|
||||||
// Non-Windows File System Methods
|
// Non-Windows File System Methods
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool Platform::file_exists(const char* path)
|
bool PlatformBackend::file_exists(const char* path)
|
||||||
{
|
{
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat(path, &buffer) == 0) && S_ISREG(buffer.st_mode);
|
return (stat(path, &buffer) == 0) && S_ISREG(buffer.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::file_delete(const char* path)
|
bool PlatformBackend::file_delete(const char* path)
|
||||||
{
|
{
|
||||||
BLAH_ERROR("not implemented");
|
BLAH_ERROR("not implemented");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_create(const char* path)
|
bool PlatformBackend::dir_create(const char* path)
|
||||||
{
|
{
|
||||||
char tmp[265];
|
char tmp[265];
|
||||||
char* p = NULL;
|
char* p = NULL;
|
||||||
|
@ -539,19 +532,19 @@ bool Platform::dir_create(const char* path)
|
||||||
return mkdir(tmp, S_IRWXU) == 0;
|
return mkdir(tmp, S_IRWXU) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_exists(const char* path)
|
bool PlatformBackend::dir_exists(const char* path)
|
||||||
{
|
{
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
return (stat(path, &buffer) == 0) && S_ISDIR(buffer.st_mode);
|
return (stat(path, &buffer) == 0) && S_ISDIR(buffer.st_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Platform::dir_delete(const char* path)
|
bool PlatformBackend::dir_delete(const char* path)
|
||||||
{
|
{
|
||||||
BLAH_ERROR("not implemented");
|
BLAH_ERROR("not implemented");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive)
|
void PlatformBackend::dir_enumerate(Vector<FilePath>& list, const char* path, bool recursive)
|
||||||
{
|
{
|
||||||
DIR* dirp = opendir(path);
|
DIR* dirp = opendir(path);
|
||||||
if (dirp != NULL)
|
if (dirp != NULL)
|
||||||
|
@ -572,61 +565,61 @@ void Platform::dir_enumerate(Vector<FilePath>& list, const char* path, bool recu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::dir_explore(const char* path)
|
void PlatformBackend::dir_explore(const char* path)
|
||||||
{
|
{
|
||||||
BLAH_ERROR("'dir_explore' Not Implemented");
|
BLAH_ERROR("'dir_explore' Not Implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Platform::file_open(const char* path, Platform::FileHandle* handle, FileMode mode)
|
bool PlatformBackend::file_open(const char* path, PlatformBackend::FileHandle* handle, FileMode mode)
|
||||||
{
|
{
|
||||||
const char* sdlMode = "rb";
|
const char* sdlMode = "rb";
|
||||||
if (mode == FileMode::Write)
|
if (mode == FileMode::Write)
|
||||||
sdlMode = "wb";
|
sdlMode = "wb";
|
||||||
|
|
||||||
auto ptr = SDL_RWFromFile(path, sdlMode);
|
auto ptr = SDL_RWFromFile(path, sdlMode);
|
||||||
*handle = (Platform::FileHandle)ptr;
|
*handle = (PlatformBackend::FileHandle)ptr;
|
||||||
return ptr != nullptr;
|
return ptr != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Platform::file_length(Platform::FileHandle stream)
|
int64_t PlatformBackend::file_length(PlatformBackend::FileHandle stream)
|
||||||
{
|
{
|
||||||
return SDL_RWsize((SDL_RWops*)stream);
|
return SDL_RWsize((SDL_RWops*)stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Platform::file_position(Platform::FileHandle stream)
|
int64_t PlatformBackend::file_position(PlatformBackend::FileHandle stream)
|
||||||
{
|
{
|
||||||
return SDL_RWtell((SDL_RWops*)stream);
|
return SDL_RWtell((SDL_RWops*)stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Platform::file_seek(Platform::FileHandle stream, int64_t seekTo)
|
int64_t PlatformBackend::file_seek(PlatformBackend::FileHandle stream, int64_t seekTo)
|
||||||
{
|
{
|
||||||
return SDL_RWseek((SDL_RWops*)stream, seekTo, RW_SEEK_SET);
|
return SDL_RWseek((SDL_RWops*)stream, seekTo, RW_SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Platform::file_read(Platform::FileHandle stream, void* ptr, int64_t length)
|
int64_t PlatformBackend::file_read(PlatformBackend::FileHandle stream, void* ptr, int64_t length)
|
||||||
{
|
{
|
||||||
return SDL_RWread((SDL_RWops*)stream, ptr, sizeof(char), length);
|
return SDL_RWread((SDL_RWops*)stream, ptr, sizeof(char), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t Platform::file_write(Platform::FileHandle stream, const void* ptr, int64_t length)
|
int64_t PlatformBackend::file_write(PlatformBackend::FileHandle stream, const void* ptr, int64_t length)
|
||||||
{
|
{
|
||||||
return SDL_RWwrite((SDL_RWops*)stream, ptr, sizeof(char), length);
|
return SDL_RWwrite((SDL_RWops*)stream, ptr, sizeof(char), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::file_close(Platform::FileHandle stream)
|
void PlatformBackend::file_close(PlatformBackend::FileHandle stream)
|
||||||
{
|
{
|
||||||
if (stream != nullptr)
|
if (stream != nullptr)
|
||||||
SDL_RWclose((SDL_RWops*)stream);
|
SDL_RWclose((SDL_RWops*)stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Platform::gl_get_func(const char* name)
|
void* PlatformBackend::gl_get_func(const char* name)
|
||||||
{
|
{
|
||||||
return SDL_GL_GetProcAddress(name);
|
return SDL_GL_GetProcAddress(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* Platform::gl_context_create()
|
void* PlatformBackend::gl_context_create()
|
||||||
{
|
{
|
||||||
void* pointer = SDL_GL_CreateContext(window);
|
void* pointer = SDL_GL_CreateContext(window);
|
||||||
if (pointer == nullptr)
|
if (pointer == nullptr)
|
||||||
|
@ -634,12 +627,12 @@ void* Platform::gl_context_create()
|
||||||
return pointer;
|
return pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::gl_context_make_current(void* context)
|
void PlatformBackend::gl_context_make_current(void* context)
|
||||||
{
|
{
|
||||||
SDL_GL_MakeCurrent(window, context);
|
SDL_GL_MakeCurrent(window, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::gl_context_destroy(void* context)
|
void PlatformBackend::gl_context_destroy(void* context)
|
||||||
{
|
{
|
||||||
SDL_GL_DeleteContext(context);
|
SDL_GL_DeleteContext(context);
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@
|
||||||
#include <blah/time.h>
|
#include <blah/time.h>
|
||||||
#include <blah/math/point.h>
|
#include <blah/math/point.h>
|
||||||
|
|
||||||
#include <blah/internal/platform.h>
|
#include <blah/internal/platform_backend.h>
|
||||||
#include <blah/internal/graphics.h>
|
#include <blah/internal/graphics_backend.h>
|
||||||
#include <blah/internal/input.h>
|
#include <blah/internal/input_backend.h>
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@ Config::Config()
|
||||||
target_framerate = 60;
|
target_framerate = 60;
|
||||||
max_updates = 5;
|
max_updates = 5;
|
||||||
|
|
||||||
graphics = GfxAPI::Any;
|
|
||||||
on_startup = nullptr;
|
on_startup = nullptr;
|
||||||
on_shutdown = nullptr;
|
on_shutdown = nullptr;
|
||||||
on_update = nullptr;
|
on_update = nullptr;
|
||||||
|
@ -50,54 +49,43 @@ bool App::run(const Config* c)
|
||||||
|
|
||||||
Log::print("Starting Up ...");
|
Log::print("Starting Up ...");
|
||||||
|
|
||||||
// figure out the graphics api
|
|
||||||
if (app_config.graphics == GfxAPI::Any)
|
|
||||||
{
|
|
||||||
app_config.graphics = Internal::Graphics::pick_api();
|
|
||||||
if (app_config.graphics == GfxAPI::Any)
|
|
||||||
{
|
|
||||||
Log::error("Failed to find a supported graphics api");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initialize the system
|
// initialize the system
|
||||||
if (!Internal::Platform::init(&app_config))
|
if (!PlatformBackend::init(&app_config))
|
||||||
{
|
{
|
||||||
Log::error("Failed to initialize system module");
|
Log::error("Failed to initialize Platform module");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize graphics
|
// initialize graphics
|
||||||
if (!Internal::Graphics::init(app_config.graphics))
|
if (!GraphicsBackend::init())
|
||||||
{
|
{
|
||||||
Log::error("Failed to initialize graphics module");
|
Log::error("Failed to initialize Graphics module");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// input
|
// input
|
||||||
Internal::Input::init();
|
InputBackend::init();
|
||||||
|
|
||||||
// startup
|
// startup
|
||||||
if (app_config.on_startup != nullptr)
|
if (app_config.on_startup != nullptr)
|
||||||
app_config.on_startup();
|
app_config.on_startup();
|
||||||
|
|
||||||
uint64_t time_last = Internal::Platform::time();
|
uint64_t time_last = PlatformBackend::time();
|
||||||
uint64_t time_accumulator = 0;
|
uint64_t time_accumulator = 0;
|
||||||
|
|
||||||
// display window
|
// display window
|
||||||
Internal::Platform::ready();
|
PlatformBackend::ready();
|
||||||
|
|
||||||
while (!app_is_exiting)
|
while (!app_is_exiting)
|
||||||
{
|
{
|
||||||
// poll system events
|
// poll system events
|
||||||
Internal::Platform::frame();
|
PlatformBackend::frame();
|
||||||
|
|
||||||
// update at a fixed timerate
|
// update at a fixed timerate
|
||||||
// TODO: allow a non-fixed step update?
|
// TODO: allow a non-fixed step update?
|
||||||
{
|
{
|
||||||
uint64_t time_target = (uint64_t)((1.0f / app_config.target_framerate) * 1000);
|
uint64_t time_target = (uint64_t)((1.0f / app_config.target_framerate) * 1000);
|
||||||
uint64_t time_curr = Internal::Platform::time();
|
uint64_t time_curr = PlatformBackend::time();
|
||||||
uint64_t time_diff = time_curr - time_last;
|
uint64_t time_diff = time_curr - time_last;
|
||||||
time_last = time_curr;
|
time_last = time_curr;
|
||||||
time_accumulator += time_diff;
|
time_accumulator += time_diff;
|
||||||
|
@ -105,9 +93,9 @@ bool App::run(const Config* c)
|
||||||
// do not let us run too fast
|
// do not let us run too fast
|
||||||
while (time_accumulator < time_target)
|
while (time_accumulator < time_target)
|
||||||
{
|
{
|
||||||
Internal::Platform::sleep((int)(time_target - time_accumulator));
|
PlatformBackend::sleep((int)(time_target - time_accumulator));
|
||||||
|
|
||||||
time_curr = Internal::Platform::time();
|
time_curr = PlatformBackend::time();
|
||||||
time_diff = time_curr - time_last;
|
time_diff = time_curr - time_last;
|
||||||
time_last = time_curr;
|
time_last = time_curr;
|
||||||
time_accumulator += time_diff;
|
time_accumulator += time_diff;
|
||||||
|
@ -139,8 +127,8 @@ bool App::run(const Config* c)
|
||||||
Time::previous_elapsed = Time::elapsed;
|
Time::previous_elapsed = Time::elapsed;
|
||||||
Time::elapsed += Time::delta;
|
Time::elapsed += Time::delta;
|
||||||
|
|
||||||
Internal::Input::frame();
|
InputBackend::frame();
|
||||||
Internal::Graphics::frame();
|
GraphicsBackend::frame();
|
||||||
|
|
||||||
if (app_config.on_update != nullptr)
|
if (app_config.on_update != nullptr)
|
||||||
app_config.on_update();
|
app_config.on_update();
|
||||||
|
@ -149,13 +137,13 @@ bool App::run(const Config* c)
|
||||||
|
|
||||||
// render
|
// render
|
||||||
{
|
{
|
||||||
Internal::Graphics::before_render();
|
GraphicsBackend::before_render();
|
||||||
|
|
||||||
if (app_config.on_render != nullptr)
|
if (app_config.on_render != nullptr)
|
||||||
app_config.on_render();
|
app_config.on_render();
|
||||||
|
|
||||||
Internal::Graphics::after_render();
|
GraphicsBackend::after_render();
|
||||||
Internal::Platform::present();
|
PlatformBackend::present();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -166,8 +154,8 @@ bool App::run(const Config* c)
|
||||||
if (app_config.on_shutdown != nullptr)
|
if (app_config.on_shutdown != nullptr)
|
||||||
app_config.on_shutdown();
|
app_config.on_shutdown();
|
||||||
|
|
||||||
Internal::Graphics::shutdown();
|
GraphicsBackend::shutdown();
|
||||||
Internal::Platform::shutdown();
|
PlatformBackend::shutdown();
|
||||||
|
|
||||||
// clear static state
|
// clear static state
|
||||||
Log::print("Exited");
|
Log::print("Exited");
|
||||||
|
@ -198,48 +186,48 @@ const Config* App::config()
|
||||||
|
|
||||||
const char* App::path()
|
const char* App::path()
|
||||||
{
|
{
|
||||||
return Internal::Platform::app_path();
|
return PlatformBackend::app_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* App::user_path()
|
const char* App::user_path()
|
||||||
{
|
{
|
||||||
return Internal::Platform::user_path();
|
return PlatformBackend::user_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::width()
|
int App::width()
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
Internal::Platform::get_size(&w, &h);
|
PlatformBackend::get_size(&w, &h);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::height()
|
int App::height()
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
Internal::Platform::get_size(&w, &h);
|
PlatformBackend::get_size(&w, &h);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::draw_width()
|
int App::draw_width()
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
Internal::Platform::get_draw_size(&w, &h);
|
PlatformBackend::get_draw_size(&w, &h);
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::draw_height()
|
int App::draw_height()
|
||||||
{
|
{
|
||||||
int w, h;
|
int w, h;
|
||||||
Internal::Platform::get_draw_size(&w, &h);
|
PlatformBackend::get_draw_size(&w, &h);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
float App::content_scale()
|
float App::content_scale()
|
||||||
{
|
{
|
||||||
return Internal::Platform::get_content_scale();
|
return PlatformBackend::get_content_scale();
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::fullscreen(bool enabled)
|
void App::fullscreen(bool enabled)
|
||||||
{
|
{
|
||||||
Internal::Platform::set_fullscreen(enabled);
|
PlatformBackend::set_fullscreen(enabled);
|
||||||
}
|
}
|
|
@ -2,13 +2,6 @@
|
||||||
|
|
||||||
namespace Blah
|
namespace Blah
|
||||||
{
|
{
|
||||||
enum class GfxAPI
|
|
||||||
{
|
|
||||||
Any = -1,
|
|
||||||
OpenGL,
|
|
||||||
Count
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Config
|
struct Config
|
||||||
{
|
{
|
||||||
const char* name;
|
const char* name;
|
||||||
|
@ -17,8 +10,6 @@ namespace Blah
|
||||||
int max_updates;
|
int max_updates;
|
||||||
int target_framerate;
|
int target_framerate;
|
||||||
|
|
||||||
GfxAPI graphics;
|
|
||||||
|
|
||||||
void (*on_startup)();
|
void (*on_startup)();
|
||||||
void (*on_shutdown)();
|
void (*on_shutdown)();
|
||||||
void (*on_update)();
|
void (*on_update)();
|
||||||
|
|
|
@ -135,15 +135,20 @@ Batch::~Batch()
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::push_matrix(const Mat3x2& matrix)
|
void Batch::push_matrix(const Mat3x2& matrix, bool absolute)
|
||||||
{
|
{
|
||||||
m_matrix_stack.push_back(m_matrix);
|
m_matrix_stack.push_back(m_matrix);
|
||||||
|
if (absolute)
|
||||||
|
m_matrix = matrix;
|
||||||
|
else
|
||||||
m_matrix = matrix * m_matrix;
|
m_matrix = matrix * m_matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::pop_matrix()
|
Mat3x2 Batch::pop_matrix()
|
||||||
{
|
{
|
||||||
|
auto was = m_matrix;
|
||||||
m_matrix = m_matrix_stack.pop();
|
m_matrix = m_matrix_stack.pop();
|
||||||
|
return was;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::push_scissor(const Rect& scissor)
|
void Batch::push_scissor(const Rect& scissor)
|
||||||
|
@ -212,7 +217,7 @@ void Batch::pop_color_mode()
|
||||||
|
|
||||||
void Batch::set_texture(const TextureRef& texture)
|
void Batch::set_texture(const TextureRef& texture)
|
||||||
{
|
{
|
||||||
if (m_batch.elements > 0 && texture != m_batch.texture && m_batch.texture && m_batch.texture->is_valid())
|
if (m_batch.elements > 0 && texture != m_batch.texture && m_batch.texture)
|
||||||
{
|
{
|
||||||
m_batches.push_back(m_batch);
|
m_batches.push_back(m_batch);
|
||||||
m_batch.offset += m_batch.elements;
|
m_batch.offset += m_batch.elements;
|
||||||
|
@ -222,14 +227,14 @@ void Batch::set_texture(const TextureRef& texture)
|
||||||
if (m_batch.texture != texture)
|
if (m_batch.texture != texture)
|
||||||
{
|
{
|
||||||
m_batch.texture = texture;
|
m_batch.texture = texture;
|
||||||
m_batch.flip_vertically = Graphics::info()->origin_bottom_left && texture && texture->is_valid() && texture->is_framebuffer();
|
m_batch.flip_vertically = Graphics::info()->origin_bottom_left && texture && texture->is_framebuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::render(const FrameBufferRef& target)
|
void Batch::render(const FrameBufferRef& target)
|
||||||
{
|
{
|
||||||
Point size;
|
Point size;
|
||||||
if (!target || !target->is_valid())
|
if (!target)
|
||||||
size = Point(App::draw_width(), App::draw_height());
|
size = Point(App::draw_width(), App::draw_height());
|
||||||
else
|
else
|
||||||
size = Point(target->width(), target->height());
|
size = Point(target->width(), target->height());
|
||||||
|
@ -245,7 +250,7 @@ void Batch::render(const FrameBufferRef& target, const Mat4x4& matrix)
|
||||||
|
|
||||||
// define defaults
|
// define defaults
|
||||||
{
|
{
|
||||||
if (!m_mesh || !m_mesh->is_valid())
|
if (!m_mesh)
|
||||||
{
|
{
|
||||||
m_mesh = Graphics::create_mesh();
|
m_mesh = Graphics::create_mesh();
|
||||||
m_mesh->vertex_format(attributes, 4, sizeof(Vertex));
|
m_mesh->vertex_format(attributes, 4, sizeof(Vertex));
|
||||||
|
@ -281,7 +286,7 @@ void Batch::render(const FrameBufferRef& target, const Mat4x4& matrix)
|
||||||
void Batch::render_single_batch(RenderCall& call, const DrawBatch& b, const Mat4x4& matrix)
|
void Batch::render_single_batch(RenderCall& call, const DrawBatch& b, const Mat4x4& matrix)
|
||||||
{
|
{
|
||||||
call.material = b.material;
|
call.material = b.material;
|
||||||
if (!call.material || !call.material->is_valid())
|
if (!call.material)
|
||||||
call.material = m_default_material;
|
call.material = m_default_material;
|
||||||
|
|
||||||
call.material->set_texture(texture_uniform, b.texture, 0);
|
call.material->set_texture(texture_uniform, b.texture, 0);
|
||||||
|
@ -635,6 +640,11 @@ void Batch::semi_circle_line(Vec2 center, float start_radians, float end_radians
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::circle(const Vec2 center, float radius, int steps, Color color)
|
void Batch::circle(const Vec2 center, float radius, int steps, Color color)
|
||||||
|
{
|
||||||
|
circle(center, radius, steps, color, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Batch::circle(const Vec2 center, float radius, int steps, Color center_color, Color outer_color)
|
||||||
{
|
{
|
||||||
Vec2 last = Vec2(center.x + radius, center.y);
|
Vec2 last = Vec2(center.x + radius, center.y);
|
||||||
|
|
||||||
|
@ -643,7 +653,7 @@ void Batch::circle(const Vec2 center, float radius, int steps, Color color)
|
||||||
const auto radians = (i / (float)steps) * Calc::TAU;
|
const auto radians = (i / (float)steps) * Calc::TAU;
|
||||||
const auto next = Vec2(center.x + Calc::cos(radians) * radius, center.y + Calc::sin(radians) * radius);
|
const auto next = Vec2(center.x + Calc::cos(radians) * radius, center.y + Calc::sin(radians) * radius);
|
||||||
|
|
||||||
tri(last, next, center, color);
|
tri(last, next, center, outer_color, outer_color, center_color);
|
||||||
|
|
||||||
last = next;
|
last = next;
|
||||||
}
|
}
|
||||||
|
@ -761,7 +771,7 @@ void Batch::tex()
|
||||||
|
|
||||||
void Batch::tex(const Subtexture& sub, const Vec2& pos, Color color)
|
void Batch::tex(const Subtexture& sub, const Vec2& pos, Color color)
|
||||||
{
|
{
|
||||||
if (!sub.texture || !sub.texture->is_valid())
|
if (!sub.texture)
|
||||||
{
|
{
|
||||||
PUSH_QUAD(
|
PUSH_QUAD(
|
||||||
pos.x + sub.draw_coords[0].x, pos.y + sub.draw_coords[0].y,
|
pos.x + sub.draw_coords[0].x, pos.y + sub.draw_coords[0].y,
|
||||||
|
@ -794,7 +804,7 @@ void Batch::tex(const Subtexture& sub, const Vec2& pos, const Vec2& origin, cons
|
||||||
{
|
{
|
||||||
push_matrix(Mat3x2::create_transform(pos, origin, scale, rotation));
|
push_matrix(Mat3x2::create_transform(pos, origin, scale, rotation));
|
||||||
|
|
||||||
if (!sub.texture || !sub.texture->is_valid())
|
if (!sub.texture)
|
||||||
{
|
{
|
||||||
PUSH_QUAD(
|
PUSH_QUAD(
|
||||||
sub.draw_coords[0].x, sub.draw_coords[0].y,
|
sub.draw_coords[0].x, sub.draw_coords[0].y,
|
||||||
|
|
|
@ -44,8 +44,8 @@ namespace Blah
|
||||||
Batch& operator=(const Batch& other) = delete;
|
Batch& operator=(const Batch& other) = delete;
|
||||||
~Batch();
|
~Batch();
|
||||||
|
|
||||||
void push_matrix(const Mat3x2& matrix);
|
void push_matrix(const Mat3x2& matrix, bool absolute = false);
|
||||||
void pop_matrix();
|
Mat3x2 pop_matrix();
|
||||||
void push_scissor(const Rect& scissor);
|
void push_scissor(const Rect& scissor);
|
||||||
void pop_scissor();
|
void pop_scissor();
|
||||||
void push_blend(const BlendMode& blend);
|
void push_blend(const BlendMode& blend);
|
||||||
|
@ -90,6 +90,7 @@ namespace Blah
|
||||||
void semi_circle_line(Vec2 center, float start_radians, float end_radians, float radius, int steps, float t, Color color);
|
void semi_circle_line(Vec2 center, float start_radians, float end_radians, float radius, int steps, float t, Color color);
|
||||||
|
|
||||||
void circle(const Vec2 center, float radius, int steps, Color color);
|
void circle(const Vec2 center, float radius, int steps, Color color);
|
||||||
|
void circle(const Vec2 center, float radius, int steps, Color center_color, Color outer_color);
|
||||||
void circle_line(const Vec2 center, float raidus, float t, int steps, Color color);
|
void circle_line(const Vec2 center, float raidus, float t, int steps, Color color);
|
||||||
|
|
||||||
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, Color color);
|
void quad(const Vec2& pos0, const Vec2& pos1, const Vec2& pos2, const Vec2& pos3, Color color);
|
||||||
|
|
|
@ -24,7 +24,7 @@ void Subtexture::update()
|
||||||
draw_coords[3].x = -frame.x;
|
draw_coords[3].x = -frame.x;
|
||||||
draw_coords[3].y = -frame.y + source.h;
|
draw_coords[3].y = -frame.y + source.h;
|
||||||
|
|
||||||
if (texture && texture->is_valid())
|
if (texture)
|
||||||
{
|
{
|
||||||
float uvx = 1.0f / (float)texture->width();
|
float uvx = 1.0f / (float)texture->width();
|
||||||
float uvy = 1.0f / (float)texture->height();
|
float uvy = 1.0f / (float)texture->height();
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
#include <blah/filesystem.h>
|
#include <blah/filesystem.h>
|
||||||
#include <blah/internal/platform.h>
|
#include <blah/internal/platform_backend.h>
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
|
|
||||||
bool File::exists(const FilePath& path)
|
bool File::exists(const FilePath& path)
|
||||||
{
|
{
|
||||||
return Internal::Platform::file_exists(path.cstr());
|
return PlatformBackend::file_exists(path.cstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::remove(const FilePath& path)
|
bool File::remove(const FilePath& path)
|
||||||
{
|
{
|
||||||
return Internal::Platform::file_delete(path.cstr());
|
return PlatformBackend::file_delete(path.cstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Directory::create(const FilePath& path)
|
bool Directory::create(const FilePath& path)
|
||||||
{
|
{
|
||||||
return Internal::Platform::dir_create(path.cstr());
|
return PlatformBackend::dir_create(path.cstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Directory::exists(const FilePath& path)
|
bool Directory::exists(const FilePath& path)
|
||||||
{
|
{
|
||||||
return Internal::Platform::dir_exists(path.cstr());
|
return PlatformBackend::dir_exists(path.cstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Directory::remove(const FilePath& path)
|
bool Directory::remove(const FilePath& path)
|
||||||
{
|
{
|
||||||
return Internal::Platform::dir_delete(path.cstr());
|
return PlatformBackend::dir_delete(path.cstr());
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
|
Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
|
||||||
|
@ -33,7 +33,7 @@ Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
|
||||||
Vector<FilePath> list;
|
Vector<FilePath> list;
|
||||||
|
|
||||||
// get files
|
// get files
|
||||||
Internal::Platform::dir_enumerate(list, path.cstr(), recursive);
|
PlatformBackend::dir_enumerate(list, path.cstr(), recursive);
|
||||||
|
|
||||||
// normalize path names
|
// normalize path names
|
||||||
for (auto& it : list)
|
for (auto& it : list)
|
||||||
|
@ -44,7 +44,7 @@ Vector<FilePath> Directory::enumerate(const FilePath& path, bool recursive)
|
||||||
|
|
||||||
void Directory::explore(const FilePath& path)
|
void Directory::explore(const FilePath& path)
|
||||||
{
|
{
|
||||||
Internal::Platform::dir_explore(path);
|
PlatformBackend::dir_explore(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath Path::get_file_name(const FilePath& path)
|
FilePath Path::get_file_name(const FilePath& path)
|
||||||
|
|
|
@ -19,17 +19,17 @@ namespace Blah
|
||||||
// Gets the list of Attachments from the FrameBuffer
|
// Gets the list of Attachments from the FrameBuffer
|
||||||
virtual const Attachments& attachments() const = 0;
|
virtual const Attachments& attachments() const = 0;
|
||||||
|
|
||||||
|
// Gets the Attachment at a given index from the FrameBuffer
|
||||||
|
virtual TextureRef& attachment(int index) = 0;
|
||||||
|
|
||||||
|
// Gets the Attachment at a given index from the FrameBuffer
|
||||||
|
virtual const TextureRef& attachment(int index) const = 0;
|
||||||
|
|
||||||
// Gets the width of the FrameBuffer
|
// Gets the width of the FrameBuffer
|
||||||
virtual int width() const = 0;
|
virtual int width() const = 0;
|
||||||
|
|
||||||
// Gets the height of the FrameBuffer
|
// Gets the height of the FrameBuffer
|
||||||
virtual int height() const = 0;
|
virtual int height() const = 0;
|
||||||
|
|
||||||
// Returns true if the FrameBuffer is valid
|
|
||||||
virtual bool is_valid() const = 0;
|
|
||||||
|
|
||||||
// Destroys the given FrameBuffer
|
|
||||||
virtual void dispose() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<FrameBuffer> FrameBufferRef;
|
typedef std::shared_ptr<FrameBuffer> FrameBufferRef;
|
||||||
|
|
|
@ -5,27 +5,12 @@
|
||||||
#include <blah/graphics/material.h>
|
#include <blah/graphics/material.h>
|
||||||
#include <blah/graphics/shader.h>
|
#include <blah/graphics/shader.h>
|
||||||
#include <blah/log.h>
|
#include <blah/log.h>
|
||||||
#include <blah/internal/graphics.h>
|
#include <blah/internal/graphics_backend.h>
|
||||||
#include <blah/images/image.h>
|
#include <blah/images/image.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// active graphics device
|
|
||||||
Internal::GraphicsDevice* device;
|
|
||||||
|
|
||||||
// active graphics device info
|
|
||||||
Internal::GraphicsDeviceInfo* device_info;
|
|
||||||
|
|
||||||
// list of possible device info
|
|
||||||
Internal::GraphicsDeviceInfo* device_options[] =
|
|
||||||
{
|
|
||||||
&Internal::OpenGL_DeviceInfo
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const BlendMode BlendMode::Normal = BlendMode(
|
const BlendMode BlendMode::Normal = BlendMode(
|
||||||
BlendOp::Add,
|
BlendOp::Add,
|
||||||
BlendFactor::One,
|
BlendFactor::One,
|
||||||
|
@ -37,74 +22,25 @@ const BlendMode BlendMode::Normal = BlendMode(
|
||||||
0xffffffff
|
0xffffffff
|
||||||
);
|
);
|
||||||
|
|
||||||
GfxAPI Internal::Graphics::pick_api()
|
const BlendMode BlendMode::Subtract = BlendMode(
|
||||||
{
|
BlendOp::ReverseSubtract,
|
||||||
for (int i = 0; i < (int)GfxAPI::Count; i++)
|
BlendFactor::One,
|
||||||
{
|
BlendFactor::One,
|
||||||
if (device_options[i]->supported())
|
BlendOp::Add,
|
||||||
return device_options[i]->api;
|
BlendFactor::One,
|
||||||
}
|
BlendFactor::One,
|
||||||
|
BlendMask::RGBA,
|
||||||
return GfxAPI::Any;
|
0xffffffff
|
||||||
}
|
);
|
||||||
|
|
||||||
bool Internal::Graphics::init(GfxAPI api)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < (int)GfxAPI::Count; i++)
|
|
||||||
{
|
|
||||||
if (device_options[i]->api == api)
|
|
||||||
{
|
|
||||||
device_info = device_options[i];
|
|
||||||
device = device_info->create();
|
|
||||||
if (device != nullptr)
|
|
||||||
{
|
|
||||||
device->startup();
|
|
||||||
if (device->valid)
|
|
||||||
break;
|
|
||||||
|
|
||||||
device_info->destroy(device);
|
|
||||||
device = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return device != nullptr && device->valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
const GraphicsInfo* Graphics::info()
|
const GraphicsInfo* Graphics::info()
|
||||||
{
|
{
|
||||||
if (device == nullptr || !device->valid)
|
return GraphicsBackend::info();
|
||||||
return nullptr;
|
|
||||||
return &device->info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Graphics::shutdown()
|
GraphicsRenderer Graphics::renderer()
|
||||||
{
|
{
|
||||||
if (device != nullptr && device_info != nullptr)
|
return GraphicsBackend::renderer();
|
||||||
{
|
|
||||||
device->shutdown();
|
|
||||||
device_info->destroy(device);
|
|
||||||
device = nullptr;
|
|
||||||
device_info = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Internal::Graphics::frame()
|
|
||||||
{
|
|
||||||
if (device != nullptr && device->valid)
|
|
||||||
device->update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Internal::Graphics::before_render()
|
|
||||||
{
|
|
||||||
if (device != nullptr && device->valid)
|
|
||||||
device->before_render();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Internal::Graphics::after_render()
|
|
||||||
{
|
|
||||||
if (device != nullptr && device->valid)
|
|
||||||
device->after_render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureRef Graphics::create_texture(const Image& image)
|
TextureRef Graphics::create_texture(const Image& image)
|
||||||
|
@ -125,9 +61,8 @@ TextureRef Graphics::create_texture(int width, int height, TextureFormat format)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(width > 0 && height > 0, "Texture width and height must be larger than 0");
|
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");
|
BLAH_ASSERT((int)format > (int)TextureFormat::None && (int)format < (int)TextureFormat::Count, "Invalid texture format");
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "The graphics device has not been created");
|
|
||||||
|
|
||||||
return device->create_texture(width, height, TextureFilter::Linear, TextureWrap::Repeat, TextureWrap::Repeat, format);
|
return GraphicsBackend::create_texture(width, height, TextureFilter::Linear, TextureWrap::Repeat, TextureWrap::Repeat, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureRef Graphics::create_texture(Stream& stream)
|
TextureRef Graphics::create_texture(Stream& stream)
|
||||||
|
@ -171,31 +106,27 @@ FrameBufferRef Graphics::create_framebuffer(int width, int height, const Texture
|
||||||
BLAH_ASSERT(attachment_count > 0, "At least one attachment must be provided");
|
BLAH_ASSERT(attachment_count > 0, "At least one attachment must be provided");
|
||||||
for (int i = 0; i < attachment_count; i++)
|
for (int i = 0; i < attachment_count; i++)
|
||||||
BLAH_ASSERT((int)attachments[i] > (int)TextureFormat::None && (int)attachments[i] < (int)TextureFormat::Count, "Invalid texture format");
|
BLAH_ASSERT((int)attachments[i] > (int)TextureFormat::None && (int)attachments[i] < (int)TextureFormat::Count, "Invalid texture format");
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "The graphics device has not been created");
|
|
||||||
|
|
||||||
return device->create_framebuffer(width, height, attachments, attachment_count);
|
return GraphicsBackend::create_framebuffer(width, height, attachments, attachment_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderRef Graphics::create_shader(const ShaderData* data)
|
ShaderRef Graphics::create_shader(const ShaderData* data)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "The graphics device has not been created");
|
return GraphicsBackend::create_shader(data);
|
||||||
return device->create_shader(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialRef Graphics::create_material(const ShaderRef& shader)
|
MaterialRef Graphics::create_material(const ShaderRef& shader)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "The graphics device has not been created");
|
BLAH_ASSERT(shader, "The provided shader is invalid");
|
||||||
BLAH_ASSERT(shader && shader->is_valid(), "The provided shader is invalid");
|
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// use a pool for Materials
|
// use a pool for Materials?
|
||||||
return MaterialRef(new Material(shader));
|
return MaterialRef(new Material(shader));
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshRef Graphics::create_mesh()
|
MeshRef Graphics::create_mesh()
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "Graphics device has not been created");
|
return GraphicsBackend::create_mesh();
|
||||||
return device->create_mesh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCall::RenderCall()
|
RenderCall::RenderCall()
|
||||||
|
@ -217,36 +148,27 @@ RenderCall::RenderCall()
|
||||||
|
|
||||||
void Graphics::render(const RenderCall& render_call)
|
void Graphics::render(const RenderCall& render_call)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "Graphics device has not been created");
|
|
||||||
|
|
||||||
// Validate Material
|
// Validate Material
|
||||||
if (!render_call.material || !render_call.material->is_valid())
|
if (!render_call.material)
|
||||||
{
|
{
|
||||||
Log::warn("Trying to draw with an invalid Material");
|
Log::warn("Trying to draw with an invalid Material");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Shader
|
// Validate Shader
|
||||||
if (!render_call.material->shader() || !render_call.material->shader()->is_valid())
|
if (!render_call.material->shader())
|
||||||
{
|
{
|
||||||
Log::warn("Trying to draw with an invalid Shader");
|
Log::warn("Trying to draw with an invalid Shader");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate Mesh
|
// Validate Mesh
|
||||||
if (!render_call.mesh || !render_call.mesh->is_valid())
|
if (!render_call.mesh)
|
||||||
{
|
{
|
||||||
Log::warn("Trying to draw with an invalid Mesh");
|
Log::warn("Trying to draw with an invalid Mesh");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate FrameBuffer
|
|
||||||
if (render_call.target && !render_call.target->is_valid())
|
|
||||||
{
|
|
||||||
Log::warn("Trying to draw with an invalid FrameBuffer");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy call
|
// copy call
|
||||||
RenderCall call = render_call;
|
RenderCall call = render_call;
|
||||||
|
|
||||||
|
@ -330,11 +252,10 @@ void Graphics::render(const RenderCall& render_call)
|
||||||
call.scissor.h = 0;
|
call.scissor.h = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
device->render(&call);
|
GraphicsBackend::render(&call);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::clear(const FrameBufferRef& target, uint32_t rgba)
|
void Graphics::clear(const FrameBufferRef& target, uint32_t rgba)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(device != nullptr && device->valid, "Graphics device has not been created");
|
GraphicsBackend::clear(target, rgba);
|
||||||
device->clear(target, rgba);
|
|
||||||
}
|
}
|
|
@ -32,9 +32,17 @@ namespace Blah
|
||||||
class Mesh;
|
class Mesh;
|
||||||
typedef std::shared_ptr<Mesh> MeshRef;
|
typedef std::shared_ptr<Mesh> MeshRef;
|
||||||
|
|
||||||
|
enum class GraphicsRenderer
|
||||||
|
{
|
||||||
|
None = -1,
|
||||||
|
OpenGL,
|
||||||
|
D3D11,
|
||||||
|
Metal,
|
||||||
|
Count
|
||||||
|
};
|
||||||
|
|
||||||
struct GraphicsInfo
|
struct GraphicsInfo
|
||||||
{
|
{
|
||||||
GfxAPI api = GfxAPI::Any;
|
|
||||||
bool instancing = false;
|
bool instancing = false;
|
||||||
bool origin_bottom_left = false;
|
bool origin_bottom_left = false;
|
||||||
int max_texture_size = 0;
|
int max_texture_size = 0;
|
||||||
|
@ -174,6 +182,7 @@ namespace Blah
|
||||||
inline bool operator!=(const BlendMode& rhs) const { return !(*this == rhs); }
|
inline bool operator!=(const BlendMode& rhs) const { return !(*this == rhs); }
|
||||||
|
|
||||||
static const BlendMode Normal;
|
static const BlendMode Normal;
|
||||||
|
static const BlendMode Subtract;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class UniformType
|
enum class UniformType
|
||||||
|
@ -300,6 +309,9 @@ namespace Blah
|
||||||
// Gets graphics information from the graphics device
|
// Gets graphics information from the graphics device
|
||||||
const GraphicsInfo* info();
|
const GraphicsInfo* info();
|
||||||
|
|
||||||
|
// Gets the Renderer implementation type
|
||||||
|
GraphicsRenderer renderer();
|
||||||
|
|
||||||
// Creates a new Texture.
|
// Creates a new Texture.
|
||||||
// If the Texture creation fails, it will return an invalid TextureRef.
|
// If the Texture creation fails, it will return an invalid TextureRef.
|
||||||
TextureRef create_texture(const Image& image);
|
TextureRef create_texture(const Image& image);
|
||||||
|
|
|
@ -28,16 +28,8 @@ namespace
|
||||||
|
|
||||||
Material::Material(const ShaderRef& shader)
|
Material::Material(const ShaderRef& shader)
|
||||||
{
|
{
|
||||||
|
BLAH_ASSERT(shader, "Material is being created with an invalid shader");
|
||||||
m_shader = shader;
|
m_shader = shader;
|
||||||
m_data = nullptr;
|
|
||||||
m_disposed = false;
|
|
||||||
|
|
||||||
// invalid shader
|
|
||||||
if (!m_shader || !m_shader->is_valid())
|
|
||||||
{
|
|
||||||
m_disposed = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uniforms uniforms = shader->uniforms();
|
Uniforms uniforms = shader->uniforms();
|
||||||
StackVector<size_t, BLAH_UNIFORMS> float_offsets;
|
StackVector<size_t, BLAH_UNIFORMS> float_offsets;
|
||||||
|
@ -59,16 +51,9 @@ Material::Material(const ShaderRef& shader)
|
||||||
float_size += calc_uniform_size(uniform);
|
float_size += calc_uniform_size(uniform);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_data = new float[float_size];
|
m_data.expand(float_size);
|
||||||
memset(m_data, 0, sizeof(float) * float_size);
|
|
||||||
|
|
||||||
for (auto& it : float_offsets)
|
for (auto& it : float_offsets)
|
||||||
m_floats.push_back(m_data + it);
|
m_floats.push_back(m_data.begin() + it);
|
||||||
}
|
|
||||||
|
|
||||||
Material::~Material()
|
|
||||||
{
|
|
||||||
dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShaderRef Material::shader() const
|
const ShaderRef Material::shader() const
|
||||||
|
@ -78,8 +63,7 @@ const ShaderRef Material::shader() const
|
||||||
|
|
||||||
void Material::set_texture(const char* name, const TextureRef& texture, int index)
|
void Material::set_texture(const char* name, const TextureRef& texture, int index)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
|
|
||||||
if (m_textures.size() > 0)
|
if (m_textures.size() > 0)
|
||||||
{
|
{
|
||||||
|
@ -106,8 +90,7 @@ void Material::set_texture(const char* name, const TextureRef& texture, int inde
|
||||||
|
|
||||||
TextureRef Material::get_texture(const char* name, int index) const
|
TextureRef Material::get_texture(const char* name, int index) const
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (auto& uniform : m_shader->uniforms())
|
for (auto& uniform : m_shader->uniforms())
|
||||||
|
@ -129,8 +112,7 @@ TextureRef Material::get_texture(const char* name, int index) const
|
||||||
|
|
||||||
TextureRef Material::get_texture(int slot, int index) const
|
TextureRef Material::get_texture(int slot, int index) const
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
|
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int s = 0;
|
int s = 0;
|
||||||
|
@ -155,8 +137,7 @@ TextureRef Material::get_texture(int slot, int index) const
|
||||||
|
|
||||||
void Material::set_value(const char* name, const float* value, int64_t length)
|
void Material::set_value(const char* name, const float* value, int64_t length)
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
BLAH_ASSERT(length >= 0, "Length must be >= 0");
|
BLAH_ASSERT(length >= 0, "Length must be >= 0");
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
@ -186,8 +167,7 @@ void Material::set_value(const char* name, const float* value, int64_t length)
|
||||||
|
|
||||||
const float* Material::get_value(const char* name, int64_t* length) const
|
const float* Material::get_value(const char* name, int64_t* length) const
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto& uniform : m_shader->uniforms())
|
for (auto& uniform : m_shader->uniforms())
|
||||||
|
@ -212,8 +192,7 @@ const float* Material::get_value(const char* name, int64_t* length) const
|
||||||
|
|
||||||
const float* Material::get_value(int slot, int64_t* length) const
|
const float* Material::get_value(int slot, int64_t* length) const
|
||||||
{
|
{
|
||||||
BLAH_ASSERT(!m_disposed, "Material has been disposed");
|
BLAH_ASSERT(m_shader, "Material Shader is invalid");
|
||||||
BLAH_ASSERT(m_shader && m_shader->is_valid(), "Material Shader is invalid");
|
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int s = 0;
|
int s = 0;
|
||||||
|
@ -233,21 +212,7 @@ const float* Material::get_value(int slot, int64_t* length) const
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::warn("No Uniform [%i] exists", slot);
|
||||||
*length = 0;
|
*length = 0;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
Log::warn("No Uniform [%i] exists", slot);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Material::is_valid() const
|
|
||||||
{
|
|
||||||
return !m_disposed && m_shader && m_shader->is_valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Material::dispose()
|
|
||||||
{
|
|
||||||
delete[] m_data;
|
|
||||||
m_data = nullptr;
|
|
||||||
m_shader.reset();
|
|
||||||
m_textures.clear();
|
|
||||||
m_floats.clear();
|
|
||||||
}
|
}
|
|
@ -10,8 +10,6 @@ namespace Blah
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Material(const ShaderRef& shader);
|
Material(const ShaderRef& shader);
|
||||||
~Material();
|
|
||||||
|
|
||||||
Material(const Material& src) = delete;
|
Material(const Material& src) = delete;
|
||||||
Material(Material&& src) = delete;
|
Material(Material&& src) = delete;
|
||||||
Material& operator=(const Material& src) = delete;
|
Material& operator=(const Material& src) = delete;
|
||||||
|
@ -48,18 +46,11 @@ namespace Blah
|
||||||
// is a float2, and there are 4 elements, the length should be 8.
|
// is a float2, and there are 4 elements, the length should be 8.
|
||||||
const float* get_value(int slot, int64_t* length = nullptr) const;
|
const float* get_value(int slot, int64_t* length = nullptr) const;
|
||||||
|
|
||||||
// Returns true if the Material is valid
|
|
||||||
bool is_valid() const;
|
|
||||||
|
|
||||||
// Destroys the Material
|
|
||||||
void dispose();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShaderRef m_shader;
|
ShaderRef m_shader;
|
||||||
Vector<TextureRef> m_textures;
|
Vector<TextureRef> m_textures;
|
||||||
Vector<float*> m_floats;
|
Vector<float*> m_floats;
|
||||||
float* m_data;
|
Vector<float> m_data;
|
||||||
bool m_disposed;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Material> MaterialRef;
|
typedef std::shared_ptr<Material> MaterialRef;
|
||||||
|
|
|
@ -36,12 +36,6 @@ namespace Blah
|
||||||
// Gets the instance count of the Mesh
|
// Gets the instance count of the Mesh
|
||||||
virtual int64_t instance_count() const = 0;
|
virtual int64_t instance_count() const = 0;
|
||||||
|
|
||||||
// Returns true if the Mesh is valid
|
|
||||||
virtual bool is_valid() const = 0;
|
|
||||||
|
|
||||||
// Destroys the given Mesh
|
|
||||||
virtual void dispose() = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void vertex_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
virtual void vertex_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
||||||
virtual void instance_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
virtual void instance_format_internal(const VertexAttribute* attributes, int count, int stride) = 0;
|
||||||
|
|
|
@ -24,12 +24,6 @@ namespace Blah
|
||||||
|
|
||||||
// Gets a list of Shader Attributes from Shader
|
// Gets a list of Shader Attributes from Shader
|
||||||
virtual const Attributes& attributes() const = 0;
|
virtual const Attributes& attributes() const = 0;
|
||||||
|
|
||||||
// Returns true if the Shader is valid
|
|
||||||
virtual bool is_valid() const = 0;
|
|
||||||
|
|
||||||
// Destroys the given Shader
|
|
||||||
virtual void dispose() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Shader> ShaderRef;
|
typedef std::shared_ptr<Shader> ShaderRef;
|
||||||
|
|
|
@ -45,12 +45,6 @@ namespace Blah
|
||||||
|
|
||||||
// Returns true if the Texture is part of a FrameBuffer
|
// Returns true if the Texture is part of a FrameBuffer
|
||||||
virtual bool is_framebuffer() const = 0;
|
virtual bool is_framebuffer() const = 0;
|
||||||
|
|
||||||
// Returns true if the Texture
|
|
||||||
virtual bool is_valid() const = 0;
|
|
||||||
|
|
||||||
// Destroys the given Texture
|
|
||||||
virtual void dispose() = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<Texture> TextureRef;
|
typedef std::shared_ptr<Texture> TextureRef;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <blah/time.h>
|
#include <blah/time.h>
|
||||||
#include <blah/log.h>
|
#include <blah/log.h>
|
||||||
#include <blah/math/point.h>
|
#include <blah/math/point.h>
|
||||||
#include <blah/internal/input.h>
|
#include <blah/internal/input_backend.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
|
@ -17,7 +17,7 @@ namespace
|
||||||
ControllerState g_empty_controller;
|
ControllerState g_empty_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::init()
|
void InputBackend::init()
|
||||||
{
|
{
|
||||||
g_empty_controller.name = "Disconnected";
|
g_empty_controller.name = "Disconnected";
|
||||||
for (int i = 0; i < Blah::Input::max_controllers; i++)
|
for (int i = 0; i < Blah::Input::max_controllers; i++)
|
||||||
|
@ -28,7 +28,7 @@ void Internal::Input::init()
|
||||||
g_next_state = g_empty_state;
|
g_next_state = g_empty_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::frame()
|
void InputBackend::frame()
|
||||||
{
|
{
|
||||||
// cycle states
|
// cycle states
|
||||||
g_last_state = g_curr_state;
|
g_last_state = g_curr_state;
|
||||||
|
@ -68,7 +68,7 @@ void Internal::Input::frame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_mouse_move(float x, float y)
|
void InputBackend::on_mouse_move(float x, float y)
|
||||||
{
|
{
|
||||||
g_next_state.mouse.position.x = x;
|
g_next_state.mouse.position.x = x;
|
||||||
g_next_state.mouse.position.y = y;
|
g_next_state.mouse.position.y = y;
|
||||||
|
@ -80,13 +80,13 @@ void Internal::Input::on_mouse_move(float x, float y)
|
||||||
g_next_state.mouse.draw_position.y = (y / (float)size.y) * draw.y;
|
g_next_state.mouse.draw_position.y = (y / (float)size.y) * draw.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_mouse_screen_move(float x, float y)
|
void InputBackend::on_mouse_screen_move(float x, float y)
|
||||||
{
|
{
|
||||||
g_next_state.mouse.screen_position.x = x;
|
g_next_state.mouse.screen_position.x = x;
|
||||||
g_next_state.mouse.screen_position.y = y;
|
g_next_state.mouse.screen_position.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_mouse_down(MouseButton button)
|
void InputBackend::on_mouse_down(MouseButton button)
|
||||||
{
|
{
|
||||||
int i = (int)button;
|
int i = (int)button;
|
||||||
if (i >= 0 && i < Blah::Input::max_mouse_buttons)
|
if (i >= 0 && i < Blah::Input::max_mouse_buttons)
|
||||||
|
@ -97,7 +97,7 @@ void Internal::Input::on_mouse_down(MouseButton button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_mouse_up(MouseButton button)
|
void InputBackend::on_mouse_up(MouseButton button)
|
||||||
{
|
{
|
||||||
int i = (int)button;
|
int i = (int)button;
|
||||||
if (i >= 0 && i < Blah::Input::max_mouse_buttons)
|
if (i >= 0 && i < Blah::Input::max_mouse_buttons)
|
||||||
|
@ -107,7 +107,7 @@ void Internal::Input::on_mouse_up(MouseButton button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_key_down(Key key)
|
void InputBackend::on_key_down(Key key)
|
||||||
{
|
{
|
||||||
int i = (int)key;
|
int i = (int)key;
|
||||||
if (i >= 0 && i < Blah::Input::max_keyboard_keys)
|
if (i >= 0 && i < Blah::Input::max_keyboard_keys)
|
||||||
|
@ -118,12 +118,12 @@ void Internal::Input::on_key_down(Key key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_mouse_wheel(Point wheel)
|
void InputBackend::on_mouse_wheel(Point wheel)
|
||||||
{
|
{
|
||||||
g_next_state.mouse.wheel = wheel;
|
g_next_state.mouse.wheel = wheel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_key_up(Key key)
|
void InputBackend::on_key_up(Key key)
|
||||||
{
|
{
|
||||||
int i = (int)key;
|
int i = (int)key;
|
||||||
if (i >= 0 && i < Blah::Input::max_keyboard_keys)
|
if (i >= 0 && i < Blah::Input::max_keyboard_keys)
|
||||||
|
@ -133,12 +133,12 @@ void Internal::Input::on_key_up(Key key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_text_utf8(const char* text)
|
void InputBackend::on_text_utf8(const char* text)
|
||||||
{
|
{
|
||||||
strncat(g_next_state.keyboard.text, text, Blah::Input::max_text_input);
|
strncat(g_next_state.keyboard.text, text, Blah::Input::max_text_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count)
|
void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count)
|
||||||
{
|
{
|
||||||
if (index < Blah::Input::max_controllers)
|
if (index < Blah::Input::max_controllers)
|
||||||
{
|
{
|
||||||
|
@ -152,13 +152,13 @@ void Internal::Input::on_controller_connect(int index, const char* name, int is_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_controller_disconnect(int index)
|
void InputBackend::on_controller_disconnect(int index)
|
||||||
{
|
{
|
||||||
if (index < Blah::Input::max_controllers)
|
if (index < Blah::Input::max_controllers)
|
||||||
g_next_state.controllers[index] = g_empty_controller;
|
g_next_state.controllers[index] = g_empty_controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_button_down(int index, int button)
|
void InputBackend::on_button_down(int index, int button)
|
||||||
{
|
{
|
||||||
if (index < Blah::Input::max_controllers &&
|
if (index < Blah::Input::max_controllers &&
|
||||||
button < Blah::Input::max_controller_buttons &&
|
button < Blah::Input::max_controller_buttons &&
|
||||||
|
@ -171,7 +171,7 @@ void Internal::Input::on_button_down(int index, int button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_button_up(int index, int button)
|
void InputBackend::on_button_up(int index, int button)
|
||||||
{
|
{
|
||||||
if (index < Blah::Input::max_controllers &&
|
if (index < Blah::Input::max_controllers &&
|
||||||
button < Blah::Input::max_controller_buttons &&
|
button < Blah::Input::max_controller_buttons &&
|
||||||
|
@ -183,7 +183,7 @@ void Internal::Input::on_button_up(int index, int button)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Internal::Input::on_axis_move(int index, int axis, float value)
|
void InputBackend::on_axis_move(int index, int axis, float value)
|
||||||
{
|
{
|
||||||
if (index < Blah::Input::max_controllers &&
|
if (index < Blah::Input::max_controllers &&
|
||||||
axis < Blah::Input::max_controller_axis &&
|
axis < Blah::Input::max_controller_axis &&
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <blah/streams/filestream.h>
|
#include <blah/streams/filestream.h>
|
||||||
#include <blah/internal/platform.h>
|
#include <blah/internal/platform_backend.h>
|
||||||
#include <blah/log.h>
|
#include <blah/log.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ FileStream::FileStream()
|
||||||
FileStream::FileStream(const char* path, FileMode mode)
|
FileStream::FileStream(const char* path, FileMode mode)
|
||||||
: m_mode(mode)
|
: m_mode(mode)
|
||||||
{
|
{
|
||||||
if (!Internal::Platform::file_open(path, &m_handle, mode))
|
if (!PlatformBackend::file_open(path, &m_handle, mode))
|
||||||
m_handle = nullptr;
|
m_handle = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ FileStream& FileStream::operator=(FileStream&& src) noexcept
|
||||||
FileStream::~FileStream()
|
FileStream::~FileStream()
|
||||||
{
|
{
|
||||||
if (m_handle != nullptr)
|
if (m_handle != nullptr)
|
||||||
Internal::Platform::file_close(m_handle);
|
PlatformBackend::file_close(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FileStream::length() const
|
int64_t FileStream::length() const
|
||||||
|
@ -44,7 +44,7 @@ int64_t FileStream::length() const
|
||||||
if (m_handle == nullptr)
|
if (m_handle == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Internal::Platform::file_length(m_handle);
|
return PlatformBackend::file_length(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FileStream::position() const
|
int64_t FileStream::position() const
|
||||||
|
@ -52,7 +52,7 @@ int64_t FileStream::position() const
|
||||||
if (m_handle == nullptr)
|
if (m_handle == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Internal::Platform::file_position(m_handle);
|
return PlatformBackend::file_position(m_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FileStream::seek(int64_t seek_to)
|
int64_t FileStream::seek(int64_t seek_to)
|
||||||
|
@ -60,7 +60,7 @@ int64_t FileStream::seek(int64_t seek_to)
|
||||||
if (m_handle == nullptr)
|
if (m_handle == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return Internal::Platform::file_seek(m_handle, seek_to);
|
return PlatformBackend::file_seek(m_handle, seek_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FileStream::read_into(void* ptr, int64_t length)
|
int64_t FileStream::read_into(void* ptr, int64_t length)
|
||||||
|
@ -71,7 +71,7 @@ int64_t FileStream::read_into(void* ptr, int64_t length)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Internal::Platform::file_read(m_handle, ptr, length);
|
return PlatformBackend::file_read(m_handle, ptr, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t FileStream::write_from(const void* ptr, int64_t length)
|
int64_t FileStream::write_from(const void* ptr, int64_t length)
|
||||||
|
@ -85,13 +85,13 @@ int64_t FileStream::write_from(const void* ptr, int64_t length)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Internal::Platform::file_write(m_handle, ptr, length);
|
return PlatformBackend::file_write(m_handle, ptr, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileStream::close()
|
void FileStream::close()
|
||||||
{
|
{
|
||||||
if (m_handle != nullptr)
|
if (m_handle != nullptr)
|
||||||
Internal::Platform::file_close(m_handle);
|
PlatformBackend::file_close(m_handle);
|
||||||
m_handle = nullptr;
|
m_handle = nullptr;
|
||||||
m_mode = FileMode::None;
|
m_mode = FileMode::None;
|
||||||
}
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
#include <blah/streams/stream.h>
|
#include <blah/streams/stream.h>
|
||||||
#include <blah/containers/str.h>
|
#include <blah/containers/str.h>
|
||||||
#include <blah/internal/platform.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
using namespace Blah;
|
using namespace Blah;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user