mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
(Fonts) Cleanups
This commit is contained in:
parent
6ff82319fb
commit
527d1557ce
@ -27,7 +27,6 @@
|
||||
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -50,10 +49,7 @@ static void *caca_font_init(void *data,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "../../ctr/gpu_old.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -58,7 +57,6 @@ static void* ctr_font_init(void* data, const char* font_path,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "../common/d3d10_common.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -47,7 +46,6 @@ static void *d3d10_font_init(void* data, const char* font_path,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver, &font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "../common/d3d11_common.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -46,7 +45,6 @@ static void * d3d11_font_init(void* data, const char* font_path,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver, &font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "../common/d3d12_common.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -47,7 +46,6 @@ static void * d3d12_font_init(void* data, const char* font_path,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@
|
||||
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -56,10 +55,7 @@ static void *gdi_font_init(void *data,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "../common/gl1_common.h"
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "../common/gl2_common.h"
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "../common/gl3_common.h"
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
|
||||
|
||||
@ -111,7 +110,6 @@ static void *gl3_raster_font_init(void *data,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
@interface MetalRaster : NSObject
|
||||
{
|
||||
@ -72,18 +71,15 @@
|
||||
if (driver == nil)
|
||||
return nil;
|
||||
|
||||
_driver = driver;
|
||||
_driver = driver;
|
||||
_context = driver.context;
|
||||
if (!font_renderer_create_default(
|
||||
&_font_driver,
|
||||
&_font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
return nil;
|
||||
}
|
||||
|
||||
_uniforms.projectionMatrix = matrix_proj_ortho(0, 1, 0, 1);
|
||||
_atlas = _font_driver->get_atlas(_font_data);
|
||||
_atlas = _font_driver->get_atlas(_font_data);
|
||||
_stride = MTL_ALIGN_BUFFER(_atlas->width);
|
||||
if (_stride == _atlas->width)
|
||||
{
|
||||
@ -102,7 +98,7 @@
|
||||
else
|
||||
{
|
||||
int i;
|
||||
_buffer = [_context.device newBufferWithLength:(NSUInteger)(_stride * _atlas->height)
|
||||
_buffer = [_context.device newBufferWithLength:(NSUInteger)(_stride * _atlas->height)
|
||||
options:PLATFORM_METAL_RESOURCE_STORAGE_MODE];
|
||||
void *dst = _buffer.contents;
|
||||
void *src = _atlas->buffer;
|
||||
@ -122,15 +118,13 @@
|
||||
height:_atlas->height
|
||||
mipmapped:NO];
|
||||
|
||||
_texture = [_buffer newTextureWithDescriptor:td offset:0 bytesPerRow:_stride];
|
||||
_texture = [_buffer newTextureWithDescriptor:td offset:0 bytesPerRow:_stride];
|
||||
|
||||
_capacity = 12000;
|
||||
_vert = [_context.device newBufferWithLength:sizeof(SpriteVertex) *
|
||||
_vert = [_context.device newBufferWithLength:sizeof(SpriteVertex) *
|
||||
_capacity options:PLATFORM_METAL_RESOURCE_STORAGE_MODE];
|
||||
if (![self _initializeState])
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -138,46 +132,44 @@
|
||||
- (bool)_initializeState
|
||||
{
|
||||
{
|
||||
MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
|
||||
vd.attributes[0].offset = 0;
|
||||
vd.attributes[0].format = MTLVertexFormatFloat2;
|
||||
vd.attributes[1].offset = offsetof(SpriteVertex, texCoord);
|
||||
vd.attributes[1].format = MTLVertexFormatFloat2;
|
||||
vd.attributes[2].offset = offsetof(SpriteVertex, color);
|
||||
vd.attributes[2].format = MTLVertexFormatFloat4;
|
||||
vd.layouts[0].stride = sizeof(SpriteVertex);
|
||||
NSError *err;
|
||||
MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
|
||||
|
||||
vd.attributes[0].offset = 0;
|
||||
vd.attributes[0].format = MTLVertexFormatFloat2;
|
||||
vd.attributes[1].offset = offsetof(SpriteVertex, texCoord);
|
||||
vd.attributes[1].format = MTLVertexFormatFloat2;
|
||||
vd.attributes[2].offset = offsetof(SpriteVertex, color);
|
||||
vd.attributes[2].format = MTLVertexFormatFloat4;
|
||||
vd.layouts[0].stride = sizeof(SpriteVertex);
|
||||
vd.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
|
||||
|
||||
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
||||
psd.label = @"font pipeline";
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor *ca = psd.colorAttachments[0];
|
||||
ca.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||
ca.blendingEnabled = YES;
|
||||
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
|
||||
ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
|
||||
ca.pixelFormat = MTLPixelFormatBGRA8Unorm;
|
||||
ca.blendingEnabled = YES;
|
||||
ca.sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;
|
||||
ca.sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;
|
||||
ca.destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
||||
ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
||||
ca.destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;
|
||||
|
||||
psd.sampleCount = 1;
|
||||
psd.vertexDescriptor = vd;
|
||||
psd.vertexFunction = [_context.library newFunctionWithName:@"sprite_vertex"];
|
||||
psd.fragmentFunction = [_context.library newFunctionWithName:@"sprite_fragment_a8"];
|
||||
psd.sampleCount = 1;
|
||||
psd.vertexDescriptor = vd;
|
||||
psd.vertexFunction = [_context.library newFunctionWithName:@"sprite_vertex"];
|
||||
psd.fragmentFunction = [_context.library newFunctionWithName:@"sprite_fragment_a8"];
|
||||
|
||||
NSError *err;
|
||||
_state = [_context.device newRenderPipelineStateWithDescriptor:psd error:&err];
|
||||
_state = [_context.device newRenderPipelineStateWithDescriptor:psd error:&err];
|
||||
if (err != nil)
|
||||
{
|
||||
RARCH_ERR("[MetalRaster]: error creating pipeline state: %s\n", err.localizedDescription.UTF8String);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
MTLSamplerDescriptor *sd = [MTLSamplerDescriptor new];
|
||||
sd.minFilter = MTLSamplerMinMagFilterLinear;
|
||||
sd.magFilter = MTLSamplerMinMagFilterLinear;
|
||||
_sampler = [_context.device newSamplerStateWithDescriptor:sd];
|
||||
sd.minFilter = MTLSamplerMinMagFilterLinear;
|
||||
sd.magFilter = MTLSamplerMinMagFilterLinear;
|
||||
_sampler = [_context.device newSamplerStateWithDescriptor:sd];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
@ -196,7 +188,7 @@
|
||||
|
||||
#if !defined(HAVE_COCOATOUCH)
|
||||
NSUInteger offset = glyph->atlas_offset_y;
|
||||
NSUInteger len = glyph->height * _stride;
|
||||
NSUInteger len = glyph->height * _stride;
|
||||
[_buffer didModifyRange:NSMakeRange(offset, len)];
|
||||
#endif
|
||||
|
||||
@ -206,10 +198,11 @@
|
||||
|
||||
- (int)getWidthForMessage:(const char *)msg length:(NSUInteger)length scale:(float)scale
|
||||
{
|
||||
NSUInteger i;
|
||||
int delta_x = 0;
|
||||
const struct font_glyph* glyph_q = _font_driver->get_glyph(_font_data, '?');
|
||||
|
||||
for (NSUInteger i = 0; i < length; i++)
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
const struct font_glyph *glyph;
|
||||
/* Do something smarter here ... */
|
||||
@ -231,10 +224,7 @@
|
||||
|
||||
const struct font_glyph *glyph = _font_driver->get_glyph((void *)_font_driver, code);
|
||||
if (glyph)
|
||||
{
|
||||
[self updateGlyph:glyph];
|
||||
}
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
@ -377,8 +367,8 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
||||
struct font_line_metrics *line_metrics = NULL;
|
||||
|
||||
/* If font line metrics are not supported just draw as usual */
|
||||
if (!_font_driver->get_line_metrics ||
|
||||
!_font_driver->get_line_metrics(_font_data, &line_metrics))
|
||||
if ( !_font_driver->get_line_metrics
|
||||
|| !_font_driver->get_line_metrics(_font_data, &line_metrics))
|
||||
{
|
||||
[self _renderLine:msg length:strlen(msg) scale:scale color:color posX:posX posY:posY aligned:aligned];
|
||||
return;
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -53,7 +52,6 @@ static void* ps2_font_init(void* data, const char* font_path,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
#define RSX_FONT_EMIT(c, vx, vy) \
|
||||
font_vertex[ 2 * (6 * i + c) + 0] = (x + (delta_x + off_x + vx * width) * scale) * inv_win_width; \
|
||||
@ -147,7 +146,6 @@ static void *rsx_font_init(void *data,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../common/sixel_common.h"
|
||||
|
||||
typedef struct
|
||||
@ -49,10 +48,7 @@ static void *sixel_font_init(void *data,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
#include "../common/switch_common.h"
|
||||
|
||||
@ -51,7 +50,6 @@ static void *switch_font_init(void *data, const char *font_path,
|
||||
if (!font_renderer_create_default(&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "../font_driver.h"
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
#include "../common/vga_common.h"
|
||||
|
||||
typedef struct
|
||||
@ -50,10 +49,7 @@ static void *vga_font_init(void *data,
|
||||
if (!font_renderer_create_default(
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return font;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "../font_driver.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -86,7 +85,6 @@ static void *vita2d_font_init(void *data,
|
||||
return font;
|
||||
|
||||
error:
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -85,7 +85,6 @@ static void *vulkan_font_init(void *data,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "../../wiiu/wiiu_dbg.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -51,7 +50,6 @@ static void* wiiu_font_init(void* data, const char* font_path,
|
||||
&font->font_driver,
|
||||
&font->font_data, font_path, font_size))
|
||||
{
|
||||
RARCH_WARN("Couldn't initialize font renderer.\n");
|
||||
free(font);
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user