File: GBOpenGLView.m

package info (click to toggle)
sameboy 1.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,632 kB
  • sloc: ansic: 29,954; objc: 22,249; asm: 1,424; pascal: 1,373; makefile: 1,064; xml: 111
file content (40 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#import "GBOpenGLView.h"
#import "GBView.h"
#import "NSObject+DefaultsObserver.h"
#import <OpenGL/gl.h>

@implementation GBOpenGLView

- (void)drawRect:(NSRect)dirtyRect 
{
    if (!self.shader) {
        self.shader = [[GBGLShader alloc] initWithName:[[NSUserDefaults standardUserDefaults] objectForKey:@"GBFilter"]];
    }
    
    GBView *gbview = (GBView *)self.superview;
    double scale = self.window.backingScaleFactor;
    glViewport(0, 0, self.bounds.size.width * scale, self.bounds.size.height * scale);
    
    if (gbview.gb) {
        [self.shader renderBitmap:gbview.currentBuffer
                         previous:gbview.frameBlendingMode? gbview.previousBuffer : NULL
                            sized:NSMakeSize(GB_get_screen_width(gbview.gb), GB_get_screen_height(gbview.gb))
                           inSize:self.bounds.size
                            scale:scale
                 withBlendingMode:gbview.frameBlendingMode];
    }
    glFlush();
}

- (instancetype)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
{
    __unsafe_unretained GBOpenGLView *weakSelf = self;
    self = [super initWithFrame:frameRect pixelFormat:format];
    [self observeStandardDefaultsKey:@"GBFilter" withBlock:^(id newValue) {
        weakSelf.shader = nil;
        [weakSelf setNeedsDisplay:true];

    }];
    return self;
}
@end