forum.boolean.name

forum.boolean.name (http://forum.boolean.name/index.php)
-   C++ (http://forum.boolean.name/forumdisplay.php?f=22)
-   -   glDrawRangeElements, много думал или glилософия (http://forum.boolean.name/showthread.php?t=6360)

jimon 12.09.2008 20:14

glDrawRangeElements, много думал или glилософия
 
предыстория :
хотел отрендерить модель по кускам (сначала от 0 - до 100 индекса, потом от 101 до 200 и тд)
ничего не работало и не хотело работать
наткнулся на вот эту прекрасную тему : (на англ)
http://www.gamedev.net/community/for...opic_id=331317
и дальше по домыслам доехал в чем дело

самые нужные и полезные цитаты из той темы :
1)
Цитата:

start specifies the minimum index and end the maximum index. They dont specify the range you want drawn.
2)
Цитата:

For example, if you were drawing a cube with quads your index array would look like this :

(each 4 indices making up the quads in the order: front, top, back, bottom, left, right)
[0,1,2,3],[0,3,5,4],[5,4,7,6],[6,1,2,7],[0,4,7,1],[3,5,6,2]

Now, that would give you a start of 0 and an end of 7 but a count of 24.
3)
Цитата:

As long as you provide the min and max values, it knows exactly what portion of the vertex array will be used, without ever having to read the vertex array from memory. OpenGL can then set up a DMA session to send that portion of the array straight from memory to the GPU, without ever passing through the CPU.

Specifying 0 for the min, and #-of-vertices for the max will never lead to incorrect results, it just may cause a minor performance hit as the GPU reads more data than may be necessary. For ease of debugging, I highly suggest not trying to limit these values until later, once everything else is working.
вот вырезка из спецификации

http://www.opengl.org/sdk/docs/man/x...geElements.xml
Цитата:

void glDrawRangeElements( GLenum mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const GLvoid * indices);


Parameters

..........

start
Specifies the minimum array index contained in indices

end
Specifies the maximum array index contained in indices

count
Specifies the number of elements to be rendered
что собсно и есть в спецификации, но как бы обычно пролетает мимо ушей, особенно когда куришь семплы где вся модель рисуется сразу

в общем, итог :
start указывает на минимальный номер вертекса в масиве из масива вертексов,
end указывает на максимальный номер вертекса в масиве из масива вертексов
count указывает сколько индексов рисовать

как я понимаю это понадобилось для рендера без VBO, но в чем выгода при применении VBO ?
вот цитата из nvidia vbo white paper
Цитата:

Using range elements is more efficient for two reasons:

1)If the specified range can fit into a 16-bit integer, the driver can optimize the
format of indices to pass to the GPU. It can turn a 32-bit integer format into a
16-bit integer format. In this case, there is a gain of 2×.

2)The range is precious information for the VBO manager, which can use it to
optimize its internal memory configuration.
тоесть range как я понимаю это end - start + 1, если это число вмещается в 16 битное целое (signed или unsigned ?) то драйвер оптимизирует масив индексов (понятно как - мапит зону в вертекс буфере и отнимает от индексов определённое число, и понятно что это приводит к более ускореной выборке вертексов)

но в связи с етим получается несколько вопросов :
1) если каждый раз range меняется, что будет ?
2) что лутче - рендерить один VBO с разными range или рендерить много VBO ? (так чтобы в первом и втором случае за раз рендерилось меньше N вертексов)
просто проскакивала информация что оптимальный размер VBO на видеокартах Nvidia 8xxx,9xxx это 31кб (или 31 тысяча елементов - не понятно)

Черный крыс 16.01.2014 15:02

Ответ: glDrawRangeElements, много думал или glилософия
 
Спасибо джимон!

Я как раз подумал про эту функцию так как ты описал в заблуждениях.

pozitiffcat 22.01.2014 23:13

Ответ: glDrawRangeElements, много думал или glилософия
 
Чем это не зашло?
Код:

void glDrawElements(GLenum mode,  GLsizei count,  GLenum type,  const GLvoid * indices);
пример
Код:

glDrawElements(GL_TRIANGLES, 100, GL_UNSIGNED_SHORT, reinterpret_cast<void*>(101));
со 101 индекса нарисует 100 индексов
темболее glDrawRangeElements нету в GLES2 спеке


Часовой пояс GMT +4, время: 19:02.

vBulletin® Version 3.6.5.
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Перевод: zCarot