mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
refactor: Add vertex buffer struct to ShaderTypes and remove global
This commit is contained in:
parent
c41f331e2a
commit
9d22aacaa7
@ -55,6 +55,12 @@ typedef struct
|
|||||||
vector_float2 texCoord METAL_ATTRIBUTE(VertexAttributeTexcoord);
|
vector_float2 texCoord METAL_ATTRIBUTE(VertexAttributeTexcoord);
|
||||||
} Vertex;
|
} Vertex;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
vector_float4 position;
|
||||||
|
vector_float2 texCoord;
|
||||||
|
} VertexSlang;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
vector_float4 position METAL_POSITION;
|
vector_float4 position METAL_POSITION;
|
||||||
|
@ -546,6 +546,7 @@ typedef struct MTLALIGN(16)
|
|||||||
Context *_context;
|
Context *_context;
|
||||||
id<MTLTexture> _texture; // final render texture
|
id<MTLTexture> _texture; // final render texture
|
||||||
Vertex _v[4];
|
Vertex _v[4];
|
||||||
|
VertexSlang _vertex[4];
|
||||||
CGSize _size; // size of view in pixels
|
CGSize _size; // size of view in pixels
|
||||||
CGRect _frame;
|
CGRect _frame;
|
||||||
NSUInteger _bpp;
|
NSUInteger _bpp;
|
||||||
@ -587,6 +588,15 @@ typedef struct MTLALIGN(16)
|
|||||||
self.size = d.size;
|
self.size = d.size;
|
||||||
self.frame = CGRectMake(0, 0, 1, 1);
|
self.frame = CGRectMake(0, 0, 1, 1);
|
||||||
resize_render_targets = YES;
|
resize_render_targets = YES;
|
||||||
|
|
||||||
|
// init slang vertex buffer
|
||||||
|
VertexSlang v[4] = {
|
||||||
|
{simd_make_float4(0, 1, 0, 1), simd_make_float2(0, 1)},
|
||||||
|
{simd_make_float4(1, 1, 0, 1), simd_make_float2(1, 1)},
|
||||||
|
{simd_make_float4(0, 0, 0, 1), simd_make_float2(0, 0)},
|
||||||
|
{simd_make_float4(1, 0, 0, 1), simd_make_float2(1, 0)},
|
||||||
|
};
|
||||||
|
memcpy(_vertex, v, sizeof(_vertex));
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -816,19 +826,6 @@ typedef struct MTLALIGN(16)
|
|||||||
init_history = NO;
|
init_history = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct vertex
|
|
||||||
{
|
|
||||||
simd_float4 pos;
|
|
||||||
simd_float2 tex;
|
|
||||||
} vertex_t;
|
|
||||||
|
|
||||||
static vertex_t vertex_bytes[] = {
|
|
||||||
{{0, 1, 0, 1}, {0, 1}},
|
|
||||||
{{1, 1, 0, 1}, {1, 1}},
|
|
||||||
{{0, 0, 0, 1}, {0, 0}},
|
|
||||||
{{1, 0, 0, 1}, {1, 0}},
|
|
||||||
};
|
|
||||||
|
|
||||||
- (void)drawWithEncoder:(id<MTLRenderCommandEncoder>)rce
|
- (void)drawWithEncoder:(id<MTLRenderCommandEncoder>)rce
|
||||||
{
|
{
|
||||||
if (_texture)
|
if (_texture)
|
||||||
@ -942,7 +939,7 @@ static vertex_t vertex_bytes[] = {
|
|||||||
|
|
||||||
[rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
[rce setFragmentTextures:textures withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
||||||
[rce setFragmentSamplerStates:samplers withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
[rce setFragmentSamplerStates:samplers withRange:NSMakeRange(0, SLANG_NUM_BINDINGS)];
|
||||||
[rce setVertexBytes:vertex_bytes length:sizeof(vertex_bytes) atIndex:4];
|
[rce setVertexBytes:_vertex length:sizeof(_vertex) atIndex:4];
|
||||||
[rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
[rce drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||||
|
|
||||||
if (!backBuffer)
|
if (!backBuffer)
|
||||||
@ -1162,13 +1159,13 @@ static vertex_t vertex_bytes[] = {
|
|||||||
@try
|
@try
|
||||||
{
|
{
|
||||||
MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
|
MTLVertexDescriptor *vd = [MTLVertexDescriptor new];
|
||||||
vd.attributes[0].offset = offsetof(vertex_t, pos);
|
vd.attributes[0].offset = offsetof(VertexSlang, position);
|
||||||
vd.attributes[0].format = MTLVertexFormatFloat4;
|
vd.attributes[0].format = MTLVertexFormatFloat4;
|
||||||
vd.attributes[0].bufferIndex = 4;
|
vd.attributes[0].bufferIndex = 4;
|
||||||
vd.attributes[1].offset = offsetof(vertex_t, tex);
|
vd.attributes[1].offset = offsetof(VertexSlang, texCoord);
|
||||||
vd.attributes[1].format = MTLVertexFormatFloat2;
|
vd.attributes[1].format = MTLVertexFormatFloat2;
|
||||||
vd.attributes[1].bufferIndex = 4;
|
vd.attributes[1].bufferIndex = 4;
|
||||||
vd.layouts[4].stride = sizeof(vertex_t);
|
vd.layouts[4].stride = sizeof(VertexSlang);
|
||||||
vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex;
|
vd.layouts[4].stepFunction = MTLVertexStepFunctionPerVertex;
|
||||||
|
|
||||||
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
MTLRenderPipelineDescriptor *psd = [MTLRenderPipelineDescriptor new];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user