1 #include "GLvideo_tradtex.h"
7 namespace GLVideoRenderer
9 #define BUFFER_OFFSET(i) ((char *)NULL + (i))
23 void TradTex::deleteTextures()
25 if(glIsTexture(textures
.y
)) glDeleteTextures(1, &(textures
.y
));
26 if(glIsTexture(textures
.u
)) glDeleteTextures(1, &(textures
.u
));
27 if(glIsTexture(textures
.v
)) glDeleteTextures(1, &(textures
.v
));
30 void TradTex::createTextures(VideoData
*video_data
)
33 glGenTextures(3, (GLuint
*)&textures
);
35 if (video_data
->isPlanar
) {
36 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.u
);
37 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, video_data
->glInternalFormat
,
38 video_data
->Cwidth
, video_data
->Cheight
, 0,
39 video_data
->glFormat
, video_data
->glType
, NULL
);
40 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
,
41 video_data
->glMinMaxFilter
);
42 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
,
43 video_data
->glMinMaxFilter
);
45 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.v
);
46 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, video_data
->glInternalFormat
,
47 video_data
->Cwidth
, video_data
->Cheight
, 0,
48 video_data
->glFormat
, video_data
->glType
, NULL
);
49 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
,
50 video_data
->glMinMaxFilter
);
51 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
,
52 video_data
->glMinMaxFilter
);
54 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, 0);
57 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.y
);
58 glTexImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, video_data
->glInternalFormat
,
59 video_data
->glYTextureWidth
, video_data
->Yheight
, 0,
60 video_data
->glFormat
, video_data
->glType
, NULL
);
61 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MAG_FILTER
,
62 video_data
->glMinMaxFilter
);
63 glTexParameteri(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
,
64 video_data
->glMinMaxFilter
);
66 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, 0);
69 void TradTex::uploadTextures(VideoData
*video_data
)
71 if (video_data
->isPlanar
) {
72 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.u
);
73 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, 0, 0, video_data
->Cwidth
,
74 video_data
->Cheight
, video_data
->glFormat
,
75 video_data
->glType
, video_data
->Udata
);
76 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.v
);
77 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, 0, 0, video_data
->Cwidth
,
78 video_data
->Cheight
, video_data
->glFormat
,
79 video_data
->glType
, video_data
->Vdata
);
80 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, 0);
82 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.y
);
83 glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB
, 0, 0, 0,
84 video_data
->glYTextureWidth
, video_data
->Yheight
,
85 video_data
->glFormat
, video_data
->glType
, video_data
->Ydata
);
86 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, 0);
89 void TradTex::renderVideo(VideoData
*video_data
, GLuint shader_prog
)
91 glClear(GL_COLOR_BUFFER_BIT
);
93 glUseProgramObjectARB(shader_prog
);
95 if (video_data
->isPlanar
) {
96 glActiveTexture(GL_TEXTURE1
);
97 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.u
);
98 i
= glGetUniformLocationARB(shader_prog
, "Utex");
99 glUniform1iARB(i
, 1); /* Bind Ytex to texture unit 1 */
101 glActiveTexture(GL_TEXTURE2
);
102 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.v
);
103 i
= glGetUniformLocationARB(shader_prog
, "Vtex");
104 glUniform1iARB(i
, 2); /* Bind Ytex to texture unit 2 */
107 glActiveTexture(GL_TEXTURE0
);
108 glBindTexture(GL_TEXTURE_RECTANGLE_ARB
, textures
.y
);
109 i
= glGetUniformLocationARB(shader_prog
, "Ytex");
110 glUniform1iARB(i
, 0); /* Bind Ytex to texture unit 0 */
112 /* NB, texture coordinates are relative to the texture data, (0,0)
113 * is the first texture pixel uploaded, since we use two different
114 * coordinate systems, the texture appears to be upside down */
116 glTexCoord2i(0, video_data
->Yheight
);
117 glColor3f(1., 0., 0.);
119 glTexCoord2i(video_data
->glYTextureWidth
, video_data
->Yheight
);
120 glColor3f(0., 1., 0.);
121 glVertex2i(video_data
->Ywidth
, 0);
122 glTexCoord2i(video_data
->glYTextureWidth
, 0);
123 glColor3f(0., 0., 1.);
124 glVertex2i(video_data
->Ywidth
, video_data
->Yheight
);
126 glColor3f(0., 0., 0.);
127 glVertex2i(0, video_data
->Yheight
);
129 glUseProgramObjectARB(0);