1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-14 13:33:42 +00:00

Ensured GL context is active when destructing CRTOpenGL.

This commit is contained in:
Thomas Harte 2016-04-24 20:34:25 -04:00
parent acab22d95a
commit d221c712b0
10 changed files with 38 additions and 3 deletions

View File

@ -42,10 +42,16 @@ void Machine::setup_output(float aspect_ratio)
_crt->set_output_device(Outputs::CRT::Television);
}
void Machine::close_output()
{
delete _crt;
_crt = nullptr;
}
Machine::~Machine()
{
delete[] _rom;
delete _crt;
close_output();
}
void Machine::switch_region()

View File

@ -31,6 +31,7 @@ class Machine: public CPU6502::Processor<Machine> {
Outputs::CRT::CRT *get_crt() { return _crt; }
void setup_output(float aspect_ratio);
void close_output();
private:
uint8_t *_rom, *_romPages[4], _ram[128];

View File

@ -77,6 +77,11 @@ void Machine::setup_output(float aspect_ratio)
_speaker.set_input_rate(2000000 / clock_rate_audio_divider);
}
void Machine::close_output()
{
_crt = nullptr;
}
unsigned int Machine::perform_bus_operation(CPU6502::BusOperation operation, uint16_t address, uint8_t *value)
{
unsigned int cycles = 1;

View File

@ -157,6 +157,7 @@ class Machine: public CPU6502::Processor<Machine>, Tape::Delegate {
void clear_all_keys();
void setup_output(float aspect_ratio);
void close_output();
Outputs::CRT::CRT *get_crt() { return _crt.get(); }
Outputs::Speaker *get_speaker() { return &_speaker; }

View File

@ -83,4 +83,10 @@ struct CRTDelegate: public Outputs::CRT::Delegate {
}
}
- (void)closeOutput {
@synchronized(self) {
_atari2600.close_output();
}
}
@end

View File

@ -171,4 +171,10 @@
}
}
- (void)closeOutput {
@synchronized(self) {
_electron.close_output();
}
}
@end

View File

@ -17,5 +17,6 @@
- (void)performAsync:(dispatch_block_t)action;
- (void)performSync:(dispatch_block_t)action;
- (void)setupOutputWithAspectRatio:(float)aspectRatio;
- (void)closeOutput;
@end

View File

@ -16,5 +16,6 @@
- (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio;
@property (nonatomic, weak) AudioQueue *audioQueue;
@property (nonatomic, readonly) CSOpenGLView *view;
@end

View File

@ -37,6 +37,12 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate {
return self;
}
- (void)dealloc {
[_view performWithGLContext:^{
[self closeOutput];
}];
}
- (BOOL)setSpeakerDelegate:(Outputs::Speaker::Delegate *)delegate sampleRate:(int)sampleRate {
return NO;
}
@ -53,7 +59,10 @@ struct SpeakerDelegate: public Outputs::Speaker::Delegate {
- (void)setupOutputWithAspectRatio:(float)aspectRatio {}
- (void)closeOutput {}
- (void)setView:(CSOpenGLView *)view aspectRatio:(float)aspectRatio {
_view = view;
[view performWithGLContext:^{
[self setupOutputWithAspectRatio:aspectRatio];
}];

View File

@ -80,8 +80,7 @@ Shader::Shader(const char *vertex_shader, const char *fragment_shader, const Att
Shader::~Shader()
{
// TODO: ensure this is destructed within the correct context.
// glDeleteProgram(_shader_program);
glDeleteProgram(_shader_program);
}
void Shader::bind()