How to pass array of dozens of floats to OpenGL 3.0 shader?

I use PyOpengl and Python 3.

I have 50 thousand vertices. Position of each vertex could be calculated in vertex shader as

#version 300 es  uniform v_coefficients_weights[COEFFICIENTS_AMOUNT]; in vec3 v_coefficients[COEFFICIENTS_AMOUNT]; in vec3 v_initial_position; out vec3 v_position;  void main() {     v_position = v_initial_position + v_coefficients * coefficients_weights; } 

Amount of coefficients varies between 0 and 199 — it's not a problem for me to generate 200 vertex shaders to cover each situation.

Though, I cannot provide arrays for each vertex because documentation says:

Attribute variables cannot be declared as arrays or structures.

I see following solutions of this issue:

  • hardcode suffices of variables names to emulate arrays:
    • use vectors with names like coefficients_000, coefficients_001, ..., coefficients_199;
    • use matrices to have 4 vectors in each of variable — will it be better than previous solution with vectors (maybe performance of matrices product is faster than 4 products of vectors)?
  • calculate vertices positions by myself using C/NumPy;
  • calculate vertices positions by myself in parallel using OpenCL.

Are there any other solutions of my issue? Is there optimal solution in proposed above? Will I go out of memory if I will use 200 float 3-vectors for each vertex?

I imagine the solution with hardcoded indices as:

#version 300 es  uniform v_coefficients_weights[COEFFICIENTS_AMOUNT];  in vec3 v_coefficients_000; in vec3 v_coefficients_001; ... in vec3 v_coefficients_199;  in vec3 v_initial_position; out vec3 v_position;  void main() {     v_position = v_initial_position         + v_coefficients[0] * coefficients_weights_000         + v_coefficients[1] * coefficients_weights_001         + ...         + v_coefficients[199] * coefficients_weights_199; } 

Replay

Category: opengl Time: 2016-07-30 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.240 (s). 12 q(s)