1919std::shared_ptr<Texture> Plane::NullTextureObj;
2020
2121Plane::Plane (const std::shared_ptr<Texture>& t)
22- : RenderableObject(4 , 4 ), texture_id_(0 ), texture_(t) {}
22+ : RenderableObject(6 , 4 ), texture_id_(0 ), texture_(t) {}
2323
2424bool Plane::FillVertexBuffer (GLfloat* pBuffer) {
2525 if (texture_ == nullptr || !texture_->isDirty ()) {
@@ -30,33 +30,53 @@ bool Plane::FillVertexBuffer(GLfloat* pBuffer) {
3030 glBindTexture (GL_TEXTURE_2D, texture_id_);
3131 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3232 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
33- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
34- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
33+ // Clamp to edge for ES/core profile compatibility
34+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
35+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3536
36- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, texture_->width (),
37- texture_->height (), 0 , texture_->texture_format (),
38- GL_UNSIGNED_BYTE, texture_->data ());
37+ // Prefer base internal formats for ES/core compatibility and match channels
38+ GLenum fmt = texture_->texture_format ();
39+ GLint internal_fmt = (fmt == GL_RGBA) ? GL_RGBA : GL_RGB;
40+ glTexImage2D (GL_TEXTURE_2D, 0 , internal_fmt, texture_->width (),
41+ texture_->height (), 0 , fmt, GL_UNSIGNED_BYTE,
42+ texture_->data ());
3943
4044 glBindTexture (GL_TEXTURE_2D, 0 );
4145
4246 texture_->removeDirty ();
4347
44- pBuffer[0 ] = -1 .0f ;
45- pBuffer[1 ] = -1 .0f ;
46- pBuffer[2 ] = 0 .0f ;
47- pBuffer[3 ] = 0 .0f ;
48- pBuffer[4 ] = 1 .0f ;
49- pBuffer[5 ] = -1 .0f ;
50- pBuffer[6 ] = 1 .0f ;
51- pBuffer[7 ] = 0 .0f ;
52- pBuffer[8 ] = 1 .0f ;
53- pBuffer[9 ] = 1 .0f ;
54- pBuffer[10 ] = 1 .0f ;
55- pBuffer[11 ] = 1 .0f ;
56- pBuffer[12 ] = -1 .0f ;
57- pBuffer[13 ] = 1 .0f ;
58- pBuffer[14 ] = 0 .0f ;
59- pBuffer[15 ] = 1 .0f ;
48+ // Two CCW triangles forming a full-screen quad
49+ // Triangle 0: BL, BR, TR
50+ pBuffer[0 ] = -1 .0f ; // BL.x
51+ pBuffer[1 ] = -1 .0f ; // BL.y
52+ pBuffer[2 ] = 0 .0f ; // BL.u
53+ pBuffer[3 ] = 0 .0f ; // BL.v
54+
55+ pBuffer[4 ] = 1 .0f ; // BR.x
56+ pBuffer[5 ] = -1 .0f ; // BR.y
57+ pBuffer[6 ] = 1 .0f ; // BR.u
58+ pBuffer[7 ] = 0 .0f ; // BR.v
59+
60+ pBuffer[8 ] = 1 .0f ; // TR.x
61+ pBuffer[9 ] = 1 .0f ; // TR.y
62+ pBuffer[10 ] = 1 .0f ; // TR.u
63+ pBuffer[11 ] = 1 .0f ; // TR.v
64+
65+ // Triangle 1: BL, TR, TL
66+ pBuffer[12 ] = -1 .0f ; // BL.x
67+ pBuffer[13 ] = -1 .0f ; // BL.y
68+ pBuffer[14 ] = 0 .0f ; // BL.u
69+ pBuffer[15 ] = 0 .0f ; // BL.v
70+
71+ pBuffer[16 ] = 1 .0f ; // TR.x
72+ pBuffer[17 ] = 1 .0f ; // TR.y
73+ pBuffer[18 ] = 1 .0f ; // TR.u
74+ pBuffer[19 ] = 1 .0f ; // TR.v
75+
76+ pBuffer[20 ] = -1 .0f ; // TL.x
77+ pBuffer[21 ] = 1 .0f ; // TL.y
78+ pBuffer[22 ] = 0 .0f ; // TL.u
79+ pBuffer[23 ] = 1 .0f ; // TL.v
6080
6181 return true ;
6282}
@@ -82,12 +102,14 @@ void Plane::Draw(void) {
82102 glBindTexture (GL_TEXTURE_2D, texture_id_);
83103 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
84104 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
85- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER );
86- glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER );
105+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
106+ glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
87107
88- glTexImage2D (GL_TEXTURE_2D, 0 , GL_RGBA8, texture_->width (),
89- texture_->height (), 0 , texture_->texture_format (),
90- GL_UNSIGNED_BYTE, texture_->data ());
108+ GLenum fmt = texture_->texture_format ();
109+ GLint internal_fmt = (fmt == GL_RGBA) ? GL_RGBA : GL_RGB;
110+ glTexImage2D (GL_TEXTURE_2D, 0 , internal_fmt, texture_->width (),
111+ texture_->height (), 0 , fmt, GL_UNSIGNED_BYTE,
112+ texture_->data ());
91113
92114 glBindTexture (GL_TEXTURE_2D, 0 );
93115
@@ -104,6 +126,26 @@ void Plane::Draw(void) {
104126
105127 glActiveTexture (GL_TEXTURE0);
106128 glBindTexture (GL_TEXTURE_2D, texture_id_);
129+ // Avoid culling artifacts on some platforms by temporarily disabling
130+ // face culling while drawing the screen-aligned quad.
131+ GLboolean cull_enabled = glIsEnabled (GL_CULL_FACE);
132+ if (cull_enabled) {
133+ glDisable (GL_CULL_FACE);
134+ }
107135 RenderableObject::Draw ();
136+ if (cull_enabled) {
137+ glEnable (GL_CULL_FACE);
138+ }
108139 glBindTexture (GL_TEXTURE_2D, 0 );
109140}
141+
142+ void Plane::SetupExtraUniforms (void ) {
143+ // Ensure sampler uses texture unit 0
144+ if (shader_program_) {
145+ shader_program_->setUniformValue (" u_texture" , 0 );
146+ // Backward compatibility: if shader still uses 'texture' as uniform name
147+ // (older shader), try to set it too.
148+ shader_program_->setUniformValue (" texture" , 0 );
149+ }
150+ }
151+
0 commit comments