Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 16 Jan 2012
Offline Last Active Aug 28 2016 03:53 PM

#5282608 Understanding the difference in how I should be drawing lots of objects

Posted by on 22 March 2016 - 06:24 AM

If you don't need to read the vbo on the cpu side and if you don't have to update many different parts of the vbo it would propably be faster to just push updates to the vbo using GL.BufferSubData. That way the driver doesn't have to retrieve the data back from the gpu. This is because mapping the buffer has the driver retrieve the specified part of vbo from vram into ram and then on unmap transfering the whole thing back to vram. With buffersubdata it never retrieves anything from gpu and only updates the part specified in the command.


But all of the methods suggested here are valid and the only way of knowing wich one has the most performance is to profile them with your actual use case. And when doing that you propably should look into highprecision timer and timing individual frames. Keep a list of say 600 frames and you can get the shortest the longest and the avarage. Measuring performance in how many milliseconds or if you want even in nanoseconds is important as that gives a much better idea of just how much your performance drops than frames per second. Also keeping a record of individual frames lets you see the longest frames and help you find stutters and such more easily.

All you have to worry about is if your frame time exceeds 16 milliseconds then you can no longer quarantee 60 fps and you might need to optimize. Or if you are targeting a differrent fps(for vr i think you need over 90 and for mobile 30 should be enough) you can calculate the millisecond limit by 1000/fps.

#5265927 C# Color Wheel

Posted by on 11 December 2015 - 02:03 PM

I'm sorry, but I'm really not comfortable divulging the purpose of it. I understand that in some cases it could make it easier to understand the best way to do it, but in this case I've told you all that is necessary. I really want nothing more than a color picker that can restrict the range of colors that a user can pick. What more clarification do I need? The reason is not important, but if anyone has a way to accomplish this, I'm all ears.

The problem here is that there are a few thousand different methods to do this depending on what you are using to interact with the user. For example the most common approach would be to use winforms but you can also use mono, unity or pretty much anything else ever concieved to interact with the user. For all we know you might be using a COM interface to make a grid of leds go on and off. Or if you don't have anything at all then I suggest you start looking at winforms tutorials and when you have a window with some interactivity you come back and tell us what you used to make the window and we will happily figure out a way to make a color picker for that. Making a simple color picker from nothing at all is several months of work even for a professional. Even if we picked a library at random and made a ready to use color picker for it it would propably take a long long time for you to integrate it into your project. So help us help you and give us little more details.

You are right that you don't have to tell us what your project is about but everyone else is also rigth that we need more information to be able to help.

#5260828 GLSL not behaving the same between graphics cards

Posted by on 06 November 2015 - 04:26 PM


Do you check for errors when compiling and linking the shaders? Is it failing to link, but you just ignore the failure and try and render with it anyway?

I should have mentioned this in the original post, sorry. I'm not getting any errors while compiling or linking.


Do you use glGetError, glGetProgramInfoLog and glGetShaderInfoLog. Shader errors do not always show in glGetError. You can also try to use glValidateProgram. If none of these show anything then we can consider a driver bug.

#5247888 Terrain Normals : Quick questions about calculating on the fly...

Posted by on 20 August 2015 - 09:37 AM

Games like Magic Carpet or Populous the Beginning come to mind for me


As far as I know those games didn't use normals or anything similar. They just used a predrawn tileset. There just isn't any algorithm that could be used 20 years ago that could do that realtime so they faked it by using predrawn images.

#5239742 Need help creating procedural rivers

Posted by on 11 July 2015 - 09:40 AM

A 1024x1024 for A* is a really simple problem if you are running it on a processor faster than a handheld calculator. Especially when you only need to run it during worldgen. Also what I would do is just repeat three steps after a swawnpoint has been found.

1. You find the steepest downward slope around the current point and go there.

2. If there isn't a downward slope you floodfill towards directions that are even with current position until you find a downward slope and then you A* a path to that location and go back to 1.

3. If you cant find a downward slope with the floodfille you make a lake that fills the whole floodfill area and go back one step of the river and go back to 1. where you handle the lake as if the height of the terrain was one level higher(as there is now a lake there). You should also allow multiple lakes to be on top of each other to form a deeper and bigger lake.


If you continue this the river will eventually reach the ocean and it will generate nice and realistic lakes as well.


Also if you reach the spawnpoint when going backwards in step 3 then you can stop the river there and you have a nice lake there. Not all lakes have a river that leads to the ocean.

#5219974 Multithreaded mesh loading and 0xcc returned from glGenVertexArrays

Posted by on 29 March 2015 - 09:25 AM

You can't use the same context in multiple threads at the same time. You can "release" a context and "bind" it to another thread but that obviously makes you unable to use it in the original thread. You can however use multiple contexts and have them share resources with each other wich is propably what you want.



#5197453 game running slow but only consuming a tiny proportion of the CPU

Posted by on 10 December 2014 - 02:37 PM

I can't count the number of times I've seen people try to fix a performance problem without profiling. It almost always happens like this:

Yeah same here. And some people fail to find the problem even with a profiler because they cant figure out how to use the profiler or how to interpret the data.



VS Express may not have a profiler tool, but you can do your own profiling with the .NET StopWatch class.

Except he stated in the op that he is working on a c++ project and earlier today he said that he got a new VS which does have a profiler. I tought that with one time telling people not to skim the op and the thread would be enough. Skimming the posts and giving wrong advice because of it only confuses the op more.



thanks for all the helpful answers - VS Express doesn't have a profiler - but I've now got Community which does. I've checked and I'm I'm running a dual core i5 with HT, so there's 4 logical cores and the VS profiler is showing it maxing out at 25% CPU, where Task Manager was showing 12-13% - so it is one thread maxed out. And I'll not be trusting numbers from Task Manager again...

Great. Now I would suggest that you run the cpu sampling(may require admin priviliges the first time) and you can see wich function uses the most cpu and then you can even look at what lines take the most time inside that function. Tell us what you find and hopefully we can give you some easy optimization advice that will get your fps up to desired level.


Also if you can could you post the lines that use most of the time it would be easier to see what needs to be done.

#5197251 game running slow but only consuming a tiny proportion of the CPU

Posted by on 09 December 2014 - 02:14 PM

Yes, I did smile.png To be honest my first guess would be that one core is 100% busy and on 8 core machine it would exactly like 12%-13%. However I didn't mention it as OP says he has only 2 cores. Even if it's 2 actual cores + 2 virtual ones, it's still not enough. I agree it is guess game here, but even with the code available it will be. Only profiler can give some results, but unless OP will upgrade from Express to at least Community edition the profiler won't be available and guessing is all we have smile.png


Yeah without profiling the code itself will only be helpfull if someone is lucky enough to spot something thats off(more likely if that person has dealt with similar cause on his own code recently). But cpu not maxing out is only possible when some function is waiting for an event to fire wich in a singlethreaded program most likely is sleep(), A polling function, reading from a slow media(HDD) or a blocking call to gpu. But as said before we can only guess.


The reason I'm asking about the way you poll your socket is because socket.poll function is usually by default a blocking call that waits for a timeout. This timeout can only happen when the os "ticks". Wich happens in windows every ~16ms if I remember correctly. Depending what library you use you propably can set it to nonblocking.

#5195714 Best way to follow a moving object

Posted by on 01 December 2014 - 09:21 AM

If you only have 100x100 grid it would propably be faster to just floodfill from the player. That way you only have to calculate ~10 000 distances once after the player moves from a node to another and every node knows what is the fastest direction to go to reach the player. No matter how many enemies you have the pathfinding time is constant as they only have to look the next direction from the grid. If it still isn't fast enough you can spread the floodfill to multiple frames of say 1000 nodes per frame. The additional lag of the further away nodes shouldn't be very noticeable as the path far away would stay the same most of the time.

#5191657 My high score do not update after restart

Posted by on 07 November 2014 - 06:58 AM

= is an assign operator. What it basically does is put whatever is on the right side into whatever is on the left side. Tough I can see how people new to programming could assume it would work differently.

#5191646 My high score do not update after restart

Posted by on 07 November 2014 - 05:51 AM

I don't know how gameEnd is called or how your gameoverscript works but I'll make a guess that

points = highscore;

is propably wrong way around and should be

highscore = points;


#5170289 Rendering differences in OpenGL versions?

Posted by on 30 July 2014 - 05:44 AM


I don't think the graphics card type should make the difference

This is most likely the reason. Different hardware and driver will often result in different behavior, reaching from not supported features, simple driver bugs to different interpretation of shader code (AMD = more strict, NVIDIA = more relaxed).



From my experience it's more about the driver than the hardware. Also the AMD=strict, NVIDIA=relaxed hasn't been true for a long long time. It varies based on driver versions more than witch hardware you are on. With the most up to date drivers AMD is actually more relaxed allowing some incomplete textures and buffers as well as implicit casts that truncate values in shadercode while NVIDIA just gives GL invalid operation errors. Neither AMD or NVIDIA goes strictly by the standard and the relaxness/strictness varies with driver versions and what you want to do so you always have to test everything with both.


Back to op.


Yes you should use shaders to all things possible. They will almost always be faster and more reliable. And once you get used to rendering everything with shaders it actually gets easier to do than with immidiate mode. And don't be afraid of using multiple shaders. A lot of people will always say to write generic code so you can reuse it as much as possible. But with shaders you actually want to do the opposite and make as specific shaders as possible. This is because generic all purpose shaders are usually painfully slow and it would be heaps faster to just use multiple slightly different shaders even if you have to split some drawcalls into two or three.

Altough that being said. I still sometimes use immideate mode when I'm debugging the non rendering code before I have established a proper rendering system using shaders because it is super simple to get a few triangles to the screen with it.


Also be careful about the version numbers. The glsl version numbers don't match with the opengl version numbers until after opengl 3.3. see http://en.wikipedia.org/wiki/OpenGL_Shading_Language#Versions for a complete list of glsl versioning.

#5164930 Using VBOs for dynamic geometry

Posted by on 05 July 2014 - 02:31 PM

You don't actually need to invalidate the VBO when using GL.BufferData(). Inputting new data already does everything you need. If you want to use the invalidating you need to use GL.MapBuffer(). More on the subject here -> http://www.opentk.com/doc/graphics/geometry/vertex-buffer-objects.

Also if you are rendering the buffer that you just updated then the potential speedup of using multiple buffers goes to waste seeing as the drawarrays has to wait for the datatransfer to complete before starting to do the actual rendering in wich case you might aswell use a single buffer. You need to update the data of the buffer that is going to be rendered next frame instead. Besides multibuffering VBO:s isn't usually going to give you much anyways as the bottleneck is most of the time somewhere else.


Most times when gfx programmers talk about double or triple buffering what they mean is that they have two or three "screens" to wich they do all the rendering and in case of double buffering they swap the buffers after all rendering to the current frame has been completed. And in triple buffering they swap the two background rendering buffers after rendering is finished and swap the currently not in use rendering buffer with the displayd buffer when the monitor has finished presenting the buffer.


Be careful of overoptimization. What you should do is set yourself a goal fps. And only start optimizing if you get below that fps. Anything above it shouldn't matter at all. If you want 60+ fps, you add a feature and your fps drops from 200 to 120 just shrug it off and continue adding the next feature. And always start with the easiest optimizations first as they are more likely to take less time to implement and over half the time it will get you above the target fps.


Edit: oh and before you start to optimize anything profile the damn thing thoroughly so you avoid using tens of hours optimizing the part that takes 0.01% of the actual process. Use http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx to measure the time it takes on "your" end of the process on different parts of the program. And GL.BeginQuery(QueryTarget.TimeElapsed,...); and GL.EndQuery(QueryTarget.TimeElapsed); to measure the time it takes for the driver and the gpu to perform the tasks that were issued between them.

#5164059 Using VBOs for dynamic geometry

Posted by on 01 July 2014 - 10:17 AM

Creating a pool and resizing is a good idea. However there is another problem I'm facing when I use VBOs:

I'm currently using a List to store vertex data and render them as described above. This is very comfortable, because I can add/remove vertices from the list every frame. The downside is that rendering a huge amount of vertices takes ages. So VBOs are much faster for rendering, but a lot of flexibility is taken away, because now I need to use arrays to store vertex/index data. With VBOs I have to build a new vertex/index/normal buffer whenever the geometry changes and in my case, this can happen every frame. I know that this is not a VBO/OpenGL problem per se, but maybe someone has good ideas to solve that.

Your code looks like c# so I'm assuming you haven't looked at the list.ToArray() function wich is almost free so you can GL.bufferdata(list.toarray,count). Also you don't need to generate new buffers. Just update the old ones.

#5148731 Fantasy Guild Management Sim

Posted by on 22 April 2014 - 08:35 AM

Have you ever tried the ogre battle series. It had an intresting take on the combat where you couldn't directly control any of the characters but nstead you chose the strategy they used. For example you could set the strategy to kill lowest hp first, party leader first, strongest attacker first etc. Then the combat just happend on its own.


I suppose management games aren't that popular but I certainly would play a fantasy guild managament game.