Browse Source

Added F8 as MSAA toggle in examples.

bkaradzic 13 years ago
parent
commit
35d7d2ff1b

+ 2 - 1
examples/00-helloworld/helloworld.cpp

@@ -14,6 +14,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -29,7 +30,7 @@ int _main_(int _argc, char** _argv)
 		, 0
 		);
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);

+ 15 - 17
examples/01-cubes/cubes.cpp

@@ -38,18 +38,18 @@ static PosColorVertex s_cubeVertices[8] =
 
 static const uint16_t s_cubeIndices[36] =
 {
-	0, 2, 1, // 0
-	1, 2, 3,
-	4, 5, 6, // 2
-	5, 7, 6,
-	0, 4, 2, // 4
-	4, 6, 2,
-	1, 3, 5, // 6
-	5, 3, 7,
-	0, 1, 4, // 8
-	4, 1, 5,
-	2, 6, 3, // 10
-	6, 7, 3,
+	0, 1, 2, // 0
+	1, 3, 2,
+	4, 6, 5, // 2
+	5, 6, 7,
+	0, 2, 4, // 4
+	4, 2, 6,
+	1, 5, 3, // 6
+	5, 7, 3,
+	0, 4, 1, // 8
+	4, 5, 1,
+	2, 3, 6, // 10
+	6, 3, 7,
 };
 
 static const char* s_shaderPath = NULL;
@@ -99,6 +99,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -171,7 +172,7 @@ int _main_(int _argc, char** _argv)
 	bgfx::destroyVertexShader(vsh);
 	bgfx::destroyFragmentShader(fsh);
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);
@@ -228,10 +229,7 @@ int _main_(int _argc, char** _argv)
 				bgfx::setIndexBuffer(ibh);
 
 				// Set render states.
-				bgfx::setState(BGFX_STATE_RGB_WRITE
-					|BGFX_STATE_DEPTH_WRITE
-					|BGFX_STATE_DEPTH_TEST_LESS
-					);
+				bgfx::setState(BGFX_STATE_DEFAULT);
 
 				// Submit primitive for rendering to view 0.
 				bgfx::submit(0);

+ 2 - 1
examples/02-metaballs/metaballs.cpp

@@ -499,6 +499,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -571,7 +572,7 @@ int _main_(int _argc, char** _argv)
 	const uint32_t zpitch = DIMS*DIMS;
 	const float invdim = 1.0f/float(DIMS-1);
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);

+ 7 - 6
examples/03-raymarch/raymarch.cpp

@@ -159,14 +159,14 @@ void renderScreenSpaceQuad(uint32_t _view, bgfx::ProgramHandle _program, float _
 		uint16_t* indices = (uint16_t*)tib.data;
 
 		indices[0] = 0;
-		indices[1] = 1;
-		indices[2] = 2;
+		indices[1] = 2;
+		indices[2] = 1;
 		indices[3] = 0;
-		indices[4] = 2;
-		indices[5] = 3;
+		indices[4] = 3;
+		indices[5] = 2;
 
 		bgfx::setProgram(_program);
-		bgfx::setState(BGFX_STATE_RGB_WRITE|BGFX_STATE_ALPHA_WRITE|BGFX_STATE_DEPTH_TEST_LESS|BGFX_STATE_DEPTH_WRITE);
+		bgfx::setState(BGFX_STATE_DEFAULT);
 		bgfx::setIndexBuffer(&tib);
 		bgfx::setVertexBuffer(&tvb);
 		bgfx::submit(_view);
@@ -178,6 +178,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -231,7 +232,7 @@ int _main_(int _argc, char** _argv)
 
 	bgfx::ProgramHandle raymarching = loadProgram("vs_raymarching", "fs_raymarching");
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);

+ 7 - 2
examples/04-mesh/mesh.cpp

@@ -259,9 +259,13 @@ struct Mesh
 			bgfx::setVertexBuffer(group.m_vbh);
 
 			// Set render states.
-			bgfx::setState(BGFX_STATE_RGB_WRITE
+			bgfx::setState(0
+				|BGFX_STATE_RGB_WRITE
+				|BGFX_STATE_ALPHA_WRITE
 				|BGFX_STATE_DEPTH_WRITE
 				|BGFX_STATE_DEPTH_TEST_LESS
+				|BGFX_STATE_CULL_CCW
+				|BGFX_STATE_MSAA
 				);
 
 			// Submit primitive for rendering to view 0.
@@ -279,6 +283,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -326,7 +331,7 @@ int _main_(int _argc, char** _argv)
 	Mesh mesh;
 	mesh.load("meshes/bunny.bin");
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);

+ 15 - 17
examples/05-instancing/instancing.cpp

@@ -38,18 +38,18 @@ static PosColorVertex s_cubeVertices[8] =
 
 static const uint16_t s_cubeIndices[36] =
 {
-	0, 2, 1, // 0
-	1, 2, 3,
-	4, 5, 6, // 2
-	5, 7, 6,
-	0, 4, 2, // 4
-	4, 6, 2,
-	1, 3, 5, // 6
-	5, 3, 7,
-	0, 1, 4, // 8
-	4, 1, 5,
-	2, 6, 3, // 10
-	6, 7, 3,
+	0, 1, 2, // 0
+	1, 3, 2,
+	4, 6, 5, // 2
+	5, 6, 7,
+	0, 2, 4, // 4
+	4, 2, 6,
+	1, 5, 3, // 6
+	5, 7, 3,
+	0, 4, 1, // 8
+	4, 5, 1,
+	2, 3, 6, // 10
+	6, 3, 7,
 };
 
 static const char* s_shaderPath = NULL;
@@ -99,6 +99,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -171,7 +172,7 @@ int _main_(int _argc, char** _argv)
 	bgfx::destroyVertexShader(vsh);
 	bgfx::destroyFragmentShader(fsh);
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);
@@ -244,10 +245,7 @@ int _main_(int _argc, char** _argv)
 			bgfx::setInstanceDataBuffer(idb);
 
 			// Set render states.
-			bgfx::setState(BGFX_STATE_RGB_WRITE
-				|BGFX_STATE_DEPTH_WRITE
-				|BGFX_STATE_DEPTH_TEST_LESS
-				);
+			bgfx::setState(BGFX_STATE_DEFAULT);
 
 			// Submit primitive for rendering to view 0.
 			bgfx::submit(0);

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

@@ -255,6 +255,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -347,7 +348,7 @@ int _main_(int _argc, char** _argv)
 	mem = loadTexture("fieldstone-n.dds");
 	bgfx::TextureHandle textureNormal = bgfx::createTexture(mem);
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);
@@ -447,9 +448,12 @@ int _main_(int _argc, char** _argv)
 			bgfx::setTexture(1, u_texNormal, textureNormal);
 
 			// Set render states.
-			bgfx::setState(BGFX_STATE_RGB_WRITE
+			bgfx::setState(0
+				|BGFX_STATE_RGB_WRITE
+				|BGFX_STATE_ALPHA_WRITE
 				|BGFX_STATE_DEPTH_WRITE
 				|BGFX_STATE_DEPTH_TEST_LESS
+				|BGFX_STATE_MSAA
 				);
 
 			// Submit primitive for rendering to view 0.

+ 13 - 16
examples/07-callback/callback.cpp

@@ -40,18 +40,18 @@ static PosColorVertex s_cubeVertices[8] =
 
 static const uint16_t s_cubeIndices[36] =
 {
-	0, 2, 1, // 0
-	1, 2, 3,
-	4, 5, 6, // 2
-	5, 7, 6,
-	0, 4, 2, // 4
-	4, 6, 2,
-	1, 3, 5, // 6
-	5, 3, 7,
-	0, 1, 4, // 8
-	4, 1, 5,
-	2, 6, 3, // 10
-	6, 7, 3,
+	0, 1, 2, // 0
+	1, 3, 2,
+	4, 6, 5, // 2
+	5, 6, 7,
+	0, 2, 4, // 4
+	4, 2, 6,
+	1, 5, 3, // 6
+	5, 7, 3,
+	0, 4, 1, // 8
+	4, 5, 1,
+	2, 3, 6, // 10
+	6, 3, 7,
 };
 
 static const char* s_shaderPath = NULL;
@@ -390,10 +390,7 @@ int _main_(int _argc, char** _argv)
 				bgfx::setIndexBuffer(ibh);
 
 				// Set render states.
-				bgfx::setState(BGFX_STATE_RGB_WRITE
-					|BGFX_STATE_DEPTH_WRITE
-					|BGFX_STATE_DEPTH_TEST_LESS
-					);
+				bgfx::setState(BGFX_STATE_DEFAULT);
 
 				// Submit primitive for rendering to view 0.
 				bgfx::submit(0);

+ 20 - 22
examples/08-update/update.cpp

@@ -62,23 +62,23 @@ static PosColorVertex s_cubeVertices[24] =
 
 static const uint16_t s_cubeIndices[36] =
 {
-	 0,  2,  1, // 0
-	 1,  2,  3,
-
-	 4,  5,  6, // 2
-	 5,  7,  6,
-
-	 8,  9, 10, // 4
-	 9, 11, 10,
-
-	12, 13, 14, // 6
-	14, 13, 15, 
-
-	16, 17, 18, // 8
-	18, 17, 19,
-
-	20, 21, 22, // 10
-	21, 23, 22,
+	 0,  1,  2, // 0
+	 1,  3,  2,
+		  
+	 4,  6,  5, // 2
+	 5,  6,  7,
+		  
+	 8, 10,  9, // 4
+	 9, 10, 11,
+		  
+	12, 14, 13, // 6
+	14, 15, 13, 
+		  
+	16, 18, 17, // 8
+	18, 19, 17,
+		  
+	20, 22, 21, // 10
+	21, 22, 23,
 };
 
 static const char* s_shaderPath = NULL;
@@ -128,6 +128,7 @@ int _main_(int _argc, char** _argv)
 	uint32_t width = 1280;
 	uint32_t height = 720;
 	uint32_t debug = BGFX_DEBUG_TEXT;
+	uint32_t reset = BGFX_RESET_NONE;
 
 	bgfx::init();
 	bgfx::reset(width, height);
@@ -227,7 +228,7 @@ int _main_(int _argc, char** _argv)
 
 	int64_t updateTime = 0;
 
-	while (!processEvents(width, height, debug) )
+	while (!processEvents(width, height, debug, reset) )
 	{
 		// Set view 0 default viewport.
 		bgfx::setViewRect(0, 0, 0, width, height);
@@ -318,10 +319,7 @@ int _main_(int _argc, char** _argv)
 		bgfx::setTexture(0, u_texCube, textureCube);
 
 		// Set render states.
-		bgfx::setState(BGFX_STATE_RGB_WRITE
-			|BGFX_STATE_DEPTH_WRITE
-			|BGFX_STATE_DEPTH_TEST_LESS
-			);
+		bgfx::setState(BGFX_STATE_DEFAULT);
 
 		// Submit primitive for rendering to view 0.
 		bgfx::submit(0);

+ 33 - 25
examples/common/processevents.h

@@ -6,11 +6,11 @@
 #ifndef __PROCESS_EVENTS_H__
 #define __PROCESS_EVENTS_H__
 
-inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
+inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug, uint32_t& _reset)
 {
 	using namespace entry;
 
-	bool resize = false;
+	bool reset = false;
 
 	const Event* ev;
 	do
@@ -42,27 +42,35 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
 					{
 						return true;
 					}
-					else if (key->m_key == Key::F1 && key->m_down)
+					else if (key->m_down)
 					{
-						_debug ^= BGFX_DEBUG_STATS;
-						bgfx::setDebug(_debug);
-						return false;
-					}
-					else if (key->m_key == Key::F9 && key->m_down)
-					{
-						setWindowSize(640, 480);
-						_width = 640;
-						_height = 480;
-					}
-					else if (key->m_key == Key::F10 && key->m_down)
-					{
-						setWindowSize(1280, 720);
-						_width = 1280;
-						_height = 720;
-					}
-					else if (key->m_key == Key::F11 && key->m_down)
-					{
-						toggleWindowFrame();
+						if (key->m_key == Key::F1)
+						{
+							_debug ^= BGFX_DEBUG_STATS;
+							bgfx::setDebug(_debug);
+							return false;
+						}
+						else if (key->m_key == Key::F8)
+						{
+							_reset ^= BGFX_RESET_MSAA_X16;
+							reset = true;
+						}
+						else if (key->m_key == Key::F9)
+						{
+							setWindowSize(640, 480);
+							_width = 640;
+							_height = 480;
+						}
+						else if (key->m_key == Key::F10)
+						{
+							setWindowSize(1280, 720);
+							_width = 1280;
+							_height = 720;
+						}
+						else if (key->m_key == Key::F11)
+						{
+							toggleWindowFrame();
+						}
 					}
 				}
 				break;
@@ -72,7 +80,7 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
 					const SizeEvent* size = static_cast<const SizeEvent*>(ev);
 					_width = size->m_width;
 					_height = size->m_height;
-					resize = true;
+					reset = true;
 				}
 				break;
 
@@ -82,9 +90,9 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
 		}
 	} while (NULL != ev);
 
-	if (resize)
+	if (reset)
 	{
-		bgfx::reset(_width, _height);
+		bgfx::reset(_width, _height, _reset);
 	}
 
 	return false;

+ 5 - 3
src/renderer_gl.cpp

@@ -2229,7 +2229,7 @@ namespace bgfx
 			GL_CHECK(glBindVertexArray(0) );
 		}
 
-		GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderCtx.m_backBufferFbo) );
+		GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, 0) );
 
 		s_renderCtx.updateResolution(m_render->m_resolution);
 
@@ -2286,6 +2286,8 @@ namespace bgfx
 
 		if (0 == (m_render->m_debug&BGFX_DEBUG_IFH) )
 		{
+			GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, s_renderCtx.m_backBufferFbo) );
+
 			for (uint32_t item = 0, numItems = m_render->m_num; item < numItems; ++item)
 			{
 				key.decode(m_render->m_sortKeys[item]);
@@ -2946,6 +2948,8 @@ namespace bgfx
 				}
 			}
 
+			s_renderCtx.blitMsaaFbo();
+
 			if (0 < m_render->m_num)
 			{
 				captureElapsed = -bx::getHPCounter();
@@ -2954,8 +2958,6 @@ namespace bgfx
 			}
 		}
 
-		s_renderCtx.blitMsaaFbo();
-
 		int64_t now = bx::getHPCounter();
 		elapsed += now;