Author Topic: Cpct?  (Read 15386 times)

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #120 on: April 20, 2021, 07:46:54 am »
I'm porting GLSLShader and ShadowHelper right now. Around line 382, ShadowHelper does world.setAmbientLight(col.getRed(), col.getRed(), col.getBlue()). Is that a bug or did you use red twice on purpose?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #121 on: April 20, 2021, 09:09:54 am »
Opps, no....that's supposed to be col.getGreen(). The Android version does is correctly though.

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #122 on: April 22, 2021, 09:01:40 pm »
This is what my renderVertexArray(int) method looks like, because I couldn't find OpenTK equivalents for the ARBMultitexture stuff. Could that be the problem?

Code: [Select]
       private void renderVertexArray(int curPos) {
              if (curPos != 0) {
                     bool dissed = false;
                     // For Projective the texture coordinates from ...
                     for (int i = 0; i < projective.Length; i++) {
                            if (projective[i] && buffersEnabled[i]) {
//                                   ARBMultitexture.glClientActiveTextureARB(stageMap[i]);
                                   GL.DisableClientState(ArrayCap.TextureCoordArray);
                                   dissed = true;
                            }
                     }
                     GL.DrawArrays(PrimitiveType.Triangles, 0, curPos);
                     if (dissed) {
                            // And on again if required. Actually, this should be dead, but you are not in the driver.
                            for (int i = 0; i < projective.Length; i++) {
                                   if (projective[i] && buffersEnabled[i]) {
//                                          ARBMultitexture.glClientActiveTextureARB(stageMap[i]);
                                          GL.EnableClientState(ArrayCap.TextureCoordArray);
                                   }
                            }
                     }
              }
       }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #123 on: April 23, 2021, 07:25:39 am »
I'm not sure what you mean, because there is ARBMultitexture-stuff in your code anyway. However, it might be worth a try and see if your constants are the same as they are in normal OpenGL. These should just be integers and if your toolkit isn't doing something really strange with them, something like PrimitiveType.Triangles should have the same value as OpenGL's GL_TRIANGLES.

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #124 on: April 23, 2021, 07:50:28 am »
The ARBMultitexture lines are commented out in the above code. But I found GL.ActiveTexture((TextureUnit)stageMap), which I hope is the same. Still, no progress on the vertex array problem. As for PrimtiveType.Triangles, I'm confident about it.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #125 on: April 23, 2021, 09:18:32 am »
I see...it shouldn't matter much though, because it's only used for projective texturing, which in most cases, you don't need unless you are using shadow mapping and, well, projective textures.

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #126 on: May 19, 2021, 12:51:53 am »
Our little engine has a very specific approach to OpenGL, so online examples aren't always very helpful. I have found the following answer (https://stackoverflow.com/questions/61030683/opengl-opentk-drawing-with-indices-attempted-to-read-or-write-protected-memo) to a similar problem, but I can't fit it into the pipeline. GLRenderer.renderVertexArray(int) is currently throwing:
Quote
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at OpenTK.Graphics.OpenGL.GL.DrawArrays(PrimitiveType mode, Int32 first, Int32 count)
   at co.ratto.threed.GLRenderer.renderVertexArray(Int32 curPos)
   at co.ratto.threed.GLRenderer.drawVertexArray(VisList visList, Int32 start, Int32 end, FrameBuffer buffer, World world)
   at co.ratto.threed.World.draw(FrameBuffer buffer, Boolean wireframe, UInt32 frameColor, Int32 start, Int32 end)
   at co.ratto.threed.World.draw(FrameBuffer buffer, Boolean wireframe, UInt32 frameColor)
   at co.ratto.threed.World.draw(FrameBuffer buffer)
   at co.ratto.threed.SkyBox.render(World world, FrameBuffer buffer)
   at LivingForest.draw()
   at LivingForest.gameLoop()
   at LivingForest.OnUpdateFrame(FrameEventArgs e)
   at OpenTK.GameWindow.RaiseUpdateFrame(Stopwatch watch, Double elapsed, Double& timestamp)
   at OpenTK.GameWindow.DispatchUpdateFrame(Stopwatch watch)
   at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second)
   at LivingForest..ctor()
   at LivingForest.Main(String[] args)

And this is my port (almost identical to yours):
Code: [Select]
       private void createVertexArrays(int max) {
              GL.EnableClientState(ArrayCap.TextureCoordArray);
              for (int i = 0; i < max; i++) {
                     multiTextures[i] = new FloatBuffer(VertexArraySize * 2);
                     GL.ActiveTexture((TextureUnit)stageMap[i]);
                     GL.TexCoordPointer(2, TexCoordPointerType.Float, 8, multiTextures[i].array);
                     if (i == 0) {
                            textures = multiTextures[0];
                            buffersEnabled[0] = true;
                     }
              }
       }
       private void renderVertexArray(int curPos) {
              if (curPos != 0) {
                     bool dissed = false;
                     // For Projective the Texture Coordinates from ...
                     for (int i = 0; i < projective.Length; i++) {
                            if (projective[i] && buffersEnabled[i]) {
                                   GL.ActiveTexture((TextureUnit)stageMap[i]);
                                   GL.DisableClientState(ArrayCap.TextureCoordArray);
                                   dissed = true;
                            }
                     }
                     GL.DrawArrays(PrimitiveType.Triangles, 0, curPos);
                     if (dissed) {
                            // And on again if necessary. Actually, that should be dead, but you are not in it in the driver.
                            for (int i = 0; i < projective.Length; i++) {
                                   if (projective[i] && buffersEnabled[i]) {
                                          GL.ActiveTexture((TextureUnit)stageMap[i]);
                                          GL.EnableClientState(ArrayCap.TextureCoordArray);
                                   }
                            }
                     }
              }
       }

If you have any insights I would greatly appreciate them.

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #127 on: May 19, 2021, 09:24:42 am »
Never mind that. After too long with no success, I've started rendering things beautifully. A lot of different problems at the moment, like the fact that no compiled object is working. Only so many blitting methods work at all, for that matter, maxPolysVisible can't be much more than 512k for some reason, and a few other mysteries.

Oh, and C# can't catch exceptions across threads, which is a nuisance. I may have to switch to Tasks, if that's doable.
« Last Edit: May 20, 2021, 08:44:11 am by AGP »

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #128 on: June 25, 2021, 09:24:33 am »
I think that I've figured out my problem with CompiledInstance memory errors: I had to delete the reflection (I really wish you would forget Java 1.1 ever existed), and I can't see how your code ever calls Object3DCompiler.compile(...) (or Versionhelper5.compile(...) for that matter). Help me out?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #129 on: June 28, 2021, 07:34:05 am »
It's called from within World.compile(), which you can most likely ignore, because it's only relevant if you call World.compileAllObjects() and from within WorldProcessor.processInternal(), which is the "normal" way.

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #130 on: June 28, 2021, 07:44:50 pm »
I put in a bizarre wait of 2.5 seconds and cleared that block as far is this bit. Now, no matter what I try indices is null. What I'm trying is hacky, anyway, so I'd rather ask you when indices in CompiledInstance.renderVBO() might be null. The C# runtime operates very differently from the JVM.

Code: [Select]
              do {
                     if (indexed) {
                            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indicesId);
                                   System.Console.WriteLine("CompiledInstance.renderVBO(): Is indices null? "+(indices==null));
                                          if (indices==null){
                                                 indices = new IntBuffer(tris.Count * 3);
                                                 //return;
                                                 while (indices == null)
                                                 continue;}
                            GL.DrawElements(primitiveType, indexCount, DrawElementsType.UnsignedInt, indices.array);
                                   System.Console.WriteLine("CompiledInstance.renderVBO(): BindBuffer()?");
                            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
                     } else {
                            System.Console.WriteLine("\n\nCompiledInstance.renderVBO(): GL.DrawArrays(...).\n");
                            GL.DrawArrays(primitiveType, 0, cnt);
                     }
              }

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #131 on: June 29, 2021, 07:41:40 am »
Indices can be null, if the object in question hasn't been compiled with indexed geometry. This should only be the case if the object is a dynamic one (i.e. animated or has an attribute list attached to it or a vertex controller). Or you can force non-indexed compilation by using the corresponding build() call.

However, if the indexed flag in a compiled instance is true, indices can't be null unless you did something wrong when compiling the object.
« Last Edit: June 29, 2021, 01:58:56 pm by EgonOlsen »

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #132 on: July 04, 2021, 07:54:37 am »
It's infuriating that although I don't know why the indexed flag is true, the following block produces the following output. I don't suppose anyone would have any insights here?

Code: [Select]
              do {
                     if (indexed) {
                            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indicesId);
                                   System.Console.WriteLine("CompiledInstance.renderVBO(): Is indices null? "+(indices==null));
                                   if (indices==null){
                                          indexed = false;//A HACK
                                                               System.Console.WriteLine("HACKHACKHACKHACKHACKHACK");
                                                 indices = new IntBuffer(tris.Count * 3);
                                   return;}
                            if (indexed){//A HACK
                            GL.DrawElements(primitiveType, indexCount, DrawElementsType.UnsignedInt, indices.array);
                                   System.Console.WriteLine("CompiledInstance.renderVBO(): BindBuffer()?");
                            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);}
                     } else {
                            System.Console.WriteLine("\n\nCompiledInstance.renderVBO(): GL.DrawArrays(...).\n");
                            GL.DrawArrays(primitiveType, 0, cnt);
                     }
              }

Quote
CompiledInstance.renderVBO(): Is indices null? True
HACKHACKHACKHACKHACKHACK

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at co.ratto.threed.CompiledInstance.renderVBO(Boolean vertexAlpha, IRenderHook hook)
   at co.ratto.threed.CompiledInstance.render(Int32 myID, IRenderer renderer, Single[] ambient, Single[] cols, Boolean intoDepthMap, Camera cam, Single[][] lights, Boolean wireFrame, Object[] data)
   at co.ratto.threed.GLRenderer.drawVertexArray(VisList visList, Int32 start, Int32 end, FrameBuffer buffer, World world)
   at co.ratto.threed.World.draw(FrameBuffer buffer, Boolean wireframe, UInt32 frameColor, Int32 start, Int32 end)
   at co.ratto.threed.World.draw(FrameBuffer buffer, Boolean wireframe, UInt32 frameColor)
   at co.ratto.threed.World.draw(FrameBuffer buffer)
   at co.ratto.threed.SkyBox.render(World world, FrameBuffer buffer)
   at LivingForest.draw()
   at LivingForest.gameLoop()
   at LivingForest.OnUpdateFrame(FrameEventArgs e)
   at OpenTK.GameWindow.RaiseUpdateFrame(Stopwatch watch, Double elapsed, Double& timestamp)
   at OpenTK.GameWindow.DispatchUpdateFrame(Stopwatch watch)
   at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second)
   at LivingForest..ctor()
   at LivingForest.Main(String[] args)
« Last Edit: July 04, 2021, 08:12:41 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12241
    • View Profile
    • http://www.jpct.net
Re: Cpct?
« Reply #133 on: July 04, 2021, 10:32:33 am »
What's the actual line that throws this exception? The stack trace doesn't tell... ???

Offline AGP

  • quad
  • ******
  • Posts: 1719
    • View Profile
Re: Cpct?
« Reply #134 on: July 04, 2021, 07:33:33 pm »
It has to be GL.DrawElements(primitiveType, indexCount, DrawElementsType.UnsignedInt, indices.array) because there's a printout right after it that doesn't get printed.