Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add GFX context cleanups and C-types.

  • Loading branch information...
commit 7507ce24f809126275063b037a173f23f84ad6be 1 parent 3283014
@voidcycles authored
View
2  resources/shaders/blit-vs.glsl
@@ -7,6 +7,6 @@ varying vec2 vTexCoord;
void main()
{
vTexCoord = vec2(TexCoord);
- gl_Position = gl_ModelViewProjectionMatrix * vec4(Position.x, Position.y, 0.0, 1.0);
+ gl_Position = vec4(Position.x, Position.y, 0.0, 1.0) * 2.0 - 1.0;
}
View
92 source/framework/types.h
@@ -31,6 +31,98 @@
// ============================================================================================== //
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// ============================================================================================== //
+
+#if (defined(VD_TARGET_WINDOWS) && defined(_MSC_VER))
+
+// ============================================================================================== //
+
+typedef signed __int8 vd_flag;
+typedef signed __int8 vd_i8;
+typedef unsigned __int8 vd_u8;
+typedef signed __int16 vd_i16;
+typedef unsigned __int16 vd_u16;
+typedef signed __int32 vd_i32;
+typedef unsigned __int32 vd_u32;
+typedef signed __int64 vd_i64;
+typedef unsigned __int64 vd_u64;
+typedef unsigned __int16 vd_f16;
+typedef float vd_f32;
+typedef double vd_f64;
+typedef wchar_t vd_utf8;
+typedef size_t vd_size;
+typedef vd_u32 vd_tag;
+typedef intptr_t vd_address;
+typedef void* vd_ptr;
+
+// ============================================================================================== //
+
+#else
+
+// ============================================================================================== //
+
+#include <stdint.h>
+
+typedef int8_t vd_flag;
+typedef int8_t vd_i8;
+typedef uint8_t vd_u8;
+typedef int16_t vd_i16;
+typedef uint16_t vd_u16;
+typedef int32_t vd_i32;
+typedef uint32_t vd_u32;
+typedef int64_t vd_i64;
+typedef uint64_t vd_u64;
+typedef uint16_t vd_f16;
+typedef float vd_f32;
+typedef double vd_f64;
+typedef wchar_t vd_utf8;
+typedef size_t vd_size;
+typedef vd_u32 vd_tag;
+typedef intptr_t vd_address;
+typedef void* vd_ptr;
+
+#endif
+
+// ============================================================================================== //
+
+typedef vd_u32 vd_code;
+typedef vd_u32 vd_status;
+typedef vd_u64 vd_uid[2];
+
+// ============================================================================================== //
+
+#if defined(VD_USE_DOUBLE_PRECISION)
+typedef vd_i64 vd_int;
+typedef vd_f64 vd_real;
+#ifdef VD_USE_SINGLE_PRECISION
+#undef VD_USE_SINGLE_PRECISION
+#endif
+#elif defined(VD_USE_SINGLE_PRECISION)
+typedef vd_i32 vd_int;
+typedef vd_f32 vd_real;
+#else
+#define VD_USE_SINGLE_PRECISION 1
+typedef vd_i32 vd_int;
+typedef vd_f32 vd_real;
+
+// ============================================================================================== //
+#warning "No numeric precision flag defined! Using single precision floating-point for numeric values!"
+// ============================================================================================== //
+
+#endif
+
+// ============================================================================================== //
+
+#ifdef __cplusplus
+}
+#endif
+
+// ============================================================================================== //
+
VD_NAMESPACE_BEGIN();
// ============================================================================================== //
View
7 source/graphics/gl/context.cpp
@@ -1636,7 +1636,6 @@ Context::Submit(
const Geometry::Data& data = geo->GetData();
vdGlobalAssertMsg(glGetError() == GL_NO_ERROR, "OpenGL error prior to render geometry.");
-
vd::u32 attrib = Geometry::AttributeSlot::ToInteger(Geometry::AttributeSlot::Index);
if(data.Buffers[attrib] < VD_U32_MAX)
{
@@ -1727,9 +1726,9 @@ Context::Attach(
Geometry* geo,
Shader* shader)
{
- for(vd::u32 i = Graphics::Geometry::AttributeSlot::StartIndex; i < Graphics::Geometry::AttributeSlot::Count; i++)
+ for(vd::u32 i = Geometry::AttributeSlot::StartIndex; i < Geometry::AttributeSlot::Count; i++)
{
- Graphics::Geometry::AttributeSlot::Value attrib = Graphics::Geometry::AttributeSlot::FromInteger(i);
+ Geometry::AttributeSlot::Value attrib = Graphics::Geometry::AttributeSlot::FromInteger(i);
vd::u32 buffer = geo->GetBuffer(attrib);
if(buffer < VD_U32_MAX)
{
@@ -1750,7 +1749,7 @@ Context::Detach(
Geometry* geo,
Shader* shader)
{
- for(vd::u32 i = Graphics::Geometry::AttributeSlot::StartIndex; i < Graphics::Geometry::AttributeSlot::Count; i++)
+ for(vd::u32 i = Geometry::AttributeSlot::StartIndex; i < Geometry::AttributeSlot::Count; i++)
{
Graphics::Geometry::AttributeSlot::Value attrib = Graphics::Geometry::AttributeSlot::FromInteger(i);
vd::u32 buffer = geo->GetBuffer(attrib);
View
152 source/interface/trackball.cpp
@@ -29,6 +29,158 @@
// ============================================================================================== //
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// ============================================================================================== //
+
+static const float kTol = 0.001;
+static const float kRad2Deg = 180. / 3.1415927;
+static const float kDeg2Rad = 3.1415927 / 180.;
+
+float gRadiusTrackball;
+float gStartPtTrackball[3];
+float gEndPtTrackball[3];
+long gXCenterTrackball = 0, gYCenterTrackball = 0;
+
+// ============================================================================================== //
+
+void vdTrackballStart(
+ long x, long y,
+ long originX, long originY,
+ long width, long height)
+{
+ float xxyy;
+ float nx, ny;
+
+ nx = width;
+ ny = height;
+
+ if (nx > ny)
+ gRadiusTrackball = ny * 0.5;
+ else
+ gRadiusTrackball = nx * 0.5;
+
+ gXCenterTrackball = originX + width * 0.5;
+ gYCenterTrackball = originY + height * 0.5;
+
+ gStartPtTrackball[0] = x - gXCenterTrackball;
+ gStartPtTrackball[1] = y - gYCenterTrackball;
+
+ xxyy = gStartPtTrackball [0] * gStartPtTrackball[0] + gStartPtTrackball [1] * gStartPtTrackball [1];
+ if (xxyy > gRadiusTrackball * gRadiusTrackball)
+ {
+ gStartPtTrackball[2] = 0.;
+ }
+ else
+ {
+ gStartPtTrackball[2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy);
+ }
+}
+
+void vdTrackballRollTo(
+ long x, long y, float rot [4])
+{
+ float xxyy;
+ float cosAng, sinAng;
+ float ls, le, lr;
+
+ gEndPtTrackball[0] = x - gXCenterTrackball;
+ gEndPtTrackball[1] = y - gYCenterTrackball;
+
+ if (fabs (gEndPtTrackball [0] - gStartPtTrackball [0]) < kTol && fabs (gEndPtTrackball [1] - gStartPtTrackball [1]) < kTol)
+ return;
+
+ xxyy = gEndPtTrackball [0] * gEndPtTrackball [0] + gEndPtTrackball [1] * gEndPtTrackball [1];
+
+ if (xxyy > gRadiusTrackball * gRadiusTrackball)
+ {
+ gEndPtTrackball [2] = 0.;
+ }
+ else
+ {
+ gEndPtTrackball[ 2] = sqrt (gRadiusTrackball * gRadiusTrackball - xxyy);
+ }
+
+ rot[1] = gStartPtTrackball[1] * gEndPtTrackball[2] - gStartPtTrackball[2] * gEndPtTrackball[1];
+ rot[2] = -gStartPtTrackball[0] * gEndPtTrackball[2] + gStartPtTrackball[2] * gEndPtTrackball[0];
+ rot[3] = gStartPtTrackball[0] * gEndPtTrackball[1] - gStartPtTrackball[1] * gEndPtTrackball[0];
+
+ cosAng = gStartPtTrackball[0] * gEndPtTrackball[0] + gStartPtTrackball[1] * gEndPtTrackball[1] + gStartPtTrackball[2] * gEndPtTrackball[2]; // (s . e)
+ ls = sqrt(gStartPtTrackball[0] * gStartPtTrackball[0] + gStartPtTrackball[1] * gStartPtTrackball[1] + gStartPtTrackball[2] * gStartPtTrackball[2]);
+ ls = 1. / ls; // 1 / ||s||
+ le = sqrt(gEndPtTrackball[0] * gEndPtTrackball[0] + gEndPtTrackball[1] * gEndPtTrackball[1] + gEndPtTrackball[2] * gEndPtTrackball[2]);
+ le = 1. / le; // 1 / ||e||
+ cosAng = cosAng * ls * le;
+
+ sinAng = lr = sqrt(rot[1] * rot[1] + rot[2] * rot[2] + rot[3] * rot[3]);
+
+ sinAng = sinAng * ls * le;
+ rot[0] = (float) atan2 (sinAng, cosAng) * kRad2Deg;
+
+ // Normalize the rotation axis.
+ lr = 1.0 / lr;
+ rot[1] *= lr;
+ rot[2] *= lr;
+ rot[3] *= lr;
+}
+
+static
+void ConvertAxisToQuaternion(
+ float *A, float *q)
+{
+ float ang2;
+ float sinAng2;
+
+ ang2 = A[0] * kDeg2Rad * 0.5;
+ sinAng2 = sin(ang2);
+ q[0] = A[1] * sinAng2;
+ q[1] = A[2] * sinAng2;
+ q[2] = A[3] * sinAng2;
+ q[3] = cos(ang2);
+}
+
+void vdTrackballAddTo(
+ float * dA, float * A)
+{
+ float q0[4], q1[4], q2[4];
+ float theta2, sinTheta2;
+
+ ConvertAxisToQuaternion(A, q0);
+ ConvertAxisToQuaternion(dA, q1);
+
+ // q2 = q1 + q0;
+ q2[0] = q1[1]*q0[2] - q1[2]*q0[1] + q1[3]*q0[0] + q1[0]*q0[3];
+ q2[1] = q1[2]*q0[0] - q1[0]*q0[2] + q1[3]*q0[1] + q1[1]*q0[3];
+ q2[2] = q1[0]*q0[1] - q1[1]*q0[0] + q1[3]*q0[2] + q1[2]*q0[3];
+ q2[3] = q1[3]*q0[3] - q1[0]*q0[0] - q1[1]*q0[1] - q1[2]*q0[2];
+
+ if (fabs(fabs(q2[3] - 1.)) < 1.0e-7) {
+ // Identity rotation.
+ A[0] = 0.0f;
+ A[1] = 1.0f;
+ A[2] = A[3] = 0.0f;
+ return;
+ }
+
+ theta2 = (float) acos (q2[3]);
+ sinTheta2 = (float) (1.0 / sin ((double) theta2));
+
+ A[0] = theta2 * 2.0f * kRad2Deg;
+ A[1] = q2[0] * sinTheta2;
+ A[2] = q2[1] * sinTheta2;
+ A[3] = q2[2] * sinTheta2;
+}
+
+// ============================================================================================== //
+
+#ifdef __cplusplus
+}
+#endif
+
+// ============================================================================================== //
+
VD_INTERFACE_NAMESPACE_BEGIN();
// ============================================================================================== //
View
17 source/interface/trackball.h
@@ -30,6 +30,23 @@
#include "interface/interface.h"
#include "interface/controls.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// called with the start position and the window origin + size
+void vdTrackballStart(long x, long y, long originX, long originY, long width, long height);
+
+// calculated rotation based on current mouse position
+void vdTrackballRollTo(long x, long y, float rot [4]); // rot is output rotation angle
+
+// add a GL rotation (dA) to an existing GL rotation (A)
+void vdTrackballAddTo(float * dA, float * A);
+
+#ifdef __cplusplus
+}
+#endif
+
// ============================================================================================== //
VD_INTERFACE_NAMESPACE_BEGIN();
Please sign in to comment.
Something went wrong with that request. Please try again.