diff --git a/examples/14-shadowvolumes/shadowvolumes.cpp b/examples/14-shadowvolumes/shadowvolumes.cpp index 7a921c377..9f2bd4d7f 100644 --- a/examples/14-shadowvolumes/shadowvolumes.cpp +++ b/examples/14-shadowvolumes/shadowvolumes.cpp @@ -1786,7 +1786,7 @@ void createNearClipVolume(float* __restrict _outPlanes24f bool clipTest(const float* _planes, uint8_t _planeNum, const Mesh& _mesh, const float* _scale, const float* _translate) { float (*volumePlanes)[4] = (float(*)[4])_planes; - float scale = bx::fmax(bx::fmax(_scale[0], _scale[1]), _scale[2]); + float scale = bx::max(_scale[0], _scale[1], _scale[2]); const GroupArray& groups = _mesh.m_groups; for (GroupArray::const_iterator it = groups.begin(), itEnd = groups.end(); it != itEnd; ++it) diff --git a/examples/16-shadowmaps/shadowmaps.cpp b/examples/16-shadowmaps/shadowmaps.cpp index 9656790f0..ae54e313c 100644 --- a/examples/16-shadowmaps/shadowmaps.cpp +++ b/examples/16-shadowmaps/shadowmaps.cpp @@ -2478,12 +2478,12 @@ public: bx::vec3MulMtx(lightSpaceFrustumCorner, frustumCorners[ii][jj], lightView[0]); // Update bounding box. - min[0] = bx::fmin(min[0], lightSpaceFrustumCorner[0]); - max[0] = bx::fmax(max[0], lightSpaceFrustumCorner[0]); - min[1] = bx::fmin(min[1], lightSpaceFrustumCorner[1]); - max[1] = bx::fmax(max[1], lightSpaceFrustumCorner[1]); - min[2] = bx::fmin(min[2], lightSpaceFrustumCorner[2]); - max[2] = bx::fmax(max[2], lightSpaceFrustumCorner[2]); + min[0] = bx::min(min[0], lightSpaceFrustumCorner[0]); + max[0] = bx::max(max[0], lightSpaceFrustumCorner[0]); + min[1] = bx::min(min[1], lightSpaceFrustumCorner[1]); + max[1] = bx::max(max[1], lightSpaceFrustumCorner[1]); + min[2] = bx::min(min[2], lightSpaceFrustumCorner[2]); + max[2] = bx::max(max[2], lightSpaceFrustumCorner[2]); } float minproj[3]; diff --git a/examples/18-ibl/ibl.cpp b/examples/18-ibl/ibl.cpp index d07c2d25d..3a65ab3f8 100644 --- a/examples/18-ibl/ibl.cpp +++ b/examples/18-ibl/ibl.cpp @@ -272,7 +272,7 @@ struct Camera latLongFromVec(ll[0], ll[1], toPosNorm); ll[0] += consume[0]; ll[1] -= consume[1]; - ll[1] = bx::fclamp(ll[1], 0.02f, 0.98f); + ll[1] = bx::clamp(ll[1], 0.02f, 0.98f); float tmp[3]; vecFromLatLong(tmp, ll[0], ll[1]); @@ -292,7 +292,7 @@ struct Camera void update(float _dt) { - const float amount = bx::fmin(_dt/0.12f, 1.0f); + const float amount = bx::min(_dt/0.12f, 1.0f); consumeOrbit(amount); @@ -829,7 +829,7 @@ public: bgfx::setViewRect(1, 0, 0, uint16_t(m_width), uint16_t(m_height) ); // Env rotation. - const float amount = bx::fmin(deltaTimeSec/0.12f, 1.0f); + const float amount = bx::min(deltaTimeSec/0.12f, 1.0f); m_settings.m_envRotCurr = bx::flerp(m_settings.m_envRotCurr, m_settings.m_envRotDest, amount); // Env mtx. diff --git a/examples/21-deferred/deferred.cpp b/examples/21-deferred/deferred.cpp index 6a1b13fdd..95ab71e43 100644 --- a/examples/21-deferred/deferred.cpp +++ b/examples/21-deferred/deferred.cpp @@ -580,20 +580,20 @@ public: for (uint32_t ii = 1; ii < 8; ++ii) { bx::vec3MulMtxH(xyz, box[ii], vp); - minx = bx::fmin(minx, xyz[0]); - miny = bx::fmin(miny, xyz[1]); - maxx = bx::fmax(maxx, xyz[0]); - maxy = bx::fmax(maxy, xyz[1]); - maxz = bx::fmax(maxz, xyz[2]); + minx = bx::min(minx, xyz[0]); + miny = bx::min(miny, xyz[1]); + maxx = bx::max(maxx, xyz[0]); + maxy = bx::max(maxy, xyz[1]); + maxz = bx::max(maxz, xyz[2]); } // Cull light if it's fully behind camera. if (maxz >= 0.0f) { - float x0 = bx::fclamp( (minx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width); - float y0 = bx::fclamp( (miny * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height); - float x1 = bx::fclamp( (maxx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width); - float y1 = bx::fclamp( (maxy * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height); + float x0 = bx::clamp( (minx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width); + float y0 = bx::clamp( (miny * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height); + float x1 = bx::clamp( (maxx * 0.5f + 0.5f) * m_width, 0.0f, (float)m_width); + float y1 = bx::clamp( (maxy * 0.5f + 0.5f) * m_height, 0.0f, (float)m_height); if (m_showScissorRects) { diff --git a/examples/23-vectordisplay/vectordisplay.cpp b/examples/23-vectordisplay/vectordisplay.cpp index c9b677619..ca1be8387 100644 --- a/examples/23-vectordisplay/vectordisplay.cpp +++ b/examples/23-vectordisplay/vectordisplay.cpp @@ -385,9 +385,9 @@ void VectorDisplay::endDraw() { float pa2a = normalizef(pline->a - line->a); float a2pa = normalizef(line->a - pline->a); - float maxshorten = bx::fmin(line->len, pline->len) / 2.0f; + float maxshorten = bx::min(line->len, pline->len) / 2.0f; - if (bx::fmin(a2pa, pa2a) <= (bx::kPi / 2.0f + FLT_EPSILON) ) + if (bx::min(a2pa, pa2a) <= (bx::kPi / 2.0f + FLT_EPSILON) ) { if (a2pa < pa2a) { @@ -550,8 +550,8 @@ float VectorDisplay::effectiveThickness() else { // this makes thickness=16 at 2048x1536 - float v = (0.01f * (m_screenWidth + m_screenHeight) / 2.0f) * m_drawScale / 2.0f; - return bx::fmax(v, 6.0f); + float vv = (0.01f * (m_screenWidth + m_screenHeight) / 2.0f) * m_drawScale / 2.0f; + return bx::max(vv, 6.0f); } } @@ -622,7 +622,7 @@ void VectorDisplay::drawFan(float _cx, float _cy, float _pa, float _a, float _t, if (a2pa < pa2a) { _t = -_t; - nsteps = (int)bx::fmax(1, bx::fround(a2pa / (bx::kPi / 8.0f) ) ); + nsteps = (int32_t)bx::max(1.0f, bx::fround(a2pa / (bx::kPi / 8.0f) ) ); angles = (float*)alloca(sizeof(float) * (nsteps + 1) ); for (i = 0; i <= nsteps; i++) { @@ -631,7 +631,7 @@ void VectorDisplay::drawFan(float _cx, float _cy, float _pa, float _a, float _t, } else { - nsteps = (int)bx::fmax(1, bx::fround(pa2a / (bx::kPi / 8.0f) ) ); + nsteps = (int32_t)bx::max(1.0f, bx::fround(pa2a / (bx::kPi / 8.0f) ) ); angles = (float*)alloca(sizeof(float) * (nsteps + 1) ); for (i = 0; i <= nsteps; i++) { @@ -853,14 +853,14 @@ void VectorDisplay::genLinetex() // generate { for (y = 0; y < TEXTURE_SIZE; y++) { - float distance = bx::fmin(1.0f + float distance = bx::min(1.0f , bx::fsqrt( (float)( (x - HALF_TEXTURE_SIZE) * (x - HALF_TEXTURE_SIZE) + (y - HALF_TEXTURE_SIZE) * (y - HALF_TEXTURE_SIZE) ) ) / (float)HALF_TEXTURE_SIZE ); float line = bx::fpow(16.0f, -2.0f * distance); float glow = bx::fpow( 2.0f, -4.0f * distance) / 10.0f; glow = 0; - float val = bx::fsaturate(line + glow); + float val = bx::clamp(line + glow, 0.0f, 1.0f); texbuf[(x + y * TEXTURE_SIZE) * 4 + 0] = 0xff; texbuf[(x + y * TEXTURE_SIZE) * 4 + 1] = 0xff; diff --git a/examples/27-terrain/terrain.cpp b/examples/27-terrain/terrain.cpp index 655688663..164f512b0 100644 --- a/examples/27-terrain/terrain.cpp +++ b/examples/27-terrain/terrain.cpp @@ -319,12 +319,12 @@ public: float brushAttn = m_brush.m_size - bx::fsqrt(a2 + b2); // Raise/Lower and scale by brush power. - height += 0.0f < bx::fclamp(brushAttn*m_brush.m_power, 0.0f, m_brush.m_power) && m_brush.m_raise + height += 0.0f < bx::clamp(brushAttn*m_brush.m_power, 0.0f, m_brush.m_power) && m_brush.m_raise ? 1.0f : -1.0f ; - m_terrain.m_heightMap[heightMapPos] = (uint8_t)bx::fclamp(height, 0.0f, 255.0f); + m_terrain.m_heightMap[heightMapPos] = (uint8_t)bx::clamp(height, 0.0f, 255.0f); m_terrain.m_dirty = true; } } diff --git a/examples/28-wireframe/wireframe.cpp b/examples/28-wireframe/wireframe.cpp index 9ee9524cb..9170bf3cf 100644 --- a/examples/28-wireframe/wireframe.cpp +++ b/examples/28-wireframe/wireframe.cpp @@ -116,7 +116,7 @@ struct Camera bx::vec3ToLatLong(&ll[0], &ll[1], toPosNorm); ll[0] += consume[0]; ll[1] -= consume[1]; - ll[1] = bx::fclamp(ll[1], 0.02f, 0.98f); + ll[1] = bx::clamp(ll[1], 0.02f, 0.98f); float tmp[3]; bx::vec3FromLatLong(tmp, ll[0], ll[1]); @@ -136,7 +136,7 @@ struct Camera void update(float _dt) { - const float amount = bx::fmin(_dt/0.12f, 1.0f); + const float amount = bx::min(_dt/0.12f, 1.0f); consumeOrbit(amount); diff --git a/examples/common/bounds.cpp b/examples/common/bounds.cpp index b8cfc5416..db26a1e11 100644 --- a/examples/common/bounds.cpp +++ b/examples/common/bounds.cpp @@ -134,12 +134,12 @@ void toAabb(Aabb& _aabb, const void* _vertices, uint32_t _numVertices, uint32_t float xx = position[0]; float yy = position[1]; float zz = position[2]; - min[0] = bx::fmin(xx, min[0]); - min[1] = bx::fmin(yy, min[1]); - min[2] = bx::fmin(zz, min[2]); - max[0] = bx::fmax(xx, max[0]); - max[1] = bx::fmax(yy, max[1]); - max[2] = bx::fmax(zz, max[2]); + min[0] = bx::min(xx, min[0]); + min[1] = bx::min(yy, min[1]); + min[2] = bx::min(zz, min[2]); + max[0] = bx::max(xx, max[0]); + max[1] = bx::max(yy, max[1]); + max[2] = bx::max(zz, max[2]); } _aabb.m_min[0] = min[0]; @@ -170,12 +170,12 @@ void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _num float xx = position[0]; float yy = position[1]; float zz = position[2]; - min[0] = bx::fmin(xx, min[0]); - min[1] = bx::fmin(yy, min[1]); - min[2] = bx::fmin(zz, min[2]); - max[0] = bx::fmax(xx, max[0]); - max[1] = bx::fmax(yy, max[1]); - max[2] = bx::fmax(zz, max[2]); + min[0] = bx::min(xx, min[0]); + min[1] = bx::min(yy, min[1]); + min[2] = bx::min(zz, min[2]); + max[0] = bx::max(xx, max[0]); + max[1] = bx::max(yy, max[1]); + max[2] = bx::max(zz, max[2]); } _aabb.m_min[0] = min[0]; @@ -300,7 +300,7 @@ void calcMaxBoundingSphere(Sphere& _sphere, const void* _vertices, uint32_t _num float zz = position[2] - center[2]; float distSq = xx*xx + yy*yy + zz*zz; - maxDistSq = bx::fmax(distSq, maxDistSq); + maxDistSq = bx::max(distSq, maxDistSq); } bx::vec3Move(_sphere.m_center, center); @@ -512,8 +512,8 @@ bool intersect(const Ray& _ray, const Aabb& _aabb, Hit* _hit) float max[3]; bx::vec3Max(max, t0, t1); - const float tmin = bx::fmax3(min[0], min[1], min[2]); - const float tmax = bx::fmin3(max[0], max[1], max[2]); + const float tmin = bx::max(min[0], min[1], min[2]); + const float tmax = bx::min(max[0], max[1], max[2]); if (tmax < 0.0f || tmin > tmax) diff --git a/examples/common/debugdraw/debugdraw.cpp b/examples/common/debugdraw/debugdraw.cpp index 3418dd96f..3cdf25016 100644 --- a/examples/common/debugdraw/debugdraw.cpp +++ b/examples/common/debugdraw/debugdraw.cpp @@ -1301,7 +1301,7 @@ struct DebugDraw const Attrib& attrib = m_attrib[m_stack]; const uint32_t num = getCircleLod(attrib.m_lod); const float step = bx::kPi * 2.0f / num; - _weight = bx::fclamp(_weight, 0.0f, 2.0f); + _weight = bx::clamp(_weight, 0.0f, 2.0f); float udir[3]; float vdir[3]; @@ -1348,7 +1348,7 @@ struct DebugDraw const Attrib& attrib = m_attrib[m_stack]; const uint32_t num = getCircleLod(attrib.m_lod); const float step = bx::kPi * 2.0f / num; - _weight = bx::fclamp(_weight, 0.0f, 2.0f); + _weight = bx::clamp(_weight, 0.0f, 2.0f); float xy0[2]; float xy1[2]; diff --git a/examples/common/example-glue.cpp b/examples/common/example-glue.cpp index a4f5a1cac..6bc2a9124 100644 --- a/examples/common/example-glue.cpp +++ b/examples/common/example-glue.cpp @@ -250,7 +250,7 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) const float maxWidth = 30.0f*scale; const float cpuMs = float( (encoderStats.cpuTimeEnd-encoderStats.cpuTimeBegin)*toCpuMs); - const float cpuWidth = bx::fclamp(cpuMs*scale, 1.0f, maxWidth); + const float cpuWidth = bx::clamp(cpuMs*scale, 1.0f, maxWidth); if (bar(cpuWidth, maxWidth, itemHeight, cpuColor) ) { @@ -280,8 +280,8 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) ImGui::Text("%3d %3d %s", pos, viewStats.view, viewStats.name); const float maxWidth = 30.0f*scale; - const float cpuWidth = bx::fclamp(float(viewStats.cpuTimeElapsed*toCpuMs)*scale, 1.0f, maxWidth); - const float gpuWidth = bx::fclamp(float(viewStats.gpuTimeElapsed*toGpuMs)*scale, 1.0f, maxWidth); + const float cpuWidth = bx::clamp(float(viewStats.cpuTimeElapsed*toCpuMs)*scale, 1.0f, maxWidth); + const float gpuWidth = bx::clamp(float(viewStats.gpuTimeElapsed*toGpuMs)*scale, 1.0f, maxWidth); ImGui::SameLine(64.0f); diff --git a/examples/common/imgui/imgui.cpp b/examples/common/imgui/imgui.cpp index 3a29d57ef..5c670dba2 100644 --- a/examples/common/imgui/imgui.cpp +++ b/examples/common/imgui/imgui.cpp @@ -172,11 +172,11 @@ struct OcornutImguiContext state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA); } - const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) ); - const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) ); + const uint16_t xx = uint16_t(bx::max(cmd->ClipRect.x, 0.0f) ); + const uint16_t yy = uint16_t(bx::max(cmd->ClipRect.y, 0.0f) ); bgfx::setScissor(xx, yy - , uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx) - , uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy) + , uint16_t(bx::min(cmd->ClipRect.z, 65535.0f)-xx) + , uint16_t(bx::min(cmd->ClipRect.w, 65535.0f)-yy) ); bgfx::setState(state); diff --git a/examples/common/ps/particle_system.cpp b/examples/common/ps/particle_system.cpp index 7ad93331a..5aa9a4572 100644 --- a/examples/common/ps/particle_system.cpp +++ b/examples/common/ps/particle_system.cpp @@ -345,8 +345,8 @@ namespace ps const float ttPos = easePos(particle.life); const float ttScale = easeScale(particle.life); - const float ttBlend = bx::fsaturate(easeBlend(particle.life) ); - const float ttRgba = bx::fsaturate(easeRgba(particle.life) ); + const float ttBlend = bx::clamp(easeBlend(particle.life), 0.0f, 1.0f); + const float ttRgba = bx::clamp(easeRgba(particle.life), 0.0f, 1.0f); float p0[3]; bx::vec3Lerp(p0, particle.start, particle.end[0], ttPos); diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 833923c81..37c7026ec 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -4272,7 +4272,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, uint32_t _rgba, float _depth, uint8_t _stencil) ) { - BX_CHECK(bx::fequal(_depth, bx::fclamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_CHECK(bx::fequal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); @@ -4282,7 +4282,7 @@ namespace bgfx BGFX_API_FUNC(void setViewClear(ViewId _id, uint16_t _flags, float _depth, uint8_t _stencil, uint8_t _0, uint8_t _1, uint8_t _2, uint8_t _3, uint8_t _4, uint8_t _5, uint8_t _6, uint8_t _7) ) { - BX_CHECK(bx::fequal(_depth, bx::fclamp(_depth, 0.0f, 1.0f), 0.0001f) + BX_CHECK(bx::fequal(_depth, bx::clamp(_depth, 0.0f, 1.0f), 0.0001f) , "Clear depth value must be between 0.0 and 1.0 (_depth %f)." , _depth ); diff --git a/src/topology.cpp b/src/topology.cpp index 0be14ded4..05dece9aa 100644 --- a/src/topology.cpp +++ b/src/topology.cpp @@ -223,6 +223,16 @@ namespace bgfx return 0; } + inline float fmin3(float _a, float _b, float _c) + { + return bx::min(_a, _b, _c); + } + + inline float fmax3(float _a, float _b, float _c) + { + return bx::max(_a, _b, _c); + } + inline float favg3(float _a, float _b, float _c) { return (_a + _b + _c) * 1.0f/3.0f; diff --git a/tools/texturev/texturev.cpp b/tools/texturev/texturev.cpp index 6025dcf33..931e39c05 100644 --- a/tools/texturev/texturev.cpp +++ b/tools/texturev/texturev.cpp @@ -308,7 +308,7 @@ struct View float ev = m_ev; bx::fromString(&ev, _argv[2]); - m_ev = bx::fclamp(ev, kEvMin, kEvMax); + m_ev = bx::clamp(ev, kEvMin, kEvMax); } else { @@ -406,7 +406,7 @@ struct View m_zoom = zoom; } - m_zoom = bx::fclamp(m_zoom, 0.01f, 10.0f); + m_zoom = bx::clamp(m_zoom, 0.01f, 10.0f); } else { @@ -478,7 +478,7 @@ struct View { float time; bx::fromString(&time, _argv[2]); - m_transitionTime = bx::fclamp(time, 0.0f, 5.0f); + m_transitionTime = bx::clamp(time, 0.0f, 5.0f); } else { @@ -963,7 +963,7 @@ struct InterpolatorT const double freq = double(bx::getHPFrequency() ); int64_t now = bx::getHPCounter(); float time = (float)(double(now - offset) / freq); - float lerp = bx::fclamp(time, 0.0, duration) / duration; + float lerp = bx::clamp(time, 0.0f, duration) / duration; return lerpT(from, to, easeT(lerp) ); } @@ -1782,8 +1782,8 @@ int _main_(int _argc, char** _argv) result[0] = bx::fround(bx::fabs(result[0]) ); result[1] = bx::fround(bx::fabs(result[1]) ); - scale.set(bx::fmin(float(width) / result[0] - , float(height) / result[1]) + scale.set(bx::min(float(width) / result[0] + , float(height) / result[1]) , 0.1f*view.m_transitionTime ); }