CDecalsDrawerGL4::CDecalsDrawerGL4() : CEventClient("[CDecalsDrawerGL4]", 314159, false) , curWorstDecalIdx(-1) , curWorstDecalRating(1e6) , maxDecals(0) , maxDecalGroups(0) , useSSBO(false) , laggedFrames(0) , overlapStage(0) , depthTex(0) , atlasTex(0) { //if (!GetDrawDecals()) { // return; //} if (!GLEW_ARB_depth_clamp) throw opengl_error(LOG_SECTION_DECALS_GL4 ": missing GL_ARB_depth_clamp"); if (!GLEW_ARB_vertex_array_object) throw opengl_error(LOG_SECTION_DECALS_GL4 ": missing GL_ARB_vertex_array_object"); if (!globalRendering->haveGLSL) throw opengl_error(LOG_SECTION_DECALS_GL4 ": missing GLSL"); if (!dynamic_cast<CSMFReadMap*>(readMap)) throw unsupported_error(LOG_SECTION_DECALS_GL4 ": only SMF supported"); if (static_cast<CSMFReadMap*>(readMap)->GetNormalsTexture() <= 0) throw unsupported_error(LOG_SECTION_DECALS_GL4 ": advanced map shading must be enabled"); DetectMaxDecals(); LoadShaders(); if (!decalShader->IsValid()) { throw opengl_error(LOG_SECTION_DECALS_GL4 ": cannot compile shader"); } glGenTextures(1, &depthTex); CreateBoundingBoxVBOs(); CreateStructureVBOs(); SunChanged(); ViewResize(); GenerateAtlasTexture(); fboOverlap.Bind(); //fboOverlap.CreateRenderBuffer(GL_COLOR_ATTACHMENT0, GL_RGBA8, OVERLAP_TEST_TEXTURE_SIZE, OVERLAP_TEST_TEXTURE_SIZE); fboOverlap.CreateRenderBuffer(GL_STENCIL_ATTACHMENT, GL_STENCIL_INDEX8, OVERLAP_TEST_TEXTURE_SIZE, OVERLAP_TEST_TEXTURE_SIZE); fboOverlap.CheckStatus(LOG_SECTION_DECALS_GL4); fboOverlap.Unbind(); eventHandler.AddClient(this); CExplosionCreator::AddExplosionListener(this); decalDrawer = this; }
static void ieee0(Void) { /* Clear all exception flags */ if (fedisableexcept(FE_ALL_EXCEPT)==-1) unsupported_error(); if (feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW)==-1) unsupported_error(); }
void CDecalsDrawerGL4::DetectMaxDecals() { // detect hw limits const int maxDecalsUBO = globalRendering->glslMaxUniformBufferSize / sizeof(SGLSLDecal); const int maxDecalsSSBO = 0xFFFFFF; // SSBO min supported size is 16MB const int maxDecalGroupsUBO = globalRendering->glslMaxUniformBufferSize / sizeof(SDecalGroup); const int maxDecalGroupsSSBO = maxDecalGroupsUBO; // groups are always saved in a UBO const int userWanted = decalLevel * 512; // detect if SSBO is needed and available if (userWanted > maxDecalsUBO) { if (GLEW_ARB_shader_storage_buffer_object) { useSSBO = true; } } // now calc the actual max usable maxDecals = (useSSBO) ? maxDecalsUBO : maxDecalsSSBO; maxDecalGroups = (useSSBO) ? maxDecalGroupsUBO : maxDecalGroupsSSBO; maxDecals = std::min({userWanted, maxDecals, maxDecalGroups}); maxDecalGroups = std::min(maxDecalGroups, maxDecals); if (maxDecals == 0 || maxDecalGroups == 0) throw unsupported_error(LOG_SECTION_DECALS_GL4 ": no UBO/SSBO"); //FIXME LOG_L(L_ERROR, "MaxDecals=%i[UBO=%i SSBO=%i] MaxDecalGroups=%i[UBO=%i SSBO=%i] useSSBO=%i", maxDecals, maxDecalsUBO, maxDecalsSSBO, maxDecalGroups, maxDecalGroupsUBO, maxDecalGroupsSSBO, int(useSSBO)); decals.resize(maxDecals); freeIds.resize(maxDecals - 1); // idx = 0 is invalid, so -1 std::iota(freeIds.begin(), freeIds.end(), 1); // start with 1, 0 is illegal std::random_shuffle(freeIds.begin(), freeIds.end()); groups.reserve(maxDecalGroups); }
void CMyMath::Init() { good_fpu_init(); for (int a = 0; a < NUM_HEADINGS; ++a) { float ang = (a - (NUM_HEADINGS / 2)) * 2 * PI / NUM_HEADINGS; float2 v; v.x = math::sin(ang); v.y = math::cos(ang); headingToVectorTable[a] = v; } unsigned checksum = 0; for (int a = 0; a < NUM_HEADINGS; ++a) { checksum = 33 * checksum + *(unsigned*) &headingToVectorTable[a].x; checksum *= 33; checksum = 33 * checksum + *(unsigned*) &headingToVectorTable[a].y; } #ifdef USE_VALGRIND if (RUNNING_ON_VALGRIND) { // Valgrind doesn't allow us setting the FPU, so syncing is impossible LOG_L(L_WARNING, "Valgrind detected sync checking disabled!"); return; } #endif #ifdef STREFLOP_H if (checksum != HEADING_CHECKSUM) { throw unsupported_error( "Invalid headingToVectorTable checksum. Most likely" " your streflop library was not compiled with the correct" " options, or you are not using streflop at all."); } #endif }