BASIC

Author Topic: Problem with the maximum number of 3D objects.  (Read 863 times)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Normally, GENX_OBJ() only returns -1 if there is not enough memory but that is not the case.
It seems that GLBASIC don't allow more than 4096 3d object.

------
EDIT
------
In fact, the GENX_OBJ()  function gives 4095 at the beginning and decreases with each call, it has nothing to do with the memory, this function is probably just in relation to a memory array of 4096.
It is very restrictive that the maximum number of objects is not related to the available memory (as the help says), but only with a precalculated memory array, because a 3D world can often contain more than 4096 objects  :(
« Last Edit: 2019-Feb-19 by Snoopy »

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
actually its 4224=4096+128 objects, but whos counting anyways? lol

i realize this defeats the purpose of having no extra files to load, yet...
u can reuse object ID numbers, and can save infinite amounts of objects to drive.

Code: GLBasic [Select]
INC num, 1 ////etc etc etc
CreateCube(num, sz)

// ------------------------------------------------------------- //
// -=#  CREATECUBE_NO_TEXTURE: Fast but without texture  #=-
// ------------------------------------------------------------- //
FUNCTION CreateCube_no_texture:  num, sz
        // Diese Variablen sind als LOCAL definiert:
        // num, sz,

        // 2-4-3-1
        // | | | |
        // 6-8-7-5
        //   | |
        //   6-5
        //   | |
        //   2-1
        //   | |
        //   4-3 Strip: 4 3 8 7 5 3 1 4 2 8 6 5 2 1

        // Normals + culling is wrong!!

LOCAL s[], n, m, x,y,z
        DIM s[14]
        s[0]=4; s[1]=3; s[2]=8; s[3]=7; s[4]=5
        s[5]=3; s[6]=1; s[7]=4; s[8]=2; s[9]=8
        s[10]=6;s[11]=5;s[12]=2;s[13]=1
        X_OBJSTART 0
                FOR m=0 TO 13
                        n=s[m]-1
                        x = MOD(n, 2)
                        y = 1-INTEGER(n/4)
                        z = 1-MOD(INTEGER(n/2), 2)
                        X_OBJADDVERTEX  x-.5, y-.5, z-.5, 0, 0, RGB(255,255,255)
                NEXT
        X_OBJEND
        X_SAVEOBJ "Filename" + num + ".png", 0
ENDFUNCTION

« Last Edit: 2019-Feb-19 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Hmm, I think you didn't understand the problem, but perhaps I'm poorly explained.
While you were answering me I wrote a modification in my first message, maybe it's clearer no?

If you exceed the number of 4096 objects in your program, your program crashes completely.
« Last Edit: 2019-Feb-19 by Snoopy »

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1634
  • Particle Hawk
    • View Profile
ye, sounds like an array crash
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Yes  :(

By cons, you are right in my test program it's not 4096 but 4224 the max  :D  :S 

I'm going to bed, this bug gives me a headache :sick:

Thank You Hemlos.

« Last Edit: 2019-Feb-19 by Snoopy »

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3652
    • View Profile
    • Space Fractal
confirmed.

howover if you have access to the source code and download it. Not sure why Gernot limit it, since its could been higher. its currectly limited to 4096. If you ask me, this should been possible to change to whatever limit, so its a array issue.

But if you have download the source code, you can change this line in the file rainbows3d.h to a higher value:

#define GLR_MAX_OBJECTS      0x1000

0x1000 is set to extractly 4096 and not sure its possible to REDIM it.

You can actuelly download the source code and recompile it.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Indeed, recompiling the source code could be a good idea, but my code will not be portable from one version to another  :(
Moreover, it's unfortunate that memory allocations are static and not dynamic (no difference between a cube or a complex object) and I guess it's the same for all other resources: sprites, sounds, ... 

For now I think I will dynamically allocate / deallocate objects in real time in my program (trying not to have too much slowdown).

Thanks for the confirmation Spacefractal.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3652
    • View Profile
    • Space Fractal
There is a _build.bat for every platform, which will compile the whole platform. Then done then you can build as normal. There is a limit of 4096 objects in this case, but would been nice if you can set it  to any number by your self. but for now, this is the way for go.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10708
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
You need more than 4000 different 3D objects? Really?

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Yes, it's not so strange :)

Here are some reasons:
1 / We can only assign one texture per object (it's also a problem for the lightmapping).
2 / You have implemented a frustrum optimization by object (thanks, needless to do it), so it's interesting for speed.
3 / For example, games like Minecraft require a lot of objects.
4 / Moreover, what is important for the speed (and the memory) in Opengl is not the number of objects but the complexity of each object.

But rest assured, on the maps where I need more, I will assign them on the fly (I hope without much slowdown).

Thank you for your interest and long life to GLB on Steam  :good:

--- EDIT ---

Hmm ... after Gernot's intervention, I thought about it and maybe I was wrong.
I'm looking for too much speed, I'll see my algorithm again tomorrow.

Thank you Gernot you helped me without even answering me  :D
« Last Edit: 2019-Mar-01 by Snoopy »

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10708
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Re: Problem with the maximum number of 3D objects.
« Reply #10 on: 2019-Mar-09 »
You don't need a separate object if you want to switch the texture.

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Re: Problem with the maximum number of 3D objects.
« Reply #11 on: 2019-Mar-12 »
Yes, of course, but not the coordinates of the texture, as I have said, it's a problem for the lightmapping.
In fact, I had:
- different objects.
- similar objects but with different texture coordinates.
- but also similar objects with the same texture coordinates ... it's stupid  =D (especially for the low speed gained during the display).

I take this topic to ask you if one day the problem to make a lightmapping will be solved?
In summary, the possibility to assign multiple textures with different coordinates on the same object.
I think the lightmapping is important in a 3D game for a good rendering without asking the GPU too much (especially on mobile).

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 3652
    • View Profile
    • Space Fractal
Re: Problem with the maximum number of 3D objects.
« Reply #12 on: 2019-Mar-12 »
Snoopy, can you use the source code. its a easy fix with the total number objects really. Its can been happens more than 4096 is required throught if speed is not a issue.

Just change the define and rebuild it with the platforms _build.bat and then you can have more than 4096 objects.

Source Code is possible to download.
Greedy Mouse - Karma Miwa - Spot Race - CatchOut - Android Extras - is on a vacation trip, home before end of few days in jan.

Offline Snoopy

  • Dr. Type
  • ****
  • Posts: 282
    • View Profile
Re: Problem with the maximum number of 3D objects.
« Reply #13 on: 2019-Mar-13 »
No, but it's ok now, it was just a cloning problem with objects and I took the opportunity to ask for information on multitexturing.
But you're right, one day I will have to look at the source code.