namespace Dream { UnitTest::Suite AssertionTestSuite { "Dream::Assertion", {"Throw Exception", [](UnitTest::Examiner & examiner) { bool exception_thrown = false; exception_thrown = false; try { DREAM_ASSERT(1 == 0); } catch (AssertionError & err) { exception_thrown = true; } examiner << "Assertion should fail"; examiner.check(exception_thrown); exception_thrown = false; try { DREAM_ASSERT(1 == 1); } catch (AssertionError & err) { exception_thrown = true; } examiner << "Assertion was okay"; examiner.check(!exception_thrown); } }, }; }
Ref<Program> RendererState::load_program(const Path & name) { GLuint vertex_shader = compile_shader_of_type(GL_VERTEX_SHADER, name.with_extension("vertex-shader")); #ifndef DREAM_OPENGLES2 GLuint geometry_shader = compile_shader_of_type(GL_GEOMETRY_SHADER, name.with_extension("geometry-shader")); #endif GLuint fragment_shader = compile_shader_of_type(GL_FRAGMENT_SHADER, name.with_extension("fragment-shader")); Ref<Program> program = new Program; // We must have at least one shader for the program to do anything: DREAM_ASSERT(vertex_shader || fragment_shader); if (vertex_shader) program->attach(vertex_shader); #ifndef DREAM_OPENGLES2 if (geometry_shader) program->attach(geometry_shader); #endif if (fragment_shader) program->attach(fragment_shader); program->link(); program->bind_fragment_location("fragment_color"); return program; }
void check_graphics_error() { #ifdef DREAM_DEBUG GLenum error = GL_NO_ERROR; while ((error = glGetError()) != GL_NO_ERROR) { logger()->log(LOG_ERROR, LogBuffer() << "OpenGL Error #" << error); // Abort due to error DREAM_ASSERT(error == GL_NO_ERROR); } #endif }
Mixer::Mixer () { const ALCchar * device_name = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); AudioError::reset(); _audio_device = _default_audio_device(); _audio_context = alcCreateContext(_audio_device, NULL); AudioError::check("Initializing Audio Context"); bool result = alcMakeContextCurrent(_audio_context); LogBuffer buffer; buffer << "OpenAL Context Initialized..." << std::endl; buffer << "OpenAL Vendor: " << alGetString(AL_VENDOR) << " " << alGetString(AL_VERSION) << std::endl; buffer << "OpenAL Device: '" << device_name << "'" << std::endl; logger()->log(LOG_INFO, buffer); //al_distance_model(AL_LINEAR_DISTANCE); set_listener_position(0); set_listener_velocity(0); set_listener_orientation(Vec3(0.0, 0.0, -1.0), Vec3(0.0, 1.0, 0.0)); DREAM_ASSERT(result && "Failed to initialize audio hardware!?"); }
static Ref<Sound> load_wave_data (const Ptr<IData> data) { DecoderT decoder = NULL; Shared<Buffer> buffer = data->buffer(); std::size_t i = 4; uint32_t chunk_length; int32_t magic; i += buffer->read(i, chunk_length, LITTLE); i += buffer->read(i, magic, BIG); if (magic != 'WAVE') throw LoadError("Could not load WAV data"); bool found_header; uint16_t audio_format, channel_count, block_align, bits_per_sample; uint32_t sample_frequency, byte_rate; while (i < buffer->size()) { i += buffer->read(i, magic, BIG); i += buffer->read(i, chunk_length, LITTLE); if (magic == 'fmt ') { // Decode header found_header = true; i += buffer->read(i, audio_format, LITTLE); i += buffer->read(i, channel_count, LITTLE); i += buffer->read(i, sample_frequency, LITTLE); i += buffer->read(i, byte_rate, LITTLE); i += buffer->read(i, block_align, LITTLE); i += buffer->read(i, bits_per_sample, LITTLE); i += chunk_length - 16; if (audio_format == 1) { if (bits_per_sample == 8) // Copy samples verbatim. decoder = decode_linear_codec; else // Use PCM16 decoder - will pass through if endian doesn't need to be converted. decoder = decode_pcm16_codec; } else if (audio_format == 7) { //bits_per_sample *= 2; //decoder = decode_ulaw_codec; throw LoadError("Unsupported WAV encoding (ULaw)"); } else { throw LoadError("Unsupported WAV encoding (Unknown)"); } } else if (magic == 'data') { if (!found_header) throw LoadError("Corrupt or truncated data"); StaticBuffer sample_data(&(*buffer)[i], chunk_length); DREAM_ASSERT(decoder != NULL); return decoder(&sample_data, channel_count, bits_per_sample, sample_frequency); } else { // Unknown header i += chunk_length; } } throw LoadError("Corrupt or truncated data"); }