Sign in to follow this  
mshafey

OpenGL Posssible memory leak in OpenGL Intel Win7 drivers

Recommended Posts

Hi.

I have been experiencing a memory leak when using pixel buffer objects to update textures. The leak seems to only occur on certain platforms with certain operating systems, and so we began to suspect the leak is occurring inside the Intel HD Series Windows 7 driver. Below is a summary of our testing on different platforms.

Can anyone tell if I'm doing something wrong in the code, or if this is potentially a driver leak?

Series 4 Chipset (Lenovo SL300), Windows XP SP3: [b]No Leak[/b]

Series 4 Chipset (Lenovo SL300), Windows 7: [b]Leaks ~500 kB/min[/b]

Intel HD Series (Lenovo X1), Windows 7: [b]Leaks ~500 kB/min[/b]

Intel HD 3000 (11" MacBook Air) Mac OS 10.7.3: [b]No Leak[/b]

Nvidia Quadro NVS, Windows XP: [b]No Leak[/b]

Here is a stripped down version of the code to reproduce this issue (VS2008 project at [url="http://www.viionsystems.com/Intel_HD_Series_Win7_Leak_Test_Case.zip"]http://www.viionsyst...k_Test_Case.zip[/url]). Extensive testing of this code shows no memory leaks detectable by VS2008's memory leak detector, yet GPU memory seems to grow indefinitely (according to ProcessExplorer).

I would appreciate any thoughts from the community on this issue.

[code]
#include <stdio.h>
#include <windows.h>
#include "GL\GLee.h"
#include "GL\freeglut.h"

unsigned int w = 640;
unsigned int h = 480;
unsigned int s = 4;

char* img = NULL;
char* texData1 = NULL;
char* texData2 = NULL;
char* mappedBuf = NULL;

GLuint pixelbufferHandle;

void timerCallback(int value);
void initializeTextureBuffer();
void mapAndCopyToBuffer(char* img1);
void paintGL();
void changeSize(int w, int h);

GLuint errorCode;

#define checkForGLError() \
if ((errorCode = glGetError()) != GL_NO_ERROR) \
printf("OpenGL error at %s line %i: %s", __FILE__, __LINE__-1, gluErrorString(errorCode) );


int main(int argc, char **argv)
{
texData1 = new char[w * h * s];
texData2 = new char[w * h * s];
memset(texData1, 85, w * h * s);
memset(texData2, 170, w * h * s);

img = texData1;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

glutInitWindowPosition(300, 300);
glutInitWindowSize(w, h);
glutCreateWindow("Window");
glutDisplayFunc(paintGL);
glutReshapeFunc(changeSize);

initializeTextureBuffer();

timerCallback(0);

glutMainLoop();

glDeleteBuffers(1, &pixelbufferHandle);
delete[] texData1;
delete[] texData2;

return 0;
}

void initializeTextureBuffer()
{
glGenBuffers(1, &pixelbufferHandle);
checkForGLError();
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);
checkForGLError();

glBufferData(GL_PIXEL_UNPACK_BUFFER, w * h * s, 0, GL_DYNAMIC_DRAW);

checkForGLError();

// initialize and upload the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
checkForGLError();

// Specify filtering and edge actions

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

img = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);

if (img == NULL){
return;
}

memset(img, 0, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
}

void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(mappedBuf, img1, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}

void paintGL()
{
if (img == texData1) img = texData2;
else img = texData1; // swap images

mapAndCopyToBuffer(img);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glDisable(GL_BLEND);
glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_MULTISAMPLE);

glBegin(GL_QUADS);
{
glTexCoord2f(0,0); glVertex3f(-1, 1, 0);
glTexCoord2f(1,0); glVertex3f(1, 1, 0);
glTexCoord2f(1,1); glVertex3f(1, -1, 0);
glTexCoord2f(0,1); glVertex3f(-1, -1, 0);
}
glEnd();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glutSwapBuffers();
}

void changeSize(int w, int h)
{
glViewport(0, 0, w, h);
}

void timerCallback(int value)
{
glutPostRedisplay();
glutTimerFunc(5, timerCallback, 0);
}
[/code]

Share this post


Link to post
Share on other sites
[CODE]void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(mappedBuf, img1, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/CODE]

seems like you don't free your mappedBuf after using it. you need to do this if you want to really free some memory:

[CODE]
void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(mappedBuf, img1, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
delete [] mappedBuf; //this is what you need, see explanation below
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}
[/CODE]



this indicates you're not completely aware of how to use pointers.

to clear things up:

[CODE]
int* pointer = 0; // creates an 8-byte pointer to an integer, pointer's value is 0 (Null-pointer) EDIT: yep it was unintialized...
int value = *pointer; // ERROR: you tried to access the contents of a null-pointer, this is illegal
pointer = new int; // dynamically (at runtime) assigns 4 bytes of memory at the place which is pointed by pointer, pointer is now valid
int value_2 = *pointer; // VALID: pointer actually points to somewhere, so value_2 should be either 0 or a random number, this depends on the compiler
delete pointer; // tells the operating system to free the place pointed by pointer
int value_3 = *pointer; // VALID: pointer still points to somewhere in the memory, and most probably you'll get back the old value pointed by pointer, since nothing has overwritten it. BUT this cannot be guaranteed (so DO NOT do this)
pointer = 0; // now pointer is a null-pointer again, but this doesn't free up any space, as opposed to delete
int value_4 = *pointer; //ERROR: you tried to access a null pointer again.
// for arrays you need to use this:
pointer = new int[32]; // allocate 32 integers (4 bytes per int) to the place pointed by pointer
//pointer will actually point to the first element of the array meaning this will be valid, and give a value:
int value_5 = *pointer; // VALID: gives back pointer[0]
delete [] pointer; //this frees up the space pointed by pointer, but pointer will still be valid, so you need to set it to 0
pointer = 0; // now pointer is a null-pointer again
// to check wether pointer is valid you can use a simple if
if(pointer) // if pointer is 0 (logical false) it will be invalid (null-pointer) else it will be valid
{
std::cout << "Pointer is valid.\n";
}
else
{
std::cout << "Pointer is INvalid.\n";
}
[/CODE]

oh and please write back if this solved your problem.

best regards,
Yours3!f

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329240914' post='4913038']
seems like you don't free your mappedBuf after using it. you need to do this if you want to really free some memory:
[/quote]

But we didn't allocate any memory here. What I understand is that after the call to glMapBuffer(), mappedBuf should be treated as GPU memory, so it's not up to us to free it. We copy the texture into this mapped memory, then call glUnmapBuffer() to indicate to OpenGL that we're done copying/modifying that buffer (the buffer that belongs to the driver, not us).

Just to be sure, I tried to delete[] mappedBuf now (before the statement where I set it to NULL). It crashes.

Share this post


Link to post
Share on other sites
[quote name='mshafey' timestamp='1329242080' post='4913052']
But we didn't allocate any memory here. What I understand is that after the call to glMapBuffer(), mappedBuf should be treated as GPU memory, so it's not up to us to free it. We copy the texture into this mapped memory, then call glUnmapBuffer() to indicate to OpenGL that we're done copying/modifying that buffer (the buffer that belongs to the driver, not us).
[/quote]

Any pointer in your code resides in CPU memory. The data contained within may come from GPU memory, but the pointer still needs to be declared in your code.

This function doesn't make any sense:

[source]
void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(mappedBuf, img1, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/source]

The memcpy is copying img1 into mappedBuf and then you are setting mappedBuf to NULL. I suspect that you meant: memcpy(img1,mappedBuf,w * h * s);?

Also, since you know that img1 and mappedBuf will be w * h * s bytes, and that mappedBuf is only used in this function, why not do this:

[source]
void mapAndCopyToBuffer(char* img1)
{
char *mappedBuf;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = new char[w * h * s];
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(img1, mappedBuf, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
delete [] mappedBuf;
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}
[/source]

Share this post


Link to post
Share on other sites
@Yours3!f - glMapBuffer doesn't work that way. I [b]strongly[/b] suggest that you read the documentation for it. The "fix" you gave will actually crash the program (if you're lucky).
@MarkS - the code does make sense. That's the way glMapBuffer works, and it's correct and in accordance with the documentation (aside from an extra unnecessary glBindBuffer which shouldn't be a cause of the observed leak).

@OP: have you tried this using glBufferSubData instead of glMapBuffer? It would be interesting to know if the same symptoms are observed with that. The following should be equivalent:
[code]void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
glBufferSubData (GL_PIXEL_UNPACK_BUFFER_ARB, 0, w * h * s, img1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/code]

Oh - and make sure that the value of s is 4. ;)

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329240914' post='4913038']
seems like you don't free your mappedBuf after using it. you need to do this if you want to really free some memory:
[/quote]
The pointer returned by glMapBuffer shall not be deleted. It is a pointer to memory managed by OpenGL. The memory can be thought of as deleted by glUnmapBuffer, and he is correctly calling it once he's done.

[quote name='Yours3!f' timestamp='1329240914' post='4913038']
this indicates you're not completely aware of how to use pointers.
[/quote]
Likewise, it shows that you are not thinking about every aspect of pointers; you shall only delete a pointer that you allocated.

[quote name='MarkS' timestamp='1329244193' post='4913063']
This function doesn't make any sense:

[source]
void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(mappedBuf, img1, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/source]

The memcpy is copying img1 into mappedBuf and then you are setting mappedBuf to NULL. I suspect that you meant: memcpy(img1,mappedBuf,w * h * s);?
[/quote]
First of all, the target is an unpack buffer, which is a buffer you write to. Second, the buffer is mapped as write only. Third, he's copying from the image to the mapped buffer. Fourth, he's unmapping the buffer when he's done. Finally, he's creating a texture from the mapped buffer he just wrote to.

So the chain of commands lines up perfectly for writing to the mapped buffer and updating the texture.

[quote name='MarkS' timestamp='1329244193' post='4913063']
Also, since you know that img1 and mappedBuf will be w * h * s bytes, and that mappedBuf is only used in this function, why not do this:

[source]
void mapAndCopyToBuffer(char* img1)
{
char *mappedBuf;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
mappedBuf = new char[w * h * s];
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy(img1, mappedBuf, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
delete [] mappedBuf;
mappedBuf = NULL;

glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle);

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}
[/source]
[/quote]
This, on the other hand, makes little sense. Reading from a write-to buffer target? Reading from write-only mapped memory? Allocating memory with new, only to overwrite the pointer the line after? Attempting to delete the pointer returned by glMapBuffer? The logical flow of the function makes little sense also by reading from a buffer and then creating a texture from the same buffer.

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1329245602' post='4913072']@OP: have you tried this using glBufferSubData instead of glMapBuffer? It would be interesting to know if the same symptoms are observed with that. The following should be equivalent:
[code]void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
glBufferSubData (GL_PIXEL_UNPACK_BUFFER_ARB, 0, w * h * s, img1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/code]

Oh - and make sure that the value of s is 4. ;)
[/quote]

Thanks for the suggestion. I've tried your code, it works, but it doesn't fix the leak. I'm still seeing memory leaking at the same rate on the affected platforms.

Share this post


Link to post
Share on other sites
[quote name='mshafey' timestamp='1329247414' post='4913082']
Thanks for the suggestion. I've tried your code, it works, but it doesn't fix the leak. I'm still seeing memory leaking at the same rate on the affected platforms.
[/quote]
That's interesting. Let's try to pin down which call is causing it. What happens if you comment out the glTexSubImage2D call? And if you comment out the glMapBuffer block (but leave glTexSubImage2D in and coming from the PBO)?

Share this post


Link to post
Share on other sites
[quote]
Just to be sure, I tried to delete[] mappedBuf now (before the statement where I set it to NULL). It crashes.
[/quote]

ok, so I was wrong [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] but still you're doing pretty intresting things with those pointers...

I tried to decypher what you're trying to do with the pointers so here it is:
[quote]
img = 0
img points to where texdata1 does
img points to the write-only memory from where OGL will take back the texture data
fill img with 0-s
copy img-s content back to GPU (unmapping to pixelbufferhandle)
since img points to the write-only memory of OGL, you make it point to texdata1
fill mappedbuf with img (essentially texdata1)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)

loop:
img points to texdata1, so set it to texdata2
fill mappedbuf with img (essentially texdata2)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)

img points to texdata2, so set it to texdata1
fill mappedbuf with img (essentially texdata1)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)
[/quote]

the code essentially sets the texture to grey and white very fast, but with setting glutTimerFunc(5, timerCallback, 0); to glutTimerFunc(120, timerCallback, 0);
I can clearly see this behaviour.

So next I tried to modify the source you've given (on Linux [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] thanks for the portable code!) so that it makes more sense:
[CODE]
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "GLee.h"
#include "GL/freeglut.h"
unsigned int w = 640;
unsigned int h = 480;
unsigned int s = 4;
char* texData1 = NULL;
char* texData2 = NULL;
char* mappedBuf = NULL;
GLuint pixelbufferHandle;
bool pingpong = true; //so that the first time we use texdata1
void timerCallback ( int value );
void initializeTextureBuffer();
void mapAndCopyToBuffer ( char* img1 );
void paintGL();
void changeSize ( int w, int h );
GLuint errorCode;
#define checkForGLError() \
if ((errorCode = glGetError()) != GL_NO_ERROR) \
printf("OpenGL error at %s line %i: %s", __FILE__, __LINE__-1, gluErrorString(errorCode) );

int main ( int argc, char **argv )
{
texData1 = new char[w * h * s];
texData2 = new char[w * h * s];
memset ( texData1, 0, w * h * s );
memset ( texData2, 255, w * h * s );
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutInitWindowPosition ( 300, 300 );
glutInitWindowSize ( w, h );
glutCreateWindow ( "Window" );
glutDisplayFunc ( paintGL );
glutReshapeFunc ( changeSize );
glDisable ( GL_BLEND );
glDepthMask ( GL_FALSE );
glDisable ( GL_CULL_FACE );
glDisable ( GL_DEPTH_TEST );
glEnable ( GL_TEXTURE_2D );
glEnable ( GL_MULTISAMPLE );
initializeTextureBuffer();
timerCallback ( 0 );
glutMainLoop();
glDeleteBuffers ( 1, &pixelbufferHandle );
delete[] texData1;
delete[] texData2;
return 0;
}
void initializeTextureBuffer()
{
glGenBuffers ( 1, &pixelbufferHandle );
checkForGLError();
glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle );
checkForGLError();
glBufferData ( GL_PIXEL_UNPACK_BUFFER, w * h * s, 0, GL_DYNAMIC_DRAW );
checkForGLError();
// Specify filtering and edge actions
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP );
// initialize and upload the texture
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0 );
checkForGLError();
mappedBuf = ( char* ) glMapBuffer ( GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY );
checkForGLError();
if ( !mappedBuf )
{
std::cerr << "Couldn't create write-only mapping buffer.\n Exiting.\n";
exit ( 1 );
}
memset(mappedBuf, 0, w * h * s);
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER);
checkForGLError();
}
void mapAndCopyToBuffer ( char* img_ptr )
{
mappedBuf = (char*) glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY);
memcpy ( mappedBuf, img_ptr, w * h * s );
if (!glUnmapBuffer ( GL_PIXEL_UNPACK_BUFFER ))
{
std::cerr << "Buffer has already been unmapped.\n Exiting.\n";
exit(1);
}
checkForGLError();
glTexSubImage2D ( GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0 );
checkForGLError();
}
void paintGL()
{
if ( pingpong )
{
mapAndCopyToBuffer ( texData1 );
}
else
{
mapAndCopyToBuffer ( texData2 );
}
pingpong = !pingpong;
glMatrixMode ( GL_MODELVIEW );
glPushMatrix();
glBegin ( GL_QUADS );
{
glTexCoord2f ( 0,0 );
glVertex3f ( -1, 1, 0 );
glTexCoord2f ( 1,0 );
glVertex3f ( 1, 1, 0 );
glTexCoord2f ( 1,1 );
glVertex3f ( 1, -1, 0 );
glTexCoord2f ( 0,1 );
glVertex3f ( -1, -1, 0 );
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void changeSize ( int w, int h )
{
glViewport ( 0, 0, w, h );
}
void timerCallback ( int value )
{
glutPostRedisplay();
glutTimerFunc ( 1, timerCallback, 0 );
}
// kate: indent-mode cstyle; space-indent on; indent-width 0;
[/CODE]

EDIT: corrected the not-mapping back issue :)

I don't know if the memory leak is still present with this version since I don't own an intel graphics card... could you please test this?

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329257604' post='4913132']
[quote]
Just to be sure, I tried to delete[] mappedBuf now (before the statement where I set it to NULL). It crashes.
[/quote]

ok, so I was wrong [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] but still you're doing pretty intresting things with those pointers...

I tried to decypher what you're trying to do with the pointers so here it is:
[quote]
img = 0
img points to where texdata1 does
img points to the write-only memory from where OGL will take back the texture data
fill img with 0-s
copy img-s content back to GPU (unmapping to pixelbufferhandle)
since img points to the write-only memory of OGL, you make it point to texdata1
fill mappedbuf with img (essentially texdata1)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)

loop:
img points to texdata1, so set it to texdata2
fill mappedbuf with img (essentially texdata2)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)

img points to texdata2, so set it to texdata1
fill mappedbuf with img (essentially texdata1)
upload mappedbuf to GPU (unmapping to pixelbufferhandle)
[/quote]

the code essentially sets the texture to grey and white very fast, but with setting glutTimerFunc(5, timerCallback, 0); to glutTimerFunc(120, timerCallback, 0);
I can clearly see this behaviour.

So next I tried to modify the source you've given (on Linux [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] thanks for the portable code!) so that it makes more sense:
[CODE]
#include <iostream>
#include <stdio.h>
#include <string.h>
#include "GLee.h"
#include "GL/freeglut.h"
unsigned int w = 640;
unsigned int h = 480;
unsigned int s = 4;
char* texData1 = NULL;
char* texData2 = NULL;
char* mappedBuf = NULL;
GLuint pixelbufferHandle;
bool pingpong = true; //so that the first time we use texdata1
void timerCallback ( int value );
void initializeTextureBuffer();
void mapAndCopyToBuffer ( char* img1 );
void paintGL();
void changeSize ( int w, int h );
GLuint errorCode;
#define checkForGLError() \
if ((errorCode = glGetError()) != GL_NO_ERROR) \
printf("OpenGL error at %s line %i: %s", __FILE__, __LINE__-1, gluErrorString(errorCode) );

int main ( int argc, char **argv )
{
texData1 = new char[w * h * s];
texData2 = new char[w * h * s];
memset ( texData1, 0, w * h * s );
memset ( texData2, 255, w * h * s );
glutInit ( &argc, argv );
glutInitDisplayMode ( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutInitWindowPosition ( 300, 300 );
glutInitWindowSize ( w, h );
glutCreateWindow ( "Window" );
glutDisplayFunc ( paintGL );
glutReshapeFunc ( changeSize );
glDisable ( GL_BLEND );
glDepthMask ( GL_FALSE );
glDisable ( GL_CULL_FACE );
glDisable ( GL_DEPTH_TEST );
glEnable ( GL_TEXTURE_2D );
glEnable ( GL_MULTISAMPLE );
initializeTextureBuffer();
timerCallback ( 0 );
glutMainLoop();
glDeleteBuffers ( 1, &pixelbufferHandle );
delete[] texData1;
delete[] texData2;
return 0;
}
void initializeTextureBuffer()
{
glGenBuffers ( 1, &pixelbufferHandle );
checkForGLError();
glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, pixelbufferHandle );
checkForGLError();
glBufferData ( GL_PIXEL_UNPACK_BUFFER, w * h * s, 0, GL_DYNAMIC_DRAW );
checkForGLError();
// Specify filtering and edge actions
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP );
glTexParameteri ( GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP );
// initialize and upload the texture
glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0 );
checkForGLError();
mappedBuf = ( char* ) glMapBuffer ( GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY );
checkForGLError();
if ( !mappedBuf )
{
std::cerr << "Couldn't create write-only mapping buffer.\n Exiting.\n";
exit ( 1 );
}
}
void mapAndCopyToBuffer ( char* img_ptr )
{
memcpy ( mappedBuf, img_ptr, w * h * s );
glUnmapBuffer ( GL_PIXEL_UNPACK_BUFFER );
glTexSubImage2D ( GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0 );
}
void paintGL()
{
if ( pingpong )
{
mapAndCopyToBuffer ( texData1 );
}
else
{
mapAndCopyToBuffer ( texData2 );
}
pingpong = !pingpong;
glMatrixMode ( GL_MODELVIEW );
glPushMatrix();
glBegin ( GL_QUADS );
{
glTexCoord2f ( 0,0 );
glVertex3f ( -1, 1, 0 );
glTexCoord2f ( 1,0 );
glVertex3f ( 1, 1, 0 );
glTexCoord2f ( 1,1 );
glVertex3f ( 1, -1, 0 );
glTexCoord2f ( 0,1 );
glVertex3f ( -1, -1, 0 );
}
glEnd();
glPopMatrix();
glutSwapBuffers();
}
void changeSize ( int w, int h )
{
glViewport ( 0, 0, w, h );
}
void timerCallback ( int value )
{
glutPostRedisplay();
glutTimerFunc ( 240, timerCallback, 0 );
}
// kate: indent-mode cstyle; space-indent on; indent-width 4;
[/CODE]



I don't know if the memory leak is still present with this version since I don't own an intel graphics card... could you please test this?
[/quote]

that should not work, you've kindof botched his original sample, you map the buffer in the initialization routine, but when modifying the pixel buffer, you unmap that pointer(and never map it again(or bind the correct pbo).)

glUnmapBuffer should be throwing errors pretty much after the first draw.

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1329245602' post='4913072']
@Yours3!f - glMapBuffer doesn't work that way. I [b]strongly[/b] suggest that you read the documentation for it. The "fix" you gave will actually crash the program (if you're lucky).
@MarkS - the code does make sense. That's the way glMapBuffer works, and it's correct and in accordance with the documentation (aside from an extra unnecessary glBindBuffer which shouldn't be a cause of the observed leak).

@OP: have you tried this using glBufferSubData instead of glMapBuffer? It would be interesting to know if the same symptoms are observed with that. The following should be equivalent:
[code]void mapAndCopyToBuffer(char* img1)
{
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pixelbufferHandle);
glBufferSubData (GL_PIXEL_UNPACK_BUFFER_ARB, 0, w * h * s, img1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
}[/code]

Oh - and make sure that the value of s is 4. ;)
[/quote]

hehe now you got me. I didn't read the specs for glMapBuffer, but now I see clearly how it works... :)
I just searched the code quickly to find some error prone stuff, but didn't catch the glMapBuffer

I hope the collision course I gave on pointers at least cleared some stuff in his head :)

Share this post


Link to post
Share on other sites
[quote]
that should not work, you've kindof botched his original sample, you map the buffer in the initialization routine, but when modifying the pixel buffer, you unmap that pointer(and never map it again(or bind the correct pbo).)

glUnmapBuffer should be throwing errors pretty much after the first draw.
[/quote]
well it does work, glUnmapBuffer doesn't throw any errors if you add checking after it. It reproduces the same behaviour on Linux Mint 12.1 64 bit HD 5670 Catalyst 12.1

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329258346' post='4913139']
[quote]
that should not work, you've kindof botched his original sample, you map the buffer in the initialization routine, but when modifying the pixel buffer, you unmap that pointer(and never map it again(or bind the correct pbo).)

glUnmapBuffer should be throwing errors pretty much after the first draw.
[/quote]
well it does work, glUnmapBuffer doesn't throw any errors if you add checking after it. It reproduces the same behaviour on Linux Mint 12.1 64 bit HD 5670 Catalyst 12.1
[/quote]
Try check its return value. In any case, here's what the specification has to say about double unmapping:
[quote]
If the buffer data store is already in the unmapped state, UnmapBuffer returns FALSE, and an INVALID_OPERATION error is generated.
[/quote]
I have noticed before that error flags are not always set properly for error conditions when they should be according to the specification. I generally trust set flags to indicate an error, but I rarely trust a reset flag to indicate no error.

It is possible that the pointer returned by the mapping remains valid in your particular case as far as the memory mapper and the content of the buffer is concerned. It is not guaranteed in anyway by the specification though.

edit: And the relevant quote from the specification regarding unmapping the buffer:
[quote]
Unmapping a mapped buffer object invalidates the pointer to its data store [...]
[/quote]

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329258189' post='4913138']
I hope the collision course I gave on pointers at least cleared some stuff in his head [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]
i'm sorry, but he was doing nothing wrong in his initial code when it comes to pointers. and to be fair, he seems to have a better understanding then your "course"

for example:
[code]
int* pointer; // creates an 8-byte pointer to an integer, pointer's value is 0 (Null-pointer)
///////////This is not true, first of all, pointers generally are 4-bytes(although it isn't impossible for the architecture your working on to use 8-byte's for a pointer, generally they are only 4 bytes.)
//////////Secondly, not defining a value, does [B]NOT[/B] mean it defaults as a null pointer, it is simply undefined(do not rely on uninitialized pointers to equal 0, this is extremely bad practice.)

int value = *pointer; // ERROR: you tried to access the contents of a null-pointer, this is illegal
//again, not invalid, but is undefined behavior(generally seg-fault level, but it is not illegal by compilation to access a null pointer.)

pointer = new int; // dynamically (at runtime) assigns 4 bytes of memory at the place which is pointed by pointer, pointer is now valid
//pointer is not "now" valid, the assumption is that you were successful in creating the memory, but does not gurantee the returned data is valid(i.e: out of memory errors)

int value_2 = *pointer; // VALID: pointer actually points to somewhere, so value_2 should be either 0 or a random number, this depends on the compiler
//Yes, undefined behavior.

delete pointer; // tells the operating system to free the place pointed by pointer
//Assuming that the pointer was successfully created.

int value_3 = *pointer; // VALID: pointer still points to somewhere in the memory, and most probably you'll get back the old value pointed by pointer, since nothing has overwritten it. BUT this cannot be guaranteed (so DO NOT do this)
//Yes, undefined behavior.

pointer = 0; // now pointer is a null-pointer again, but this doesn't free up any space, as opposed to delete
//Yipee, finally, the pointer actually points to 0.

int value_4 = *pointer; //ERROR: you tried to access a null pointer again.
//No, not an Error, just undefiend attempt at reading w/e is written at the first address in ram.(this could be theoretically valid in some embedded systems.)

// for arrays you need to use this:
pointer = new int[32]; // allocate 32 integers (4 bytes per int) to the place pointed by pointer
//pointer will actually point to the first element of the array meaning this will be valid, and give a value:
int value_5 = *pointer; // VALID: gives back pointer[0]

delete [] pointer; //this frees up the space pointed by pointer, but pointer will still be valid, so you need to set it to 0
//pointer is pointing to undefined data after deletion.
pointer = 0; // now pointer is a null-pointer again
// to check wether pointer is valid you can use a simple if
if(pointer) // if pointer is 0 (logical false) it will be invalid (null-pointer) else it will be valid
//again, some embeded systems can use 0 as a logical address, as well, null does not always = 0, in 16/8 bit days, the processor did some near/far stuff with pointers, so do not assume null = 0
{
std::cout << "Pointer is valid.\n";
}
else
{
std::cout << "Pointer is INvalid.\n";
}

[/code]
generally, my nitpick is with your first line, claiming that an uninitialized pointer is always 0 is wrong, it is UNDEFINED, never trust data that is uninitiated, and for suggesting that it well become 0 tells me your understanding of pointers/data structures is flawed.

[quote]
well it does work, glUnmapBuffer doesn't throw any errors if you add checking after it. It reproduces the same behaviour on Linux Mint 12.1 64 bit HD 5670 Catalyst 12.1
[/quote]

as brother bob said, check the return value.

as per specifications, it should not work in the same way as OP describes. I can not tell you why it does, but it shouldn't.

Share this post


Link to post
Share on other sites
..snip..

[img]http://public.gamedev.net//public/style_emoticons/default/ohmy.png[/img]

Oops... I misunderstood the nature of glMapBuffer. I looked at his code and thought "Wait a minute. He just had data sent to him in mappedBuf from glMapBuffer and now he is overwriting it? [img]http://public.gamedev.net//public/style_emoticons/default/huh.png[/img] "...

[img]http://public.gamedev.net//public/style_emoticons/default/sleep.png[/img]

Share this post


Link to post
Share on other sites
I have noticed before that error flags are not always set properly for error conditions when they should be according to the specification. I generally trust set flags to indicate an error, but I rarely trust a reset flag to indicate no error.

you're right it returns false.

Share this post


Link to post
Share on other sites
[quote]
This is not true, first of all, pointers generally are 4-bytes(although it isn't impossible for the architecture your working on to use 8-byte's for a pointer, generally they are only 4 bytes.)

[/quote]

Just a nitpick, I don't like the word "generally" here. You could say, however, that for 32 bit executables a pointer is generally 4 bytes and for a 64 bit executable it is generally 8 bytes. ;)

Share this post


Link to post
Share on other sites
[quote name='Madhed' timestamp='1329259950' post='4913160']
[quote]
This is not true, first of all, pointers generally are 4-bytes(although it isn't impossible for the architecture your working on to use 8-byte's for a pointer, generally they are only 4 bytes.)

[/quote]

Just a nitpick, I don't like the word "generally" here. You could say, however, that for 32 bit executables a pointer is generally 4 bytes and for a 64 bit executable it is generally 8 bytes. ;)
[/quote]

true enough sir, assuming the executable is built for 64-bit processor's, however in my experience, 32 bit executable's have far outweighed 64 executable's, even in 64 bit environments..

Share this post


Link to post
Share on other sites
[quote name='slicer4ever' timestamp='1329259378' post='4913151']
i'm sorry, but he was doing nothing wrong in his initial code when it comes to pointers. and to be fair, he seems to have a better understanding then your "course"

for example:
[code]
int* pointer; // creates an 8-byte pointer to an integer, pointer's value is 0 (Null-pointer)
///////////This is not true, first of all, pointers generally are 4-bytes(although it isn't impossible for the architecture your working on to use 8-byte's for a pointer, generally they are only 4 bytes.)
//////////Secondly, not defining a value, does [B]NOT[/B] mean it defaults as a null pointer, it is simply undefined(do not rely on uninitialized pointers to equal 0, this is extremely bad practice.)

int value = *pointer; // ERROR: you tried to access the contents of a null-pointer, this is illegal
//again, not invalid, but is undefined behavior(generally seg-fault level, but it is not illegal by compilation to access a null pointer.)

pointer = new int; // dynamically (at runtime) assigns 4 bytes of memory at the place which is pointed by pointer, pointer is now valid
//pointer is not "now" valid, the assumption is that you were successful in creating the memory, but does not gurantee the returned data is valid(i.e: out of memory errors)

int value_2 = *pointer; // VALID: pointer actually points to somewhere, so value_2 should be either 0 or a random number, this depends on the compiler
//Yes, undefined behavior.

delete pointer; // tells the operating system to free the place pointed by pointer
//Assuming that the pointer was successfully created.

int value_3 = *pointer; // VALID: pointer still points to somewhere in the memory, and most probably you'll get back the old value pointed by pointer, since nothing has overwritten it. BUT this cannot be guaranteed (so DO NOT do this)
//Yes, undefined behavior.

pointer = 0; // now pointer is a null-pointer again, but this doesn't free up any space, as opposed to delete
//Yipee, finally, the pointer actually points to 0.

int value_4 = *pointer; //ERROR: you tried to access a null pointer again.
//No, not an Error, just undefiend attempt at reading w/e is written at the first address in ram.(this could be theoretically valid in some embedded systems.)

// for arrays you need to use this:
pointer = new int[32]; // allocate 32 integers (4 bytes per int) to the place pointed by pointer
//pointer will actually point to the first element of the array meaning this will be valid, and give a value:
int value_5 = *pointer; // VALID: gives back pointer[0]

delete [] pointer; //this frees up the space pointed by pointer, but pointer will still be valid, so you need to set it to 0
//pointer is pointing to undefined data after deletion.
pointer = 0; // now pointer is a null-pointer again
// to check wether pointer is valid you can use a simple if
if(pointer) // if pointer is 0 (logical false) it will be invalid (null-pointer) else it will be valid
//again, some embeded systems can use 0 as a logical address, as well, null does not always = 0, in 16/8 bit days, the processor did some near/far stuff with pointers, so do not assume null = 0
{
std::cout << "Pointer is valid.\n";
}
else
{
std::cout << "Pointer is INvalid.\n";
}

[/code]
generally, my nitpick is with your first line, claiming that an uninitialized pointer is always 0 is wrong, it is UNDEFINED, never trust data that is uninitiated, and for suggesting that it well become 0 tells me your understanding of pointers/data structures is flawed.
[/quote]

you're right about the first line, 8 bytes is in fact platform specific :) but for 64 bit systems it should be 8 bytes
and pointer declaration depends on the compiler (but you are right it should be undefined), for me this code works (with g++ on linux):
[CODE]
int* a;
if(a == 0)
{
std::cout << "A is 0.\n";
}
[/CODE]

What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329260792' post='4913164']
What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.
[/quote]
It works on neither Visual C++ nor g++. Or, rather, it works for the very same reason that your unmapped buffer appeared valid; undefined behavior. Try, for example, to enable optimization and see that happens.

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329260792' post='4913164']
What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.
[/quote]

Not for me...
[code]c:\test>cat a.cpp
#include <stdio.h>
int main()
{
int* ptr;
printf("%p\n", ptr);
}
c:\test>g++ a.cpp

c:\test>a.exe
7EFDE000

c:\test>cl a.cpp /nologo
a.cpp
c:\test\a.cpp(5) : warning C4700: uninitialized local variable 'ptr' used

c:\test>a.exe
00000001

c:\test>[/code]

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1329261373' post='4913169']
[quote name='Yours3!f' timestamp='1329260792' post='4913164']
What I described should work using Visual C++ and g++ as well. I don't know about the embedded systems, so thanks for clarifying.
[/quote]
It works on neither Visual C++ nor g++. Or, rather, it works for the very same reason that your unmapped buffer appeared valid; undefined behavior. Try, for example, to enable optimization and see that happens.
[/quote]

I use kdevelop which uses cmake and by default sets optimization to -O3, I tried in both debug and release mode, both works. Again it shouldn't.

Share this post


Link to post
Share on other sites
[quote name='Yours3!f' timestamp='1329262329' post='4913178']
try this:
[/quote]
Primitives at global scope are always default initialized to zero. At function scope, they are not.

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1329262789' post='4913180']
[quote name='Yours3!f' timestamp='1329262329' post='4913178']
try this:
[/quote]
Primitives at global scope are always default initialized to zero. At function scope, they are not.
[/quote]

I know, that's why replied it. but lets return to the topic now. solving the memory leak...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627784
    • Total Posts
      2979036
  • Similar Content

    • By JFT
      Hi,

      I am trying to optimize shadow mapping for an rts-view (nearly top down) with directional light.

      My approach so far is to intersect the camera view frustum with the plane of the terrain on which all the units are moving and
      fit a box around the four intersection points:

      Then I use the center of the box and the light direction to construct a view matrix.
      To construct the orthographic projection matrix I use the corners of my box. 

      With that I somehow do not get the wanted results (no shadows) /shadow map is not correctly created for the view of the camera.
      I think I am maybe missing some translation/rotation?

      Is there a better way for rts-views with a single shadow map ?

      Thanks for your help beforehand!
    • By lonewolff
      Hi guys,
      With OpenGL not having a dedicated SDK, how were libraries like GLUT and the likes ever written?
      Could someone these days write an OpenGL library from scratch? How would you even go about this?
      Obviously this question stems from the fact that there is no OpenGL SDK.
      DirectX is a bit different as MS has the advantage of having the relationship with the vendors and having full access to OS source code and the entire works.
      If I were to attempt to write the most absolute basic lib to access OpenGL on the GPU, how would I go about this?
    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
  • Popular Now