2018-06-11 17:23:51 +00:00
|
|
|
#import "GBOpenGLView.h"
|
|
|
|
#import "GBView.h"
|
|
|
|
#include <OpenGL/gl.h>
|
|
|
|
|
|
|
|
@implementation GBOpenGLView
|
|
|
|
|
2020-04-24 17:37:57 +00:00
|
|
|
- (void)drawRect:(NSRect)dirtyRect
|
|
|
|
{
|
2018-06-11 17:23:51 +00:00
|
|
|
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);
|
|
|
|
|
2020-03-27 14:26:51 +00:00
|
|
|
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];
|
|
|
|
}
|
2018-06-11 17:23:51 +00:00
|
|
|
glFlush();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithFrame:(NSRect)frameRect pixelFormat:(NSOpenGLPixelFormat *)format
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(filterChanged) name:@"GBFilterChanged" object:nil];
|
|
|
|
return [super initWithFrame:frameRect pixelFormat:format];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) filterChanged
|
|
|
|
{
|
|
|
|
self.shader = nil;
|
2021-10-23 10:36:58 +00:00
|
|
|
[self setNeedsDisplay:true];
|
2018-06-11 17:23:51 +00:00
|
|
|
}
|
|
|
|
@end
|