DTRenderer/src/DTRendererRender.h

64 lines
2.8 KiB
C
Raw Normal View History

2017-05-16 12:53:28 +00:00
#ifndef DTRENDERER_RENDER_H
#define DTRENDERER_RENDER_H
#include "dqn.h"
#define DTRRENDER_INV_255 1.0f/255.0f
2017-05-16 12:53:28 +00:00
typedef struct PlatformRenderBuffer PlatformRenderBuffer;
typedef struct DTRBitmap DTRBitmap;
////////////////////////////////////////////////////////////////////////////////////////////////////
// Utility
////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct DTRRenderTransform
{
f32 rotation = 0; // Rotation in degrees
DqnV2 anchor = DqnV2_1f(0.5f); // Anchor has expected range of [0->1]
DqnV2 scale = DqnV2_1f(1.0f);
} DTRRenderTransform;
inline DTRRenderTransform DTRRender_DefaultTransform()
{
DTRRenderTransform result = {};
return result;
}
// NOTE: 0.33f is the midpoint of a triangle
inline DTRRenderTransform DTRRender_DefaultTriangleTransform()
{
DTRRenderTransform result = {};
result.anchor = DqnV2_1f(0.33f);
return result;
}
2017-05-16 12:53:28 +00:00
// NOTE(doyle): 1 suffix represents the range the color is being sent in which
// means all the colors should be in the range of [0-1]
inline f32 DTRRender_SRGB1ToLinearSpacef (f32 val);
inline DqnV4 DTRRender_SRGB1ToLinearSpaceV4(DqnV4 color);
inline f32 DTRRender_LinearToSRGB1Spacef (f32 val);
inline DqnV4 DTRRender_LinearToSRGB1SpaceV4(DqnV4 color);
// Takes SRGB in [0->1], converts to linear space, premultiplies alpha and returns
// color back in SRGB space.
inline DqnV4 DTRRender_PreMultiplyAlphaSRGB1WithLinearConversion(DqnV4 color);
////////////////////////////////////////////////////////////////////////////////////////////////////
// Rendering
////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE: All colors should be in the range of [0->1] where DqnV4 is a struct with 4 floats, rgba
// Leaving len = -1 for text will make the system use strlen to determine len.
void DTRRender_Text (PlatformRenderBuffer *const renderBuffer, const DTRFont font, DqnV2 pos, const char *const text, DqnV4 color = DqnV4_1f(1), i32 len = -1);
void DTRRender_Line (PlatformRenderBuffer *const renderBuffer, DqnV2i a, DqnV2i b, DqnV4 color);
void DTRRender_Rectangle(PlatformRenderBuffer *const renderBuffer, DqnV2 min, DqnV2 max, DqnV4 color, const DTRRenderTransform transform = DTRRender_DefaultTransform());
void DTRRender_Triangle (PlatformRenderBuffer *const renderBuffer, DqnV2 p1, DqnV2 p2, DqnV2 p3, DqnV4 color, const DTRRenderTransform transform = DTRRender_DefaultTriangleTransform());
void DTRRender_Bitmap (PlatformRenderBuffer *const renderBuffer, DTRBitmap *const bitmap, DqnV2 pos, const DTRRenderTransform transform = DTRRender_DefaultTransform(), DqnV4 color = DqnV4_4f(1, 1, 1, 1));
void DTRRender_Clear (PlatformRenderBuffer *const renderBuffer, DqnV3 color);
2017-05-16 12:53:28 +00:00
#endif