/** * For RECT textures / unnormalized texcoords. * Only a subset of wrap modes supported. */ static INLINE void linear_texcoord_unnorm_4(unsigned wrapMode, const float s[4], unsigned size, int icoord0[4], int icoord1[4], float w[4]) { uint ch; switch (wrapMode) { case PIPE_TEX_WRAP_CLAMP: for (ch = 0; ch < 4; ch++) { /* Not exactly what the spec says, but it matches NVIDIA output */ float u = CLAMP(s[ch] - 0.5F, 0.0f, (float) size - 1.0f); icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; w[ch] = FRAC(u); } return; case PIPE_TEX_WRAP_CLAMP_TO_EDGE: /* fall-through */ case PIPE_TEX_WRAP_CLAMP_TO_BORDER: for (ch = 0; ch < 4; ch++) { float u = CLAMP(s[ch], 0.5F, (float) size - 0.5F); u -= 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; if (icoord1[ch] > (int) size - 1) icoord1[ch] = size - 1; w[ch] = FRAC(u); } break; default: assert(0); } }
static void ConvertOriginBrush(FILE * f, int num, vec3_t origin) { char pattern[6][5][4] = { {"+++", "+-+", "-++", " - ", "- "}, {"+++", "-++", "++-", "+ ", " +"}, {"+++", "++-", "+-+", " - ", " +"}, {"---", "+--", "-+-", " - ", "+ "}, {"---", "--+", "+--", "- ", " +"}, {"---", "-+-", "--+", " + ", " +"} }; int i; #define S(a,b,c) (pattern[a][b][c] == '+' ? +1 : pattern[a][b][c] == '-' ? -1 : 0) #define FRAC(x) ((x) - floor(x)) /* start brush */ fprintf(f, "\t// brush %d\n", num); fprintf(f, "\t{\n"); fprintf(f, "\tbrushDef\n"); fprintf(f, "\t{\n"); /* print brush side */ /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */ for(i = 0; i < 6; ++i) fprintf(f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( ( %.8f %.8f %.8f ) ( %.8f %.8f %.8f ) ) %s %d 0 0\n", origin[0] + 8 * S(i, 0, 0), origin[1] + 8 * S(i, 0, 1), origin[2] + 8 * S(i, 0, 2), origin[0] + 8 * S(i, 1, 0), origin[1] + 8 * S(i, 1, 1), origin[2] + 8 * S(i, 1, 2), origin[0] + 8 * S(i, 2, 0), origin[1] + 8 * S(i, 2, 1), origin[2] + 8 * S(i, 2, 2), 1 / 16.0, 0.0, FRAC((S(i, 3, 0) * origin[0] + S(i, 3, 1) * origin[1] + S(i, 3, 2) * origin[2]) / 16.0 + 0.5), 0.0, 1 / 16.0, FRAC((S(i, 4, 0) * origin[0] + S(i, 4, 1) * origin[1] + S(i, 4, 2) * origin[2]) / 16.0 + 0.5), "common/origin", 0); #undef FRAC #undef S /* end brush */ fprintf(f, "\t}\n"); fprintf(f, "\t}\n\n"); }
/** * Do several things here: * 1. Compute lambda from the texcoords, if needed * 2. Determine if we're minifying or magnifying * 3. If minifying, choose mipmap levels * 4. Return image filter to use within mipmap images * \param level0 Returns first mipmap level to sample from * \param level1 Returns second mipmap level to sample from * \param levelBlend Returns blend factor between levels, in [0,1] * \param imgFilter Returns either the min or mag filter, depending on lambda */ static void choose_mipmap_levels(const struct pipe_texture *texture, const struct pipe_sampler_state *sampler, const float s[QUAD_SIZE], const float t[QUAD_SIZE], const float p[QUAD_SIZE], boolean computeLambda, float lodbias, unsigned *level0, unsigned *level1, float *levelBlend, unsigned *imgFilter) { if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NONE) { /* no mipmap selection needed */ *level0 = *level1 = CLAMP((int) sampler->min_lod, 0, (int) texture->last_level); if (sampler->min_img_filter != sampler->mag_img_filter) { /* non-mipmapped texture, but still need to determine if doing * minification or magnification. */ float lambda = compute_lambda(texture, sampler, s, t, p, lodbias); if (lambda <= 0.0) { *imgFilter = sampler->mag_img_filter; } else { *imgFilter = sampler->min_img_filter; } } else { *imgFilter = sampler->mag_img_filter; } } else { float lambda; if (computeLambda) /* fragment shader */ lambda = compute_lambda(texture, sampler, s, t, p, lodbias); else /* vertex shader */ lambda = lodbias; /* not really a bias, but absolute LOD */ if (lambda <= 0.0) { /* XXX threshold depends on the filter */ /* magnifying */ *imgFilter = sampler->mag_img_filter; *level0 = *level1 = 0; } else { /* minifying */ *imgFilter = sampler->min_img_filter; /* choose mipmap level(s) and compute the blend factor between them */ if (sampler->min_mip_filter == PIPE_TEX_MIPFILTER_NEAREST) { /* Nearest mipmap level */ const int lvl = (int) (lambda + 0.5); *level0 = *level1 = CLAMP(lvl, 0, (int) texture->last_level); } else { /* Linear interpolation between mipmap levels */ const int lvl = (int) lambda; *level0 = CLAMP(lvl, 0, (int) texture->last_level); *level1 = CLAMP(lvl + 1, 0, (int) texture->last_level); *levelBlend = FRAC(lambda); /* blending weight between levels */ } } } }
/** * Used to compute texel locations for linear sampling for four texcoords. * \param wrapMode PIPE_TEX_WRAP_x * \param s the texcoords * \param size the texture image size * \param icoord0 returns first texture indexes * \param icoord1 returns second texture indexes (usually icoord0 + 1) * \param w returns blend factor/weight between texture indexes * \param icoord returns the computed integer texture coords */ static INLINE void linear_texcoord_4(unsigned wrapMode, const float s[4], unsigned size, int icoord0[4], int icoord1[4], float w[4]) { uint ch; switch (wrapMode) { case PIPE_TEX_WRAP_REPEAT: for (ch = 0; ch < 4; ch++) { float u = s[ch] * size - 0.5F; icoord0[ch] = REMAINDER(util_ifloor(u), size); icoord1[ch] = REMAINDER(icoord0[ch] + 1, size); w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_CLAMP: for (ch = 0; ch < 4; ch++) { float u = CLAMP(s[ch], 0.0F, 1.0F); u = u * size - 0.5f; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_CLAMP_TO_EDGE: for (ch = 0; ch < 4; ch++) { float u = CLAMP(s[ch], 0.0F, 1.0F); u = u * size - 0.5f; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; if (icoord0[ch] < 0) icoord0[ch] = 0; if (icoord1[ch] >= (int) size) icoord1[ch] = size - 1; w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_CLAMP_TO_BORDER: { const float min = -1.0F / (2.0F * size); const float max = 1.0F - min; for (ch = 0; ch < 4; ch++) { float u = CLAMP(s[ch], min, max); u = u * size - 0.5f; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; w[ch] = FRAC(u); } } break;; case PIPE_TEX_WRAP_MIRROR_REPEAT: for (ch = 0; ch < 4; ch++) { const int flr = util_ifloor(s[ch]); float u; if (flr & 1) u = 1.0F - (s[ch] - (float) flr); else u = s[ch] - (float) flr; u = u * size - 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; if (icoord0[ch] < 0) icoord0[ch] = 0; if (icoord1[ch] >= (int) size) icoord1[ch] = size - 1; w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_MIRROR_CLAMP: for (ch = 0; ch < 4; ch++) { float u = fabsf(s[ch]); if (u >= 1.0F) u = (float) size; else u *= size; u -= 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE: for (ch = 0; ch < 4; ch++) { float u = fabsf(s[ch]); if (u >= 1.0F) u = (float) size; else u *= size; u -= 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; if (icoord0[ch] < 0) icoord0[ch] = 0; if (icoord1[ch] >= (int) size) icoord1[ch] = size - 1; w[ch] = FRAC(u); } break;; case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER: { const float min = -1.0F / (2.0F * size); const float max = 1.0F - min; for (ch = 0; ch < 4; ch++) { float u = fabsf(s[ch]); if (u <= min) u = min * size; else if (u >= max) u = max * size; else u *= size; u -= 0.5F; icoord0[ch] = util_ifloor(u); icoord1[ch] = icoord0[ch] + 1; w[ch] = FRAC(u); } } break;; default: assert(0); } }
void MapWidget::paintGL() { QTime time; time.start(); g_debugWidget->reset(); g_dataResource->getMapObject()->newFrame(); if (m_width < 1 || m_height < 1) { return; } QOpenGLFunctions gl(context()); m_transform.setGl(&gl); m_transform.setTransform(m_width, m_height, *m_transform.getMapParam()); glClearColor(0.05, 0.05, 0.1f, 1); glClear(GL_COLOR_BUFFER_BIT); glEnable(GL_MULTISAMPLE); double starPlus = m_transform.getMapParam()->m_starMagAdd; QEasingCurve curve(QEasingCurve::InExpo); m_transform.getMapParam()->m_maxStarMag = starPlus + 5 + 12.0 * curve.valueForProgress(FRAC(m_transform.getMapParam()->m_fov, SkMath::toRad(90), SkMath::toRad(0.5))); m_transform.getMapParam()->m_fov = CLAMP(m_transform.getMapParam()->m_fov, SkMath::toRad(0.01), R90); //qDebug() << m_transform.getMapParam()->m_maxStarMag; //qDebug() << SkMath::toDeg(m_transform.getMapParam()->m_fov); m_renderer->render(&m_transform); /* QPainter p; m_overlayImage->fill(Qt::transparent); static int a = 100; a++; p.begin(m_overlayImage); p.setRenderHint(QPainter::Antialiasing); p.setPen(Qt::green); p.drawLine(0, 0, 1000, 1000); p.drawLine(500, 10, 5000, 1000); p.fillRect(QRect(10, 10, 100, 100 + a), QColor(255, 255, 0, 128)); p.end(); m_painterOverlay->render(&m_transform, m_overlayImage); */ g_debugWidget->addText("FSP", QString::number(1000 / (float)time.elapsed())); //qDebug() << time.elapsed() << 1000 / (float)time.elapsed(); //qDebug() << SkMath::toDeg(mapParam.m_fov); writeDebug(); }
/*================================================================================================== * count_merger: * * for each halo stored in mtree[].* we count the number of progenitors * complying with our criterion for a merger * *==================================================================================================*/ uint64_t count_merger(MTREE *mtree, uint64_t nhalos, uint64_t *nhalos_M0) { uint64_t ihalo, iprog, halo_nmerger; halo_nmerger = 0; double frac, frac_max; *nhalos_M0 = 0; // loop over all haloes for(ihalo=0; ihalo<nhalos; ihalo++) { // reset counter for mergers for this halo to zero mtree[ihalo].nmerger = 0; // set array of merging progenitor ids to NULL mtree[ihalo].iprogmerger = NULL; // 1. check: is the actual progenitor a meaningful progenitor if( mtree[ihalo].npart > M0 ) { // count the number of halos above our "mass" criterion (*nhalos_M0)++; #ifdef GOTTLOEBER_CRITERION // is there at least 1 progenitor if(mtree[ihalo].nprog > 0) { // mass ratio with the most likely progenitor frac_max = FRAC((double)mtree[ihalo].npartprog[0]/(double)mtree[ihalo].npart); // or search for the largest fraction for(iprog=1; iprog<MIN(GOTTLOEBER_CRITERION,mtree[ihalo].nprog); iprog++) { frac = FRAC((double)mtree[ihalo].npartprog[0]/(double)mtree[ihalo].npart); if(frac > frac_max) frac_max = frac; } if((1.-frac_max) > MERGER_RATIO) { // increase the number of mergers for this halo and store the merging progenitor iprog mtree[ihalo].nmerger++; mtree[ihalo].iprogmerger = (uint64_t *) realloc(mtree[ihalo].iprogmerger, mtree[ihalo].nmerger*sizeof(uint64_t)); mtree[ihalo].iprogmerger[mtree[ihalo].nmerger-1] = iprog; // increase the number of total mergers halo_nmerger++; } } #else // GOTTLOEBER_CRITERION // are there at least 2 progenitors to check? if(mtree[ihalo].nprog > 1) { // loop over all progenitor but the actual main progenitor for(iprog=1; iprog<MIN(MAX_NPROG_FOR_MERGER_CHECK,mtree[ihalo].nprog); iprog++) { // 2. check: is this progenitor a meaningful progenitor if( mtree[ihalo].npartprog[iprog] > Mi ) { // 3. check: physical definition of a merger frac = (double)mtree[ihalo].npartprog[iprog]/(double)(mtree[ihalo].npartprog[0]); if(FRAC(frac) > MERGER_RATIO){ // increase the number of mergers for this halo and store the merging progenitor iprog mtree[ihalo].nmerger++; mtree[ihalo].iprogmerger = (uint64_t *) realloc(mtree[ihalo].iprogmerger, mtree[ihalo].nmerger*sizeof(uint64_t)); mtree[ihalo].iprogmerger[mtree[ihalo].nmerger-1] = iprog; // increase the number of total mergers halo_nmerger++; // one halo is only allowed to have one merger at a time break; // this will leave the for(iprog)-loop } // if(MERGER_RATIO) } // if(mtree[ihalo].npartprog[iprog] > Mi) } // for(iprog) } // if(mtree[ihalo].npart > M0) #endif // GOTTLOEBER_CRITERION } // if(nprog>0) } // for(ihalo) return(halo_nmerger); }
/* Adapted from * http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm */ static void _drawaaline (SDL_Surface* surface, Uint32 color, int x1, int _y1, int x2, int y2, int blend) { float grad, xd, yd; float xgap, ygap, xend, yend, xf, yf; float brightness1, brightness2; float swaptmp; int x, y, ix1, ix2, iy1, iy2; int pixx, pixy; Uint8* pixel; Uint8* pm = (Uint8*)surface->pixels; Uint8* colorptr = (Uint8*)&color; const int hasalpha = surface->format->Amask; pixx = surface->format->BytesPerPixel; pixy = surface->pitch; xd = x2 - x1; yd = y2 - _y1; if (xd == 0 && yd == 0) { /* Single point. Due to the nature of the aaline clipping, this * is less exact than the normal line. */ SET_PIXEL_AT (surface, surface->format, x1, _y1, color); return; } if (SDL_BYTEORDER == SDL_BIG_ENDIAN) color <<= 8; if (fabs (xd) > fabs (yd)) { if (x1 > x2) { swaptmp = x1; x1 = x2; x2 = swaptmp; swaptmp = _y1; _y1 = y2; y2 = swaptmp; xd = x2 - x1; yd = y2 - _y1; } grad = yd / xd; /* This makes more sense than trunc(x1+0.5) */ xend = trunc ((float)x1) + 0.5; yend = _y1 + grad * (xend - x1); xgap = INVFRAC ((float)x1); ix1 = (int)xend; iy1 = (int)yend; yf = yend + grad; brightness1 = INVFRAC (yend) * xgap; brightness2 = FRAC (yend) * xgap; pixel = pm + pixx * ix1 + pixy * iy1; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixy; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); xend = trunc ((float)x2) + 0.5; yend = y2 + grad * (xend - x2); /* this also differs from Hugo's description. */ xgap = FRAC ((float)x2); ix2 = (int)xend; iy2 = (int)yend; brightness1 = INVFRAC (yend) * xgap; brightness2 = FRAC (yend) * xgap; pixel = pm + pixx * ix2 + pixy * iy2; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixy; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); for (x = ix1 + 1; x < ix2; ++x) { brightness1 = INVFRAC (yf); brightness2 = FRAC (yf); pixel = pm + pixx * x + pixy * (int)yf; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixy; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); yf += grad; } } else { if (_y1 > y2) { swaptmp = _y1; _y1 = y2; y2 = swaptmp; swaptmp = x1; x1 = x2; x2 = swaptmp; yd = y2 - _y1; xd = x2 - x1; } grad = xd / yd; /* This makes more sense than trunc(x1+0.5) */ yend = trunc ((float)_y1) + .5; xend = x1 + grad * (yend - _y1); ygap = INVFRAC ((float)_y1); iy1 = (int)yend; ix1 = (int)xend; xf = xend + grad; brightness1 = INVFRAC (xend) * ygap; brightness2 = FRAC (xend) * ygap; pixel = pm + pixx * ix1 + pixy * iy1; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixx; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); yend = trunc ((float)y2) + 0.5; xend = x2 + grad * (yend - y2); ygap = FRAC ((float)y2); iy2 = (int)yend; ix2 = (int)xend; brightness1 = INVFRAC (xend) * ygap; brightness2 = FRAC (xend) * ygap; pixel = pm + pixx * ix2 + pixy * iy2; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixx; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); for (y = iy1 + 1; y < iy2; ++y) { brightness1 = INVFRAC (xf); brightness2 = FRAC (xf); pixel = pm + pixx * (int)xf + pixy * y; DRAWPIX32 (pixel, colorptr, brightness1, blend, hasalpha); pixel += pixx; DRAWPIX32 (pixel, colorptr, brightness2, blend, hasalpha); xf += grad; } } }