I'm working on implementing the code from the GLSL ocean shader demo into my program.
The problem I have is that when I have another memoryViewer, unrelated to the ocean, and do:
I might have solved it temporarily, but still do not understand...
Now I instead have a problem that it runs out of memory after using the shader for a few minutes.
I'm bad at the GLSL, but some variable is building up an eating the memory in the ocean.
The 'time' variable is being reset in my program, so it's some other variable.
How can I prevent the shader from running out of memory?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Daniel concerning the MemViewer if i'm remember this bug is solved in GLScene 1.5.
For the problem with shader :
1) I don't think the problem comes from the GLSL Script
2) Can you put also the VertexShader Script and how you do for instantiate the Shader, and how you pass parameters to it or can you make a little sample i'll can check
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Something generates an error after ~5 minutes running the program. Last time it was a error directing to this function in GLScene.pas: function TGLBaseSceneObject.AbsoluteMatrixAsAddress : PMatrix;
Sometimes its an out of memory error.
This is the code I use:
procedureTForm1.InitRender(Sender:TObject;varrci:TRenderContextInfo);beginifnot(GL_ARB_shader_objectsandGL_ARB_vertex_programandGL_ARB_vertex_shaderandGL_ARB_fragment_shader)thenbeginShowMessage('Your hardware/driver doesn''t support GLSL and can''t execute this demo!');Halt;end;ifinit.Tag<>0thenExit;init.Tag:=1;programObject:=TGLProgramHandle.CreateAndAllocate;programObject.AddShader(TGLVertexShaderHandle,LoadStringFromFile('ocean_vp.glsl'),True);programObject.AddShader(TGLFragmentShaderHandle,LoadStringFromFile('ocean_fp.glsl'),True);ifnotprogramObject.LinkProgramthenraiseException.Create(programObject.InfoLog);ifnotprogramObject.ValidateProgramthenraiseException.Create(programObject.InfoLog);//initializetheheightmapwithMatLib.LibMaterialByName('waterGLSL')dobeginPrepareBuildList;glActiveTextureARB(GL_TEXTURE0_ARB);glBindTexture(GL_TEXTURE_2D,Material.Texture.Handle);glActiveTextureARB(GL_TEXTURE0_ARB);end;//initializetheheightmapwithMatLib.LibMaterialByName('cubeMapGLSL')dobeginPrepareBuildList;glActiveTextureARB(GL_TEXTURE1_ARB);glBindTexture(GL_TEXTURE_CUBE_MAP_ARB,Material.Texture.Handle);glActiveTextureARB(GL_TEXTURE0_ARB);end;programObject.UseProgramObject;programObject.Uniform1i['NormalMap']:=0;programObject.Uniform1i['EnvironmentMap']:=1;programObject.EndUseProgramObject;CheckOpenGLError;end;procedureTForm1.GLUserShader1DoApply(Sender:TObject;varrci:TRenderContextInfo);varmat:TMatrix;camPos:TVector;beginglGetFloatv(GL_MODELVIEW_MATRIX,@mat);InvertMatrix(mat);programObject.UseProgramObject;programObject.Uniform1f['Time']:=OceanShaderTimeVar*30*0.1;camPos:=GLCamera3.AbsolutePosition;programObject.Uniform4f['EyePos']:=camPos;end;procedureTForm1.GLUserShader1DoUnApply(Sender:TObject;Pass:Integer;varrci:TRenderContextInfo;varContinue:Boolean);beginprogramObject.EndUseProgramObject;end;procedureTForm1.OceanDGLRender(Sender:TObject;varrci:TRenderContextInfo);varx,y:Integer;v:TTexPointList;cont:Boolean;beginGLUserShader1DoApply(Self,rci);glEnableClientState(GL_VERTEX_ARRAY);ifnotAssigned(vbo)thenbeginv:=TTexPointList.Create;v.Capacity:=Sqr(200+1);y:=-200;whiley<200dobeginx:=-200;whilex<=200dobeginv.Add(y,x);v.Add(y+2,x);Inc(x,2);end;Inc(y,2);v.Add(y,200);v.Add(y,-200);end;vbo:=TGLVBOArrayBufferHandle.CreateAndAllocate();vbo.Bind;vbo.BufferData(v.List,v.DataSize,GL_STATIC_DRAW_ARB);nbVerts:=v.Count;glVertexPointer(2,GL_FLOAT,0,nil);glDrawArrays(GL_QUAD_STRIP,0,nbVerts);vbo.UnBind;v.Free;endelsebeginvbo.Bind;glVertexPointer(2,GL_FLOAT,0,nil);glDrawArrays(GL_TRIANGLE_STRIP,0,nbVerts);vbo.UnBind;end;glDisableClientState(GL_VERTEX_ARRAY);GLUserShader1DoUnApply(Self,0,rci,cont);end;
Last edit: Daniel 2017-11-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all!
Once again I call for your help!
I'm working on implementing the code from the GLSL ocean shader demo into my program.
The problem I have is that when I have another memoryViewer, unrelated to the ocean, and do:
Then the shader doesn't work.
Any idea why not?
I can upload the sample if needed.
Cheers!
Hi again!
I might have solved it temporarily, but still do not understand...
Now I instead have a problem that it runs out of memory after using the shader for a few minutes.
I'm bad at the GLSL, but some variable is building up an eating the memory in the ocean.
The 'time' variable is being reset in my program, so it's some other variable.
How can I prevent the shader from running out of memory?
Hi Daniel concerning the MemViewer if i'm remember this bug is solved in GLScene 1.5.
For the problem with shader :
1) I don't think the problem comes from the GLSL Script
2) Can you put also the VertexShader Script and how you do for instantiate the Shader, and how you pass parameters to it or can you make a little sample i'll can check
Thanks
Hi Jerome!
Thank you again for helping!
The above code is from the vertexShader.
Here is the fragment shader:
Another vertexshader I tried:
Something generates an error after ~5 minutes running the program. Last time it was a error directing to this function in GLScene.pas: function TGLBaseSceneObject.AbsoluteMatrixAsAddress : PMatrix;
Sometimes its an out of memory error.
This is the code I use:
Last edit: Daniel 2017-11-08
Now after 12 minutes I got, Error: "Unknown uniform 'Time' or program not in use (D:.....\Source\GLContext,pas, line 1487)"
And then
Vertex info
.--------------
(0) : fatal error C9999: out of memory - internal malloc failed
Try to pass the follwing part
in you InitRender procedure
and becarefull
you have
else you have
I suppose it's your error
Thanks Jerome!
I solved it now! It was a bad loop calling the initRender over and over...
I will stress test it and see if it works as intended!!