Skip to content

Commit

Permalink
pass pixel format to vgerNew
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Jun 3, 2024
1 parent 6c8fbab commit 1c843d9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
4 changes: 3 additions & 1 deletion Sources/vger/include/vger.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ enum vgerCreateFlags {
VGER_TRIPLE_BUFFER = 1 << 1,
};

#ifdef __OBJC__
/// Create a new state object.
vgerContext vgerNew(uint32_t flags);
vgerContext vgerNew(uint32_t flags, MTLPixelFormat pixelFormat);
#endif

/// Deallocate state object.
void vgerDelete(vgerContext);
Expand Down
8 changes: 4 additions & 4 deletions Sources/vger/vger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#import "bezier.h"
#import "vger_private.h"

vger::vger(uint32_t flags) {
vger::vger(uint32_t flags, MTLPixelFormat pixelFormat) {
device = MTLCreateSystemDefaultDevice();
renderer = [[vgerRenderer alloc] initWithDevice:device pixelFormat:MTLPixelFormatBGRA8Unorm];
renderer = [[vgerRenderer alloc] initWithDevice:device pixelFormat:pixelFormat];
glowRenderer = [[vgerRenderer alloc] initWithDevice:device pixelFormat:MTLPixelFormatRGBA16Unorm];
glyphCache = [[vgerGlyphCache alloc] initWithDevice:device];

Expand Down Expand Up @@ -64,8 +64,8 @@
textureLoader = [[MTKTextureLoader alloc] initWithDevice:device];
}

vgerContext vgerNew(uint32_t flags) {
return new vger(flags);
vgerContext vgerNew(uint32_t flags, MTLPixelFormat pixelFormat) {
return new vger(flags, pixelFormat);
}

void vgerDelete(vgerContext vg) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/vger/vger_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct vger {
/// Have we already computed glyph bounds?
bool computedGlyphBounds = false;

vger(uint32_t flags);
vger(uint32_t flags, MTLPixelFormat pixelFormat);

void addPrim(const vgerPrim& prim) {
scenes[currentScene].prims[currentLayer].append(prim);
Expand Down
2 changes: 1 addition & 1 deletion Sources/vgerSwift/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import vger

class Renderer: NSObject, MTKViewDelegate {

var vg = vgerNew(0)
var vg = vgerNew(0, .bgra8Unorm)
var device: MTLDevice!
var queue: MTLCommandQueue!
var renderCallback : ((vgerContext, CGSize) -> Void)?
Expand Down
38 changes: 19 additions & 19 deletions Tests/vgerTests/vgerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ - (void) testBasic {
float theta = 0;
float ap = .5 * M_PI;

auto vg = vgerNew(0);
auto vg = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vg, 512, 512, 1.0);

Expand Down Expand Up @@ -161,7 +161,7 @@ - (void) testBasic {

- (void) testTransformStack {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand All @@ -185,7 +185,7 @@ - (void) testTransformStack {

- (void) testRotate {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand All @@ -207,7 +207,7 @@ - (void) testRotate {

- (void) testRects {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);
assert(vger);

vgerBegin(vger, 512, 512, 1.0);
Expand Down Expand Up @@ -245,7 +245,7 @@ - (NSURL*) getImageURL:(NSString*)name {

- (void) testRenderTexture {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand All @@ -264,7 +264,7 @@ - (void) testRenderTexture {

- (void) testText {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand All @@ -281,7 +281,7 @@ - (void) testText {

- (void) testScaleText {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand Down Expand Up @@ -316,7 +316,7 @@ - (void) testBezierPerf {

int N = 10000;

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

[self measureBlock:^{

Expand Down Expand Up @@ -352,7 +352,7 @@ - (void) testBezierPerf {

- (void) testBezierPerfSplit {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

[self measureBlock:^{

Expand Down Expand Up @@ -484,7 +484,7 @@ - (void) testPrimDemo {
auto cyan = float4{0,1,1,1};
auto magenta = float4{1,0,1,1};

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 800, 800, 1.0);

Expand Down Expand Up @@ -618,7 +618,7 @@ - (void) testPaint {

- (void) testTextAlgin {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand Down Expand Up @@ -652,7 +652,7 @@ - (void) testPathFill {
int w = 512, h = 512;
float2 sz = {float(w),float(h)};

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, w, h, 1.0);

Expand All @@ -676,7 +676,7 @@ - (void) testEmptyPathFill {
int w = 512, h = 512;
float2 sz = {float(w),float(h)};

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, w, h, 1.0);

Expand Down Expand Up @@ -708,7 +708,7 @@ - (void) testPathFillCircle {
int w = 512, h = 512;
float2 sz = {float(w),float(h)};

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, w, h, 1.0);

Expand All @@ -728,7 +728,7 @@ - (void) testPathFillCircle {

- (void) testTextBox {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand Down Expand Up @@ -762,7 +762,7 @@ - (void) testTiger {

printf("size: %f x %f\n", image->width, image->height);

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

vgerBegin(vger, 512, 512, 1.0);

Expand Down Expand Up @@ -809,7 +809,7 @@ - (void) testTigerPerf {

printf("size: %f x %f\n", image->width, image->height);

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

[self measureBlock:^{

Expand Down Expand Up @@ -878,7 +878,7 @@ - (void) testTextLayoutKey {

- (void) testLayers {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);
vgerSetLayerCount(vger, 2);

vgerBegin(vger, 512, 512, 1.0);
Expand All @@ -902,7 +902,7 @@ - (void) testLayers {

- (void) testPathRectangle {

auto vger = vgerNew(0);
auto vger = vgerNew(0, MTLPixelFormatBGRA8Unorm);

auto w = 0.5f;
auto h = 50.0f;
Expand Down

0 comments on commit 1c843d9

Please sign in to comment.