Panagiotis Christopoulos Charitos 12 년 전
부모
커밋
b57a8b8b2c
10개의 변경된 파일106개의 추가작업 그리고 32개의 파일을 삭제
  1. 2 1
      CMakeLists.txt
  2. 3 3
      include/anki/core/NativeWindow.h
  3. 2 1
      include/anki/gl/Fbo.h
  4. 1 1
      shaders/IsCommon.glsl
  5. 17 14
      shaders/IsLp.glsl
  6. 4 1
      src/core/NativeWindowAndroid.cpp
  7. 19 1
      src/gl/Fbo.cpp
  8. 45 0
      src/gl/ShaderProgram.cpp
  9. 4 6
      src/renderer/Is.cpp
  10. 9 4
      tools/texture/ankitexture.py

+ 2 - 1
CMakeLists.txt

@@ -98,7 +98,8 @@ IF(${ANKI_BUILD_TYPE} STREQUAL "Debug")
 ELSE()
 	# Release
 
-	SET(COMPILER_FLAGS "${COMPILER_FLAGS} -ffast-math -O4 -flto -DNODEBUG ")
+	# -flto ?
+	SET(COMPILER_FLAGS "${COMPILER_FLAGS} -ffast-math -O4 -DNODEBUG ")
 
 	# Add this because Android compiler complains
 	IF(ANDROID)

+ 3 - 3
include/anki/core/NativeWindow.h

@@ -17,9 +17,9 @@ struct NativeWindowInitializer
 {
 	U32 width = 640;
 	U32 height = 768;
-	Array<U32, 4> rgbaBits = {{8, 8, 8, 8}};
-	U32 depthBits = 24;
-	U32 stencilBits = 8;
+	Array<U32, 4> rgbaBits = {{8, 8, 8, 0}};
+	U32 depthBits = 0;
+	U32 stencilBits = 0;
 	U32 samplesCount = 0;
 	static const Bool doubleBuffer = true;
 	/// Create a fullscreen window with the desktop's resolution

+ 2 - 1
include/anki/gl/Fbo.h

@@ -64,7 +64,8 @@ public:
 
 	/// Unbind all targets. Unbinds both draw and read FBOs so the active is
 	/// the default FBO
-	static void bindDefault(const FboTarget target = FT_ALL);
+	static void bindDefault(const FboTarget target = FT_ALL,
+		Bool noReadbacks = false);
 
 	/// Returns true if the FBO is ready for draw calls
 	Bool isComplete() const;

+ 1 - 1
shaders/IsCommon.glsl

@@ -33,7 +33,7 @@ struct Tile
 // The base of all lights
 struct Light
 {
-	vec4 posRadius; // xyz: Light pos in eye space. w: The radius
+	vec4 posRadius; // xyz: Light pos in eye space. w: The -1/radius
 	vec4 diffuseColorShadowmapId; // xyz: diff color, w: shadowmap tex ID
 	vec4 specularColorTexId; // xyz: spec color, w: diffuse tex ID
 };

+ 17 - 14
shaders/IsLp.glsl

@@ -18,9 +18,11 @@ out vec2 vLimitsOfNearPlaneOpt;
 
 void main()
 {
+	float instIdF = float(gl_InstanceID);
+
 	vec2 ij = vec2(
-		float(gl_InstanceID % TILES_X_COUNT), 
-		float(gl_InstanceID / TILES_X_COUNT));
+		mod(instIdF, float(TILES_X_COUNT)), 
+		floor(instIdF / float(TILES_X_COUNT)));
 
 	vInstanceId = int(gl_InstanceID);
 
@@ -171,9 +173,7 @@ vec3 calcPhong(in vec3 fragPosVspace, in vec3 diffuse,
 //==============================================================================
 float calcSpotFactor(in SpotLight light, in vec3 frag2LightVec)
 {
-	vec3 l = -frag2LightVec;
-
-	float costheta = dot(l, light.lightDir.xyz);
+	float costheta = -dot(frag2LightVec, light.lightDir.xyz);
 	float spotFactor = smoothstep(
 		light.outerCosInnerCos.x, 
 		light.outerCosInnerCos.y, 
@@ -240,14 +240,17 @@ void main()
 	// Ambient color
 	fColor = diffColor * sceneAmbientColor.rgb;
 
+	//Tile tile = tiles[vInstanceId];
+	#define tile tiles[vInstanceId]
+
 	// Point lights
-	uint pointLightsCount = tiles[vInstanceId].lightsCount[0];
+	uint pointLightsCount = tile.lightsCount[0];
 	for(uint i = 0U; i < pointLightsCount; ++i)
 	{
 #if __VERSION__ > 430
-		uint lightId = tiles[vInstanceId].pointLightIndices[i];
+		uint lightId = tile.pointLightIndices[i];
 #else
-		uint lightId = tiles[vInstanceId].pointLightIndices[i / 4U][i % 4U];
+		uint lightId = tile.pointLightIndices[i / 4U][i % 4U];
 #endif
 		PointLight light = pointLights[lightId];
 
@@ -261,14 +264,14 @@ void main()
 	}
 
 	// Spot lights
-	uint spotLightsCount = tiles[vInstanceId].lightsCount[2];
+	uint spotLightsCount = tile.lightsCount[2];
 
 	for(uint i = 0U; i < spotLightsCount; ++i)
 	{
 #if __VERSION__ > 430
-		uint lightId = tiles[vInstanceId].spotLightIndices[i];
+		uint lightId = tile.spotLightIndices[i];
 #else
-		uint lightId = tiles[vInstanceId].spotLightIndices[i / 4U][i % 4U];
+		uint lightId = tile.spotLightIndices[i / 4U][i % 4U];
 #endif
 		SpotLight light = spotLights[lightId];
 
@@ -287,14 +290,14 @@ void main()
 	}
 
 	// Spot lights with shadow
-	uint spotTexLightsCount = tiles[vInstanceId].lightsCount[3];
+	uint spotTexLightsCount = tile.lightsCount[3];
 
 	for(uint i = 0U; i < spotTexLightsCount; ++i)
 	{
 #if __VERSION__ > 430
-		uint lightId = tiles[vInstanceId].spotTexLightIndices[i];
+		uint lightId = tile.spotTexLightIndices[i];
 #else
-		uint lightId = tiles[vInstanceId].spotTexLightIndices[i / 4U][i % 4U];
+		uint lightId = tile.spotTexLightIndices[i / 4U][i % 4U];
 #endif
 		SpotTexLight light = spotTexLights[lightId];
 

+ 4 - 1
src/core/NativeWindowAndroid.cpp

@@ -4,6 +4,7 @@
 #include "anki/util/Exception.h"
 #include "anki/util/Array.h"
 #include "anki/util/StdTypes.h"
+#include "anki/core/Counters.h"
 
 namespace anki {
 
@@ -65,7 +66,7 @@ void NativeWindowImpl::create(NativeWindowInitializer& init)
 	// EGL config
 	//  
 	attribs[attr++] = EGL_SURFACE_TYPE;
-	attribs[attr++] = EGL_WINDOW_BIT,
+	attribs[attr++] = EGL_WINDOW_BIT;
 
 	attribs[attr++] = EGL_RENDERABLE_TYPE;
 	attribs[attr++] = EGL_OPENGL_ES2_BIT;
@@ -192,11 +193,13 @@ void NativeWindow::destroy()
 //==============================================================================
 void NativeWindow::swapBuffers()
 {
+	ANKI_COUNTER_START_TIMER(C_SWAP_BUFFERS_TIME);
 	ANKI_ASSERT(isCreated());
 	if(eglSwapBuffers(impl->display, impl->surface) == EGL_FALSE)
 	{
 		throw ANKI_EXCEPTION("eglSwapBuffers() failed");
 	}
+	ANKI_COUNTER_STOP_TIMER_INC(C_SWAP_BUFFERS_TIME);
 }
 
 } // end namespace anki

+ 19 - 1
src/gl/Fbo.cpp

@@ -87,7 +87,7 @@ void Fbo::bind(const FboTarget target, Bool noReadbacks) const
 }
 
 //==============================================================================
-void Fbo::bindDefault(const FboTarget target)
+void Fbo::bindDefault(const FboTarget target, Bool noReadbacks)
 {
 	if(target == FT_ALL)
 	{
@@ -96,6 +96,14 @@ void Fbo::bindDefault(const FboTarget target)
 			glBindFramebuffer(GL_FRAMEBUFFER, 0);
 			currentDraw = currentRead = nullptr;
 		}
+
+#if ANKI_GL == ANKI_GL_ES
+		if(noReadbacks)
+		{
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT 
+				| GL_STENCIL_BUFFER_BIT);
+		}
+#endif
 	}
 	else if(target == FT_DRAW)
 	{
@@ -104,6 +112,14 @@ void Fbo::bindDefault(const FboTarget target)
 			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
 			currentDraw = nullptr;
 		}
+
+#if ANKI_GL == ANKI_GL_ES
+		if(noReadbacks)
+		{
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT 
+				| GL_STENCIL_BUFFER_BIT);
+		}
+#endif
 	}
 	else
 	{
@@ -113,6 +129,8 @@ void Fbo::bindDefault(const FboTarget target)
 			glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
 			currentRead = nullptr;
 		}
+
+		ANKI_ASSERT(noReadbacks == false && "Doesn't make sense");
 	}
 }
 

+ 45 - 0
src/gl/ShaderProgram.cpp

@@ -10,6 +10,13 @@
 #include <sstream>
 #include <iomanip>
 
+#define ANKI_DUMP_SHADERS ANKI_DEBUG
+
+#if ANKI_DUMP_SHADERS
+#	include "anki/core/App.h"
+#	include "anki/util/File.h"
+#endif
+
 namespace anki {
 
 //==============================================================================
@@ -546,6 +553,44 @@ GLuint ShaderProgram::createAndCompileShader(const char* sourceCode,
 	fullSrc += sourceCode;
 	sourceStrs[0] = fullSrc.c_str();
 
+#if ANKI_DUMP_SHADERS
+	{
+		const char* ext = nullptr;
+		switch(type)
+		{
+		case GL_VERTEX_SHADER:
+			ext = ".vert";
+			break;
+		case GL_FRAGMENT_SHADER:
+			ext = ".frag";
+			break;
+#	if ANKI_GL == ANKI_GL_DESKTOP
+		case GL_TESS_EVALUATION_SHADER:
+			ext = ".te";
+			break;
+		case GL_TESS_CONTROL_SHADER:
+			ext = ".tc";
+			break;
+		case GL_GEOMETRY_SHADER:
+			ext = ".geom";
+			break;
+		case GL_COMPUTE_SHADER:
+			ext = ".comp";
+			break;
+#	endif
+		default:
+			ANKI_ASSERT(0);
+		}
+
+		File file(
+			(AppSingleton::get().getCachePath() + "/" 
+			+ std::to_string(shader) + ext).c_str(), 
+			File::OF_WRITE);
+
+		file.writeText("%s", fullSrc.c_str());
+	}
+#endif
+
 	// compile
 	glShaderSource(shader, 1, sourceStrs, NULL);
 	glCompileShader(shader);

+ 4 - 6
src/renderer/Is.cpp

@@ -830,11 +830,11 @@ void Is::lightPass()
 	// shader prog
 	lightPassProg->bind();
 
+	commonUbo.setBinding(COMMON_UNIFORMS_BLOCK_BINDING);
+
 	lightPassProg->findUniformVariable("limitsOfNearPlane").set(
 		Vec4(r->getLimitsOfNearPlane(), r->getLimitsOfNearPlane2()));
 
-	commonUbo.setBinding(COMMON_UNIFORMS_BLOCK_BINDING);
-
 	if(pointLightsSize > 0)
 	{
 		lightsUbo.setBindingRange(POINT_LIGHTS_BLOCK_BINDING, pointLightsOffset,
@@ -874,21 +874,19 @@ void Is::setState()
 
 	if(drawToDefaultFbo)
 	{
-		Fbo::bindDefault();
+		Fbo::bindDefault(Fbo::FT_ALL, true);
 
 		GlStateSingleton::get().setViewport(
 			0, 0, r->getWindowWidth(), r->getWindowHeight());
 	}
 	else
 	{
-		fbo.bind();
+		fbo.bind(Fbo::FT_ALL, true);
 
 		GlStateSingleton::get().setViewport(
 			0, 0, r->getWidth(), r->getHeight());
 	}
 
-	r->clearAfterBindingFbo(
-		GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 	GlStateSingleton::get().disable(GL_DEPTH_TEST);
 	GlStateSingleton::get().disable(GL_BLEND);
 }

+ 9 - 4
tools/texture/ankitexture.py

@@ -299,11 +299,16 @@ def create_etc_images(mips_fnames, tmp_dir, fast, color_format, convert_path):
 			os.path.join(tmp_dir, os.path.basename(convert_path)))
 
 	for fname in mips_fnames:
-		fname = fname + ".tga"
+		# Unfortunately we need to flip the image. Use convert again
+		in_fname = fname + ".tga"
+		flipped_fname = fname + "_flip.tga"
+		args = ["convert", in_fname, "-flip", flipped_fname]
+		subprocess.check_call(args)
+		in_fname = flipped_fname
 
-		printi("  %s" % fname)
+		printi("  %s" % in_fname)
 
-		args = ["etcpack", fname, tmp_dir, "-c", "etc2"]
+		args = ["etcpack", in_fname, tmp_dir, "-c", "etc2"]
 
 		if fast:
 			args.append("-s")
@@ -592,7 +597,7 @@ def convert(in_files, out, fast, typ, normal, tmp_dir, convert_path, no_alpha):
 							tmp_width, tmp_height, color_format)
 				# Write ETC
 				elif compression == 2:
-					write_etc(tex_file, in_base_fname + ".pkm", \
+					write_etc(tex_file, in_base_fname + "_flip.pkm", \
 							tmp_width, tmp_height, color_format)
 			
 			tmp_width = tmp_width / 2