OPENGL: Allow backends to draw textures clipped
This commit is contained in:
parent
7b36b56925
commit
b60c99ce98
7 changed files with 41 additions and 11 deletions
|
@ -30,7 +30,7 @@ CLUT8LookUpPipeline::CLUT8LookUpPipeline()
|
|||
: ShaderPipeline(ShaderMan.query(ShaderManager::kCLUT8LookUp)), _paletteTexture(nullptr) {
|
||||
}
|
||||
|
||||
void CLUT8LookUpPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
|
||||
void CLUT8LookUpPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
|
||||
// Set the palette texture.
|
||||
GL_CALL(glActiveTexture(GL_TEXTURE1));
|
||||
if (_paletteTexture) {
|
||||
|
@ -38,7 +38,7 @@ void CLUT8LookUpPipeline::drawTexture(const GLTexture &texture, const GLfloat *c
|
|||
}
|
||||
|
||||
GL_CALL(glActiveTexture(GL_TEXTURE0));
|
||||
ShaderPipeline::drawTexture(texture, coordinates);
|
||||
ShaderPipeline::drawTexture(texture, coordinates, texcoords);
|
||||
}
|
||||
#endif // !USE_FORCED_GLES
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
void setPaletteTexture(const GLTexture *paletteTexture) { _paletteTexture = paletteTexture; }
|
||||
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates);
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords);
|
||||
|
||||
private:
|
||||
const GLTexture *_paletteTexture;
|
||||
|
|
|
@ -45,10 +45,10 @@ void FixedPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
|||
GL_CALL(glColor4f(r, g, b, a));
|
||||
}
|
||||
|
||||
void FixedPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
|
||||
void FixedPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
|
||||
texture.bind();
|
||||
|
||||
GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texture.getTexCoords()));
|
||||
GL_CALL(glTexCoordPointer(2, GL_FLOAT, 0, texcoords));
|
||||
GL_CALL(glVertexPointer(2, GL_FLOAT, 0, coordinates));
|
||||
GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class FixedPipeline : public Pipeline {
|
|||
public:
|
||||
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
|
||||
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates);
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords);
|
||||
|
||||
virtual void setProjectionMatrix(const GLfloat *projectionMatrix);
|
||||
|
||||
|
|
|
@ -79,7 +79,11 @@ public:
|
|||
* @param texture Texture to use for drawing.
|
||||
* @param coordinates x1, y1, x2, y2 coordinates where to draw the texture.
|
||||
*/
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates) = 0;
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) = 0;
|
||||
|
||||
void drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
|
||||
drawTexture(texture, coordinates, texture.getTexCoords());
|
||||
}
|
||||
|
||||
void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h) {
|
||||
const GLfloat coordinates[4*2] = {
|
||||
|
@ -88,7 +92,33 @@ public:
|
|||
x, y + h,
|
||||
x + w, y + h
|
||||
};
|
||||
drawTexture(texture, coordinates);
|
||||
drawTexture(texture, coordinates, texture.getTexCoords());
|
||||
}
|
||||
|
||||
void drawTexture(const GLTexture &texture, GLfloat x, GLfloat y, GLfloat w, GLfloat h, const Common::Rect &clip) {
|
||||
const GLfloat coordinates[4*2] = {
|
||||
x, y,
|
||||
x + w, y,
|
||||
x, y + h,
|
||||
x + w, y + h
|
||||
};
|
||||
|
||||
const uint tw = texture.getWidth(),
|
||||
th = texture.getHeight();
|
||||
|
||||
if (tw == 0 || th == 0) {
|
||||
// Nothing to display
|
||||
return;
|
||||
}
|
||||
|
||||
const GLfloat texcoords[4*2] = {
|
||||
(float)clip.left / tw, (float)clip.top / th,
|
||||
(float)clip.right / tw, (float)clip.top / th,
|
||||
(float)clip.left / tw, (float)clip.bottom / th,
|
||||
(float)clip.right / tw, (float)clip.bottom / th
|
||||
};
|
||||
|
||||
drawTexture(texture, coordinates, texcoords);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,10 +77,10 @@ void ShaderPipeline::setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a) {
|
|||
}
|
||||
}
|
||||
|
||||
void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates) {
|
||||
void ShaderPipeline::drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords) {
|
||||
texture.bind();
|
||||
|
||||
GL_CALL(glVertexAttribPointer(_texCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texture.getTexCoords()));
|
||||
GL_CALL(glVertexAttribPointer(_texCoordAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, texcoords));
|
||||
GL_CALL(glVertexAttribPointer(_vertexAttribLocation, 2, GL_FLOAT, GL_FALSE, 0, coordinates));
|
||||
GL_CALL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
virtual void setColor(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
|
||||
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates);
|
||||
virtual void drawTexture(const GLTexture &texture, const GLfloat *coordinates, const GLfloat *texcoords);
|
||||
|
||||
virtual void setProjectionMatrix(const GLfloat *projectionMatrix);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue