Main Menu

Cpct?

Started by AGP, September 16, 2019, 06:45:59 PM

Previous topic - Next topic

AGP

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?

EgonOlsen

Opps, no....that's supposed to be col.getGreen(). The Android version does is correctly though.

AGP

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?


       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);
                                   }
                            }
                     }
              }
       }

EgonOlsen

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.

AGP

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.

EgonOlsen

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.

AGP

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):

       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.

AGP

#127
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.

AGP

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?

EgonOlsen

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.

AGP

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.


              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);
                     }
              }

EgonOlsen

#131
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.

AGP

#132
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?


              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)

EgonOlsen

What's the actual line that throws this exception? The stack trace doesn't tell... ???

AGP

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.