Jump to content

Texture Arrays


SpiderPig
 Share

Recommended Posts

Okay I've solved it.  If I use a 4096x4096 texture the crash occurs.  Using a 1024x1024 works perfectly.  @Josh any ideas why this would happen?

 

EDIT : Something is being set when loading the texture before assigning it to the array.  If I don't load the texture and set my own, any size works.  But if I load an image before making my own to assign to the array and the two sizes don't match, it crashes.

Link to comment
Share on other sites

8 minutes ago, SpiderPig said:

With no compression it is, yes.  Even if i didn't use the texture that I loaded, and set the pixels for the array manually after loading the texture, the two different sizes would cause the crash.  Obviously it's something that's easily avoided now, I'm just more curious as to why it happened.

Until you determine the cause I would not consider it solved. You either have random memory overwrite or a failure to allocate memory.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

This code shows a yellow texture;

int _width = 512;
int _height = 512;
char* buf = new char[ _width * _height * 3];

int index = 0;
for (int x = 0; x < _width; x++) {
	for (int y = 0; y < _height; y++) {
		buf[index] = 255;
		buf[index + 1] = 255;
		buf[index + 2] = 0;
		index+=3;
	}
}

OpenGLShader* shader = (OpenGLShader*)mat->GetShader();
glUseProgram(shader->program);

GLuint _buffer;
glGenTextures(1, &_buffer);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, _buffer);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);

glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, _width, _height, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

GLenum e5 = glGetError();
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _width, _height, 1, GL_RGB, GL_UNSIGNED_BYTE, buf);

glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

However loading a texture with a different size at the beginning (1024 x 1024) causes the crash.

Texture* texture = Texture::Load("Materials\\bluegrid.tex");//1024x1024

int _width = 512;//works if these are made 1024 as well
int _height = 512;
char* buf = new char[ _width * _height * 3];

int index = 0;
for (int x = 0; x < _width; x++) {
	for (int y = 0; y < _height; y++) {
		buf[index] = 255;
		buf[index + 1] = 255;
		buf[index + 2] = 0;
		index+=3;
	}
}

OpenGLShader* shader = (OpenGLShader*)mat->GetShader();
glUseProgram(shader->program);

GLuint _buffer;
glGenTextures(1, &_buffer);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, _buffer);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);

glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_RGB8, _width, _height, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

GLenum e5 = glGetError();
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, _width, _height, 1, GL_RGB, GL_UNSIGNED_BYTE, buf);

glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

 

Link to comment
Share on other sites

In the code I sent you there is a block of four lines of code. Above this block is a comment:

//Don't forget these commands or you will have random crashes that are very hard to track down!

I think this will fix your problem. ;)

  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

The arrays don't like working with z-sort off... with z sort off everything is black.  With it on I get the sky seeping around the edges of buildings.  Same problem as here; https://www.leadwerks.com/community/topic/17428-background-seeps-around-edges/#comment-113247

I can't turn Z-Sort on everything because the tree models don't like it on... EDIT : This happens with multi-sampling on at any level.

Seeping_002.png.114124d8f91aa73dcdbbb9d271cc0ab2.png

Link to comment
Share on other sites

So it does not occur when MSAA is disabled. This issue actually has nothing to do with texture arrays.

This is happening because the depth texture is twice (or more) the resolution of the context. There is not a single correct depth value at each pixel, but the sorted objects are being drawn directly on the context after the MSAA rendering has been all filtered into a non-multisampled display.

You could render these buildings in a second world by themselves, making sure the camera has color buffer clearing disabled.

What is it that you are trying to do with this?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Quote

So it does not occur when MSAA is disabled.

Correct.

What I noticed with texture arrays is, the material had to have z-sort enabled in order for the textures to show.  With z-sort enabled on my terrain, and MSAA enabled I get this issue.  Can the resolution of the depth texture be changed to match the context or is this impractical?

Link to comment
Share on other sites

38 minutes ago, SpiderPig said:

Correct.

What I noticed with texture arrays is, the material had to have z-sort enabled in order for the textures to show.  With z-sort enabled on my terrain, and MSAA enabled I get this issue.  Can the resolution of the depth texture be changed to match the context or is this impractical?

Sure. Disable MSAA ?

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...