View Issue Details

IDProjectCategoryView StatusLast Update
0004395The Dark ModGraphicspublic18.09.2017 13:32
Reporternbohr1more Assigned Toduzenko  
PrioritynormalSeveritynormalReproducibilityalways
Status resolvedResolutionfixed 
Product VersionTDM 2.04 
Target VersionTDM 2.05Fixed in VersionTDM 2.05 
Summary0004395: Lightgem Pixel Pack Buffer Optimization
DescriptionDuzenko's OpenGL 2.1 "Pixel Pack Buffer" optimization.

Discussion:

http://forums.thedarkmod.com/topic/18346-lightgem-optimization/page-2#entry395542
TagsNo tags attached.
Attached Files
duzenko_patch.diff (2,868 bytes)   
Index: game/LightGem.cpp
===================================================================
--- game/LightGem.cpp	(revision 6634)
+++ game/LightGem.cpp	(working copy)
@@ -429,16 +429,16 @@
 
 			// The order is RGB. NOTE: Serp - I have moved the scale into the rgb multiplier
 			// this is to move the calculation into the precompiler (could move to .h directly)
-			m_fColVal[in] += (buffer[0] * (DARKMOD_LG_RED  * DARKMOD_LG_SCALE) +
-							  buffer[1] * (DARKMOD_LG_GREEN* DARKMOD_LG_SCALE) +
-							  buffer[2] * (DARKMOD_LG_BLUE * DARKMOD_LG_SCALE));
+			m_fColVal[in] += (buffer[0] * (DARKMOD_LG_RED  ) +
+							  buffer[1] * (DARKMOD_LG_GREEN) +
+							  buffer[2] * (DARKMOD_LG_BLUE ));
 		}
 	}
 
 	// Calculate the average for each value
 	// Could be moved to the return
-	m_fColVal[0] *= DARKMOD_LG_TRIRATIO;
-	m_fColVal[1] *= DARKMOD_LG_TRIRATIO;
-	m_fColVal[2] *= DARKMOD_LG_TRIRATIO;
-	m_fColVal[3] *= DARKMOD_LG_TRIRATIO;
+	m_fColVal[0] *= DARKMOD_LG_TRIRATIO * DARKMOD_LG_SCALE;
+	m_fColVal[1] *= DARKMOD_LG_TRIRATIO * DARKMOD_LG_SCALE;
+	m_fColVal[2] *= DARKMOD_LG_TRIRATIO * DARKMOD_LG_SCALE;
+	m_fColVal[3] *= DARKMOD_LG_TRIRATIO * DARKMOD_LG_SCALE;
 }
Index: renderer/RenderSystem.cpp
===================================================================
--- renderer/RenderSystem.cpp	(revision 6634)
+++ renderer/RenderSystem.cpp	(working copy)
@@ -293,6 +293,7 @@
 =============
 */
 idRenderSystemLocal::~idRenderSystemLocal( void ) {
+	qglDeleteBuffersARB(1, &pbo);
 }
 
 /*
@@ -1011,7 +1012,27 @@
 
 	qglReadBuffer( GL_BACK );
 
-	qglReadPixels(rc->x, rc->y, rc->width, rc->height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
+	if (1) {
+		static int nbytes = 64 * 64 * 3;
+		if (!pbo) {
+			qglGenBuffersARB(1, &pbo);
+			qglBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
+			qglBufferDataARB(GL_PIXEL_PACK_BUFFER, nbytes, NULL, GL_STREAM_READ);
+			qglBindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
+		}
+		qglBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
+		unsigned char* ptr = (unsigned char*)qglMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
+		if (ptr) {
+			memcpy(buffer, ptr, nbytes);
+			qglUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
+		}
+		else {
+			// handle error
+		}
+		qglReadPixels(rc->x, rc->y, rc->width, rc->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
+		qglBindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
+	} else
+		qglReadPixels(rc->x, rc->y, rc->width, rc->height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
 }
 
 /*
Index: renderer/tr_local.h
===================================================================
--- renderer/tr_local.h	(revision 6634)
+++ renderer/tr_local.h	(working copy)
@@ -696,6 +696,9 @@
 ** by the frontend.
 */
 class idRenderSystemLocal : public idRenderSystem {
+private:
+	GLuint pbo;
+
 public:
 	// external functions
 	virtual void			Init( void );
duzenko_patch.diff (2,868 bytes)   

Relationships

related to 0003684 new Investigate GPL Renderer Improvements 
related to 0004621 resolvednbohr1more Lightgem does not initialize when installing a new mission or via vid_restart. 

Activities

nbohr1more

nbohr1more

17.10.2016 04:15

developer   ~0008378

Src Rev 6635

Binary 14607
nbohr1more

nbohr1more

23.10.2016 15:34

developer   ~0008388

Fix for restart issue:

Index: renderer/RenderSystem.cpp
===================================================================
--- renderer/RenderSystem.cpp (revision 6638)
+++ renderer/RenderSystem.cpp (working copy)
@@ -1031,7 +1031,8 @@
             qglUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
         }
         else {
- // handle error
+ // vid_restart ?
+ pbo = 0;
         }
         qglReadPixels(rc->x, rc->y, rc->width, rc->height, GL_RGB, GL_UNSIGNED_BYTE, 0);
         qglBindBufferARB(GL_PIXEL_PACK_BUFFER, 0);
nbohr1more

nbohr1more

24.10.2016 00:57

developer   ~0008390

Binary 14609
Src 6640
duzenko

duzenko

27.12.2016 14:44

developer   ~0008646

Check the ARB extension before use
SVN revision: 6735

Issue History

Date Modified Username Field Change
17.10.2016 03:35 nbohr1more New Issue
17.10.2016 03:35 nbohr1more Status new => assigned
17.10.2016 03:35 nbohr1more Assigned To => nbohr1more
17.10.2016 03:35 nbohr1more File Added: duzenko_patch.diff
17.10.2016 04:15 nbohr1more Note Added: 0008378
17.10.2016 04:16 nbohr1more Status assigned => feedback
23.10.2016 15:34 nbohr1more Note Added: 0008388
23.10.2016 15:34 nbohr1more Status feedback => assigned
24.10.2016 00:57 nbohr1more Note Added: 0008390
24.10.2016 00:57 nbohr1more Status assigned => feedback
25.10.2016 04:01 nbohr1more Assigned To nbohr1more => duzenko
22.11.2016 17:37 nbohr1more Status feedback => resolved
22.11.2016 17:37 nbohr1more Resolution open => fixed
22.11.2016 17:37 nbohr1more Fixed in Version => TDM 2.05
01.12.2016 21:07 nbohr1more Relationship added related to 0003684
27.12.2016 14:44 duzenko Note Added: 0008646
18.09.2017 13:32 nbohr1more Relationship added related to 0004621