Browse Source

Fixed compile errors. Added default part of view debug name. Added example how to use view debug name.

Branimir Karadžić 11 years ago
parent
commit
208a348ab2

+ 3 - 0
examples/02-metaballs/metaballs.cpp

@@ -699,6 +699,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Set vertex and index buffer.
 		bgfx::setVertexBuffer(&tvb, 0, numVertices);
 
+		// Set render states.
+		bgfx::setState(BGFX_STATE_DEFAULT);
+
 		// Submit primitive for rendering to view 0.
 		bgfx::submit(0);
 

+ 2 - 2
examples/06-bump/bump.cpp

@@ -201,8 +201,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		float lightPosRadius[4][4];
 		for (uint32_t ii = 0; ii < numLights; ++ii)
 		{
-			lightPosRadius[ii][0] = sin( (time*(0.1f + ii*0.17f) + float(ii*M_PI_2)*1.37f ) )*3.0f;
-			lightPosRadius[ii][1] = cos( (time*(0.2f + ii*0.29f) + float(ii*M_PI_2)*1.49f ) )*3.0f;
+			lightPosRadius[ii][0] = sin( (time*(0.1f + ii*0.17f) + ii*bx::piHalf*1.37f ) )*3.0f;
+			lightPosRadius[ii][1] = cos( (time*(0.2f + ii*0.29f) + ii*bx::piHalf*1.49f ) )*3.0f;
 			lightPosRadius[ii][2] = -2.5f;
 			lightPosRadius[ii][3] = 3.0f;
 		}

+ 13 - 1
examples/09-hdr/hdr.cpp

@@ -167,6 +167,18 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		, 0
 		);
 
+	// Set view debug names.
+	bgfx::setViewName(0, "Skybox");
+	bgfx::setViewName(1, "Mesh");
+	bgfx::setViewName(2, "Luminance");
+	bgfx::setViewName(3, "Downscale luminance 0");
+	bgfx::setViewName(4, "Downscale luminance 1");
+	bgfx::setViewName(5, "Downscale luminance 2");
+	bgfx::setViewName(6, "Downscale luminance 3");
+	bgfx::setViewName(7, "Brightness");
+	bgfx::setViewName(8, "Blur vertical");
+	bgfx::setViewName(9, "Blur horizontal + tonemap");
+
 	bgfx::TextureHandle uffizi = loadTexture("uffizi.dds", BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP);
 
 	bgfx::ProgramHandle skyProgram     = loadProgram("vs_hdr_skybox",  "fs_hdr_skybox");
@@ -296,7 +308,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		// Use debug font to print information about this example.
 		bgfx::dbgTextClear();
 		bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/09-hdr");
-		bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Using multiple views and render targets.");
+		bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Using multiple views and frame buffers.");
 		bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
 
 		// Set views.

+ 1 - 1
examples/11-fontsdf/fontsdf.cpp

@@ -158,7 +158,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		}
 
 		recomputeVisibleText |= imguiSlider("Scroll", textScroll, 0.0f, (lineCount-visibleLineCount) , 1.0f);
-		imguiSlider("Rotate", textRotation, 0.0f, (float) M_PI *2.0f , 0.1f);
+		imguiSlider("Rotate", textRotation, 0.0f, bx::pi*2.0f , 0.1f);
 		recomputeVisibleText |= imguiSlider("Scale", textScale, 0.1f, 10.0f , 0.1f);
 
 		if (recomputeVisibleText)

+ 3 - 3
examples/13-stencil/stencil.cpp

@@ -1130,9 +1130,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		const float radius = (scene == StencilReflectionScene) ? 15.0f : 25.0f;
 		for (uint8_t ii = 0; ii < numLights; ++ii)
 		{
-			lightPosRadius[ii][0] = sin( (lightTimeAccumulator*1.1f + ii*0.03f + float(ii*M_PI_2)*1.07f ) )*20.0f;
-			lightPosRadius[ii][1] = 8.0f + (1.0f - cos( (lightTimeAccumulator*1.5f + ii*0.29f + float(ii*M_PI_2)*1.49f ) ))*4.0f;
-			lightPosRadius[ii][2] = cos( (lightTimeAccumulator*1.3f + ii*0.13f + float(ii*M_PI_2)*1.79f ) )*20.0f;
+			lightPosRadius[ii][0] = sin( (lightTimeAccumulator*1.1f + ii*0.03f + ii*bx::piHalf*1.07f ) )*20.0f;
+			lightPosRadius[ii][1] = 8.0f + (1.0f - cos( (lightTimeAccumulator*1.5f + ii*0.29f + bx::piHalf*1.49f ) ))*4.0f;
+			lightPosRadius[ii][2] = cos( (lightTimeAccumulator*1.3f + ii*0.13f + ii*bx::piHalf*1.79f ) )*20.0f;
 			lightPosRadius[ii][3] = radius;
 		}
 		memcpy(s_uniforms.m_lightPosRadius, lightPosRadius, numLights * 4*sizeof(float));

+ 7 - 7
examples/14-shadowvolumes/shadowvolumes.cpp

@@ -1813,7 +1813,7 @@ void createNearClipVolume(float* __restrict _outPlanes24f
 	// -1.0f - behind near plane
 	float lightSide = float( (d > delta) - (d < -delta) );
 
-	float t = tanf(_fovy*( (float)M_PI/180.0f)*0.5f) * _near;
+	float t = tanf(bx::toRad(_fovy)*0.5f) * _near;
 	float b = -t;
 	float r = t * _aspect;
 	float l = -r;
@@ -2352,9 +2352,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		{
 			for (uint8_t ii = 0; ii < settings_numLights; ++ii)
 			{
-				lightPosRadius[ii][0] = cos(2.0f*float(M_PI)/settings_numLights * float(ii) + lightTimeAccumulator * 1.1f + 3.0f) * 20.0f;
+				lightPosRadius[ii][0] = cos(2.0f*bx::pi/settings_numLights * float(ii) + lightTimeAccumulator * 1.1f + 3.0f) * 20.0f;
 				lightPosRadius[ii][1] = 20.0f;
-				lightPosRadius[ii][2] = sin(2.0f*float(M_PI)/settings_numLights * float(ii) + lightTimeAccumulator * 1.1f + 3.0f) * 20.0f;
+				lightPosRadius[ii][2] = sin(2.0f*bx::pi/settings_numLights * float(ii) + lightTimeAccumulator * 1.1f + 3.0f) * 20.0f;
 				lightPosRadius[ii][3] = 20.0f;
 			}
 		}
@@ -2362,9 +2362,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		{
 			for (uint8_t ii = 0; ii < settings_numLights; ++ii)
 			{
-				lightPosRadius[ii][0] = cos(float(ii) * 2.0f/settings_numLights + lightTimeAccumulator * 1.3f + float(M_PI) ) * 40.0f;
+				lightPosRadius[ii][0] = cos(float(ii) * 2.0f/settings_numLights + lightTimeAccumulator * 1.3f + bx::pi) * 40.0f;
 				lightPosRadius[ii][1] = 20.0f;
-				lightPosRadius[ii][2] = sin(float(ii) * 2.0f/settings_numLights + lightTimeAccumulator * 1.3f + float(M_PI) ) * 40.0f;
+				lightPosRadius[ii][2] = sin(float(ii) * 2.0f/settings_numLights + lightTimeAccumulator * 1.3f + bx::pi) * 40.0f;
 				lightPosRadius[ii][3] = 20.0f;
 			}
 		}
@@ -2495,7 +2495,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			inst.m_scale[0]    = 21.0f;
 			inst.m_scale[1]    = 21.0f;
 			inst.m_scale[2]    = 21.0f;
-			inst.m_rotation[0] = float(M_PI);
+			inst.m_rotation[0] = bx::pi;
 			inst.m_rotation[1] = 0.0f;
 			inst.m_rotation[2] = 0.0f;
 			inst.m_pos[0]      = 0.0f;
@@ -2562,7 +2562,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 				inst.m_scale[1]    = 5.0f;
 				inst.m_scale[2]    = 5.0f;
 				inst.m_rotation[0] = 0.0f;
-				inst.m_rotation[1] = float(M_PI);
+				inst.m_rotation[1] = bx::pi;
 				inst.m_rotation[2] = 0.0f;
 				inst.m_pos[0]      = currX;
 				inst.m_pos[1]      = 0.0f;

+ 1 - 1
examples/15-shadowmaps-simple/shadowmaps_simple.cpp

@@ -539,7 +539,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 		float mtxBunny[16];
 		bx::mtxSRT(mtxBunny
 			, 5.0f, 5.0f, 5.0f
-			, 0.0f, float(M_PI) - timeAccumulatorScene, 0.0f
+			, 0.0f, bx::pi - timeAccumulatorScene, 0.0f
 			, 15.0f, 5.0f, 0.0f
 			);
 

+ 3 - 3
examples/16-shadowmaps/shadowmaps.cpp

@@ -2046,7 +2046,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 	const float camAspect  = float(int32_t(viewState.m_width) ) / float(int32_t(viewState.m_height) );
 	const float camNear    = 0.1f;
 	const float camFar     = 2000.0f;
-	const float projHeight = 1.0f/tanf(camFovy*( (float)M_PI/180.0f)*0.5f);
+	const float projHeight = 1.0f/tanf(bx::toRad(camFovy)*0.5f);
 	const float projWidth  = projHeight * 1.0f/camAspect;
 	bx::mtxProj(viewState.m_proj, camFovy, camAspect, camNear, camFar);
 	cameraGetViewMtx(viewState.m_view);
@@ -2329,9 +2329,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 				, 0.0f
 				, float(ii)
 				, 0.0f
-				, sinf(float(ii)*2.0f*float(M_PI)/float(numTrees) ) * 60.0f
+				, sinf(float(ii)*2.0f*bx::pi/float(numTrees) ) * 60.0f
 				, 0.0f
-				, cosf(float(ii)*2.0f*float(M_PI)/float(numTrees) ) * 60.0f
+				, cosf(float(ii)*2.0f*bx::pi/float(numTrees) ) * 60.0f
 				);
 		}
 

+ 1 - 1
examples/18-ibl/ibl.cpp

@@ -701,7 +701,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 				, 1.0f
 				, 1.0f
 				, 0.0f
-				, (float(M_PI))+time
+				, bx::pi+time
 				, 0.0f
 				, 0.0f
 				, -1.0f

+ 1 - 1
examples/19-oit/oit.cpp

@@ -365,7 +365,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 					//mtxIdentity(mtx);
 					mtx[12] = -2.5f + float(xx)*2.5f;
 					mtx[13] = -2.5f + float(yy)*2.5f;
-					mtx[14] = -2.5f + float(zz)*2.5f; //0.0f; // sinf(time + ( (xx+1)*(yy+1)/9.0f)*float(M_PI) )*50.0f+50.0f; //90.0f - (xx+1)*(yy+1)*10.0f;
+					mtx[14] = -2.5f + float(zz)*2.5f;
 
 					// Set transform for draw call.
 					bgfx::setTransform(mtx);

+ 4 - 4
examples/21-deferred/deferred.cpp

@@ -530,10 +530,10 @@ int _main_(int /*_argc*/, char** /*_argv*/)
 			{
 				Sphere lightPosRadius;
 
-				float lightTime = time * lightAnimationSpeed * (sin(light/float(numLights) * float(M_PI_2) ) * 0.5f + 0.5f);
-				lightPosRadius.m_center[0] = sin( ( (lightTime + light*0.47f) + float(M_PI_2)*1.37f ) )*offset;
-				lightPosRadius.m_center[1] = cos( ( (lightTime + light*0.69f) + float(M_PI_2)*1.49f ) )*offset;
-				lightPosRadius.m_center[2] = sin( ( (lightTime + light*0.37f) + float(M_PI_2)*1.57f ) )*2.0f;
+				float lightTime = time * lightAnimationSpeed * (sin(light/float(numLights) * bx::piHalf ) * 0.5f + 0.5f);
+				lightPosRadius.m_center[0] = sin( ( (lightTime + light*0.47f) + bx::piHalf*1.37f ) )*offset;
+				lightPosRadius.m_center[1] = cos( ( (lightTime + light*0.69f) + bx::piHalf*1.49f ) )*offset;
+				lightPosRadius.m_center[2] = sin( ( (lightTime + light*0.37f) + bx::piHalf*1.57f ) )*2.0f;
 				lightPosRadius.m_radius = 2.0f;
 
 				Aabb aabb;

+ 0 - 7
src/bgfx.cpp

@@ -976,13 +976,6 @@ namespace bgfx
 		m_submit->m_transientVb = createTransientVertexBuffer(BGFX_CONFIG_TRANSIENT_VERTEX_BUFFER_SIZE);
 		m_submit->m_transientIb = createTransientIndexBuffer(BGFX_CONFIG_TRANSIENT_INDEX_BUFFER_SIZE);
 		frame();
-
-		for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
-		{
-			char name[256];
-			bx::snprintf(name, sizeof(name), "%02d view", ii);
-			setViewName(ii, name);
-		}
 	}
 
 	void Context::shutdown()

+ 6 - 0
src/config.h

@@ -164,6 +164,12 @@
 #	define BGFX_CONFIG_MAX_VIEWS 32
 #endif // BGFX_CONFIG_MAX_VIEWS
 
+#define BGFX_CONFIG_MAX_VIEW_NAME_RESERVED 5
+
+#ifndef BGFX_CONFIG_MAX_VIEW_NAME
+#	define BGFX_CONFIG_MAX_VIEW_NAME 256
+#endif // BGFX_CONFIG_MAX_VIEW_NAME
+
 #ifndef BGFX_CONFIG_MAX_VERTEX_DECLS
 #	define BGFX_CONFIG_MAX_VERTEX_DECLS 64
 #endif // BGFX_CONFIG_MAX_VERTEX_DECLS

+ 13 - 2
src/renderer_d3d11.cpp

@@ -15,7 +15,7 @@
 
 namespace bgfx
 {
-	static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][256];
+	static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
 
 	struct PrimInfo
 	{
@@ -770,6 +770,14 @@ RENDERDOC_IMPORT
 				g_caps.formats[ii] = DXGI_FORMAT_UNKNOWN == s_textureFormat[ii].m_fmt ? 0 : 1;
 			}
 
+			// Init reserved part of view name.
+			for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
+			{
+				char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1];
+				bx::snprintf(name, sizeof(name), "%3d  ", ii);
+				mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED);
+			}
+
 			updateMsaa();
 			postReset();
 		}
@@ -1036,7 +1044,10 @@ RENDERDOC_IMPORT
 
 		void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE
 		{
-			mbstowcs(&s_viewNameW[_id][0], _name, BX_COUNTOF(s_viewNameW[0]) );
+			mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
+				, _name
+				, BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
+				);
 		}
 
 		void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE

+ 13 - 2
src/renderer_d3d9.cpp

@@ -10,7 +10,7 @@
 
 namespace bgfx
 {
-	static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][256];
+	static wchar_t s_viewNameW[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
 
 	struct PrimInfo
 	{
@@ -566,6 +566,14 @@ namespace bgfx
 				DX_RELEASE(swapChain, 0);
 			}
 
+			// Init reserved part of view name.
+			for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
+			{
+				char name[BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1];
+				bx::snprintf(name, sizeof(name), "%3d  ", ii);
+				mbstowcs(s_viewNameW[ii], name, BGFX_CONFIG_MAX_VIEW_NAME_RESERVED);
+			}
+
 			postReset();
 
 			m_initialized = true;
@@ -838,7 +846,10 @@ namespace bgfx
 
 		void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE
 		{
-			mbstowcs(&s_viewNameW[_id][0], _name, BX_COUNTOF(s_viewNameW[0]) );
+			mbstowcs(&s_viewNameW[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
+				, _name
+				, BX_COUNTOF(s_viewNameW[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
+				);
 		}
 
 		void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE

+ 11 - 2
src/renderer_gl.cpp

@@ -12,7 +12,7 @@
 
 namespace bgfx
 {
-	static char s_viewName[BGFX_CONFIG_MAX_VIEWS][256];
+	static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
 
 	struct PrimInfo
 	{
@@ -1357,6 +1357,12 @@ namespace bgfx
 			{
 				m_queries.create();
 			}
+
+			// Init reserved part of view name.
+			for (uint8_t ii = 0; ii < BGFX_CONFIG_MAX_VIEWS; ++ii)
+			{
+				bx::snprintf(s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED+1, "%3d  ", ii);
+			}
 		}
 
 		void shutdown()
@@ -1598,7 +1604,10 @@ namespace bgfx
 
 		void updateViewName(uint8_t _id, const char* _name) BX_OVERRIDE
 		{
-			bx::strlcpy(&s_viewName[_id][0], _name, BX_COUNTOF(s_viewName[0]) );
+			bx::strlcpy(&s_viewName[_id][BGFX_CONFIG_MAX_VIEW_NAME_RESERVED]
+				, _name
+				, BX_COUNTOF(s_viewName[0])-BGFX_CONFIG_MAX_VIEW_NAME_RESERVED
+				);
 		}
 
 		void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE