SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Cocoa/GBOpenGLView.m
1 #import "GBOpenGLView.h"
2 #import "GBView.h"
3 #import "NSObject+DefaultsObserver.h"
4 #import <OpenGL/gl.h>
5
6 @implementation GBOpenGLView
7
8 - (void)drawRect:(NSRect)dirtyRect
9 {
10 if (!self.shader) {
11 self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]];
12 }
13
14 GBView *gbview = (GBView *)self.superview;
15 double scale = self.window.backingScaleFactor;
16 glViewport(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale);
17
18 if (gbview.gb) {
19 [self.shader renderBitmap:gbview.currentBuffer
20 previous:gbview.frameBlendingMode? gbview.previousBuffer : NULL
21 sized:NSMakeSize(GB_get_screen_width(gbview.gb), GB_get_screen_height(gbview.gb))
22 inSize:self.bounds.size
23 scale:scale
24 withBlendingMode:gbview.frameBlendingMode];
25 }
26 glFlush();
27 }
28
29 - (instancetype)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
30 {
31 __unsafe_unretained GBOpenGLView *weakSelf = self;
32 self = [super initWithFrame:frameRect pixelFormat:format];
33 [self observeStandardDefaultsKey:@"GBFilter" withBlock:^(id newValue) {
34 weakSelf.shader = nil;
35 [weakSelf setNeedsDisplay:true];
36
37 }];
38 return self;
39 }
40 @end
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.