Use index as coordinate in OpenGL

I want to implement a timer viewer that allows the user to scale and smoothly pan.

I already did opengl instant mode, but now it is deprecated in favor of VBOs. In all VBOs examples, I can find the XYZ coordinates for storing each point.

I suspect that I need to save all my data in VRAM in order to get the frame rate during panning, which can be called “smooth”, but I only have Y data (dependent variable). X is an independent variable that can be calculated from the index, and Z is a constant. If I need to store X and Z, then my memory requirements (both the buffer size and the CPU-> GPU block transfer) will triple. And I have tens of millions of data points through which the user can pan, so memory usage will be non-trivial.

Is there any method for drawing a 1-D vertex array where the index is used as another coordinate or storing a 1-D array (possibly in a texture?) And using a shader program to generate XYZ? I get the impression that I need a simple shader anyway in the framework of the new model of the pipeline with fixed functionality in order to implement scaling and translation, so if I could combine the generation of X and Z coordinates and Y scaling / translation, which would be ideal .

Is it possible? Do you know any sample code that does this? Or can you at least give me some pseudo-code saying that GL is making the call in what order?

Thank!

EDIT: to make sure this is clear, here is the equivalent immediate mode code and the vertex array code:

// immediate
glBegin(GL_LINE_STRIP);
for( int i = 0; i < N; ++i )
    glVertex2(i, y[i]);
glEnd();

// vertex array
struct { float x, y; } v[N];
for( int i = 0; i < N; ++i ) {
    v[i].x = i;
    v[i].y = y[i];
}
glVertexPointer(2, GL_FLOAT, 0, v);
glDrawArrays(GL_LINE_STRIP, 0, N);

, v[] y[].

+5
2

OpenGL.

(VBO) , , GL. VBO :

glGenBuffers( 1, &buf_id);
glBindBuffer( GL_ARRAY_BUFFER, buf_id );
glBufferData( GL_ARRAY_BUFFER, N*sizeof(float), data_ptr, GL_STATIC_DRAW );

:

glBindBuffer( GL_ARRAY_BUFFER, buf_id );
glEnableVertexAttribArray(0);  // hard-coded here for the sake of example
glVertexAttribPointer(0, 1, GL_FLOAT, false, 0, NULL);

, . :

#version 130
in float at_coord_Y;

void main() {
    float coord_X = float(gl_VertexID);
    gl_Position = vec4(coord_X,at_coord_Y,0.0,1.0);
}

, at_coord_Y , (= 0 ):

glBindAttribLocation(program_id,0,"at_coord_Y");

, , :

const int attrib_pos = glGetAttribLocation(program_id,"at_coord_Y");

!

+4

XY VRAM?

( ).

.

0

All Articles