Reputation: 695
This is using an OpenGL port called lwjgl. So lets say I have a double array:
double[] orthographic={1.0,0.0,0.0,0.0,
0.0,1.0,0.0,0.0,
0.0,0.0,-2.0,5.0,
0.0,0.0,0.0,1.0,};
And I have a vertex shader:
String vertexshader = "#version 430 core"
+ System.getProperty("line.separator")
+ "layout(location = 0) in vec4 vertexin;"
//Does this have to be a dvec4?
+ "layout(location = 1)uniform mat4 orthographic;"
//Does this have to be a dmat4?
+ "void main(){"
+ "gl_Position = orthographic * vertexin;"
//Is this multiplication correct? Do I need to reverse it?
+ "}";
And lets also say I have a theoretic completely functioning fragment shader. So I want to send the orthographic array into the mat4. How would I do this given that it is a double array? Can I just use gluniformmatrix4()? Do I need to make mat4 into dmat4? If so that would mean I have to make vec4 into dvec4 because of casting. Well if I was to do this then OpenGL would throw an error
Failure in compiling vertex shader. Error log:
0(2) : error C7011: implicit cast from "f64vec4" to "vec4"
I have googled this but to no avail. There is literally only 4 things matching the search none of them relevant. Am I playing with the wrong things here? My screen resolution is
static public int height=720;
static public int width=height/9*16;
Should I be using normalized coordinates [-1,1] or just ordinary coordinates [-whatever,whatever] so that I can use floats instead of doubles. If I make a vec4 that is say 2 in any direction then it is off the screen. But could I make my coordinates range half of width for x and half of height for y but so that they would be still on the screen? Say y could be 360,-360 and y could be 640,-640 and still be on the screen?
Upvotes: 0
Views: 528
Reputation: 43369
Up until recently GPUs only supported single- or half-precision floating-point in the programmable pipeline. In fact, for many years there was some disagreement over how many bits single-precision floating-point even had. D3D9 only required 24-bit single-precision in the pixel shader stage and AMD/ATi hardware followed that requirement pretty much until they rolled out D3D10 class GPUs (now desktop vendors all agree that single-precision is 32-bit).
float[] orthographic = {1.0f,0.0f, 0.0f,0.0f,
0.0f,1.0f, 0.0f,0.0f,
0.0f,0.0f,-2.0f,5.0f,
0.0f,0.0f, 0.0f,1.0f };
dmat4
.This extension (GL_ARB_gpu_shader_fp64
) introduces the necessary function to set a double-precision 4x4 matrix uniform:
glUniformMatrix4dv (...)
Incidentally, there is a different extension (GL_ARB_vertex_attrib_64bit
) necessary to use double-precision vertex attributes.
Now, since you are using Java, your actual function name and the parameters you pass will be a little bit different, but the point is you need a GPU that supports FP64 to even do this. And there is very little real-world benefit to this, Java teaches some bad habits sadly; not all of floating-point's problems can be solved by doubling the precision.
Upvotes: 3