mirror of https://github.com/bjornbytes/lovr.git
Avoid redundant strlen in font printing;
This commit is contained in:
parent
fae7786c8d
commit
d66057ee70
|
@ -852,13 +852,14 @@ static int l_lovrGraphicsSkybox(lua_State* L) {
|
|||
}
|
||||
|
||||
static int l_lovrGraphicsPrint(lua_State* L) {
|
||||
const char* str = luaL_checkstring(L, 1);
|
||||
size_t length;
|
||||
const char* str = luaL_checklstring(L, 1, &length);
|
||||
float transform[16];
|
||||
int index = luax_readmat4(L, 2, transform, 1, NULL);
|
||||
float wrap = luaL_optnumber(L, index++, 0);
|
||||
HorizontalAlign halign = luaL_checkoption(L, index++, "center", HorizontalAligns);
|
||||
VerticalAlign valign = luaL_checkoption(L, index++, "middle", VerticalAligns);
|
||||
lovrGraphicsPrint(str, transform, wrap, halign, valign);
|
||||
lovrGraphicsPrint(str, length, transform, wrap, halign, valign);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ Rasterizer* lovrFontGetRasterizer(Font* font) {
|
|||
return font->rasterizer;
|
||||
}
|
||||
|
||||
void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign halign, VerticalAlign valign, float* vertices, float* offsety, uint32_t* vertexCount) {
|
||||
void lovrFontRender(Font* font, const char* str, size_t length, float wrap, HorizontalAlign halign, VerticalAlign valign, float* vertices, float* offsety, uint32_t* vertexCount) {
|
||||
FontAtlas* atlas = &font->atlas;
|
||||
|
||||
float cx = 0;
|
||||
|
@ -77,9 +77,8 @@ void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign hal
|
|||
float v = atlas->height;
|
||||
float scale = 1 / font->pixelDensity;
|
||||
|
||||
int len = strlen(str);
|
||||
const char* start = str;
|
||||
const char* end = str + len;
|
||||
const char* end = str + length;
|
||||
unsigned int previous = '\0';
|
||||
unsigned int codepoint;
|
||||
size_t bytes;
|
||||
|
@ -119,7 +118,7 @@ void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign hal
|
|||
|
||||
// Start over if texture was repacked
|
||||
if (u != atlas->width || v != atlas->height) {
|
||||
lovrFontRender(font, start, wrap, halign, valign, vertices, offsety, vertexCount);
|
||||
lovrFontRender(font, start, length, wrap, halign, valign, vertices, offsety, vertexCount);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ Font* lovrFontInit(Font* font, Rasterizer* rasterizer);
|
|||
#define lovrFontCreate(...) lovrFontInit(lovrAlloc(Font), __VA_ARGS__)
|
||||
void lovrFontDestroy(void* ref);
|
||||
Rasterizer* lovrFontGetRasterizer(Font* font);
|
||||
void lovrFontRender(Font* font, const char* str, float wrap, HorizontalAlign halign, VerticalAlign valign, float* vertices, float* offsety, uint32_t* vertexCount);
|
||||
void lovrFontRender(Font* font, const char* str, size_t length, float wrap, HorizontalAlign halign, VerticalAlign valign, float* vertices, float* offsety, uint32_t* vertexCount);
|
||||
float lovrFontGetWidth(Font* font, const char* string, float wrap);
|
||||
float lovrFontGetHeight(Font* font);
|
||||
float lovrFontGetAscent(Font* font);
|
||||
|
|
|
@ -879,14 +879,14 @@ void lovrGraphicsSkybox(Texture* texture, float angle, float ax, float ay, float
|
|||
});
|
||||
}
|
||||
|
||||
void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign) {
|
||||
void lovrGraphicsPrint(const char* str, size_t length, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign) {
|
||||
Font* font = lovrGraphicsGetFont();
|
||||
float scale = 1 / font->pixelDensity;
|
||||
float offsety;
|
||||
uint32_t vertexCount;
|
||||
uint32_t maxVertices = strlen(str) * 6;
|
||||
uint32_t maxVertices = length * 6;
|
||||
float* vertices = lovrGraphicsGetVertexPointer(maxVertices);
|
||||
lovrFontRender(font, str, wrap, halign, valign, vertices, &offsety, &vertexCount);
|
||||
lovrFontRender(font, str, length, wrap, halign, valign, vertices, &offsety, &vertexCount);
|
||||
|
||||
Pipeline pipeline = state.pipeline;
|
||||
pipeline.alphaSampling = true;
|
||||
|
|
|
@ -233,7 +233,7 @@ void lovrGraphicsCircle(DrawStyle style, Material* material, mat4 transform, int
|
|||
void lovrGraphicsCylinder(Material* material, float x1, float y1, float z1, float x2, float y2, float z2, float r1, float r2, bool capped, int segments);
|
||||
void lovrGraphicsSphere(Material* material, mat4 transform, int segments);
|
||||
void lovrGraphicsSkybox(Texture* texture, float angle, float ax, float ay, float az);
|
||||
void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
||||
void lovrGraphicsPrint(const char* str, size_t length, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
||||
void lovrGraphicsFill(Texture* texture, float u, float v, float w, float h);
|
||||
#define lovrGraphicsStencil lovrGpuStencil
|
||||
#define lovrGraphicsCompute lovrGpuCompute
|
||||
|
|
Loading…
Reference in New Issue