Commits

spencercw committed 763a17e

Improve performance of OpenGL texture upload.

  • Participants
  • Parent commits 41d3173

Comments (0)

Files changed (1)

gb_emulator/src/gb_video_opengl.cpp

 
 #include <GL/wglew.h>
 
+#include <gb_emulator/gb.h>
 #include <gb_emulator/glew_error.h>
 
 namespace fs = boost::filesystem;
 
 	// Upload the texture into video memory
 	glBindTexture(GL_TEXTURE_2D, texture_);
-	for (unsigned y = 0; y != SCALED_HEIGHT; ++y)
-	{
-		memcpy(&textureBuffer_[y * TEXTURE_WIDTH], &scaledPixelBuffer_[y * SCALED_WIDTH],
-			SCALED_WIDTH * sizeof(uint32_t));
-	}
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_BGRA,
-		GL_UNSIGNED_BYTE, textureBuffer_.get());
+	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, SCALED_WIDTH, SCALED_HEIGHT, GL_BGRA, GL_UNSIGNED_BYTE,
+		scaledPixelBuffer_.get());
 
 	// Update the display
 	glClearColor(0.f, 0.f, 0.f, 0.f);
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	glDrawArrays(GL_QUADS, 0, 4);
-	
+
 	if (!SwapBuffers(deviceContext_))
 	{
 		throw system_error(GetLastError(), system_category(), "Failed to swap buffers");
 	// Create the texture
 	glGenTextures(1, &texture_);
 	glBindTexture(GL_TEXTURE_2D, texture_);
+	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_BGRA,
+		GL_UNSIGNED_BYTE, textureBuffer_.get());
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
 	glBindTexture(GL_TEXTURE_2D, 0);